function get_response() { $response = $this->response; $form = $response->get_form($this->actions_name, 'step3'); $resource = new resource(); $resource->get_instance_by_id($this->appliance->resources); // if not openQRM resource if ($resource->id != 0) { $virtualization = new virtualization(); $virtualization->get_instance_by_id($resource->vtype); } $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'); // prepare image list according to the resource capabilities + vtype $image = new image(); $list = $image->get_list(); unset($list[0]); unset($list[1]); $images = array(); // openQRM if ($resource->id == 0) { $images[] = array(0, 'Local openQRM Installation'); // local-server integrated resource } else { if (strstr($resource->capabilities, "TYPE=local-server")) { $local_image = new image(); $local_image->get_instance_by_id($resource->imageid); $images[] = array($local_image->id, 'Local OS Installation'); // local-deployment VMs } else { if (strstr($virtualization->type, "-vm-local")) { $virtualization_plugin_name = $virtualization->get_plugin_name(); $deployment = new deployment(); $deployment_id_arr = $deployment->get_deployment_ids(); $possible_deployment_types_arr = ''; foreach ($deployment_id_arr as $deployment_id_db) { $deployment_id = $deployment_id_db['deployment_id']; $deployment->get_instance_by_id($deployment_id); if ($deployment->storagetype === $virtualization_plugin_name) { $possible_deployment_types_arr[] = $deployment->type; } } // filter image list with only the images from the VM deployment type foreach ($list as $value) { $image_id = $value['value']; $image->get_instance_by_id($image_id); // is image active ? then do not show it here if ($image->isactive == 1) { continue; } if (!in_array($image->type, $possible_deployment_types_arr)) { continue; } // filter local-server images $images[] = array($image_id, $image->id . ' / ' . $image->name . ' (' . $image->type . ')'); } // network-deployment - show only network-boot images } else { if (strstr($virtualization->type, "-vm-net")) { foreach ($list as $value) { $image_id = $value['value']; $image->get_instance_by_id($image_id); // is image active ? then do not show it here if ($image->isactive == 1) { continue; } // filter local-server images if (strstr($image->capabilities, "TYPE=local-server")) { continue; } $is_network_deployment = false; if ($image->is_network_deployment() === true) { $is_network_deployment = true; } if ($is_network_deployment) { $images[] = array($image_id, $image->id . ' / ' . $image->name . ' (' . $image->type . ')'); } } // network deployment - physical systems - show only network-boot images } else { foreach ($list as $value) { $image_id = $value['value']; $image->get_instance_by_id($image_id); // is image active ? then do not show it here if ($image->isactive == 1) { continue; } // filter local-server images if (strstr($image->capabilities, "TYPE=local-server")) { continue; } $is_network_deployment = false; if ($image->is_network_deployment() === true) { $is_network_deployment = true; } if ($is_network_deployment) { $images[] = array($image_id, $image->id . ' / ' . $image->name . ' (' . $image->type . ')'); } } } } } } // handle appliance is new or edited $selected = $this->response->html->request()->get('image_id'); if ($selected === '' && isset($this->appliance->imageid)) { $selected = $this->appliance->imageid; } $d['image']['label'] = $this->lang['form_image']; $d['image']['required'] = true; $d['image']['object']['type'] = 'htmlobject_select'; $d['image']['object']['attrib']['index'] = array(0, 1); $d['image']['object']['attrib']['id'] = 'image'; $d['image']['object']['attrib']['name'] = 'image'; $d['image']['object']['attrib']['options'] = $images; $d['image']['object']['attrib']['selected'] = array($selected); $d['image_edit'] = ''; if ($this->appliance->resources != 0) { $d['image_edit']['label'] = $this->lang['form_image_edit']; $d['image_edit']['object']['type'] = 'htmlobject_input'; $d['image_edit']['object']['attrib']['type'] = 'checkbox'; $d['image_edit']['object']['attrib']['id'] = 'image_edit'; $d['image_edit']['object']['attrib']['name'] = 'image_edit'; $d['image_edit']['object']['attrib']['checked'] = true; } $form->add($d); $response->form = $form; return $response; }
function action() { $deployment = new deployment(); $deployment_id_array = $deployment->get_deployment_ids(); $info = '<div class="infotext">' . $this->lang['info'] . '</div>'; $storage_link_section = ''; if (isset($this->appliance)) { $resource = new resource(); $resource->get_instance_by_id($this->appliance->resources); $virtualization = new virtualization(); $virtualization->get_instance_by_id($resource->vtype); #$resourceinfo = '<b>Server:</b> '.$this->appliance->id.' / '.$this->appliance->name.'<br>'; $info = '<b>Resource:</b> ' . $resource->id . ' / ' . $resource->ip . ' ' . $resource->hostname . ' - ' . $virtualization->name . '<br><br>' . $info; foreach ($deployment_id_array as $id) { $new_image_link = ''; $deployment->get_instance_by_id($id['deployment_id']); if ($deployment->storagetype != 'none' && $deployment->storagetype != 'local-server') { if (strstr($resource->capabilities, "TYPE=local-server")) { // disable - local-server already has an image and cannot be re-deployed with a differenet one continue; } else { if (strstr($virtualization->type, "-vm-local")) { // get virt plugin name, check if deployment->storagetype == virt plugin name if ($deployment->storagetype === $virtualization->get_plugin_name()) { $new_image_link = $this->response->get_url($this->actions_name, 'load') . '&iplugin=' . $deployment->storagetype; } } else { if (strstr($virtualization->type, "-vm-net")) { // find with image-deployment type hook if deployment is network-deployment $is_network_deployment = false; $rootdevice_identifier_hook = $this->openqrm->get('basedir') . "/web/boot-service/image." . $deployment->type . ".php"; if (file_exists($rootdevice_identifier_hook)) { require_once "{$rootdevice_identifier_hook}"; $image_is_network_deployment_function = "get_" . $deployment->type . "_is_network_deployment"; $image_is_network_deployment_function = str_replace("-", "_", $image_is_network_deployment_function); if ($image_is_network_deployment_function()) { $new_image_link = $this->response->get_url($this->actions_name, 'load') . '&iplugin=' . $deployment->storagetype; } } } else { // $new_image_link = "/openqrm/base/index.php?plugin=".$deployment->storagetype; // same as vm-net // all network deployment types } } } if ($new_image_link !== '') { $storage_link_section .= "<a href='" . $new_image_link . "' style='text-decoration: none'><img title='" . sprintf($this->lang['create_image'], $deployment->description) . "' alt='" . sprintf($this->lang['create_image'], $deployment->description) . "' src='/openqrm/base/plugins/" . $deployment->storagetype . "/img/plugin.png' border=0> " . $deployment->description . "</a><br>"; } } } } else { foreach ($deployment_id_array as $deployment_id) { $deployment->get_instance_by_id($deployment_id['deployment_id']); if ($deployment->storagetype != 'none' && $deployment->storagetype != 'local-server') { #$new_image_link = "/openqrm/base/index.php?plugin=".$deployment->storagetype; $new_image_link = $this->response->get_url($this->actions_name, 'load') . '&iplugin=' . $deployment->storagetype; switch ($deployment->storagetype) { case 'coraid-storage': case 'equallogic-storage': case 'netapp-storage': $new_image_link = "/openqrm/base/index.php?iframe=/openqrm/base/plugins/" . $deployment->storagetype . "/" . $deployment->storagetype . "-manager.php"; break; } $storage_link_section .= "<a href='" . $new_image_link . "' style='text-decoration: none'><img title='" . sprintf($this->lang['create_image'], $deployment->description) . "' alt='" . sprintf($this->lang['create_image'], $deployment->description) . "' src='/openqrm/base/plugins/" . $deployment->storagetype . "/img/plugin.png' border=0> " . $deployment->description . "</a><br>"; } } } if (!strlen($storage_link_section)) { $storage_link_section = $this->lang['start_storage_plugin']; } $t = $this->response->html->template($this->tpldir . '/image-add.tpl.php'); $t->add($storage_link_section, 'image_new'); $t->add($this->lang['label'], 'label'); $t->add($this->lang['title'], 'title'); $t->add($this->openqrm->get('baseurl'), 'baseurl'); $t->add($this->lang['please_wait'], 'please_wait'); $t->add($this->lang['canceled'], 'canceled'); $t->add($this->prefix_tab, 'prefix_tab'); $t->add($info, 'info'); $t->group_elements(array('param_' => 'form')); return $t; }
function get_response() { $response = $this->response; $form = $response->get_form($this->actions_name, 'edit'); $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 = $this->openqrm->image(); $image->get_instance_by_id($id); $storage = $this->openqrm->storage(); $storage->get_instance_by_id($image->storageid); $deployment = $this->openqrm->deployment(); $deployment->get_instance_by_id($storage->type); $storage_resource = $this->openqrm->resource(); $storage_resource->get_instance_by_id($storage->resource_id); // making the deployment parameters plugg-able $rootdevice_identifier_hook = $this->openqrm->get('basedir') . "/web/boot-service/image." . $deployment->type . ".php"; if (file_exists($rootdevice_identifier_hook)) { require_once "{$rootdevice_identifier_hook}"; // run function returning rootdevice array $get_rootfs_transfer_methods_function = "get_" . $deployment->type . "_rootfs_transfer_methods"; $get_rootfs_transfer_methods_function = str_replace("-", "_", $get_rootfs_transfer_methods_function); $rootfs_transfer_methods = $get_rootfs_transfer_methods_function(); $get_rootfs_set_password_method_function = "get_" . $deployment->type . "_rootfs_set_password_method"; $get_rootfs_set_password_method_function = str_replace("-", "_", $get_rootfs_set_password_method_function); $rootfs_set_password_method = $get_rootfs_set_password_method_function(); $get_rootfs_local_deployment_enabled_function = "get_" . $deployment->type . "_local_deployment_enabled"; $get_rootfs_local_deployment_enabled_function = str_replace("-", "_", $get_rootfs_local_deployment_enabled_function); $rootfs_local_deployment_enabled = $get_rootfs_local_deployment_enabled_function(); } else { $rootfs_transfer_methods = false; $rootfs_set_password_method = false; $rootfs_local_deployment_enabled = false; } // making the local deployment parameter plugg-able $local_deployment_methods_input = ""; if ($rootfs_local_deployment_enabled) { $local_deployment_methods_arr[] = array("value" => "", "label" => ""); $local_deployment = new deployment(); $deployment_id_arr = $local_deployment->get_deployment_ids(); foreach ($deployment_id_arr as $deployment_id) { $local_deployment->get_instance_by_id($deployment_id['deployment_id']); $local_deployment_templates_identifier_hook = $this->openqrm->get('basedir') . "/web/boot-service/template." . $local_deployment->type . ".php"; if (file_exists($local_deployment_templates_identifier_hook)) { require_once "{$local_deployment_templates_identifier_hook}"; $deployment_function = "get_" . "{$local_deployment->type}" . "_methods"; $deployment_function = str_replace("-", "_", $deployment_function); $local_deployment_methods_arr[] = $deployment_function(); } } } // in case the deployment method provides the rootfs-transfer options $nfs_image_identifier_array = array(); if ($rootfs_transfer_methods) { // prepare the install-from and transfer-to selects $nfs_image_identifier_array[] = array("value" => "", "label" => ""); $nfs_image = new image(); $image_arr = $nfs_image->get_ids(); foreach ($image_arr as $id) { $i_id = $id['image_id']; $timage = new image(); $timage->get_instance_by_id($i_id); if (strstr($timage->type, "nfs")) { $timage_name = $timage->name; $nfs_image_identifier_array[] = array("value" => "{$i_id}", "label" => "{$timage_name}"); } } } $html = new htmlobject_div(); $html->text = '<a href="../../plugins/' . $deployment->storagetype . '/' . $deployment->storagetype . '-about.php" target="_blank" class="doculink">' . $deployment->description . '</a>'; $html->id = 'htmlobject_image_type'; $storage_deploy_box = new htmlobject_box(); $storage_deploy_box->id = 'htmlobject_box_image_deploy'; $storage_deploy_box->css = 'htmlobject_box'; $storage_deploy_box->label = 'Deployment'; $storage_deploy_box->content = $html; $html = new htmlobject_div(); $html->text = $deployment->storagedescription; $html->id = 'htmlobject_storage_type'; $storage_type_box = new htmlobject_box(); $storage_type_box->id = 'htmlobject_box_storage_type'; $storage_type_box->css = 'htmlobject_box'; $storage_type_box->label = 'Storage'; $storage_type_box->content = $html; #$storage_resource->id / $html = new htmlobject_div(); $html->text = "{$storage_resource->ip}"; $html->id = 'htmlobject_storage_resource'; $storage_resource_box = new htmlobject_box(); $storage_resource_box->id = 'htmlobject_box_storage_resource'; $storage_resource_box->css = 'htmlobject_box'; $storage_resource_box->label = 'Resource'; $storage_resource_box->content = $html; // in case the deployment type allows to set the password in the image if ($rootfs_set_password_method) { $d['image_password']['label'] = $this->lang['form_image_password']; $d['image_password']['required'] = false; $d['image_password']['object']['type'] = 'htmlobject_input'; $d['image_password']['object']['attrib']['id'] = 'pass_1'; $d['image_password']['object']['attrib']['type'] = 'password'; $d['image_password']['object']['attrib']['name'] = 'image_password'; $d['image_password_2']['label'] = $this->lang['form_image_password_repeat']; $d['image_password_2']['required'] = false; $d['image_password_2']['object']['type'] = 'htmlobject_input'; $d['image_password_2']['object']['attrib']['id'] = 'pass_2'; $d['image_password_2']['object']['attrib']['type'] = 'password'; $d['image_password_2']['object']['attrib']['name'] = 'image_password_2'; } else { $d['image_password'] = ''; $d['image_password_2'] = ''; } if ($rootfs_transfer_methods) { $d['install_from_local']['label'] = $this->lang['form_install_from_local']; $d['install_from_local']['required'] = false; $d['install_from_local']['object']['type'] = 'htmlobject_input'; $d['install_from_local']['object']['attrib']['id'] = 'install_from_local'; $d['install_from_local']['object']['attrib']['name'] = 'install_from_local'; $d['transfer_to_local']['label'] = $this->lang['form_transfer_to_local']; $d['transfer_to_local']['required'] = false; $d['transfer_to_local']['object']['type'] = 'htmlobject_input'; $d['transfer_to_local']['object']['attrib']['id'] = 'transfer_to_local'; $d['transfer_to_local']['object']['attrib']['name'] = 'transfer_to_local'; $d['install_from_nfs']['label'] = $this->lang['form_install_from_nfs']; $d['install_from_nfs']['required'] = false; $d['install_from_nfs']['object']['type'] = 'htmlobject_select'; $d['install_from_nfs']['object']['attrib']['index'] = array('value', 'label'); $d['install_from_nfs']['object']['attrib']['id'] = 'install_from_nfs'; $d['install_from_nfs']['object']['attrib']['name'] = 'install_from_nfs'; $d['install_from_nfs']['object']['attrib']['options'] = $nfs_image_identifier_array; $d['transfer_to_nfs']['label'] = $this->lang['form_transfer_to_nfs']; $d['transfer_to_nfs']['required'] = false; $d['transfer_to_nfs']['object']['type'] = 'htmlobject_select'; $d['transfer_to_nfs']['object']['attrib']['index'] = array('value', 'label'); $d['transfer_to_nfs']['object']['attrib']['id'] = 'transfer_to_nfs'; $d['transfer_to_nfs']['object']['attrib']['name'] = 'transfer_to_nfs'; $d['transfer_to_nfs']['object']['attrib']['options'] = $nfs_image_identifier_array; } else { $d['install_from_local'] = ''; $d['transfer_to_local'] = ''; $d['install_from_nfs'] = ''; $d['transfer_to_nfs'] = ''; } if ($rootfs_local_deployment_enabled) { $d['install_from_template']['label'] = $this->lang['form_install_from_template']; $d['install_from_template']['required'] = false; $d['install_from_template']['object']['type'] = 'htmlobject_select'; $d['install_from_template']['object']['attrib']['index'] = array('value', 'label'); $d['install_from_template']['object']['attrib']['id'] = 'install_from_template'; $d['install_from_template']['object']['attrib']['name'] = 'install_from_template'; $d['install_from_template']['object']['attrib']['options'] = $local_deployment_methods_arr; } else { $d['install_from_template'] = ''; } $image_version_arr[] = array("value" => "Linux", "label" => "Linux"); $image_version_arr[] = array("value" => "Windows", "label" => "Windows"); $image_version_arr[] = array("value" => "Other", "label" => "Other"); $d['image_version']['label'] = $this->lang['form_image_version']; $d['image_version']['required'] = false; $d['image_version']['object']['type'] = 'htmlobject_select'; $d['image_version']['object']['attrib']['index'] = array('value', 'label'); $d['image_version']['object']['attrib']['id'] = 'image_version'; $d['image_version']['object']['attrib']['name'] = 'image_version'; $d['image_version']['object']['attrib']['options'] = $image_version_arr; $d['image_version']['object']['attrib']['selected'] = array($image->version); $d['image_comment']['label'] = $this->lang['form_comment']; $d['image_comment']['object']['type'] = 'htmlobject_textarea'; $d['image_comment']['object']['attrib']['id'] = 'comment'; $d['image_comment']['object']['attrib']['name'] = 'image_comment'; $d['image_comment']['object']['attrib']['value'] = $image->comment; $form->add($d); $response->form = $form; return $response; }