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.
}
$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)
{
return array(0, 'invalid VM reference');
@ -459,8 +460,11 @@ final class Application extends Base
$mgr_guest_metrics = $di->get('vms_guest_metrics');
$mgr_hosts = $di->get('hosts');
$mgr_messages = $di->get('messages');
$mgr_metrics = $di->get('vms_metrics');
$mgr_networks = $di->get('networks');
$mgr_vbds = $di->get('vbds');
$mgr_vdis = $di->get('vdis');
$mgr_vifs = $di->get('vifs');
$mgr_srs = $di->get('srs');
@ -479,34 +483,87 @@ final class Application extends Base
$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
? $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;
$preferred_host = ('OpaqueRef:NULL' !== $vm->affinity)
? $vm->affinity
: null;
$pv_drivers_up_to_date = $guest_metrics
? $guest_metrics->PV_drivers_up_to_date
: false;
$vbds = array();
foreach ($vm->VBDs as $vbd_ref)
$snapshots = array();
foreach ($vm->snapshots as $snapshot_ref)
{
$vbd = $mgr_vbds->first($vbd_ref);
$vbds[] = $vbd->getProperties();
$snapshot = $mgr_vms->first($snapshot_ref);
$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();
foreach ($vm->VIFs as $vif_ref)
{
$vif = $mgr_vifs->first($vif_ref);
$vifs[] = $vif->getProperties();
$vif = $mgr_vifs->first($vif_ref);
$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(
@ -516,12 +573,15 @@ final class Application extends Base
'HVM_boot_params' => $vm->HVM_boot_params,
'memory_dynamic_max' => $vm->memory_dynamic_max,
'memory_dynamic_min' => $vm->memory_dynamic_min,
'messages' => $messages,
'name_description' => $vm->name_description,
'name_label' => $vm->name_label,
'networks' => $networks,
'os_version' => $os_version,
'power_state' => $vm->power_state,
'preferred_host' => $preferred_host,
'PV_drivers_up_to_date' => $pv_drivers_up_to_date,
'snapshots' => $snapshots,
'start_time' => $start_time,
'tags' => $vm->tags,
'total_memory' => $total_memory,
@ -533,6 +593,8 @@ final class Application extends Base
'VIFs' => $vifs,
);
var_dump($entry);
$c->respond($id, $entry);
}
@ -741,9 +803,11 @@ final class Application extends Base
isset($objects['sr'])
and $this->_di->get('srs')->batchImport($objects['sr']);
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'])
and $this->_di->get('vifs')->batchImport($objects['vifs']);
and $this->_di->get('vifs')->batchImport($objects['vif']);
isset($objects['vm'])
and $this->_di->get('vms')->batchImport($objects['vm']);
isset($objects['vm_guest_metrics'])
@ -782,6 +846,7 @@ final class Application extends Base
'pool' => 'pools',
'SR' => 'srs',
'VBD' => 'vbds',
'VDI' => 'vdis',
'VIF' => 'vifs',
'VM' => 'vms',
'VM_guest_metrics' => 'vms_guest_metrics',

View File

@ -35,7 +35,7 @@ Message::init(array(
'id',
'uuid',
'timestamp',
'timestamp' => true,
'name',
'body',
'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_metadata',
'snapshot_of',
'snapshot_time',
'snapshot_time' => true,
'snapshots' => true,
'transportable_snapshot_id',
@ -92,35 +92,35 @@ VM::init(array(
// Various.
'consoles' => true,
// 'affinity',
// 'appliance',
// 'blobs',
// 'blocked_operations',
// 'children' => true, // ???
// 'crash_dumps' => true,
// 'ha_always_run', // @deprecated
// 'ha_restart_priority',
// 'HVM_boot_policy',
// 'HVM_shadow_multiplier',
// 'is_snapshot_from_vmpp',
// 'last_boot_CPU_flags',
// 'last_booted_record',
// 'order',
// 'other_config',
// 'parent', // ???
// 'PCI_bus', // @deprecated
// 'protection_policy',
// 'PV_args',
// 'PV_bootloader',
// 'PV_bootloader_args',
// 'PV_kernel',
// 'PV_legacy_args',
// 'PV_ramdisk',
// 'recommendations',
// 'start_delay',
// 'suspend_SR',
// 'suspend_VDI',
// 'user_version',
// 'version',
// 'xenstore_data',
'affinity',
'appliance',
'blobs',
'blocked_operations',
'children' => true, // ???
'crash_dumps' => true,
'ha_always_run', // @deprecated
'ha_restart_priority',
'HVM_boot_policy',
'HVM_shadow_multiplier',
'is_snapshot_from_vmpp',
'last_boot_CPU_flags',
'last_booted_record',
'order',
'other_config',
'parent', // ???
'PCI_bus', // @deprecated
'protection_policy',
'PV_args',
'PV_bootloader',
'PV_bootloader_args',
'PV_kernel',
'PV_legacy_args',
'PV_ramdisk',
'recommendations',
'start_delay',
'suspend_SR',
'suspend_VDI',
'user_version',
'version',
'xenstore_data',
));

View File

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