コード例 #1
0
 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();
                 // 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->form_action = $this->response->html->thisfile;
         $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));
         $d['form'] = $this->response->get_form($this->actions_name, 'target', false)->get_elements();
         $d['table'] = $table;
     }
     return $d;
 }
コード例 #2
0
 function imtarget()
 {
     $h = array();
     $h['image_icon']['title'] = '&#160;';
     $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'] = '&#160;';
     $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 = "&#160;";
             }
             // 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;
 }
コード例 #3
0
ファイル: image.select.class.php プロジェクト: kelubo/OpenQRM
 function select()
 {
     $d = array();
     $h = array();
     $h['image_isactive']['title'] = $this->lang['table_isactive'];
     $h['image_id']['title'] = $this->lang['table_id'];
     $h['image_id']['hidden'] = true;
     $h['image_name']['title'] = $this->lang['table_name'];
     $h['image_name']['hidden'] = true;
     $h['image_type']['title'] = $this->lang['table_deployment'];
     $h['image_type']['hidden'] = true;
     $h['image_rootdevice']['title'] = $this->lang['table_root'];
     $h['image_rootdevice']['hidden'] = true;
     $h['image_version']['title'] = $this->lang['table_version'];
     $h['image_version']['hidden'] = true;
     $h['image_capabilities']['title'] = $this->lang['table_capabilities'];
     $h['image_capabilities']['hidden'] = true;
     $h['image_data']['title'] = '&#160;';
     $h['image_data']['sortable'] = false;
     $h['image_comment']['title'] = '&#160;';
     $h['image_comment']['sortable'] = false;
     $h['image_edit']['title'] = '&#160;';
     $h['image_edit']['sortable'] = false;
     $image = new image();
     $params = $this->response->get_array($this->actions_name, 'select');
     $b = array();
     // unset unnecessary params
     unset($params['image[sort]']);
     unset($params['image[order]']);
     unset($params['image[limit]']);
     unset($params['image[offset]']);
     unset($params['image_filter']);
     $table = $this->response->html->tablebuilder('image', $params);
     $table->offset = 0;
     $table->sort = 'image_id';
     $table->limit = 20;
     $table->order = 'ASC';
     $table->max = $image->get_count();
     $table->init();
     // handle table params
     $tps = $table->get_params();
     $tp = '';
     foreach ($tps['image'] as $k => $v) {
         $tp .= '&image[' . $k . ']=' . $v;
     }
     $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) {
         if ($this->response->html->request()->get('image_filter') === '' || $this->response->html->request()->get('image_filter') == $image_db["image_type"]) {
             // prepare the values for the array
             $image = new image();
             $image->get_instance_by_id($image_db["image_id"]);
             // edit
             $a = $this->response->html->a();
             $a->title = $this->lang['action_edit'];
             $a->label = $this->lang['action_edit'];
             //	$a->handler = 'onclick="wait();"';
             $a->css = 'edit';
             $a->href = $this->response->get_url($this->actions_name, 'edit') . '&image_id=' . $image->id . '' . $tp;
             $image_edit = $a->get_string();
             // force remove
             $a = $this->response->html->a();
             $a->title = $this->lang['action_remove'];
             $a->label = $this->lang['action_remove'];
             $a->css = 'remove';
             $a->href = $this->response->get_url($this->actions_name, 'remove') . '&image_identifier=' . $image->id . '' . $tp;
             $image_remove = $a->get_string();
             $image_actions = $image_edit;
             // set the active icon
             $isactive_icon = '<span class="pill inactive">' . $this->lang['lang_inactive'] . '</span>';
             if ($image_db["image_isactive"] == 1) {
                 $isactive_icon = '<span class="pill active">' . $this->lang['lang_active'] . '</span>';
             } else {
                 $image_actions .= $image_remove;
             }
             // infos
             $storage = new storage();
             $storage->get_instance_by_id($image_db['image_storageid']);
             $deployment = new deployment();
             $deployment->get_instance_by_id($storage->type);
             $link = $storage->name;
             if ($deployment->storagetype !== 'local-server') {
                 $a = $this->response->html->a();
                 $a->label = $storage->name;
                 $a->handler = 'onclick="wait();"';
                 $a->href = $this->response->html->thisfile . '?plugin=' . $deployment->storagetype . '&' . str_replace('-', '_', $deployment->storagetype) . '_action=edit&storage_id=' . $storage->id;
                 $link = $a->get_string();
             }
             $data = '<div class="data">';
             $data .= '<b>' . $this->lang['table_id'] . '</b>: ' . $image_db["image_id"] . '<br>';
             $data .= '<b>' . $this->lang['table_name'] . '</b>: ' . $image_db["image_name"] . '<br>';
             $data .= '<b>' . $this->lang['table_deployment'] . '</b>: ' . $image_db["image_type"] . '<br>';
             $data .= '<b>' . $this->lang['table_storage'] . '</b>: ' . $link . '<br>';
             if (isset($image_db["image_rootdevice"])) {
                 $root = str_replace($image_db["image_name"], '', $image_db["image_rootdevice"]);
                 // vmware
                 $root = str_replace(':/.vmdk', '', $root);
                 $data .= '<b>' . $this->lang['table_root'] . '</b>: ' . $root . '<br>';
             }
             if (isset($image_db["image_version"])) {
                 $data .= '<b>' . $this->lang['table_version'] . '</b>: ' . $image_db["image_version"] . '<br>';
             }
             if (isset($image_db["image_capabilities"])) {
                 $data .= '<b>' . $this->lang['table_capabilities'] . '</b>: ' . $image_db["image_capabilities"];
             }
             $data .= '</div>';
             $b[] = array('image_isactive' => $isactive_icon, 'image_id' => $image_db["image_id"], 'image_name' => $image_db["image_name"], 'image_rootdevice' => $image_db["image_rootdevice"], 'image_version' => $image_db["image_version"], 'image_capabilities' => $image_db["image_capabilities"], 'image_data' => $data, 'image_comment' => $image_db["image_comment"], 'image_edit' => $image_actions);
         }
     }
     // Filter
     $types = $this->openqrm->deployment();
     $list = $types->get_list();
     $filter = array();
     foreach ($list as $l) {
         $filter[] = array($l['label']);
     }
     asort($filter);
     array_unshift($filter, array('', ''));
     $select = $this->response->html->select();
     $select->add($filter, array(0, 0));
     $select->name = 'image_filter';
     $select->handler = 'onchange="wait();this.form.submit();return false;"';
     $select->selected = array($this->response->html->request()->get('image_filter'));
     $box = $this->response->html->box();
     $box->add($select);
     $box->id = 'image_filter_box';
     $box->css = 'htmlobject_box';
     $box->label = $this->lang['lang_filter'];
     $add = $this->response->html->a();
     $add->title = $this->lang['action_add'];
     $add->label = $this->lang['action_add'];
     $add->handler = 'onclick="wait();"';
     $add->css = 'add';
     $add->href = $this->response->get_url($this->actions_name, "add") . '' . $tp;
     $table->id = 'Tabelle';
     $table->css = 'htmlobject_table';
     $table->border = 1;
     $table->cellspacing = 0;
     $table->cellpadding = 3;
     $table->autosort = false;
     $table->sort_link = false;
     if ($this->response->html->request()->get('image_filter') !== '') {
         $table->max = count($b);
     } else {
         $table->max = $image->get_count() - 2;
     }
     $table->head = $h;
     $table->body = $b;
     $table->form_action = $this->response->html->thisfile;
     $d['form'] = $this->response->get_form($this->actions_name, 'select', false)->get_elements();
     $d['add'] = $add->get_string();
     $d['table'] = $table;
     $d['filter'] = $box->get_string();
     return $d;
 }