Various updates.

This commit is contained in:
Julien Fontanet 2013-03-25 18:47:29 +01:00
parent 25d00f2fcb
commit ce1f58956a
18 changed files with 730 additions and 302 deletions

8
composer.lock generated
View File

@ -188,12 +188,12 @@
"source": {
"type": "git",
"url": "https://github.com/vatesfr/rekodi.git",
"reference": "a0122f7958e9375626d265497b1bfef62c552915"
"reference": "2ed168af2f75ad359fa78d57c6372f5d50b032f0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/vatesfr/rekodi/zipball/a0122f7958e9375626d265497b1bfef62c552915",
"reference": "a0122f7958e9375626d265497b1bfef62c552915",
"url": "https://api.github.com/repos/vatesfr/rekodi/zipball/2ed168af2f75ad359fa78d57c6372f5d50b032f0",
"reference": "2ed168af2f75ad359fa78d57c6372f5d50b032f0",
"shasum": ""
},
"require": {
@ -222,7 +222,7 @@
"keywords": [
"event"
],
"time": "2013-03-22 15:41:39"
"time": "2013-03-25 17:30:48"
}
],
"packages-dev": [

View File

@ -505,88 +505,30 @@ final class Application extends Base
foreach ($events as $event)
{
$_ = array_keys($event);
if (!$keys)
{
$keys = $_;
var_export($keys); echo PHP_EOL;
}
elseif ($_ !== $keys)
{
$keys = array_intersect($keys, $_);
var_export($keys); echo PHP_EOL;
}
$class = $event['class'];
$ref = $event['ref'];
$snapshot = $event['snapshot']; // Not present in the documentation.
echo "$class - $ref\n";
$objects[$class][$ref] = $snapshot;
echo "Event: $class ($ref)\n";
}
isset($objects['pool'])
and $this->updateXenPools($objects['pool']);
isset($objects['host'])
and $this->updateXenHosts($objects['host']);
isset($objects['sr'])
and $this->_di->get('srs')->batchImport($objects['sr']);
isset($objects['vif'])
and $this->_di->get('vifs')->batchImport($objects['vifs']);
isset($objects['vm'])
and $this->updateXenVms($objects['vm']);
and $this->_di->get('vms')->batchImport($objects['vm']);
isset($objects['vm_guest_metrics'])
and $this->_di->get('vms_guest_metrics')->batchImport($objects['vm_guest_metrics']);
isset($objects['vm_metrics'])
and $this->_di->get('vms_metrics')->batchImport($objects['vm_metrics']);
// Requeue this request.
return true;
}
/**
*
*/
function updateXenPools(array $pools)
{
foreach ($pools as $ref => $pool)
{
$this->_update($this->_xenPools[$ref], $pool);
}
}
/**
*
*/
function updateXenHosts(array $hosts)
{
foreach ($hosts as $ref => $host)
{
$this->_update($this->_xenHosts[$ref], $host);
}
}
/**
*
*/
function updateXenVms(array $vms)
{
$manager = $this->_di->get('vms');
foreach ($vms as $id => $properties)
{
$properties['id'] = $id;
$vm = $manager->get($id, false);
if (!$vm)
{
$manager->create($properties);
echo "new VM: $id\n";
}
else
{
$vm->set($properties, true);
$manager->save($vm);
echo "updated VM: $id\n";
}
}
}
/**
*
*/
@ -606,14 +548,28 @@ final class Application extends Base
//--------------------------------------
// map(XCP class: manager)
$classes = array(
'SR' => 'srs',
'VIF' => 'vifs',
'VM' => 'vms',
'VM_guest_metrics' => 'vms_guest_metrics',
'VM_metrics' => 'vms_metrics',
);
foreach ($config['xcp'] as $_)
{
$xcp = new XCP($loop, $_['url'], $_['username'], $_['password']);
$xcp->queue(
'VM.get_all_records',
null,
array($this, 'updateXenVms')
);
foreach ($classes as $class => $manager)
{
$xcp->queue(
$class.'.get_all_records',
null,
array($this->_di->get($manager), 'batchImport')
);
}
$xcp->queue(
'event.register',
array(array('host', 'pool', 'vm'))

99
lib/Bean/BeanAbstract.php Normal file
View File

@ -0,0 +1,99 @@
<?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;
/**
* @todo Migrate check() and checkAndSet() to \Rekodi\Bean.
*/
abstract class BeanAbstract extends \Rekodi\Bean
{
/**
* This function is not necessary but allow us to dynamically
* initialize our beans.
*/
static final function init($fields)
{
foreach ($fields as $key => $value)
{
if (is_bool($value))
{
static::$_fields[$key] = $value;
}
else
{
static::$_fields[$value] = false;
}
}
}
/**
*
*/
static function check($field, &$value)
{
return isset(static::$_fields[$field]);
}
/**
*
*/
function __get($name)
{
$value = parent::__get($name);
if (static::$_fields[$name])
{
return json_decode($value, true);
}
return $value;
}
/**
*
*/
function __set($name, $value)
{
if (is_array($value)
|| is_object($value))
{
$value = json_encode($value);
}
return parent::__set($name, $value);
}
/**
*
*/
final function checkAndSet($field, $value)
{
if (!self::check($field, $value))
{
return false;
}
$this->__set($field, $value);
return true;
}
}

36
lib/Bean/SR.php Normal file
View File

@ -0,0 +1,36 @@
<?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 SR extends BeanAbstract
{
protected static $_fields;
}
SR::init(array(
'id',
));

View File

@ -27,21 +27,12 @@ namespace Bean;
/**
*
*/
final class Token extends \Rekodi\Bean
final class Token extends BeanAbstract
{
/**
* This function is not necessary but allow us to dynamically
* initialize our bean.
*/
static function init()
{
self::$_fields = array_flip(array(
'id',
'expiration',
'user_id',
));
}
protected static $_fields;
}
Token::init();
Token::init(array(
'id',
'expiration',
'user_id',
));

View File

@ -25,9 +25,9 @@
namespace Bean;
/**
* @todo Migrate check() and checkAndSet() to \Rekodi\Bean.
*
*/
final class User extends \Rekodi\Bean
final class User extends BeanAbstract
{
/**
*
@ -83,20 +83,6 @@ final class User extends \Rekodi\Bean
: false;
}
/**
* This function is not necessary but allow us to dynamically
* initialize our bean.
*/
static function init()
{
self::$_fields = array_flip(array(
'id',
'name',
'password',
'permission',
));
}
/**
*
*/
@ -104,8 +90,6 @@ final class User extends \Rekodi\Bean
{
switch ($field)
{
case 'id':
return true;
case 'name':
return (
is_string($value)
@ -124,23 +108,13 @@ final class User extends \Rekodi\Bean
return (false !== $value);
}
return false;
}
/**
*
*/
function checkAndSet($field, $value)
{
if (!self::check($field, $value))
{
return false;
}
$this->__set($field, $value);
return true;
return parent::check($field, $value);
}
protected static $_fields;
}
User::init();
User::init(array(
'id',
'name',
'password',
));

36
lib/Bean/VIF.php Normal file
View File

@ -0,0 +1,36 @@
<?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 VIF extends BeanAbstract
{
protected static $_fields;
}
VIF::init(array(
'id',
));

View File

@ -27,147 +27,99 @@ namespace Bean;
/**
*
*/
final class VM extends \Rekodi\Bean
final class VM extends BeanAbstract
{
/**
* This function is not necessary but allow us to dynamically
* initialize our bean.
*/
static function init()
{
self::$_fields = array_flip(array(
// Identifiers.
'id',
'name_label',
'resident_on', // The host this VM is currently resident on.
'domarch', // Domain architecture if available, null otherwise.
'domid', // Domain ID.
// Description.
'name_description',
'is_a_template',
'is_a_snapshot',
'is_control_domain',
'tags',
// Technical characteristics.
'attached_PCIs',
'platform',
'VBDs', // Virtual Block Devices.
'VCPUs_at_startup',
'VCPUs_max',
'VCPUs_params',
'VGPUs',
'VIFs', // Virtual Network Interface (string[]). @todo
//'VTPMs', // Virtual Trust Platform Modules ???
// Event-related actions.
'actions_after_crash',
'actions_after_reboot',
'actions_after_shutdown',
// Current state.
'guest_metrics',
'memory_dynamic_max',
'memory_dynamic_min',
'memory_overhead',
'memory_static_max',
'memory_static_min',
'memory_target',
'metrics',
'power_state',
// Snapshot-related info.
'shutdown_delay',
'snapshot_info',
'snapshot_metadata',
'snapshot_of',
'snapshot_time',
'snapshots',
'transportable_snapshot_id',
// Operations.
'allowed_operations',
'current_operations',
// Various.
'consoles',
// 'affinity',
// 'appliance',
// 'bios_strings',
// 'blobs',
// 'blocked_operations',
// 'children', // ???
// 'crash_dumps',
// 'ha_always_run',
// 'ha_restart_priority',
// 'HVM_boot_params',
// 'HVM_boot_policy',
// 'HVM_shadow_multiplier',
// 'is_snapshot_from_vmpp',
// 'last_boot_CPU_flags',
// 'last_booted_record',
// 'order',
// 'other_config',
// 'parent', // ???
// 'PCI_bus',
// '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',
));
}
function __get($name)
{
static $json_encoded;
if (!$json_encoded)
{
$json_encoded = array_flip(array(
'VBDs',
'VCPUs_params',
'VGPUs',
'VIFs',
'allowed_operations',
'consoles',
'crash_dumps',
'current_operations',
'platform',
'snapshot_info',
'tags',
));
}
$value = parent::__get($name);
if (isset($json_encoded[$name]))
{
return json_decode($value, true);
}
return $value;
}
function __set($name, $value)
{
if (is_array($value)
|| is_object($value))
{
$value = json_encode($value);
}
return parent::__set($name, $value);
}
protected static $_fields;
}
VM::init();
VM::init(array(
// Identifiers.
'id',
'name_label',
'resident_on', // The host this VM is currently resident on.
'domarch', // Domain architecture if available, null otherwise.
'domid', // Domain ID.
// Description.
'name_description',
'is_a_template',
'is_a_snapshot',
'is_control_domain',
'tags' => true,
// Technical characteristics.
'attached_PCIs' => true,
'platform',
'VBDs' => true, // Virtual Block Devices.
'VCPUs_at_startup',
'VCPUs_max',
'VCPUs_params' => true,
'VGPUs' => true,
'VIFs' => true, // Virtual Network Interface.
//'VTPMs' => true, // Virtual Trust Platform Modules ???
// Event-related actions.
'actions_after_crash',
'actions_after_reboot',
'actions_after_shutdown',
// Current state.
'guest_metrics',
'memory_dynamic_max',
'memory_dynamic_min',
'memory_overhead',
'memory_static_max',
//'memory_static_min', // @deprecated
'memory_target',
'metrics',
'power_state',
// Snapshot-related info.
'shutdown_delay',
'snapshot_info',
'snapshot_metadata',
'snapshot_of',
'snapshot_time',
'snapshots' => true,
'transportable_snapshot_id',
// Operations.
'allowed_operations' => true,
'current_operations',
// Various.
'consoles' => true,
// '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',
// '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

@ -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 Bean;
/**
*
*/
final class VMGuestMetrics extends BeanAbstract
{
protected static $_fields;
}
VMGuestMetrics::init(array(
'id',
'memory' => true,
'networks' => true,
));

40
lib/Bean/VMMetrics.php Normal file
View File

@ -0,0 +1,40 @@
<?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 VMMetrics extends BeanAbstract
{
protected static $_fields;
}
VMMetrics::init(array(
'id',
'memory_actual',
'VCPUs_utilisation' => true,
'start_time',
));

View File

@ -87,6 +87,42 @@ final class DI extends Base
return JSONDatabase::factory($config['database.file']);
}
private function _init_database_cache()
{
$database = new \Rekodi\Manager\Memory;
$database->createTable('srs', function ($table) {
$table
->string('id')->unique()
->boolean('shared')
;
});
$database->createTable('vifs', function ($table) {
$table
->string('id')->unique()
;
});
$database->createTable('vms', function ($table) {
$table
->string('id')->unique()
->string('power_state')
->boolean('is_control_domain')
;
});
$database->createTable('vms_metrics', function ($table) {
$table
->string('id')->unique()
;
});
$database->createTable('vms_guest_metrics', function ($table) {
$table
->string('id')->unique()
;
});
return $database;
}
private function _init_errorLogger()
{
return new ErrorLogger($this->get('logger'));
@ -126,29 +162,41 @@ final class DI extends Base
return new Loop;
}
//--------------------------------------
// Managers
private function _init_srs()
{
return new \Manager\SRs($this->get('database.cache'));
}
private function _init_tokens()
{
return new \Manager\Tokens(
$this->get('database')
);
return new \Manager\Tokens($this->get('database'));
}
private function _init_users()
{
return new \Manager\Users(
$this->get('database')
);
return new \Manager\Users($this->get('database'));
}
private function _init_vifs()
{
return new \Manager\VIFs($this->get('database.cache'));
}
private function _init_vms()
{
$database = new \Rekodi\Manager\Memory;
$database->createTable('vms', function ($table) {
$table
->string('id')->unique()
;
});
return new \Manager\VMs($this->get('database.cache'));
}
return new \Manager\VMs($database);
private function _init_vmsGuestMetrics()
{
return new \Manager\VMsGuestMetrics($this->get('database.cache'));
}
private function _init_vmsMetrics()
{
return new \Manager\VMsMetrics($this->get('database.cache'));
}
}

View File

@ -32,11 +32,11 @@ abstract class ManagerAbstract
/**
*
*/
protected function __construct(\Rekodi\Manager $manager, $table, $bean)
protected function __construct(\Rekodi\Manager $database, $table, $bean)
{
$this->_manager = $manager;
$this->_table = $table;
$this->_bean = $bean;
$this->_database = $database;
$this->_table = $table;
$this->_bean = $bean;
}
/**
@ -53,30 +53,49 @@ abstract class ManagerAbstract
$class = $this->_bean;
$bean = new $class($properties, true);
$new_props = $this->_manager->create(
$new_props = $this->_database->create(
$this->_table,
array($bean->getProperties())
);
if (count($new_props) !== 1)
{
trigger_error(
'unexpected number of created '.$this->_table.' ('.$n.')',
E_USER_ERROR
);
}
$bean->set($new_props[0]);
$bean->markAsClean();
return $bean;
}
/**
*
*/
function count(array $filter = null)
{
return $this->_database->count(
$this->_table,
$filter
);
}
/**
*
*/
function createOrUpdate(array $properties)
{
$bean = $this->get($properties['id'], false);
if (!$bean)
{
return $this->create($properties);
}
$bean->set($properties, true);
$this->save($bean);
return $bean;
}
/**
*
*/
function delete($id)
{
$n = $this->_manager->delete($this->_table, array('id' => $id));
$n = $this->_database->delete($this->_table, array('id' => $id));
if (1 !== $n)
{
@ -92,7 +111,7 @@ abstract class ManagerAbstract
*/
function getBy($field, $value, $default = 'fatal error')
{
$beans = $this->_manager->get(
$beans = $this->_database->get(
$this->_table,
array($field => $value)
);
@ -135,7 +154,7 @@ abstract class ManagerAbstract
*/
function getArray($filter = null, $fields = null)
{
return $this->_manager->get(
return $this->_database->get(
$this->_table,
$filter,
$fields
@ -154,7 +173,7 @@ abstract class ManagerAbstract
return;
}
$n = $this->_manager->update(
$n = $this->_database->update(
$this->_table,
array('id' => $bean->id),
$bean->getDirty()
@ -172,15 +191,15 @@ abstract class ManagerAbstract
/**
* @var \Rekodi\Manager
*/
private $_manager;
protected $_database;
/**
* @var string
*/
private $_table;
protected $_table;
/**
* @var string
*/
private $_bean;
protected $_bean;
}

43
lib/Manager/SRs.php Normal file
View File

@ -0,0 +1,43 @@
<?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 SRs extends XCPAbstract
{
/**
*
*/
function __construct(\Rekodi\Manager $manager)
{
parent::__construct(
$manager,
'srs',
'\Bean\SRs'
);
}
}

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

View File

@ -27,7 +27,7 @@ namespace Manager;
/**
*
*/
final class VMs extends ManagerAbstract
final class VMs extends XCPAbstract
{
/**
*

View File

@ -0,0 +1,43 @@
<?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 VMsGuestMetrics extends XCPAbstract
{
/**
*
*/
function __construct(\Rekodi\Manager $manager)
{
parent::__construct(
$manager,
'vms_guest_metrics',
'\Bean\VMGuestMetrics'
);
}
}

View File

@ -0,0 +1,43 @@
<?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 VMsMetrics extends XCPAbstract
{
/**
*
*/
function __construct(\Rekodi\Manager $manager)
{
parent::__construct(
$manager,
'vms_metrics',
'\Bean\VMMetrics'
);
}
}

View File

@ -0,0 +1,70 @@
<?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;
/**
*
*/
abstract class XCPAbstract extends ManagerAbstract
{
/**
*
*/
function batchImport(array $objects)
{
foreach ($objects as $id => $properties)
{
$properties['id'] = $id;
unset($properties['uuid']);
$n = $this->_database->update(
$this->_table,
array('id' => $id),
$properties
);
if (1 === $n)
{
echo $this->_table.': updated ('.$id.')', PHP_EOL;
}
elseif (0 === $n)
{
$this->_database->create(
$this->_table,
array($properties)
);
echo $this->_table.': new ('.$id.')', PHP_EOL;
}
else
{
trigger_error(
'unexpected number of updated '.$this->_table.' ('.$n.')',
E_USER_ERROR
);
}
}
}
}