Various updates.

This commit is contained in:
Julien Fontanet 2013-03-26 19:02:18 +01:00
parent 2c0913637b
commit 5f26cd7342
11 changed files with 268 additions and 12 deletions

View File

@ -444,8 +444,69 @@ final class Application extends Base
function api_vm_getAll($id, array $params, Client $c)
{
// @todo Handles parameter.
$di = $this->_di;
$c->respond($id, $this->_di->get('vms')->getArray());
$mgr_guest_metrics = $di->get('vms_guest_metrics');
$mgr_hosts = $di->get('hosts');
$mgr_metrics = $di->get('vms_metrics');
$mgr_vms = $di->get('vms');
$vms = $mgr_vms->get(array(
'is_a_snapshot' => false,
'is_a_template' => false,
'is_control_domain' => false,
));
$entries = array();
foreach ($vms as $vm)
{
$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'];
$entries[] = array(
'host_name' => $host ? $host->name_label : null,
'host_uuid' => $host ? $host->uuid : null,
'name_description' => $vm->name_description,
'name_label' => $vm->name_label,
'networks' => $networks,
'power_state' => $vm->power_state,
'start_time' => $start_time,
'total_memory' => $total_memory,
'used_memory' => $used_memory,
'uuid' => $vm->uuid,
'VBDs' => count($vm->VBDs),
'VCPUs_utilisation' => $metrics->VCPUs_utilisation,
'VIFs' => count($vm->VIFs),
);
// var_export(array(
// 'vm' => $vm->getProperties(),
// 'metrics' => $metrics->getProperties(),
// 'guest_metrics' => $guest_metrics->getProperties(),
// ));
}
$c->respond($id, $entries);
}
/**
@ -486,13 +547,6 @@ final class Application extends Base
}
}
/**
* - Nombre de serveurs connectés.
* - Nombre de running VMs.
* - Total RAM/CPUs allouées aux running VMS.
* - Nombre de SR.
* - Nombre de VMs (ni templates ni snapshots).
*/
$stats = array(
'hosts' => $mgr_vms->count(array(
'is_control_domain' => true,
@ -620,6 +674,7 @@ final class Application extends Base
// map(XCP class: manager)
$classes = array(
'host' => 'hosts',
'message' => 'messages',
'pool' => 'pools',
'SR' => 'srs',

84
lib/Bean/Host.php Normal file
View File

@ -0,0 +1,84 @@
<?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 Host extends BeanAbstract
{
protected static $_fields;
}
Host::init(array(
'id',
'uuid',
'API_version_major',
'API_version_minor',
'API_version_vendor',
'API_version_vendor_implementation' => true,
'PBDs' => true,
'PCIs' => true,
'PGPUs' => true,
'PIFs' => true,
'address',
'allowed_operations' => true,
'bios_strings' => true,
'blobs' => true,
'capabilities' => true,
'chipset_info' => true,
'cpu_configuration' => true,
'cpu_info' => true,
'crash_dump_sr',
'crashdumps' => true,
'current_operations' => true,
'edition',
'enabled',
'external_auth_configuration' => true,
'external_auth_service_name',
'external_auth_type',
'ha_network_peers' => true,
'ha_statefiles' => true,
'host_CPUs' => true,
'hostname',
'license_params' => true,
'license_server' => true,
'local_cache_sr',
'logging' => true,
'memory_overhead',
'metrics',
'name_description',
'name_label',
'other_config' => true,
'patches' => true,
'power_on_config' => true,
'power_on_mode',
'resident_VMs' => true,
'sched_policy',
'software_version' => true,
'supported_bootloaders' => true,
'suspend_image_sr',
'tags' => true,
));

View File

@ -37,7 +37,7 @@ Message::init(array(
'timestamp',
'name',
'message',
'body',
'priority',
'cls', // Not class like in Event !!!

View File

@ -56,7 +56,6 @@ Pool::init(array(
'restrictions' => true,
'suspend_image_SR',
'tags' => true,
'uuid',
'vswitch_controller',
'wlb_enabled',
'wlb_url',

View File

@ -35,5 +35,22 @@ SR::init(array(
'id',
'uuid',
'PBDs' => true,
'VDIs' => true,
'allowed_operations' => true,
'blobs' => true,
'content_type',
'current_operations' => true,
'introduced_by',
'local_cache_enabled',
'name_description',
'name_label',
'other_config' => true,
'physical_size',
'physical_utilisation',
'shared',
'sm_config' => true,
'tags' => true,
'type',
'virtual_allocation',
));

View File

@ -34,4 +34,26 @@ final class VIF extends BeanAbstract
VIF::init(array(
'id',
'uuid',
'MAC',
'MAC_autogenerated',
'MTU',
'VM',
'allowed_operations' => true,
'current_operations' => true,
'currently_attached',
'device',
'ipv4_allowed' => true,
'ipv6_allowed' => true,
'locking_mode',
'metrics',
'network',
'other_config' => true,
'qos_algorithm_params' => true,
'qos_algorithm_type',
'qos_supported_algorithms' => true,
'runtime_properties' => true,
'status_code',
'status_detail',
));

View File

@ -35,6 +35,14 @@ VMGuestMetrics::init(array(
'id',
'uuid',
'PV_drivers_up_to_date',
'PV_drivers_version' => true,
'disks' => true,
'last_updated' => true,
'live',
'memory' => true,
'networks' => true,
'os_version' => true,
'other' => true,
'other_config' => true,
));

View File

@ -35,7 +35,15 @@ VMMetrics::init(array(
'id',
'uuid',
'memory_actual',
'VCPUs_CPU' => true,
'VCPUs_flags' => true,
'VCPUs_number',
'start_time',
'VCPUs_params' => true,
'VCPUs_utilisation' => true,
'install_time' => true,
'last_updated' => true,
'memory_actual',
'other_config' => true,
'start_time' => true,
'state' => true,
));

View File

@ -91,6 +91,11 @@ final class DI extends Base
{
$database = new \Rekodi\Manager\Memory;
$database->createTable('hosts', function ($table) {
$table
->string('id')->unique()
;
});
$database->createTable('messages', function ($table) {
$table
->string('id')->unique()
@ -175,10 +180,16 @@ final class DI extends Base
//--------------------------------------
// Managers
private function _init_hosts()
{
return new \Manager\Hosts($this->get('database.cache'));
}
private function _init_messages()
{
return new \Manager\Messages($this->get('database.cache'));
}
private function _init_pools()
{
return new \Manager\Pools($this->get('database.cache'));

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

View File

@ -34,6 +34,19 @@ abstract class XCPAbstract extends ManagerAbstract
*/
function batchImport(array $objects)
{
// Used for development to print bean's attributes.
// $object = reset($objects);
// ksort($object);
// foreach ($object as $field => $value)
// {
// var_export($field);
// if (is_array($value) || is_object($value))
// {
// echo ' => true';
// }
// echo ",\n";
// }
foreach ($objects as $ref => $properties)
{
$properties['id'] = $ref;