Various updates.

This commit is contained in:
Julien Fontanet 2013-03-27 18:02:29 +01:00
parent 5f26cd7342
commit 50647fd9b7
8 changed files with 313 additions and 3 deletions

View File

@ -438,6 +438,104 @@ final class Application extends Base
$c->respond($id, true);
}
/**
*
*/
function api_vm_get($id, array $params, Client $c)
{
// Checks parameter.
if (!isset($params[0]))
{
return -32602; // Invalid params.
}
$di = $this->_di;
$vm = $di->get('vms')->first(array('uuid' => $params[0]), false);
if (!$vm)
{
return array(0, 'invalid VM reference');
}
$mgr_guest_metrics = $di->get('vms_guest_metrics');
$mgr_hosts = $di->get('hosts');
$mgr_metrics = $di->get('vms_metrics');
$mgr_vbds = $di->get('vbds');
$mgr_vifs = $di->get('vifs');
$mgr_srs = $di->get('srs');
$guest_metrics = $mgr_guest_metrics->first($vm->guest_metrics, false);
$host = $mgr_hosts->first($vm->resident_on, false);
$metrics = $mgr_metrics->first($vm->metrics);
if ($guest_metrics && ($_ = $guest_metrics->memory))
{
$used_memory = $_['used'];
$total_memory = $_['total'];
}
else
{
$used_memory = null;
$total_memory = $metrics->memory_actual;
}
$networks = $guest_metrics
? $guest_metrics->networks
: null;
$start_time = (0 === $metrics->start_time['timestamp'])
? null
: $metrics->start_time['timestamp'];
$os_version = $guest_metrics
? $guest_metrics->os_version
: null;
$pv_drivers_up_to_date = $guest_metrics
? $guest_metrics->PV_drivers_up_to_date
: false;
$vbds = array();
foreach ($vm->VBDs as $vbd_ref)
{
$vbd = $mgr_vbds->first($vbd_ref);
$vbds[] = $vbd->getProperties();
}
$vifs = array();
foreach ($vm->VIFs as $vif_ref)
{
$vif = $mgr_vifs->first($vif_ref);
$vifs[] = $vif->getProperties();
}
$entry = array(
'bios' => $vm->bios_strings,
'host_name' => $host ? $host->name_label : null,
'host_uuid' => $host ? $host->uuid : null,
'HVM_boot_params' => $vm->HVM_boot_params,
'memory_dynamic_max' => $vm->memory_dynamic_max,
'memory_dynamic_min' => $vm->memory_dynamic_min,
'name_description' => $vm->name_description,
'name_label' => $vm->name_label,
'networks' => $networks,
'os_version' => $os_version,
'power_state' => $vm->power_state,
'PV_drivers_up_to_date' => $pv_drivers_up_to_date,
'start_time' => $start_time,
'tags' => $vm->tags,
'total_memory' => $total_memory,
'used_memory' => $used_memory,
'uuid' => $vm->uuid,
'VBDs' => $vbds,
'VCPUs_number' => $metrics->VCPUs_number,
'VCPUs_utilisation' => $metrics->VCPUs_utilisation,
'VIFs' => $vifs,
);
$c->respond($id, $entry);
}
/**
*
*/
@ -636,10 +734,14 @@ final class Application extends Base
isset($objects['message'])
and $this->_di->get('messages')->batchImport($objects['message']);
isset($objects['network'])
and $this->_di->get('networks')->batchImport($objects['network']);
isset($objects['pool'])
and $this->_di->get('pools')->batchImport($objects['pool']);
isset($objects['sr'])
and $this->_di->get('srs')->batchImport($objects['sr']);
isset($objects['vbd'])
and $this->_di->get('vbds')->batchImport($objects['vbds']);
isset($objects['vif'])
and $this->_di->get('vifs')->batchImport($objects['vifs']);
isset($objects['vm'])
@ -676,8 +778,10 @@ final class Application extends Base
$classes = array(
'host' => 'hosts',
'message' => 'messages',
'network' => 'networks',
'pool' => 'pools',
'SR' => 'srs',
'VBD' => 'vbds',
'VIF' => 'vifs',
'VM' => 'vms',
'VM_guest_metrics' => 'vms_guest_metrics',

50
lib/Bean/Network.php Normal file
View File

@ -0,0 +1,50 @@
<?php
/**
* This file is a part of Xen Orchestra Server.
*
* Xen Orchestra Server is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* Xen Orchestra Server is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xen Orchestra Server. If not, see
* <http://www.gnu.org/licenses/>.
*
* @author Julien Fontanet <julien.fontanet@vates.fr>
* @license http://www.gnu.org/licenses/gpl-3.0-standalone.html GPLv3
*
* @package Xen Orchestra Server
*/
namespace Bean;
/**
*
*/
final class Network extends BeanAbstract
{
protected static $_fields;
}
Network::init(array(
'id',
'uuid',
'allowed_operations' => true,
'blobs' => true,
'bridge',
'current_operations' => true,
'default_locking_mode',
'MTU',
'name_description',
'name_label',
'other_config' => true,
'PIFs' => true,
'tags' => true,
'VIFs' => true,
));

59
lib/Bean/VBD.php Normal file
View File

@ -0,0 +1,59 @@
<?php
/**
* This file is a part of Xen Orchestra Server.
*
* Xen Orchestra Server is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* Xen Orchestra Server is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xen Orchestra Server. If not, see
* <http://www.gnu.org/licenses/>.
*
* @author Julien Fontanet <julien.fontanet@vates.fr>
* @license http://www.gnu.org/licenses/gpl-3.0-standalone.html GPLv3
*
* @package Xen Orchestra Server
*/
namespace Bean;
/**
*
*/
final class VBD extends BeanAbstract
{
protected static $_fields;
}
VBD::init(array(
'id',
'uuid',
'allowed_operations' => true,
'bootable',
'current_operations' => true,
'currently_attached',
'device',
'empty',
'metrics',
'mode',
'other_config' => true,
'qos_algorithm_params' => true,
'qos_algorithm_type',
'qos_supported_algorithms' => true,
'runtime_properties' => true,
'status_code',
'status_detail',
'storage_lock',
'type',
'unpluggable',
'userdevice',
'VDI',
'VM',
));

View File

@ -55,5 +55,4 @@ VIF::init(array(
'runtime_properties' => true,
'status_code',
'status_detail',
));

View File

@ -49,6 +49,8 @@ VM::init(array(
// Technical characteristics.
'attached_PCIs' => true,
'bios_strings' => true,
'HVM_boot_params' => true,
'platform',
'VBDs' => true, // Virtual Block Devices.
'VCPUs_at_startup',
@ -92,14 +94,12 @@ VM::init(array(
// 'affinity',
// 'appliance',
// 'bios_strings',
// 'blobs',
// 'blocked_operations',
// 'children' => true, // ???
// 'crash_dumps' => true,
// 'ha_always_run', // @deprecated
// 'ha_restart_priority',
// 'HVM_boot_params',
// 'HVM_boot_policy',
// 'HVM_shadow_multiplier',
// 'is_snapshot_from_vmpp',

View File

@ -101,6 +101,11 @@ final class DI extends Base
->string('id')->unique()
;
});
$database->createTable('networks', function ($table) {
$table
->string('id')->unique()
;
});
$database->createTable('pools', function ($table) {
$table
->string('id')->unique()
@ -112,6 +117,11 @@ final class DI extends Base
->boolean('shared')
;
});
$database->createTable('vbds', function ($table) {
$table
->string('id')->unique()
;
});
$database->createTable('vifs', function ($table) {
$table
->string('id')->unique()
@ -190,6 +200,11 @@ final class DI extends Base
return new \Manager\Messages($this->get('database.cache'));
}
private function _init_networks()
{
return new \Manager\Networks($this->get('database.cache'));
}
private function _init_pools()
{
return new \Manager\Pools($this->get('database.cache'));
@ -210,6 +225,11 @@ final class DI extends Base
return new \Manager\Users($this->get('database'));
}
private function _init_vbds()
{
return new \Manager\VBDs($this->get('database.cache'));
}
private function _init_vifs()
{
return new \Manager\VIFs($this->get('database.cache'));

39
lib/Manager/Networks.php Normal file
View File

@ -0,0 +1,39 @@
<?php
/**
* This file is a part of Xen Orchestra Server.
*
* Xen Orchestra Server is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* Xen Orchestra Server is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xen Orchestra Server. If not, see
* <http://www.gnu.org/licenses/>.
*
* @author Julien Fontanet <julien.fontanet@vates.fr>
* @license http://www.gnu.org/licenses/gpl-3.0-standalone.html GPLv3
*
* @package Xen Orchestra Server
*/
namespace Manager;
/**
*
*/
final class Networks extends XCPAbstract
{
/**
*
*/
function __construct(\Rekodi\Manager $manager)
{
parent::__construct($manager, 'networks', '\Bean\Network');
}
}

39
lib/Manager/VBDs.php Normal file
View File

@ -0,0 +1,39 @@
<?php
/**
* This file is a part of Xen Orchestra Server.
*
* Xen Orchestra Server is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* Xen Orchestra Server is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xen Orchestra Server. If not, see
* <http://www.gnu.org/licenses/>.
*
* @author Julien Fontanet <julien.fontanet@vates.fr>
* @license http://www.gnu.org/licenses/gpl-3.0-standalone.html GPLv3
*
* @package Xen Orchestra Server
*/
namespace Manager;
/**
*
*/
final class VBDs extends XCPAbstract
{
/**
*
*/
function __construct(\Rekodi\Manager $manager)
{
parent::__construct($manager, 'vbds', '\Bean\VBD');
}
}