From 50647fd9b78b49360db97f2e6e4bc2595ca9c458 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Wed, 27 Mar 2013 18:02:29 +0100 Subject: [PATCH] Various updates. --- lib/Application.php | 104 +++++++++++++++++++++++++++++++++++++++ lib/Bean/Network.php | 50 +++++++++++++++++++ lib/Bean/VBD.php | 59 ++++++++++++++++++++++ lib/Bean/VIF.php | 1 - lib/Bean/VM.php | 4 +- lib/DI.php | 20 ++++++++ lib/Manager/Networks.php | 39 +++++++++++++++ lib/Manager/VBDs.php | 39 +++++++++++++++ 8 files changed, 313 insertions(+), 3 deletions(-) create mode 100644 lib/Bean/Network.php create mode 100644 lib/Bean/VBD.php create mode 100644 lib/Manager/Networks.php create mode 100644 lib/Manager/VBDs.php diff --git a/lib/Application.php b/lib/Application.php index 5773425cd..fd355a79c 100644 --- a/lib/Application.php +++ b/lib/Application.php @@ -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', diff --git a/lib/Bean/Network.php b/lib/Bean/Network.php new file mode 100644 index 000000000..ea32a17e7 --- /dev/null +++ b/lib/Bean/Network.php @@ -0,0 +1,50 @@ +. + * + * @author Julien Fontanet + * @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, +)); diff --git a/lib/Bean/VBD.php b/lib/Bean/VBD.php new file mode 100644 index 000000000..231f7bacc --- /dev/null +++ b/lib/Bean/VBD.php @@ -0,0 +1,59 @@ +. + * + * @author Julien Fontanet + * @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', +)); diff --git a/lib/Bean/VIF.php b/lib/Bean/VIF.php index 29c1b10c4..07d229adc 100644 --- a/lib/Bean/VIF.php +++ b/lib/Bean/VIF.php @@ -55,5 +55,4 @@ VIF::init(array( 'runtime_properties' => true, 'status_code', 'status_detail', - )); diff --git a/lib/Bean/VM.php b/lib/Bean/VM.php index 11f8a149c..39ba9c92c 100644 --- a/lib/Bean/VM.php +++ b/lib/Bean/VM.php @@ -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', diff --git a/lib/DI.php b/lib/DI.php index b918ba256..08d730ef4 100644 --- a/lib/DI.php +++ b/lib/DI.php @@ -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')); diff --git a/lib/Manager/Networks.php b/lib/Manager/Networks.php new file mode 100644 index 000000000..8b71444e5 --- /dev/null +++ b/lib/Manager/Networks.php @@ -0,0 +1,39 @@ +. + * + * @author Julien Fontanet + * @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'); + } +} diff --git a/lib/Manager/VBDs.php b/lib/Manager/VBDs.php new file mode 100644 index 000000000..7ca4f2288 --- /dev/null +++ b/lib/Manager/VBDs.php @@ -0,0 +1,39 @@ +. + * + * @author Julien Fontanet + * @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'); + } +}