本文整理汇总了PHP中resource::add方法的典型用法代码示例。如果您正苦于以下问题:PHP resource::add方法的具体用法?PHP resource::add怎么用?PHP resource::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource
的用法示例。
在下文中一共展示了resource::add方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: lockindex
/**
* Lock cache index
*
* @return boolean True on success, false otherwise.
* @since Nooku Server 0.7s
*/
private function lockindex()
{
$looptime = 300;
$data_lock = $this->_db->add($this->_hash.'-index_lock', 1, false, 30);
if ($data_lock === FALSE) {
$lock_counter = 0;
// loop until you find that the lock has been released. that implies that data get from other thread has finished
while ( $data_lock === FALSE ) {
if ( $lock_counter > $looptime ) {
return false;
break;
}
usleep(100);
$data_lock = $this->_db->add($this->_hash.'-index_lock', 1, false, 30);
$lock_counter++;
}
}
return true;
}
示例2: gradientRectangle
/**
* Draw a rectangle filled with a gradient from $color1 to
* $color2.
*
* @param integer $x The left x-coordinate of the rectangle.
* @param integer $y The top y-coordinate of the rectangle.
* @param integer $width The width of the rectangle.
* @param integer $height The height of the rectangle.
* @param string $color The outline color of the rectangle.
* @param string $fill1 The name of the start color for the gradient.
* @param string $fill2 The name of the end color for the gradient.
*/
function gradientRectangle($x, $y, $width, $height, $color = 'black', $fill1 = 'black', $fill2 = 'white')
{
$s = new SWFShape();
if ($color != 'none') {
$color = $this->allocateColor($color);
$s->setLine(1, $color['red'], $color['green'], $color['blue'], $color['alpha']);
}
$fill1 = $this->allocateColor($fill1);
$fill2 = $this->allocateColor($fill2);
$gradient = new SWFGradient();
$gradient->addEntry(0.0, $fill1['red'], $fill1['green'], $fill1['blue'], $fill1['alpha']);
$gradient->addEntry(1.0, $fill2['red'], $fill2['green'], $fill2['blue'], $fill2['alpha']);
$f = $s->addFill($gradient, SWFFILL_LINEAR_GRADIENT);
$f->scaleTo($width / $this->_width);
$f->moveTo($x, $y);
$s->setRightFill($f);
$verts[0] = array('x' => $x, 'y' => $y);
$verts[1] = array('x' => $x + $width, 'y' => $y);
$verts[2] = array('x' => $x + $width, 'y' => $y + $height);
$verts[3] = array('x' => $x, 'y' => $y + $height);
$first_done = false;
foreach ($verts as $vert) {
if (!$first_done) {
$s->movePenTo($vert['x'], $vert['y']);
$first_done = true;
$first_x = $vert['x'];
$first_y = $vert['y'];
}
$s->drawLineTo($vert['x'], $vert['y']);
}
$s->drawLineTo($first_x, $first_y);
return $this->_movie->add($s);
}
示例3: acquireLock
/**
* Acquires a lock on the given $key.
*
* @param string $key
* @param int $waitTime usleep()
* @param int $maxTime seconds
*/
public function acquireLock($key, $waitTime, $maxTime)
{
if (strlen($key) > self::MAX_KEY_LENGTH) {
throw new ezcCacheInvalidKeyException($key, 'Length > ' . self::MAX_KEY_LENGTH . '.');
}
// add() does not replace and returns true on success. $maxTime is
// obeyed by Memcache expiry.
while ($this->memcache->add($key, $key, false, $maxTime) === false) {
// Wait for next check
usleep($waitTime);
}
}
示例4: _getLock
/**
* 对资源加锁
* @param string $key 缓存锁键
* @param int $lockTime 缓存锁失效时间
* @param string $server_key 指定服务器
* @return bool
*/
private function _getLock($key, $lockTime = 3, $server_key = NULL)
{
if (is_null($server_key)) {
$ret = $this->mcd->add($this->_buildKey($key, 'LOCK_CTL'), 1, $lockTime);
} else {
$ret = $this->mcd->addByKey($server_key, $this->_buildKey($key, 'LOCK_CTL'), 1, $lockTime);
}
$this->_checkStats(__FUNCTION__, 0, $native = true);
BaseModelCommon::addStatInfo('mc', 0, 1);
defined('DAGGER_DEBUG') && BaseModelCommon::debug(intval($ret), "mcd_lock_time({$key})({$lockTime})({$server_key})");
return $ret;
}
示例5: add
/**
* add
* @param string $key
* @param string|array|object $value
* @param int $ttl
* @param string $tableName
* @param resource $connectionResource
* @return boolean
*/
public function add($key, $value, $ttl = 0, $tableName = '', $connectionResource = null)
{
if (0 != $ttl) {
$ttl += time();
}
if (true == $connectionResource->add($this->getRealKey($tableName, $key), array("ttl" => $ttl, "value" => $value))) {
return true;
} else {
if ($this->get($key, $tableName, $connectionResource)) {
return false;
} else {
$this->del($key, $tableName, $connectionResource);
return $connectionResource->add($this->getRealKey($tableName, $key), array("ttl" => $ttl, "value" => $value));
}
}
}
示例6: endTag
/**
* Output the end tag
*
*/
public function endTag()
{
$stackelem = array_pop($this->_stack);
if ($stackelem['sent']) {
$this->_endTag();
if (count($this->_stack) == 0 && $this->multipart) {
$this->_stream->rewind();
$len = $this->_stream->length();
$totalCount = count($this->_parts) + 1;
$header = pack('i', $totalCount);
$offset = $totalCount * 2 * 4 + 4;
$header .= pack('ii', $offset, $len);
$offset += $len;
// start/length of parts
foreach ($this->_parts as $bp) {
if (is_resource($bp)) {
rewind($bp);
$stat = fstat($bp);
$len = $stat['size'];
} else {
$len = strlen(bin2hex($bp)) / 2;
}
$header .= pack('ii', $offset, $len);
$offset += $len;
}
// Output
$this->_tempStream->add($header);
$this->_stream->rewind();
$this->_tempStream->add($this->_stream);
foreach ($this->_parts as $bp) {
if (is_resource($bp)) {
rewind($bp);
$this->_tempStream->add($bp);
fclose($bp);
} else {
$this->_tempStream->add($bp);
}
}
$this->_stream->close();
$this->_stream = $this->_tempStream;
}
}
}
示例7: copyCellCollection
/**
* Clone the cell collection
*
* @param PHPExcel_Worksheet $parent The new worksheet
* @return void
*/
public function copyCellCollection(PHPExcel_Worksheet $parent)
{
parent::copyCellCollection($parent);
// Get a new id for the new file name
$baseUnique = $this->_getUniqueID();
$newCachePrefix = substr(md5($baseUnique), 0, 8) . '.';
$cacheList = $this->getCellList();
foreach ($cacheList as $cellID) {
if ($cellID != $this->_currentObjectID) {
$obj = $this->_memcache->get($this->_cachePrefix . $cellID . '.cache');
if ($obj === false) {
// Entry no longer exists in Memcache, so clear it from the cache array
parent::deleteCacheData($cellID);
throw new PHPExcel_Exception('Cell entry ' . $cellID . ' no longer exists in MemCache');
}
if (!$this->_memcache->add($newCachePrefix . $cellID . '.cache', $obj, NULL, $this->_cacheTime)) {
$this->__destruct();
throw new PHPExcel_Exception('Failed to store cell ' . $cellID . ' in MemCache');
}
}
}
$this->_cachePrefix = $newCachePrefix;
}
示例8: create
function create($cu_id, $virtualization_type, $name, $mac, $additional_nics, $cpu, $memory, $disk, $timeout, $vncpassword, $source_image_id = null)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
global $RESOURCE_INFO_TABLE;
global $host_start_from_off_timeout;
global $RootDir;
$this->init($timeout);
global $event;
$vmware_mac_address_space = "00:50:56";
$vtype = new virtualization();
$vtype->get_instance_by_id($virtualization_type);
$virtualization_plugin_name = $vtype->get_plugin_name();
$event->log("create", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class.php", "Trying to create new VM type {$virtualization_type} ({$virtualization_plugin_name}) {$mac}/{$cpu}/{$memory}/{$disk}", "", "", 0, 0, 0);
// here we need to find out if we have a virtualization host providing the type of VMs as requested
// find out the host virtualization type via the plugin name
$vhost_type = new virtualization();
$vhost_type->get_instance_by_type($virtualization_plugin_name);
$event->log("create", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class.php", "Trying to find a virtualization host from type {$vhost_type->type} {$vhost_type->name}", "", "", 0, 0, 0);
// check if resource-pooling is enabled
$cp_conf = new cloudconfig();
$show_resource_pools = $cp_conf->get_value(25);
// resource_pools enabled ?
$vm_provision_delay = $cp_conf->get_value(40);
// delay provisioning of VMs ?
$vm_loadbalance_algorithm = $cp_conf->get_value(41);
// which LB to select ?
// for all in appliance list, find virtualization host appliances
$appliance_tmp = new appliance();
$appliance_id_list = $appliance_tmp->get_all_ids();
$active_appliance_list = array();
$active_appliance_resource_list = array();
foreach ($appliance_id_list as $id_arr) {
foreach ($id_arr as $id) {
$appliance = new appliance();
$appliance->get_instance_by_id($id);
// active ?
if ($appliance->stoptime == 0 || $appliance->resources == 0) {
if ($appliance->virtualization == $vhost_type->id) {
// we have found an active appliance from the right virtualization type
// Now we check that its resource is active and not in error
$cvm_resource = new resource();
$cvm_resource->get_instance_by_id($appliance->resources);
if (strcmp($cvm_resource->state, "active")) {
continue;
}
// here we check if there is still enough space
// to create the new VM -> max_vm setting per resource
$res_hostlimit = new cloudhostlimit();
$res_hostlimit->get_instance_by_resource($appliance->resources);
if (strlen($res_hostlimit->id)) {
if ($res_hostlimit->max_vms >= 0) {
$new_current_vms = $res_hostlimit->current_vms + 1;
if ($new_current_vms > $res_hostlimit->max_vms) {
$event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "Hostlimit max_vm is reached for resource {$appliance->resources}", "", "", 0, 0, $appliance->resources);
continue;
}
}
}
// resource pooling enabled ?
if (strcmp($show_resource_pools, "true")) {
// disabled, add any appliance from the right virtualization type
$active_appliance_list[] .= $id;
$active_appliance_resource_list[] .= $appliance->resources;
//$event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "------- resource pooling is disabled", "", "", 0, 0, 0);
} else {
//$event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "------- resource pooling is enabled $appliance->resources", "", "", 0, 0, 0);
// resource pooling enabled, check to which user group the resource belongs to
$private_resource = new cloudrespool();
$private_resource->get_instance_by_resource($appliance->resources);
// is this resource configured in the resource pools ?
//$event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "------- resource pool id $private_resource->id !", "", "", 0, 0, 0);
if (strlen($private_resource->id)) {
//$event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "------- resource $appliance->resources is in a resource pool", "", "", 0, 0, 0);
// is it hidden ?
if ($private_resource->cg_id >= 0) {
//$event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "------- resource $appliance->resources is also configured in resource pool (not hidden)", "", "", 0, 0, 0);
$cloud_user = new clouduser();
$cloud_user->get_instance_by_id($cu_id);
$cloud_user_group = new cloudusergroup();
$cloud_user_group->get_instance_by_id($cloud_user->cg_id);
//$event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "------- we have found the users group $cloud_user_group->id", "", "", 0, 0, 0);
// does it really belongs to the users group ?
if ($private_resource->cg_id == $cloud_user_group->id) {
// resource belongs to the users group, add appliance to list
//$event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "------- adding appliance $id ", "", "", 0, 0, 0);
$active_appliance_list[] .= $id;
$active_appliance_resource_list[] .= $appliance->resources;
//} else {
// $event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "Appliance $id (resource $appliance->resources) is NOT in dedicated for the users group", "", "", 0, 0, 0);
}
//} else {
// $event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "Appliance $id (resource $appliance->resources) is marked as hidden", "", "", 0, 0, 0);
}
}
}
}
}
}
//.........这里部分代码省略.........
示例9: add
/**
* add
* @param string $key
* @param string|array|object $value
* @param int $ttl
* @param string $tableName
* @param resource $connectionResource
* @return boolean
*/
public function add($key, $value, $ttl = 0, $tableName = '', $connectionResource = null)
{
return $connectionResource->add($this->getRealKey($tableName, $key), $value, $ttl);
}
示例10: getLock
/**
* 对资源加锁
* @param string $key 缓存锁键
* @param int $lockTime 缓存锁失效时间
*/
public function getLock($key, $lockTime = 3)
{
defined('DAGGER_DEBUG') && BaseModelCommon::debug($lockTime, 'mc_lock_time');
return $this->mc->add($key . self::CACHE_LOCK_CTL, 1, false, $lockTime);
}
示例11: resource
// check if resource_id is free
if (!$resource->is_id_free($resource->id)) {
$event->log("get_parameter", $_SERVER['REQUEST_TIME'], 3, "resource-monitor", "Given resource id {$resource->id} is already in use!", "", "", 0, 1, $resource->id);
echo "Given resource id {$resource->id} is already in use!";
exit;
}
$event->log("get_parameter", $_SERVER['REQUEST_TIME'], 5, "resource-monitor", "Adding new resource {$new_resource_id} ({$resource_mac})", "", "", 0, 1, $resource->id);
# send add resource to openQRM-server
$openqrm_server->send_command("openqrm_server_add_resource {$new_resource_id} {$resource_mac} {$resource_ip}");
# add resource to db
$resource_fields["resource_id"] = $new_resource_id;
$resource_fields["resource_localboot"] = 0;
$resource_fields["resource_vtype"] = 1;
$resource_fields["resource_vhostid"] = $new_resource_id;
$resource_fields["resource_subnet"] = $resource_subnet;
$resource->add($resource_fields);
}
}
if (strlen($resource_mac)) {
$resource = new resource();
$resource->get_instance_by_mac("{$resource_mac}");
// update the resource parameter in any way
$resource->update_info($resource->id, $resource_fields);
$resource->get_parameter($resource->id);
} else {
if (strlen($resource_id)) {
$resource = new resource();
$resource->get_instance_by_id($resource_id);
// update the resource parameter in any way
$resource->update_info($resource->id, $resource_fields);
$resource->get_parameter($resource->id);
示例12: add
function add()
{
$response = $this->get_response();
$form = $response->form;
$errors = array();
if (!$form->get_errors() && $this->response->submit()) {
$image_id = $form->get_request('ami_image_id');
$image = new image();
if (isset($image_id) && $image_id !== '') {
$image->get_instance_by_id($image_id);
} else {
$errors[] = $this->lang['error_boot'];
}
if (count($errors) > 0 || $form->get_errors()) {
$response->error = join('<br>', $errors);
} else {
$tables = $this->openqrm->get('table');
$custom_script_parameter = '';
$custom_script = $form->get_request('custom_script');
if (strlen($custom_script)) {
$custom_script_parameter = ' -ic ' . $custom_script;
}
$custom_name = $form->get_request('name');
$resource = new resource();
$id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
if (strlen($custom_name)) {
$name = $custom_name;
} else {
$name = $this->hc->account_type . $id;
}
$ip = "0.0.0.0";
$resource->generate_mac();
$mac = $resource->mac;
// send command to the openQRM-server
$openqrm = new openqrm_server();
$openqrm->send_command('openqrm_server_add_resource ' . $id . ' ' . $mac . ' ' . $ip);
// set resource type
$virtualization = new virtualization();
$virtualization->get_instance_by_type("hybrid-cloud-vm-local");
// add to openQRM database
$fields["resource_id"] = $id;
$fields["resource_ip"] = $ip;
$fields["resource_mac"] = $mac;
$fields["resource_hostname"] = $name;
$fields["resource_localboot"] = 0;
$fields["resource_vtype"] = $virtualization->id;
$fields["resource_vhostid"] = 0;
$fields["resource_image"] = $image->name;
$fields["resource_imageid"] = $image->id;
$rfields["resource_kernel"] = 'default';
$rfields["resource_kernelid"] = 1;
$resource->add($fields);
$resource->get_instance_by_mac($mac);
// set account id in resource capabilities
$resource->set_resource_capabilities("HCACL", $this->hc->id);
$hc_authentication = '';
if ($this->hc->account_type == 'aws' || $this->hc->account_type == 'euca') {
$hc_authentication .= ' -O ' . $this->hc->access_key;
$hc_authentication .= ' -W ' . $this->hc->secret_key;
$hc_authentication .= ' -ir ' . $this->region;
$hc_authentication .= ' -iz ' . $form->get_request('availability_zone');
}
if ($this->hc->account_type == 'lc-openstack') {
$hc_authentication .= ' -u ' . $this->hc->username;
$hc_authentication .= ' -p ' . $this->hc->password;
$hc_authentication .= ' -q ' . $this->hc->host;
$hc_authentication .= ' -x ' . $this->hc->port;
$hc_authentication .= ' -g ' . $this->hc->tenant;
$hc_authentication .= ' -e ' . $this->hc->endpoint;
}
$command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm create';
$command .= ' -i ' . $this->hc->id;
$command .= ' -n ' . $this->hc->account_name;
$command .= ' -t ' . $this->hc->account_type;
$command .= $hc_authentication;
$command .= ' -in ' . $name;
$command .= ' -im ' . $mac;
$command .= ' -a ' . $image->name;
$command .= ' -it ' . $form->get_request('type');
$command .= ' -ik ' . $form->get_request('keypair');
if ($this->hc->account_type == 'aws') {
$command .= ' -subnet ' . $form->get_request('subnet');
} else {
$command .= ' -ig ' . $form->get_request('group');
}
$command .= ' --openqrm-ui-user ' . $this->user->name;
$command .= ' --openqrm-cmd-mode background';
$command .= $custom_script_parameter;
$openqrm->send_command($command, NULL, true);
// check to have a ip from the dhcpd-resource hook
while ($resource->ip == "0.0.0.0") {
sleep(1);
clearstatcache();
$resource->get_instance_by_mac($mac);
}
// save the mgmt ip in the resource network field
$rufields["resource_network"] = $resource->ip;
$resource->update_info($resource->id, $rufields);
$response->resource_id = $id;
$response->msg = sprintf($this->lang['msg_added'], $name);
//.........这里部分代码省略.........
示例13: import
function import()
{
$response = '';
$errors = array();
$message = array();
$event = new event();
$instance_command = $this->response->html->request()->get('instance_command');
if ($instance_command !== '') {
switch ($instance_command) {
case 'add':
// instance_command=add
// &instance_name='.$name.'
// &instance_mac='.$mac.'
// &instance_public_ip='.$public_ip.'
// &instance_type='.$type.'
// &instance_keypair='.$keypair.'
// &instance_region='.$region.'
// &instance_ami='.$ami;
$now = $_SERVER['REQUEST_TIME'];
$openqrm = new openqrm_server();
$instance_name = $this->response->html->request()->get('instance_name');
$instance_mac = $this->response->html->request()->get('instance_mac');
$instance_public_ip = $this->response->html->request()->get('instance_public_ip');
$instance_type = $this->response->html->request()->get('instance_type');
$instance_keypair = $this->response->html->request()->get('instance_keypair');
$instance_region = $this->response->html->request()->get('instance_region');
$instance_ami = $this->response->html->request()->get('instance_ami');
// create resource, image and appliance
$event->log("import", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-vm-import", "Importing " . $instance_name . " - " . $instance_mac . " - " . $instance_public_ip . " - " . $instance_type . " - " . $instance_keypair . " - " . $instance_region . " - " . $instance_ami . ".", "", "", 0, 0, 0);
$import_resource = new resource();
$deployment = new deployment();
$deployment->get_instance_by_name('ami-deployment');
$virtualization = new virtualization();
$virtualization->get_instance_by_type("hybrid-cloud-vm-local");
// create resource
$resid = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
// send command to the openQRM-server
$openqrm->send_command('openqrm_server_add_resource ' . $resid . ' ' . $instance_mac . ' ' . $instance_public_ip);
// add to openQRM database
$resource_fields["resource_id"] = $resid;
$resource_fields["resource_ip"] = $instance_public_ip;
$resource_fields["resource_mac"] = $instance_mac;
$resource_fields["resource_kernel"] = 'local';
$resource_fields["resource_kernelid"] = 0;
$resource_fields["resource_localboot"] = 0;
$resource_fields["resource_hostname"] = $this->hc->account_type . $resid;
$resource_fields["resource_vtype"] = $virtualization->id;
$resource_fields["resource_vhostid"] = 0;
$import_resource->add($resource_fields);
$import_resource->get_instance_by_mac($instance_mac);
// update stats
#if ($state == 'running') {
$rfields["resource_state"] = 'idle';
#$rfields["resource_lastgood"]=$now;
#} else {
# $rfields["resource_state"]='off';
#}
#$import_resource->update_info($import_resource->id, $rfields);
// set account id in resource capabilities
$import_resource->set_resource_capabilities("HCACL", $this->id);
// auto create image object
$storage = new storage();
$storage->get_instance_by_name('ami-image-storage');
$image = new image();
$image->get_instance_by_name($instance_ami);
if (isset($image->id) && $image->id > 0) {
$image_exists = true;
} else {
$image_fields = array();
$vm_image_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
$image_fields["image_id"] = $vm_image_id;
$image_fields['image_name'] = $instance_ami;
$image_fields['image_type'] = 'ami-deployment';
$image_fields['image_rootfstype'] = 'local';
$image_fields['image_isactive'] = 0;
$image_fields['image_storageid'] = $storage->id;
$image_fields['image_comment'] = "Image Object for AMI {$instance_ami}";
$image_fields['image_rootdevice'] = $instance_ami;
$image->add($image_fields);
# update image object
$image->get_instance_by_id($vm_image_id);
// update resource with image infos
$rfields["resource_id"] = $resid;
$rfields["resource_image"] = $image->name;
$rfields["resource_imageid"] = $image->id;
$import_resource->update_info($import_resource->id, $rfields);
$import_resource->get_instance_by_mac($instance_mac);
}
// create the appliance
$appliance = new appliance();
$appliance->get_instance_by_name($instance_name);
if (isset($appliance->id) && $appliance->id > 0) {
$appliance_exists = true;
} else {
$new_appliance_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
$afields['appliance_id'] = $new_appliance_id;
$afields['appliance_name'] = $this->hc->account_type . $resid;
$afields['appliance_resources'] = $resid;
$afields['appliance_kernelid'] = '1';
$afields['appliance_imageid'] = $image->id;
//.........这里部分代码省略.........
示例14: resource
function resource_new()
{
$response = $this->get_response();
$form = $response->form;
$name = $form->get_request('name');
$ip = $form->get_request('ip');
$mac = $form->get_request('mac');
if (strlen($name)) {
if (!$form->get_errors() && $this->response->submit()) {
// check that mac adress + ip does not yet exists
$resource = new resource();
$resource->get_instance_by_mac($mac);
if (strlen($resource->id)) {
$response->error = sprintf($this->lang['msg_mac_in_use']);
return $response;
}
$resource->get_instance_by_ip($ip);
if (strlen($resource->id)) {
$response->error = sprintf($this->lang['msg_ip_in_use']);
return $response;
}
$tables = $this->openqrm->get('table');
$id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
$mac = strtolower($mac);
// send command to the openQRM-server
$openqrm = new openqrm_server();
$openqrm->send_command('openqrm_server_add_resource ' . $id . ' ' . $mac . ' ' . $ip);
// add to openQRM database
$fields["resource_id"] = $id;
$fields["resource_hostname"] = $name;
$fields["resource_ip"] = $ip;
$fields["resource_mac"] = $mac;
$fields["resource_localboot"] = 0;
$fields["resource_vtype"] = 1;
$fields["resource_vhostid"] = $id;
$fields["resource_state"] = 'unknown';
$fields["resource_lastgood"] = '-1';
$resource->add($fields);
// set lastgood to -1 to prevent automatic checking the state
$resource->update_info($id, $fields);
$response->msg = sprintf($this->lang['msg'], $name);
$response->resource_id = $id;
} else {
$response->error = sprintf($this->lang['msg_add_failed']);
}
}
return $response;
}