本文整理汇总了PHP中image::get_instance_by_id方法的典型用法代码示例。如果您正苦于以下问题:PHP image::get_instance_by_id方法的具体用法?PHP image::get_instance_by_id怎么用?PHP image::get_instance_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类image
的用法示例。
在下文中一共展示了image::get_instance_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_ami_deployment_image_rootdevice_identifier
function get_ami_deployment_image_rootdevice_identifier($id)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_ADMIN;
global $event;
$rootdevice_identifier_array = array();
$image = new image();
$image_id_list = $image->get_ids();
foreach ($image_id_list as $id => $ikey) {
$image_tmp = new image();
$image_tmp->get_instance_by_id($id);
if ($image_tmp->type === "ami-deployment") {
$rootdevice_identifier_array[] = array("value" => $image_tmp->rootdevice, "label" => $image_tmp->name);
}
}
return $rootdevice_identifier_array;
}
示例2: switch
function send_command($resource_ip, $resource_command, $command_timeout = NULL)
{
global $OPENQRM_EXEC_PORT;
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_EXECUTION_LAYER;
global $event;
global $RootDir;
// here we assume that we are the resource
// plugin hook in case a resource gets rebooted or halted
switch ($resource_command) {
case 'reboot':
// start the hook
$plugin = new plugin();
$enabled_plugins = $plugin->enabled();
foreach ($enabled_plugins as $index => $plugin_name) {
$plugin_start_resource_hook = "{$RootDir}/plugins/{$plugin_name}/openqrm-{$plugin_name}-resource-hook.php";
if (file_exists($plugin_start_resource_hook)) {
$event->log("start", $_SERVER['REQUEST_TIME'], 5, "resource.class.php", "Found plugin {$plugin_name} handling start-resource event.", "", "", 0, 0, $this->id);
// prepare resource_fields array
$resource_fields = array();
$resource_fields = $this->get_fields($this->id);
// include the plugin function file and run it
require_once "{$plugin_start_resource_hook}";
$resource_function = "openqrm_" . "{$plugin_name}" . "_resource";
$resource_function = str_replace("-", "_", $resource_function);
$resource_function("start", $resource_fields);
}
}
// here we check if the resource is virtual or a host and if
// the virtualization plugin wants to reboot it via the host
$virtualization = new virtualization();
$virtualization->get_instance_by_id($this->vtype);
$virtualization_plugin_name = $virtualization->get_plugin_name();
$plugin_resource_virtual_command_hook_vm_type = "{$RootDir}/plugins/{$virtualization_plugin_name}/openqrm-{$virtualization_plugin_name}-resource-virtual-command-hook.php";
// we also give the deployment type a chance to implement virtual commands
$deployment_plugin_name = '';
if ($this->imageid != 1) {
$image = new image();
$image->get_instance_by_id($this->imageid);
$storage = new storage();
$storage->get_instance_by_id($image->storageid);
$deployment = new deployment();
$deployment->get_instance_by_id($storage->type);
$deployment_plugin_name = $deployment->storagetype;
}
$plugin_resource_virtual_command_hook = '';
$plugin_resource_virtual_command_hook_image_type = "{$RootDir}/plugins/{$deployment_plugin_name}/openqrm-{$deployment_plugin_name}-resource-virtual-command-hook.php";
// $plugin_resource_virtual_command_hook_image_type = "$RootDir/plugins/sanboot-storage/openqrm-sanboot-storage-resource-virtual-command-hook.php";
if (file_exists($plugin_resource_virtual_command_hook_vm_type)) {
$event->log("start", $_SERVER['REQUEST_TIME'], 5, "resource.class.php", "Found virtualization {$virtualization_plugin_name} managing virtual command.", "", "", 0, 0, $this->id);
$plugin_resource_virtual_command_hook = $plugin_resource_virtual_command_hook_vm_type;
} else {
if (file_exists($plugin_resource_virtual_command_hook_image_type)) {
// check if IMAGE_VIRTUAL_RESOURCE_COMMAND=true
$event->log("start", $_SERVER['REQUEST_TIME'], 5, "resource.class.php", "Found deploymetn {$deployment_plugin_name} managing virtual command.", "", "", 0, 0, $this->id);
$image = new image();
$image->get_instance_by_id($this->imageid);
$virtual_command_enabled = $image->get_deployment_parameter("IMAGE_VIRTUAL_RESOURCE_COMMAND");
if (!strcmp($virtual_command_enabled, "true")) {
$event->log("start", $_SERVER['REQUEST_TIME'], 5, "resource.class.php", "Found IMAGE_VIRTUAL_RESOURCE_COMMAND enabled, using virtual command.", "", "", 0, 0, $this->id);
$plugin_resource_virtual_command_hook = $plugin_resource_virtual_command_hook_image_type;
$virtualization_plugin_name = $deployment_plugin_name;
} else {
$event->log("start", $_SERVER['REQUEST_TIME'], 5, "resource.class.php", "Found IMAGE_VIRTUAL_RESOURCE_COMMAND disabled, using regular command.", "", "", 0, 0, $this->id);
}
}
}
if (strlen($plugin_resource_virtual_command_hook)) {
$event->log("start", $_SERVER['REQUEST_TIME'], 5, "resource.class.php", "Found plugin {$virtualization_plugin_name} virtually handling the reboot command.", "", "", 0, 0, $this->id);
// prepare resource_fields array
$resource_fields = array();
$resource_fields = $this->get_fields($this->id);
// include the plugin function file and run it
require_once "{$plugin_resource_virtual_command_hook}";
$resource_function = "openqrm_" . "{$virtualization_plugin_name}" . "_resource_virtual_command";
$resource_function = str_replace("-", "_", $resource_function);
$resource_function("reboot", $resource_fields);
// the virtual reboot function can only be
// implemented by a single plugin depending on the
// resource type. So we return after that and
// do not try to reboot the resource via its ip
return;
}
break;
case 'halt':
// stop hook
$plugin = new plugin();
$enabled_plugins = $plugin->enabled();
foreach ($enabled_plugins as $index => $plugin_name) {
$plugin_start_resource_hook = "{$RootDir}/plugins/{$plugin_name}/openqrm-{$plugin_name}-resource-hook.php";
if (file_exists($plugin_start_resource_hook)) {
$event->log("stop", $_SERVER['REQUEST_TIME'], 5, "resource.class.php", "Found plugin {$plugin_name} handling start-resource event.", "", "", 0, 0, $this->id);
// prepare resource_fields array
$resource_fields = array();
$resource_fields = $this->get_fields($this->id);
// include the plugin function file and run it
require_once "{$plugin_start_resource_hook}";
$resource_function = "openqrm_" . "{$plugin_name}" . "_resource";
$resource_function = str_replace("-", "_", $resource_function);
$resource_function("stop", $resource_fields);
//.........这里部分代码省略.........
示例3: image
function get_response()
{
$response = $this->response;
$form = $response->get_form($this->actions_name, 'install2');
$id = $this->response->html->request()->get('image_id');
$install_server = $this->response->html->request()->get('install_server');
$submit = $form->get_elements('submit');
$submit->handler = 'onclick="wait();"';
$form->add($submit, 'submit');
$submit = $form->get_elements('cancel');
$submit->handler = 'onclick="cancel();"';
$form->add($submit, 'cancel');
$image = new image();
$image->get_instance_by_id($id);
$storage = new storage();
$storage->get_instance_by_id($install_server);
$deployment = new deployment();
$deployment->get_instance_by_id($storage->type);
// require template-deployment file
$local_deployment_templates_identifier_hook = $this->openqrm->get('basedir') . "/web/boot-service/template." . $deployment->type . ".php";
if ($this->file->exists($local_deployment_templates_identifier_hook)) {
require_once "{$local_deployment_templates_identifier_hook}";
$get_deployment_templates_function = "get_" . "{$deployment->type}" . "_templates";
$get_deployment_templates_function = str_replace("-", "_", $get_deployment_templates_function);
$local_deployment_templates_arr = $get_deployment_templates_function($install_server);
// get additional optional local-deployment parameters from the template hook
$get_additional_parameters_function = "get_" . "{$deployment->type}" . "_additional_parameters";
$get_additional_parameters_function = str_replace("-", "_", $get_additional_parameters_function);
$additional_local_deployment_parameter = $get_additional_parameters_function();
}
// persistent deployment ?
$local_deployment_persistent_arr = array();
$local_deployment_persistent_arr[] = array("value" => "0", "label" => "First boot");
$local_deployment_persistent_arr[] = array("value" => "1", "label" => "Persistent");
$d['template']['label'] = $this->lang['form_install_template'];
$d['template']['required'] = false;
$d['template']['object']['type'] = 'htmlobject_select';
$d['template']['object']['attrib']['index'] = array('value', 'label');
$d['template']['object']['attrib']['id'] = 'template';
$d['template']['object']['attrib']['name'] = 'template';
$d['template']['object']['attrib']['options'] = $local_deployment_templates_arr;
$d['persistent']['label'] = $this->lang['form_install_persistent'];
$d['persistent']['required'] = false;
$d['persistent']['object']['type'] = 'htmlobject_select';
$d['persistent']['object']['attrib']['index'] = array('value', 'label');
$d['persistent']['object']['attrib']['id'] = 'persistent';
$d['persistent']['object']['attrib']['name'] = 'persistent';
$d['persistent']['object']['attrib']['options'] = $local_deployment_persistent_arr;
$n = 1;
foreach ($additional_local_deployment_parameter as $paramters) {
if (!isset($paramters['label'])) {
continue;
}
$d['parameter' . $n]['label'] = $paramters['label'];
$d['parameter' . $n]['required'] = false;
$d['parameter' . $n]['object']['type'] = 'htmlobject_input';
$d['parameter' . $n]['object']['attrib']['id'] = 'parameter' . $n;
$d['parameter' . $n]['object']['attrib']['name'] = 'parameter' . $n;
$n++;
}
for ($j = $n; $j <= 4; $j++) {
$d['parameter' . $j] = '';
}
$form->add($d);
$response->form = $form;
return $response;
}
示例4: imtarget
function imtarget()
{
$h = array();
$h['image_icon']['title'] = ' ';
$h['image_icon']['sortable'] = false;
$h['image_id']['title'] = $this->lang['table_id'];
$h['image_name']['title'] = $this->lang['table_name'];
$h['image_version']['title'] = $this->lang['table_version'];
$h['image_type']['title'] = $this->lang['table_deployment'];
$h['image_isactive']['title'] = $this->lang['table_isactive'];
$h['image_comment']['title'] = $this->lang['table_comment'];
$h['image_comment']['sortable'] = false;
$h['edit']['title'] = ' ';
$h['edit']['sortable'] = false;
$image = new image();
$params = $this->response->get_array($this->actions_name, 'target');
$b = array();
$table = $this->response->html->tablebuilder('hybridcloud_imtarget', $params);
$table->offset = 0;
$table->sort = 'image_id';
$table->limit = 10;
$table->order = 'ASC';
$table->max = $image->get_count();
$table->init();
$image_arr = $image->display_overview(0, 10000, $table->sort, $table->order);
$image_icon = "/openqrm/base/img/image.png";
foreach ($image_arr as $index => $image_db) {
// prepare the values for the array
$image = new image();
$image->get_instance_by_id($image_db["image_id"]);
if ($image->type === 'lvm-nfs-deployment' || $image->type === 'nfs-deployment') {
$image_comment = $image_db["image_comment"];
if (!strlen($image_comment)) {
$image_comment = "-";
}
$image_version = $image_db["image_version"];
if (!strlen($image_version)) {
$image_version = " ";
}
// edit
$a = $this->response->html->a();
$a->title = $this->lang['action_import'];
$a->label = $this->lang['action_import'];
$a->handler = 'onclick="wait();"';
$a->css = 'edit';
$a->href = $this->response->get_url($this->actions_name, 'imparams') . '&image_id=' . $image->id;
$image_edit = $a->get_string();
// set the active icon
$isactive_icon = "/openqrm/base/img/enable.png";
if ($image_db["image_isactive"] == 1) {
$isactive_icon = "/openqrm/base/img/disable.png";
}
$image_isactive_icon = "<img src=" . $isactive_icon . " width='24' height='24' alt='State'>";
$b[] = array('image_icon' => "<img width='24' height='24' src='" . $image_icon . "'>", 'image_id' => $image_db["image_id"], 'image_name' => $image_db["image_name"], 'image_version' => $image_version, 'image_type' => $image_db["image_type"], 'image_isactive' => $image_isactive_icon, 'image_comment' => $image_comment, 'edit' => $image_edit);
}
}
$table->id = 'Tabelle';
$table->css = 'htmlobject_table';
$table->border = 1;
$table->cellspacing = 0;
$table->cellpadding = 3;
$table->autosort = false;
$table->sort_link = false;
$table->max = count($b);
$table->head = $h;
$table->body = $b;
$table->limit_select = array(array("value" => 10, "text" => 10), array("value" => 20, "text" => 20), array("value" => 30, "text" => 30), array("value" => 50, "text" => 50), array("value" => 100, "text" => 100));
require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php';
$hc = new hybrid_cloud();
$hc->get_instance_by_id($this->id);
$d['name'] = $hc->account_name;
$d['form'] = $this->response->get_form($this->actions_name, 'target', false)->get_elements();
$d['table'] = $table;
return $d;
}
示例5: select
function select()
{
$head['cr_status']['title'] = $this->lang['cloud_ui_request_status'];
$head['cr_id']['title'] = $this->lang['cloud_ui_request_id'];
$head['cr_id']['hidden'] = true;
$head['cr_appliance_hostname']['title'] = $this->lang['cloud_ui_request_appliance_name'];
$head['cr_appliance_hostname']['hidden'] = true;
#$head['cr_start']['title'] = $this->lang['cloud_ui_request_start'];
#$head['cr_stop']['title'] = $this->lang['cloud_ui_request_stop'];
#$head['cr_kernel_id']['title'] = $this->lang['cloud_ui_request_os'];
#$head['cr_image_id']['title'] = $this->lang['cloud_ui_request_template'];
#$head['cr_resource_type_req']['title'] = $this->lang['cloud_ui_request_system_type'];
$head['cr_req']['title'] = ' ';
$head['cr_req']['sortable'] = false;
#$head['cr_appliance_id']['title'] = $this->lang['cloud_ui_request_appliance_id'];
$head['cr_details']['title'] = $this->lang['cloud_ui_request_details'];
$head['cr_details']['sortable'] = false;
$table = $this->response->html->tablebuilder('cloud_request_table', $this->response->get_array($this->actions_name, 'requests'));
$table->css = 'htmlobject_table';
$table->border = 0;
$table->id = 'cloud_requests';
$table->head = $head;
$table->sort = 'cr_id';
$table->order = 'DESC';
$table->limit = 5;
$table->sort_link = false;
$table->autosort = false;
$table->max = $this->cloudrequest->get_count_per_user($this->clouduser->id);
$table->identifier = 'cr_id';
$table->identifier_name = $this->identifier_name;
$table->actions = array('deprovision');
$table->actions_name = $this->actions_name;
$table->form_action = $this->response->html->thisfile;
$table->limit_select = array(array("value" => 5, "text" => 5), array("value" => 10, "text" => 10), array("value" => 20, "text" => 20), array("value" => 30, "text" => 30), array("value" => 40, "text" => 40), array("value" => 50, "text" => 50));
// $table->form_action = $this->response->html->thisfile;
$table->init();
$kernel = new kernel();
$image = new image();
$virtualization = new virtualization();
$cloud_request_array = $this->cloudrequest->display_overview_per_user($this->clouduser->id, $table->offset, $table->limit, $table->sort, $table->order);
$ta = '';
foreach ($cloud_request_array as $index => $cz) {
$this->cloudrequest->get_instance_by_id($cz['cr_id']);
$cr_status = $this->cloudrequest->getstatus($this->cloudrequest->id);
if (isset($this->cloudrequest->kernel_id)) {
$kernel->get_instance_by_id($this->cloudrequest->kernel_id);
}
if (isset($this->cloudrequest->image_id)) {
$image->get_instance_by_id($this->cloudrequest->image_id);
}
if (isset($this->cloudrequest->resource_type_req)) {
$virtualization->get_instance_by_id($this->cloudrequest->resource_type_req);
}
#echo '<pre>';
#print_r($this->cloudrequest);
#echo '</pre>';
// hostname
$appliance_hostname = '-';
if (strlen($this->cloudrequest->appliance_hostname)) {
$appliance_hostname = $this->cloudrequest->appliance_hostname;
}
$cr_req = '<b>' . $this->lang['cloud_ui_request_id'] . '</b>: ' . $this->cloudrequest->id . "<br>";
$cr_req .= '<b>' . $this->lang['cloud_ui_request_appliance_name'] . '</b>: ' . $appliance_hostname . "<br>";
$cr_req .= '<b>' . $this->lang['cloud_ui_request_start'] . '</b>: ' . date("d-m-Y H:i", $this->cloudrequest->start) . "<br>";
$cr_req .= '<b>' . $this->lang['cloud_ui_request_stop'] . '</b>: ' . date("d-m-Y H:i", $this->cloudrequest->stop) . "<br>";
$cr_req .= '<b>' . $this->lang['cloud_ui_request_cpu'] . '</b>: ' . $this->cloudrequest->cpu_req . "<br>";
$cr_req .= '<b>' . $this->lang['cloud_ui_request_memory'] . '</b>: ' . $this->cloudrequest->ram_req . " MB<br>";
$cr_req .= '<b>' . $this->lang['cloud_ui_request_disk'] . '</b>: ' . $this->cloudrequest->disk_req . " MB<br>";
$cr_req .= '<b>' . $this->lang['cloud_ui_request_network'] . '</b>: ' . $this->cloudrequest->network_req . "<br>";
// details action
$a = $this->response->html->a();
$a->title = $this->lang['cloud_ui_request_components_details'];
$a->label = $this->lang['cloud_ui_request_components_details'];
$a->handler = 'onclick="javascript:cloudopenPopup(' . $this->cloudrequest->id . ');"';
$a->css = 'edit';
$a->href = '#';
$ta[] = array('cr_status' => $cr_status, 'cr_id' => $this->cloudrequest->id, 'cr_appliance_hostname' => $appliance_hostname, 'cr_req' => $cr_req, 'cr_details' => $a->get_string());
}
$table->body = $ta;
return $table;
}
示例6: remove_nfs_deployment
function remove_nfs_deployment($cloud_image_id)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
global $RESOURCE_INFO_TABLE;
global $event;
$event->log("remove_nfs_deployment", $_SERVER['REQUEST_TIME'], 5, "nfs-deployment-cloud-hook", "Removing image on storage", "", "", 0, 0, 0);
$cloudimage = new cloudimage();
$cloudimage->get_instance_by_id($cloud_image_id);
// get image
$image = new image();
$image->get_instance_by_id($cloudimage->image_id);
$image_id = $image->id;
$image_name = $image->name;
$image_type = $image->type;
$image_version = $image->version;
$image_rootdevice = $image->rootdevice;
$image_rootfstype = $image->rootfstype;
$image_storageid = $image->storageid;
$image_isshared = $image->isshared;
$image_comment = $image->comment;
$image_capabilities = $image->capabilities;
$image_deployment_parameter = $image->deployment_parameter;
// get image storage
$storage = new storage();
$storage->get_instance_by_id($image_storageid);
$storage_resource_id = $storage->resource_id;
// get storage resource
$resource = new resource();
$resource->get_instance_by_id($storage_resource_id);
$resource_id = $resource->id;
$resource_ip = $resource->ip;
// nfs-storage
$image_location_name = basename($image_rootdevice);
$image_remove_clone_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/nfs-storage/bin/openqrm-nfs-storage remove -n " . $image_location_name . " --openqrm-cmd-mode background";
$event->log("remove_nfs_deployment", $_SERVER['REQUEST_TIME'], 5, "nfs-deployment-cloud-hook", "Running : {$image_remove_clone_cmd}", "", "", 0, 0, 0);
$resource->send_command($resource_ip, $image_remove_clone_cmd);
}
示例7: 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);
}
}
}
}
}
}
//.........这里部分代码省略.........
示例8: create_private_template_deployment
function create_private_template_deployment($cloud_image_id, $private_disk, $private_image_name)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
global $RESOURCE_INFO_TABLE;
global $event;
$event->log("create_private_template_deployment", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Creating private image on storage", "", "", 0, 0, 0);
// we got the cloudimage id here, get the image out of it
$cloudimage = new cloudimage();
$cloudimage->get_instance_by_id($cloud_image_id);
// get image
$image = new image();
$image->get_instance_by_id($cloudimage->image_id);
$image_id = $image->id;
$image_name = $image->name;
$image_type = $image->type;
$image_version = $image->version;
$image_rootdevice = $image->rootdevice;
$image_rootfstype = $image->rootfstype;
$image_storageid = $image->storageid;
$image_isshared = $image->isshared;
$image_comment = $image->comment;
$image_capabilities = $image->capabilities;
$image_deployment_parameter = $image->deployment_parameter;
// get image storage
$storage = new storage();
$storage->get_instance_by_id($image_storageid);
$storage_resource_id = $storage->resource_id;
// get storage resource
$resource = new resource();
$resource->get_instance_by_id($storage_resource_id);
$resource_id = $resource->id;
$resource_ip = $resource->ip;
// create an admin user to post when cloning has finished
$openqrm_admin_user = new user("openqrm");
$openqrm_admin_user->set_user();
// parse the volume group info in the identifier
$volume_group_location = dirname($image_rootdevice);
$volume_group = basename($volume_group_location);
$image_location_name = basename($image_rootdevice);
// For template vms we assume that the image is located on the vm-host
// so we send the auth command to the vm-host instead of the image storage.
// This enables using a SAN backend with dedicated volumes per vm-host which all
// contain all "golden-images" which are used for snapshotting.
// We do this to overcome the current lvm limitation of not supporting cluster-wide snapshots
//
// Still we need to send the remove command to the storage resource since the
// create-phase automatically adapted the image->storageid, we cannot use the vm-resource here
// because cloudimage->resource_id will be set to -1 when the cloudapp is in paused/resize/private state
//
if ($cloudimage->resource_id > 0) {
$vm_resource = new resource();
$vm_resource->get_instance_by_id($cloudimage->resource_id);
// get the openvz host
$vm_host_resource = new resource();
$vm_host_resource->get_instance_by_id($vm_resource->vhostid);
// san backend ?
if ($vm_host_resource->id != $resource->id) {
$event->log("create_private_template_deployment", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Image {$image_id} IS NOT available on this template host, {$resource->id} not equal {$vm_host_resource->id} !! Assuming SAN Backend", "", "", 0, 0, $appliance_id);
} else {
$event->log("create_private_template_deployment", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Image {$image_id} IS available on this template host, {$resource->id} equal {$vm_host_resource->id}", "", "", 0, 0, $appliance_id);
}
}
$image_resize_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/template/bin/openqrm-template clone -n " . $image_location_name . " -s " . $private_image_name . " -v " . $volume_group . " -m " . $private_disk . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background";
$event->log("create_private_template_deployment", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Running : {$image_resize_cmd}", "", "", 0, 0, 0);
$resource->send_command($resource_ip, $image_resize_cmd);
// set the storage specific image root_device parameter
$new_rootdevice = str_replace($image_location_name, $private_image_name, $image->rootdevice);
return $new_rootdevice;
}
示例9: openqrm_kvm_appliance
function openqrm_kvm_appliance($cmd, $appliance_fields)
{
global $event;
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
$appliance_id = $appliance_fields["appliance_id"];
$appliance_name = $appliance_fields["appliance_name"];
$resource = new resource();
$resource->get_instance_by_id($appliance_fields["appliance_resources"]);
$appliance_ip = $resource->ip;
$appliance = new appliance();
$appliance->get_instance_by_id($appliance_id);
// check appliance values, maybe we are in update and they are incomplete
if ($appliance->imageid == 1) {
return;
}
if ($resource->id == "-1" || $resource->id == "" || !isset($resource->vtype)) {
return;
}
$openqrm_admin_user = new user("openqrm");
$openqrm_admin_user->set_user();
$event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "Handling {$cmd} event {$appliance_id}/{$appliance_name}/{$appliance_ip}", "", "", 0, 0, $appliance_id);
switch ($cmd) {
case "start":
// send command to assign image and start vm
// NOTICE : please enable this hook only if you are using the ip-mgmt plugin with vlans
// check if resource type -> kvm-vm-net
// $virtualization = new virtualization();
// $virtualization->get_instance_by_type("kvm-vm-net");
// $kvm_host_resource = new resource();
// $kvm_host_resource->get_instance_by_id($resource->vhostid);
// if ($resource->vtype != $virtualization->id) {
// $kvm_command="$OPENQRM_SERVER_BASE_DIR/openqrm/plugins/kvm/bin/openqrm-kvm-vm reset_vlans_by_mac -b start -m $resource->mac";
// $kvm_host_resource->send_command($kvm_host_resource->ip, $kvm_command);
// return;
// }
// check resource type -> kvm-vm-local
$virtualization = new virtualization();
$virtualization->get_instance_by_type("kvm-vm-local");
if ($resource->vtype != $virtualization->id) {
$event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "{$appliance_id} is not from type kvm-vm, skipping .. {$appliance_name}/{$appliance_ip}", "", "", 0, 0, $appliance_id);
return;
}
// check image is on the same storage server
// get the kvm host resource
$kvm_host_resource = new resource();
$kvm_host_resource->get_instance_by_id($resource->vhostid);
// get the kvm resource
$image = new image();
$image->get_instance_by_id($appliance->imageid);
$storage = new storage();
$storage->get_instance_by_id($image->storageid);
$kvm_resource = new resource();
$kvm_resource->get_instance_by_id($storage->resource_id);
if ($kvm_host_resource->id != $kvm_resource->id) {
$event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "Appliance {$appliance_id} image is not available on this kvm host. Assuming SAN-Backend", "", "", 0, 0, $appliance_id);
}
$kvm_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/kvm/bin/openqrm-kvm-vm start_by_mac -m " . $resource->mac . " -d " . $image->rootdevice . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password;
$kvm_host_resource->send_command($kvm_host_resource->ip, $kvm_command);
break;
case "stop":
// send command to stop the vm and deassign image
// NOTICE : please enable this hook only if you are using the ip-mgmt plugin with vlans
// check if resource type -> kvm-vm-net
// $virtualization = new virtualization();
// $virtualization->get_instance_by_type("kvm-vm-net");
// $kvm_host_resource = new resource();
// $kvm_host_resource->get_instance_by_id($resource->vhostid);
// if ($resource->vtype != $virtualization->id) {
// $kvm_command="$OPENQRM_SERVER_BASE_DIR/openqrm/plugins/kvm/bin/openqrm-kvm reset_vlans_by_mac -b stop -m $resource->mac";
// $kvm_host_resource->send_command($kvm_host_resource->ip, $kvm_command);
// return;
// }
// check resource type -> kvm-vm-local
$virtualization = new virtualization();
$virtualization->get_instance_by_type("kvm-vm-local");
if ($resource->vtype != $virtualization->id) {
$event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "{$appliance_id} is not from type kvm-vm, skipping .. {$appliance_name}/{$appliance_ip}", "", "", 0, 0, $appliance_id);
return;
}
// check image is on the same storage server
// get the kvm host resource
$kvm_host_resource = new resource();
$kvm_host_resource->get_instance_by_id($resource->vhostid);
// get the kvm resource
$image = new image();
$image->get_instance_by_id($appliance->imageid);
$storage = new storage();
$storage->get_instance_by_id($image->storageid);
$kvm_resource = new resource();
$kvm_resource->get_instance_by_id($storage->resource_id);
if ($kvm_host_resource->id != $kvm_resource->id) {
$event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "Appliance {$appliance_id} image is not available on this kvm host. Assuming SAN-Backend", "", "", 0, 0, $appliance_id);
}
$kvm_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/kvm/bin/openqrm-kvm-vm restart_by_mac -m " . $resource->mac . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background";
$kvm_host_resource->send_command($kvm_host_resource->ip, $kvm_command);
break;
case "update":
// check if the appliance was set to a kvm Host, if yes, auto-create the storage objects
//.........这里部分代码省略.........
示例10: array
function get_response()
{
$size_select_arr = array();
$availability_zones_select_arr = array();
$security_group_select_arr = array();
$subnet_select_arr = array();
$keypair_select_arr = array();
// get the datastore and vswitchlist for the selects
if (file_exists($this->statfile)) {
$lines = explode("\n", file_get_contents($this->statfile));
if (count($lines) >= 1) {
foreach ($lines as $line) {
if ($line !== '') {
$line = explode('@', $line);
switch ($line[0]) {
case 'SIZES':
$size_select_arr[] = array($line[1], $line[1]);
break;
case 'KEYPAIR':
$keypair_select_arr[] = array($line[1], $line[1]);
break;
case 'GROUP':
$security_group_select_arr[] = array($line[1], $line[1]);
break;
case 'ZONES':
$availability_zones_select_arr[] = array($line[1], $line[1]);
break;
case 'SUBNET':
$subnet_select_arr[] = array($line[1], $line[2] . " (" . $line[3] . ")");
break;
}
}
}
}
}
if ($this->hc->account_type == 'aws' || $this->hc->account_type == 'euca') {
$instance_types[] = array("t1.micro", "t1.micro");
$instance_types[] = array("m1.small", "m1.small");
$instance_types[] = array("m1.medium", "m1.medium");
$instance_types[] = array("m1.large", "m1.large");
$instance_types[] = array("m1.xlarge", "m1.xlarge");
$instance_types[] = array("m3.xlarge", "m3.xlarge");
$instance_types[] = array("m3.2xlarge", "m3.2xlarge");
$instance_types[] = array("c1.medium", "c1.medium");
$instance_types[] = array("c1.xlarge", "c1.xlarge");
$instance_types[] = array("m2.xlarge", "m2.xlarge");
$instance_types[] = array("m2.2xlarge", "m2.2xlarge");
$instance_types[] = array("m2.4xlarge", "m2.4xlarge");
$instance_types[] = array("cr1.8xlarge", "cr1.8xlarge");
$instance_types[] = array("hi1.4xlarge", "hi1.4xlarge");
$instance_types[] = array("hs1.8xlarge", "hs1.8xlarge");
$instance_types[] = array("cc1.4xlarge", "cc1.4xlarge");
$instance_types[] = array("cc2.8xlarge", "cc2.8xlarge");
$instance_types[] = array("cg1.4xlarge", "cg1.4xlarge");
$instance_type_selected = "t1.micro";
}
if ($this->hc->account_type == 'lc-openstack') {
$instance_types = $size_select_arr;
$instance_type_selected = "m1.nano";
}
// AMIs
$ami_select_arr = array();
$image = new image();
$image_id_list = $image->get_ids();
foreach ($image_id_list as $id => $ikey) {
$image_tmp = new image();
$image_tmp->get_instance_by_id($ikey['image_id']);
if ($image_tmp->type === "ami-deployment") {
$ami_select_arr[] = array($image_tmp->id, $image_tmp->comment);
}
}
$response = $this->response;
$form = $response->get_form($this->actions_name, 'add');
$submit = $form->get_elements('submit');
$submit->handler = 'onclick="wait();"';
$form->add($submit, 'submit');
$submit = $form->get_elements('cancel');
$submit->handler = 'onclick="cancel();"';
$form->add($submit, 'cancel');
if ($this->hc->account_type == 'lc-openstack') {
$d['name']['label'] = $this->lang['form_name'];
$d['name']['required'] = false;
$d['name']['validate']['regex'] = '/^[a-z0-9._:\\/-]+$/i';
$d['name']['validate']['errormsg'] = sprintf($this->lang['error_name'], 'a-z0-9._:\\/-');
$d['name']['object']['type'] = 'htmlobject_input';
$d['name']['object']['attrib']['id'] = 'name';
$d['name']['object']['attrib']['name'] = 'name';
$d['name']['object']['attrib']['type'] = 'text';
$d['name']['object']['attrib']['value'] = '';
$d['name']['object']['attrib']['maxlength'] = 255;
}
if ($this->hc->account_type == 'aws' || $this->hc->account_type == 'euca') {
$d['name'] = '';
}
$d['instance_type']['label'] = $this->lang['form_instance_type'];
$d['instance_type']['required'] = true;
$d['instance_type']['object']['type'] = 'htmlobject_select';
$d['instance_type']['object']['attrib']['name'] = 'type';
$d['instance_type']['object']['attrib']['index'] = array(0, 1);
$d['instance_type']['object']['attrib']['options'] = $instance_types;
//.........这里部分代码省略.........
示例11: select
function select()
{
$h = array();
$h['appliance_state']['title'] = ' ';
$h['appliance_state']['sortable'] = false;
/*
$h['appliance_icon']['title'] =' ';
$h['appliance_icon']['sortable'] = false;
*/
$h['appliance_id']['title'] = $this->lang['table_id'];
$h['appliance_name']['title'] = $this->lang['table_name'];
$h['appliance_values']['title'] = ' ';
$h['appliance_values']['sortable'] = false;
$h['login']['title'] = ' ';
$h['login']['sortable'] = false;
// use the appliance link hook
require_once $this->openqrm->get('webdir') . "/plugins/sshterm/openqrm-sshterm-appliance-link-hook.php";
$appliance = new appliance();
$params = $this->response->get_array($this->actions_name, 'select');
$b = array();
$table = $this->response->html->tablebuilder('login', $params);
$table->offset = 0;
$table->sort = 'appliance_id';
$table->limit = 10;
$table->order = 'ASC';
$table->init();
$appliances = $appliance->display_overview($table->offset, 100000, $table->sort, $table->order);
foreach ($appliances as $index => $appliance_db) {
$appliance = new appliance();
$appliance->get_instance_by_id($appliance_db["appliance_id"]);
$resource = new resource();
$resource->get_instance_by_id($appliance->resources);
$kernel = new kernel();
$kernel->get_instance_by_id($appliance_db["appliance_kernelid"]);
$image = new image();
$image->get_instance_by_id($appliance_db["appliance_imageid"]);
$virtualization = new virtualization();
$virtualization->get_instance_by_id($appliance_db["appliance_virtualization"]);
$resource_icon_default = "/openqrm/base/img/appliance.png";
$active_state_icon = "active";
$inactive_state_icon = "inactive";
$login = '';
if ($appliance->stoptime == 0 || $appliance->resources == 0) {
$state_icon = $active_state_icon;
// login
$login = get_sshterm_appliance_link($appliance->id);
if (is_object($login)) {
$login = $login->get_string();
}
} else {
$state_icon = $inactive_state_icon;
$login = '';
}
$str = '<strong>Kernel:</strong> ' . $kernel->name . '<br>
<strong>Image:</strong> ' . $image->name . '<br>
<strong>Resource:</strong> ' . $resource->id . " / " . $resource->ip . '<br>
<strong>Type:</strong> <span class="pill">' . $virtualization->name . "</span>";
$state_pill = $this->response->html->span();
$state_pill->css = "pill";
$state_pill->add($state_icon);
$b[] = array('appliance_state' => $state_pill->get_string(), 'appliance_id' => $appliance->id, 'appliance_name' => $appliance->name, 'appliance_values' => $str, 'login' => $login);
}
$table->id = 'Tabelle';
$table->css = 'htmlobject_table';
$table->border = 1;
$table->cellspacing = 0;
$table->cellpadding = 3;
$table->form_action = $this->response->html->thisfile;
$table->autosort = true;
$table->sort_link = false;
$table->max = count($b);
$table->head = $h;
$table->body = $b;
$table->limit_select = array(array("value" => 5, "text" => 5), array("value" => 10, "text" => 10), array("value" => 20, "text" => 20), array("value" => 30, "text" => 30), array("value" => 50, "text" => 50), array("value" => 100, "text" => 100));
$d = array();
$d['table'] = $table;
return $d;
}
示例12: 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;
//.........这里部分代码省略.........
示例13: create_private_kvm_bf_deployment
function create_private_kvm_bf_deployment($cloud_image_id, $private_disk, $private_image_name)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
global $RESOURCE_INFO_TABLE;
global $event;
$cloudimage = new cloudimage();
$cloudimage->get_instance_by_id($cloud_image_id);
$event->log("create_private_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Creating private image " . $cloudimage->image_id . " on storage.", "", "", 0, 0, 0);
// get image
$image = new image();
$image->get_instance_by_id($cloudimage->image_id);
$image_id = $image->id;
$image_name = $image->name;
$image_type = $image->type;
$image_version = $image->version;
$image_rootdevice = $image->rootdevice;
$image_rootfstype = $image->rootfstype;
$imageid = $image->storageid;
$image_isshared = $image->isshared;
$image_comment = $image->comment;
$image_capabilities = $image->capabilities;
$image_deployment_parameter = $image->deployment_parameter;
// get image storage
$storage = new storage();
$storage->get_instance_by_id($imageid);
$storage_resource_id = $storage->resource_id;
// get deployment type
$deployment = new deployment();
$deployment->get_instance_by_id($storage->type);
// get storage resource
$resource = new resource();
$resource->get_instance_by_id($storage_resource_id);
$resource_id = $resource->id;
$resource_ip = $resource->ip;
// create an admin user to post when cloning has finished
$openqrm_admin_user = new user("openqrm");
$openqrm_admin_user->set_user();
// parse the identifiers
// origin image volume name
$origin_volume_name = basename($image_rootdevice);
// location of the volume (path)
$image_location_name = dirname($image_rootdevice);
// For kvm vms we assume that the image is located on the vm-host
// so we send the auth command to the vm-host instead of the image storage.
// This enables using a NAS/Glusterfs backend with all volumes accessible for all hosts
//
// Still we need to send the remove command to the storage resource since the
// create-phase automatically adapted the image->storageid, we cannot use the vm-resource here
// because cloudimage->resource_id will be set to -1 when the cloudapp is in paused/resize/private state
//
if ($cloudimage->resource_id > 0) {
// try to get the vm resource
$vm_resource = new resource();
$vm_resource->get_instance_by_id($cloudimage->resource_id);
// get the lxc host
$vm_host_resource = new resource();
$vm_host_resource->get_instance_by_id($vm_resource->vhostid);
// san backend ?
if ($vm_host_resource->id != $resource->id) {
$event->log("create_private_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Image " . $image_id . " IS NOT available on this kvm host, " . $resource->id . " not equal " . $vm_host_resource->id . " !! Assuming SAN Backend", "", "", 0, 0, 0);
} else {
$event->log("create_private_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Image " . $image_id . " IS available on this kvm host, " . $resource->id . " equal " . $vm_host_resource->id . ".", "", "", 0, 0, 0);
}
}
$image_resize_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/kvm/bin/openqrm-kvm clone -n " . $origin_volume_name . " -s " . $private_image_name . " -v " . $image_location_name . " -m " . $private_disk . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " -t " . $deployment->type . " --openqrm-cmd-mode background";
$event->log("create_private_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Running : {$image_resize_cmd}", "", "", 0, 0, 0);
$resource->send_command($resource_ip, $image_resize_cmd);
// set the storage specific image root_device parameter
$new_rootdevice = str_replace($origin_volume_name, $private_image_name, $image->rootdevice);
return $new_rootdevice;
}
示例14: image
function get_response()
{
$response = $this->response;
$form = $response->get_form($this->actions_name, 'install1');
$id = $this->response->html->request()->get('image_id');
$submit = $form->get_elements('submit');
$submit->handler = 'onclick="wait();"';
$form->add($submit, 'submit');
$submit = $form->get_elements('cancel');
$submit->handler = 'onclick="cancel();"';
$form->add($submit, 'cancel');
$image = new image();
$image->get_instance_by_id($id);
$storage = new storage();
$deployment = new deployment();
$install_template_type = $this->response->html->request()->get('install_from_template');
if (strlen($install_template_type)) {
$deployment->get_instance_by_type($install_template_type);
$storage_select_arr = $storage->get_ids_by_storage_type($deployment->id);
} else {
$storage_select_arr = array();
}
$storage_select = array();
foreach ($storage_select_arr as $storage_db) {
$storage_id = $storage_db['storage_id'];
$storage->get_instance_by_id($storage_id);
$storage_select[] = array("value" => $storage_id, "label" => $storage_id . " - " . $storage->name);
}
$d['install_server']['label'] = $this->lang['form_install_server'];
$d['install_server']['required'] = true;
$d['install_server']['object']['type'] = 'htmlobject_select';
$d['install_server']['object']['attrib']['index'] = array('value', 'label');
$d['install_server']['object']['attrib']['id'] = 'install_server';
$d['install_server']['object']['attrib']['name'] = 'install_server';
$d['install_server']['object']['attrib']['options'] = $storage_select;
$form->add($d);
$response->form = $form;
return $response;
}
示例15: select
function select()
{
$d = array();
$id = $this->response->html->request()->get('image_id');
if ($id !== '') {
$image = new image();
$image->get_instance_by_id($id);
$storage = new storage();
$storage->get_instance_by_id($image->storageid);
$resource = new resource();
$resource->get_instance_by_id($storage->resource_id);
require_once $this->openqrm->get('basedir') . '/plugins/image-shelf/web/class/imageshelf.class.php';
$imageshelf = new imageshelf();
$imageshelf->get_instance_by_id($this->id);
$file = $this->openqrm->get('basedir') . '/plugins/image-shelf/web/image-lists/' . $imageshelf->name . '/image-shelf.conf';
if ($this->file->exists($file)) {
$this->file->remove($file);
}
$command = $this->openqrm->get('basedir') . '/plugins/image-shelf/bin/openqrm-image-shelf list';
$command .= ' -n ' . $imageshelf->name;
$command .= ' -i ' . $imageshelf->uri;
$command .= ' -u ' . $imageshelf->user;
$command .= ' -p ' . $imageshelf->password;
$command .= ' --openqrm-ui-user ' . $this->user->name;
$command .= ' --openqrm-cmd-mode background';
$openqrm_server = new openqrm_server();
$openqrm_server->send_command($command);
while (!$this->file->exists($file)) {
usleep(10000);
// sleep 10ms to unload the CPU
clearstatcache();
}
sleep(1);
$distribution = '';
$lines = explode("\n", $this->file->get_contents($file));
foreach ($lines as $line) {
$tmp = explode('|', $line);
if (isset($tmp[0]) && $tmp[0] === $this->image) {
$distribution = $tmp[1];
break;
}
}
$command = $this->openqrm->get('basedir') . '/plugins/image-shelf/bin/openqrm-image-shelf get';
$command .= ' -n ' . $imageshelf->name;
$command .= ' -i ' . $imageshelf->uri;
$command .= ' -f ' . $this->image;
$command .= ' -s ' . $resource->ip . ':' . $image->rootdevice;
$command .= ' -d ' . $distribution;
$command .= ' -u ' . $imageshelf->user;
$command .= ' -p ' . $imageshelf->password;
$command .= ' -o ' . $this->openqrm->admin()->name . ' -q ' . $this->openqrm->admin()->password;
$command .= ' --openqrm-ui-user ' . $this->user->name;
$command .= ' --openqrm-cmd-mode background';
$openqrm_server->send_command($command);
$d = sprintf($this->lang['msg'], $image->name, $this->image);
} else {
$h = array();
$h['image_icon']['title'] = ' ';
$h['image_icon']['sortable'] = false;
$h['image_id']['title'] = $this->lang['table_id'];
$h['image_name']['title'] = $this->lang['table_name'];
$h['image_version']['title'] = $this->lang['table_version'];
$h['image_type']['title'] = $this->lang['table_deployment'];
$h['image_isactive']['title'] = $this->lang['table_isactive'];
$h['image_comment']['title'] = $this->lang['table_comment'];
$h['image_comment']['sortable'] = false;
$h['edit']['title'] = ' ';
$h['edit']['sortable'] = false;
$image = new image();
$params = $this->response->get_array($this->actions_name, 'target');
$b = array();
$table = $this->response->html->tablebuilder('imageshelf_target', $params);
$table->offset = 0;
$table->sort = 'image_id';
$table->limit = 10;
$table->order = 'ASC';
$table->max = $image->get_count();
$table->init();
$image_arr = $image->display_overview(0, 10000, $table->sort, $table->order);
$image_icon = "/openqrm/base/img/image.png";
foreach ($image_arr as $index => $image_db) {
// prepare the values for the array
$image = new image();
$image->get_instance_by_id($image_db["image_id"]);
if ($image->type === 'lvm-nfs-deployment' || $image->type === 'nfs-deployment') {
$image_comment = $image_db["image_comment"];
if (!strlen($image_comment)) {
$image_comment = "-";
}
$image_version = $image_db["image_version"];
if (!strlen($image_version)) {
$image_version = "-";
}
// edit
$a = $this->response->html->a();
$a->title = $this->lang['action_edit'];
$a->handler = 'onclick="wait();"';
$a->css = 'edit';
$a->href = $this->response->get_url($this->actions_name, 'target') . '&image_id=' . $image->id;
$image_edit = $a->get_string();
//.........这里部分代码省略.........