Various updates.
This commit is contained in:
parent
25d00f2fcb
commit
ce1f58956a
|
@ -188,12 +188,12 @@
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/vatesfr/rekodi.git",
|
"url": "https://github.com/vatesfr/rekodi.git",
|
||||||
"reference": "a0122f7958e9375626d265497b1bfef62c552915"
|
"reference": "2ed168af2f75ad359fa78d57c6372f5d50b032f0"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/vatesfr/rekodi/zipball/a0122f7958e9375626d265497b1bfef62c552915",
|
"url": "https://api.github.com/repos/vatesfr/rekodi/zipball/2ed168af2f75ad359fa78d57c6372f5d50b032f0",
|
||||||
"reference": "a0122f7958e9375626d265497b1bfef62c552915",
|
"reference": "2ed168af2f75ad359fa78d57c6372f5d50b032f0",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -222,7 +222,7 @@
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"event"
|
"event"
|
||||||
],
|
],
|
||||||
"time": "2013-03-22 15:41:39"
|
"time": "2013-03-25 17:30:48"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
|
|
|
@ -505,88 +505,30 @@ final class Application extends Base
|
||||||
|
|
||||||
foreach ($events as $event)
|
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'];
|
$class = $event['class'];
|
||||||
$ref = $event['ref'];
|
$ref = $event['ref'];
|
||||||
$snapshot = $event['snapshot']; // Not present in the documentation.
|
$snapshot = $event['snapshot']; // Not present in the documentation.
|
||||||
|
|
||||||
echo "$class - $ref\n";
|
|
||||||
|
|
||||||
$objects[$class][$ref] = $snapshot;
|
$objects[$class][$ref] = $snapshot;
|
||||||
|
|
||||||
|
echo "Event: $class ($ref)\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
isset($objects['pool'])
|
isset($objects['sr'])
|
||||||
and $this->updateXenPools($objects['pool']);
|
and $this->_di->get('srs')->batchImport($objects['sr']);
|
||||||
isset($objects['host'])
|
isset($objects['vif'])
|
||||||
and $this->updateXenHosts($objects['host']);
|
and $this->_di->get('vifs')->batchImport($objects['vifs']);
|
||||||
isset($objects['vm'])
|
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.
|
// Requeue this request.
|
||||||
return true;
|
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 $_)
|
foreach ($config['xcp'] as $_)
|
||||||
{
|
{
|
||||||
$xcp = new XCP($loop, $_['url'], $_['username'], $_['password']);
|
$xcp = new XCP($loop, $_['url'], $_['username'], $_['password']);
|
||||||
$xcp->queue(
|
|
||||||
'VM.get_all_records',
|
foreach ($classes as $class => $manager)
|
||||||
null,
|
{
|
||||||
array($this, 'updateXenVms')
|
$xcp->queue(
|
||||||
);
|
$class.'.get_all_records',
|
||||||
|
null,
|
||||||
|
array($this->_di->get($manager), 'batchImport')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$xcp->queue(
|
$xcp->queue(
|
||||||
'event.register',
|
'event.register',
|
||||||
array(array('host', 'pool', 'vm'))
|
array(array('host', 'pool', 'vm'))
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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',
|
||||||
|
));
|
|
@ -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;
|
protected static $_fields;
|
||||||
}
|
}
|
||||||
Token::init();
|
Token::init(array(
|
||||||
|
'id',
|
||||||
|
'expiration',
|
||||||
|
'user_id',
|
||||||
|
));
|
||||||
|
|
|
@ -25,9 +25,9 @@
|
||||||
namespace Bean;
|
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;
|
: 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)
|
switch ($field)
|
||||||
{
|
{
|
||||||
case 'id':
|
|
||||||
return true;
|
|
||||||
case 'name':
|
case 'name':
|
||||||
return (
|
return (
|
||||||
is_string($value)
|
is_string($value)
|
||||||
|
@ -124,23 +108,13 @@ final class User extends \Rekodi\Bean
|
||||||
return (false !== $value);
|
return (false !== $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return parent::check($field, $value);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function checkAndSet($field, $value)
|
|
||||||
{
|
|
||||||
if (!self::check($field, $value))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->__set($field, $value);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static $_fields;
|
protected static $_fields;
|
||||||
}
|
}
|
||||||
User::init();
|
User::init(array(
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'password',
|
||||||
|
));
|
||||||
|
|
|
@ -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',
|
||||||
|
));
|
234
lib/Bean/VM.php
234
lib/Bean/VM.php
|
@ -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;
|
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',
|
||||||
|
));
|
||||||
|
|
|
@ -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,
|
||||||
|
));
|
|
@ -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',
|
||||||
|
));
|
74
lib/DI.php
74
lib/DI.php
|
@ -87,6 +87,42 @@ final class DI extends Base
|
||||||
return JSONDatabase::factory($config['database.file']);
|
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()
|
private function _init_errorLogger()
|
||||||
{
|
{
|
||||||
return new ErrorLogger($this->get('logger'));
|
return new ErrorLogger($this->get('logger'));
|
||||||
|
@ -126,29 +162,41 @@ final class DI extends Base
|
||||||
return new Loop;
|
return new Loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------
|
||||||
|
// Managers
|
||||||
|
|
||||||
|
private function _init_srs()
|
||||||
|
{
|
||||||
|
return new \Manager\SRs($this->get('database.cache'));
|
||||||
|
}
|
||||||
|
|
||||||
private function _init_tokens()
|
private function _init_tokens()
|
||||||
{
|
{
|
||||||
return new \Manager\Tokens(
|
return new \Manager\Tokens($this->get('database'));
|
||||||
$this->get('database')
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _init_users()
|
private function _init_users()
|
||||||
{
|
{
|
||||||
return new \Manager\Users(
|
return new \Manager\Users($this->get('database'));
|
||||||
$this->get('database')
|
}
|
||||||
);
|
|
||||||
|
private function _init_vifs()
|
||||||
|
{
|
||||||
|
return new \Manager\VIFs($this->get('database.cache'));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _init_vms()
|
private function _init_vms()
|
||||||
{
|
{
|
||||||
$database = new \Rekodi\Manager\Memory;
|
return new \Manager\VMs($this->get('database.cache'));
|
||||||
$database->createTable('vms', function ($table) {
|
}
|
||||||
$table
|
|
||||||
->string('id')->unique()
|
|
||||||
;
|
|
||||||
});
|
|
||||||
|
|
||||||
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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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->_database = $database;
|
||||||
$this->_table = $table;
|
$this->_table = $table;
|
||||||
$this->_bean = $bean;
|
$this->_bean = $bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,30 +53,49 @@ abstract class ManagerAbstract
|
||||||
$class = $this->_bean;
|
$class = $this->_bean;
|
||||||
$bean = new $class($properties, true);
|
$bean = new $class($properties, true);
|
||||||
|
|
||||||
$new_props = $this->_manager->create(
|
$new_props = $this->_database->create(
|
||||||
$this->_table,
|
$this->_table,
|
||||||
array($bean->getProperties())
|
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->set($new_props[0]);
|
||||||
$bean->markAsClean();
|
$bean->markAsClean();
|
||||||
return $bean;
|
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)
|
function delete($id)
|
||||||
{
|
{
|
||||||
$n = $this->_manager->delete($this->_table, array('id' => $id));
|
$n = $this->_database->delete($this->_table, array('id' => $id));
|
||||||
|
|
||||||
if (1 !== $n)
|
if (1 !== $n)
|
||||||
{
|
{
|
||||||
|
@ -92,7 +111,7 @@ abstract class ManagerAbstract
|
||||||
*/
|
*/
|
||||||
function getBy($field, $value, $default = 'fatal error')
|
function getBy($field, $value, $default = 'fatal error')
|
||||||
{
|
{
|
||||||
$beans = $this->_manager->get(
|
$beans = $this->_database->get(
|
||||||
$this->_table,
|
$this->_table,
|
||||||
array($field => $value)
|
array($field => $value)
|
||||||
);
|
);
|
||||||
|
@ -135,7 +154,7 @@ abstract class ManagerAbstract
|
||||||
*/
|
*/
|
||||||
function getArray($filter = null, $fields = null)
|
function getArray($filter = null, $fields = null)
|
||||||
{
|
{
|
||||||
return $this->_manager->get(
|
return $this->_database->get(
|
||||||
$this->_table,
|
$this->_table,
|
||||||
$filter,
|
$filter,
|
||||||
$fields
|
$fields
|
||||||
|
@ -154,7 +173,7 @@ abstract class ManagerAbstract
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$n = $this->_manager->update(
|
$n = $this->_database->update(
|
||||||
$this->_table,
|
$this->_table,
|
||||||
array('id' => $bean->id),
|
array('id' => $bean->id),
|
||||||
$bean->getDirty()
|
$bean->getDirty()
|
||||||
|
@ -172,15 +191,15 @@ abstract class ManagerAbstract
|
||||||
/**
|
/**
|
||||||
* @var \Rekodi\Manager
|
* @var \Rekodi\Manager
|
||||||
*/
|
*/
|
||||||
private $_manager;
|
protected $_database;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $_table;
|
protected $_table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $_bean;
|
protected $_bean;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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');
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,7 +27,7 @@ namespace Manager;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
final class VMs extends ManagerAbstract
|
final class VMs extends XCPAbstract
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -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'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue