Various updates.

This commit is contained in:
Julien Fontanet 2013-03-28 16:09:18 +01:00
parent 50647fd9b7
commit 4d608c5e7a
6 changed files with 228 additions and 47 deletions

View File

@ -449,9 +449,10 @@ final class Application extends Base
return -32602; // Invalid params. return -32602; // Invalid params.
} }
$di = $this->_di; $di = $this->_di;
$mgr_vms = $di->get('vms');
$vm = $di->get('vms')->first(array('uuid' => $params[0]), false); $vm = $mgr_vms->first(array('uuid' => $params[0]), false);
if (!$vm) if (!$vm)
{ {
return array(0, 'invalid VM reference'); return array(0, 'invalid VM reference');
@ -459,8 +460,11 @@ final class Application extends Base
$mgr_guest_metrics = $di->get('vms_guest_metrics'); $mgr_guest_metrics = $di->get('vms_guest_metrics');
$mgr_hosts = $di->get('hosts'); $mgr_hosts = $di->get('hosts');
$mgr_messages = $di->get('messages');
$mgr_metrics = $di->get('vms_metrics'); $mgr_metrics = $di->get('vms_metrics');
$mgr_networks = $di->get('networks');
$mgr_vbds = $di->get('vbds'); $mgr_vbds = $di->get('vbds');
$mgr_vdis = $di->get('vdis');
$mgr_vifs = $di->get('vifs'); $mgr_vifs = $di->get('vifs');
$mgr_srs = $di->get('srs'); $mgr_srs = $di->get('srs');
@ -479,34 +483,87 @@ final class Application extends Base
$total_memory = $metrics->memory_actual; $total_memory = $metrics->memory_actual;
} }
$messages = array();
foreach ($mgr_messages->get(array('obj_uuid' => $vm->uuid)) as $message)
{
$messages[] = array(
'body' => $message->body,
'subject' => $message->name,
'time' => $message->timestamp['timestamp'],
);
}
$networks = $guest_metrics $networks = $guest_metrics
? $guest_metrics->networks ? $guest_metrics->networks
: null; : null;
$start_time = (0 === $metrics->start_time['timestamp'])
? null
: $metrics->start_time['timestamp'];
$os_version = $guest_metrics $os_version = $guest_metrics
? $guest_metrics->os_version ? $guest_metrics->os_version
: null; : null;
$preferred_host = ('OpaqueRef:NULL' !== $vm->affinity)
? $vm->affinity
: null;
$pv_drivers_up_to_date = $guest_metrics $pv_drivers_up_to_date = $guest_metrics
? $guest_metrics->PV_drivers_up_to_date ? $guest_metrics->PV_drivers_up_to_date
: false; : false;
$vbds = array(); $snapshots = array();
foreach ($vm->VBDs as $vbd_ref) foreach ($vm->snapshots as $snapshot_ref)
{ {
$vbd = $mgr_vbds->first($vbd_ref); $snapshot = $mgr_vms->first($snapshot_ref);
$vbds[] = $vbd->getProperties(); $origin = $mgr_vms->first($snapshot->snapshot_of);
$snapshots[] = array(
'name' => $snapshot->name_label,
'origin_name' => $origin->name_label,
'origin_uuid' => $origin->uuid,
'time' => $snapshot->snapshot_time['timestamp'],
'uuid' => $snapshot->uuid,
'uuid' => $snapshot->uuid,
);
} }
$start_time = (0 === $metrics->start_time['timestamp'])
? null
: $metrics->start_time['timestamp'];
$vbds = array();
// foreach ($vm->VBDs as $vbd_ref)
// {
// $vbd = $mgr_vbds->first($vbd_ref);
// var_dump($vbd->getProperties());
// $vdi = $mgr_vdis->first($vbd->VDI);
// $sr = $mgr_srs->first($vbd->SR);
// $vbds[] = array(
// 'description' => $vbd->name_description,
// 'name' => $vbd->name_label,
// 'path' => '/dev/hda1', //@todo
// 'priority' => 0, //@todo
// 'read_only' => $vdi->read_only,
// 'size' => $vdi->virtual_size,
// 'SR_name' => $sr->name_label,
// 'SR_uuid' => $sr->uuid,
// 'uuid' => $vbd->uuid,
// );
// }
$vifs = array(); $vifs = array();
foreach ($vm->VIFs as $vif_ref) foreach ($vm->VIFs as $vif_ref)
{ {
$vif = $mgr_vifs->first($vif_ref); $vif = $mgr_vifs->first($vif_ref);
$vifs[] = $vif->getProperties(); $network = $mgr_networks->first($vif->network);
$vifs[] = array(
'currently_attached' => $vif->currently_attached,
'ip' => $networks ? array_pop($networks) : null, // @todo
'MAC' => $vif->MAC,
'network_name' => $network->name_label,
'network_uuid' => $network->uuid,
'uuid' => $vif->uuid,
);
} }
$entry = array( $entry = array(
@ -516,12 +573,15 @@ final class Application extends Base
'HVM_boot_params' => $vm->HVM_boot_params, 'HVM_boot_params' => $vm->HVM_boot_params,
'memory_dynamic_max' => $vm->memory_dynamic_max, 'memory_dynamic_max' => $vm->memory_dynamic_max,
'memory_dynamic_min' => $vm->memory_dynamic_min, 'memory_dynamic_min' => $vm->memory_dynamic_min,
'messages' => $messages,
'name_description' => $vm->name_description, 'name_description' => $vm->name_description,
'name_label' => $vm->name_label, 'name_label' => $vm->name_label,
'networks' => $networks, 'networks' => $networks,
'os_version' => $os_version, 'os_version' => $os_version,
'power_state' => $vm->power_state, 'power_state' => $vm->power_state,
'preferred_host' => $preferred_host,
'PV_drivers_up_to_date' => $pv_drivers_up_to_date, 'PV_drivers_up_to_date' => $pv_drivers_up_to_date,
'snapshots' => $snapshots,
'start_time' => $start_time, 'start_time' => $start_time,
'tags' => $vm->tags, 'tags' => $vm->tags,
'total_memory' => $total_memory, 'total_memory' => $total_memory,
@ -533,6 +593,8 @@ final class Application extends Base
'VIFs' => $vifs, 'VIFs' => $vifs,
); );
var_dump($entry);
$c->respond($id, $entry); $c->respond($id, $entry);
} }
@ -741,9 +803,11 @@ final class Application extends Base
isset($objects['sr']) isset($objects['sr'])
and $this->_di->get('srs')->batchImport($objects['sr']); and $this->_di->get('srs')->batchImport($objects['sr']);
isset($objects['vbd']) isset($objects['vbd'])
and $this->_di->get('vbds')->batchImport($objects['vbds']); and $this->_di->get('vbds')->batchImport($objects['vbd']);
isset($objects['vdi'])
and $this->_di->get('vdis')->batchImport($objects['vdi']);
isset($objects['vif']) isset($objects['vif'])
and $this->_di->get('vifs')->batchImport($objects['vifs']); and $this->_di->get('vifs')->batchImport($objects['vif']);
isset($objects['vm']) isset($objects['vm'])
and $this->_di->get('vms')->batchImport($objects['vm']); and $this->_di->get('vms')->batchImport($objects['vm']);
isset($objects['vm_guest_metrics']) isset($objects['vm_guest_metrics'])
@ -782,6 +846,7 @@ final class Application extends Base
'pool' => 'pools', 'pool' => 'pools',
'SR' => 'srs', 'SR' => 'srs',
'VBD' => 'vbds', 'VBD' => 'vbds',
'VDI' => 'vdis',
'VIF' => 'vifs', 'VIF' => 'vifs',
'VM' => 'vms', 'VM' => 'vms',
'VM_guest_metrics' => 'vms_guest_metrics', 'VM_guest_metrics' => 'vms_guest_metrics',

View File

@ -35,7 +35,7 @@ Message::init(array(
'id', 'id',
'uuid', 'uuid',
'timestamp', 'timestamp' => true,
'name', 'name',
'body', 'body',
'priority', 'priority',

67
lib/Bean/VDI.php Normal file
View File

@ -0,0 +1,67 @@
<?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 VDI extends BeanAbstract
{
protected static $_fields;
}
VDI::init(array(
'id',
'uuid',
'SR',
'VBDs' => true,
'allow_caching',
'allowed_operations' => true,
'crash_dumps' => true,
'current_operations' => true,
'is_a_snapshot',
'location',
'managed',
'metadata_latest',
'metadata_of_pool',
'missing',
'name_description',
'name_label',
'on_boot',
'other_config' => true,
'parent',
'physical_utilisation',
'read_only',
'sharable',
'sm_config' => true,
'snapshot_of',
'snapshot_time' => true,
'snapshots' => true,
'storage_lock',
'tags' => true,
'type',
'virtual_size',
'xenstore_data' => true,
));

View File

@ -81,7 +81,7 @@ VM::init(array(
'snapshot_info', 'snapshot_info',
'snapshot_metadata', 'snapshot_metadata',
'snapshot_of', 'snapshot_of',
'snapshot_time', 'snapshot_time' => true,
'snapshots' => true, 'snapshots' => true,
'transportable_snapshot_id', 'transportable_snapshot_id',
@ -92,35 +92,35 @@ VM::init(array(
// Various. // Various.
'consoles' => true, 'consoles' => true,
// 'affinity', 'affinity',
// 'appliance', 'appliance',
// 'blobs', 'blobs',
// 'blocked_operations', 'blocked_operations',
// 'children' => true, // ??? 'children' => true, // ???
// 'crash_dumps' => true, 'crash_dumps' => true,
// 'ha_always_run', // @deprecated 'ha_always_run', // @deprecated
// 'ha_restart_priority', 'ha_restart_priority',
// 'HVM_boot_policy', 'HVM_boot_policy',
// 'HVM_shadow_multiplier', 'HVM_shadow_multiplier',
// 'is_snapshot_from_vmpp', 'is_snapshot_from_vmpp',
// 'last_boot_CPU_flags', 'last_boot_CPU_flags',
// 'last_booted_record', 'last_booted_record',
// 'order', 'order',
// 'other_config', 'other_config',
// 'parent', // ??? 'parent', // ???
// 'PCI_bus', // @deprecated 'PCI_bus', // @deprecated
// 'protection_policy', 'protection_policy',
// 'PV_args', 'PV_args',
// 'PV_bootloader', 'PV_bootloader',
// 'PV_bootloader_args', 'PV_bootloader_args',
// 'PV_kernel', 'PV_kernel',
// 'PV_legacy_args', 'PV_legacy_args',
// 'PV_ramdisk', 'PV_ramdisk',
// 'recommendations', 'recommendations',
// 'start_delay', 'start_delay',
// 'suspend_SR', 'suspend_SR',
// 'suspend_VDI', 'suspend_VDI',
// 'user_version', 'user_version',
// 'version', 'version',
// 'xenstore_data', 'xenstore_data',
)); ));

View File

@ -122,6 +122,11 @@ final class DI extends Base
->string('id')->unique() ->string('id')->unique()
; ;
}); });
$database->createTable('vdis', function ($table) {
$table
->string('id')->unique()
;
});
$database->createTable('vifs', function ($table) { $database->createTable('vifs', function ($table) {
$table $table
->string('id')->unique() ->string('id')->unique()
@ -230,6 +235,11 @@ final class DI extends Base
return new \Manager\VBDs($this->get('database.cache')); return new \Manager\VBDs($this->get('database.cache'));
} }
private function _init_vdis()
{
return new \Manager\VDIs($this->get('database.cache'));
}
private function _init_vifs() private function _init_vifs()
{ {
return new \Manager\VIFs($this->get('database.cache')); return new \Manager\VIFs($this->get('database.cache'));

39
lib/Manager/VDIs.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 VDIs extends XCPAbstract
{
/**
*
*/
function __construct(\Rekodi\Manager $manager)
{
parent::__construct($manager, 'vdis', '\Bean\VDI');
}
}