function remove() { $response = $this->get_response(); $volume_names = $response->html->request()->get($this->identifier_name); $form = $response->form; if ($volume_names !== '') { $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'); $i = 0; foreach ($volume_names as $ex) { $d['param_f' . $i]['label'] = $ex; $d['param_f' . $i]['object']['type'] = 'htmlobject_input'; $d['param_f' . $i]['object']['attrib']['type'] = 'checkbox'; $d['param_f' . $i]['object']['attrib']['name'] = $this->identifier_name . '[' . $i . ']'; $d['param_f' . $i]['object']['attrib']['value'] = $ex; $d['param_f' . $i]['object']['attrib']['checked'] = true; $i++; } $form->add($d); if (!$form->get_errors() && $response->submit()) { $storage_id = $this->response->html->request()->get('storage_id'); $storage = new storage(); $resource = new resource(); $errors = array(); $message = array(); foreach ($volume_names as $key => $volume_name) { // check if an appliance is still using the volume as an image $image = new image(); $image->get_instance_by_name($volume_name); // check if it is still in use $appliance = new appliance(); $appliances_using_resource = $appliance->get_ids_per_image($image->id); if (count($appliances_using_resource) > 0) { $appliances_using_resource_str = implode(",", $appliances_using_resource[0]); $errors[] = sprintf($this->lang['msg_image_still_in_use'], $volume_name, $image->id, $appliances_using_resource_str); } else { // remove volume $linuxcoe_volume = new linuxcoe_volume(); $linuxcoe_volume->remove_by_name($volume_name); // remove the image of the volume $image->remove_by_name($volume_name); $form->remove($this->identifier_name . '[' . $key . ']'); $message[] = sprintf($this->lang['msg_removed'], $volume_name); } } if (count($errors) === 0) { $response->msg = join('<br>', $message); } else { $msg = array_merge($errors, $message); $response->error = join('<br>', $msg); } } } else { $response->msg = ''; } return $response; }
function duplicate() { $response = $this->get_response(); $form = $response->form; if (!$form->get_errors() && $this->response->submit()) { $storage_id = $this->response->html->request()->get('storage_id'); $storage = new storage(); $resource = new resource(); $deployment = new deployment(); $storage->get_instance_by_id($storage_id); $resource->get_instance_by_id($storage->resource_id); $deployment->get_instance_by_id($storage->type); $name = $form->get_request('name'); // check if volume / image name is aleady existing $image_check = new image(); $image_check->get_instance_by_name($name); if (isset($image_check->id) && $image_check->id > 0) { $error = sprintf($this->lang['error_image_exists'], $name); } $linuxcoe_volume = new linuxcoe_volume(); $linuxcoe_volume->get_instance_by_name($name); if (isset($linuxcoe_volume->id) && $linuxcoe_volume->id > 0) { $error = sprintf($this->lang['error_exists'], $name); } if (isset($error)) { $response->error = $error; } else { // add volume $linuxcoe_volume->get_instance_by_name($this->volume); $volume_fields = array(); $volume_fields["linuxcoe_volume_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $volume_fields['linuxcoe_volume_name'] = $name; $volume_fields['linuxcoe_volume_root'] = $linuxcoe_volume->root; $volume_fields['linuxcoe_volume_description'] = $linuxcoe_volume->description; $linuxcoe_volume->add($volume_fields); // add image $tables = $this->openqrm->get('table'); $image_fields = array(); $image_fields["image_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $image_fields['image_name'] = $name; $image_fields['image_type'] = $deployment->type; $image_fields['image_rootfstype'] = 'local'; $image_fields['image_storageid'] = $storage->id; $image_fields['image_comment'] = "Image Object for volume {$name}"; $image_fields['image_rootdevice'] = 'local'; $image = new image(); $image->add($image_fields); $response->msg = sprintf($this->lang['msg_cloned'], $this->volume, $name); // save image id in response for the wizard $response->image_id = $image_fields["image_id"]; } } return $response; }
function edit() { if ($this->deployment->type === 'linuxcoe-deployment') { $resource_icon_default = "/img/resource.png"; $storage_icon = "/plugins/linuxcoe/img/plugin.png"; $state_icon = $this->openqrm->get('baseurl') . "/img/" . $this->resource->state . ".png"; if ($this->file->exists($this->openqrm->get('webdir') . $storage_icon)) { $resource_icon_default = $storage_icon; } $resource_icon_default = $this->openqrm->get('baseurl') . $resource_icon_default; $d['state'] = '<img width="24" height="24" src="' . $state_icon . '">'; $d['icon'] = '<img width="24" height="24" src="' . $resource_icon_default . '">'; $d['resource'] = $this->resource->id . ' / ' . $this->resource->ip; $d['name'] = $this->storage->name; $d['id'] = $this->storage->id; $a = $this->response->html->a(); $a->label = $this->lang['action_add']; $a->css = 'add'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "add"); $d['add'] = $a->get_string(); $body = array(); $identifier_disabled = array(); $table = $this->response->html->tablebuilder('linuxcoe_edit', $this->response->get_array($this->actions_name, 'edit')); $table->sort = 'linuxcoe_volume_id'; $table->limit = 10; $table->offset = 0; $table->order = 'ASC'; $table->autosort = true; $table->sort_link = false; $table->init(); $linuxcoe_volume = new linuxcoe_volume(); $linuxcoe_volume_arr = $linuxcoe_volume->display_overview(0, 10000, $table->sort, $table->order); if (count($linuxcoe_volume_arr) >= 1) { foreach ($linuxcoe_volume_arr as $k => $v) { $c = $this->response->html->a(); $c->title = $this->lang['action_clone']; $c->label = $this->lang['action_clone']; $c->handler = 'onclick="wait();"'; $c->css = 'clone'; $c->href = $this->response->get_url($this->actions_name, "clone") . '&volume=' . $v['linuxcoe_volume_name']; // edit image $local_image = new image(); $local_image->get_instance_by_name($v['linuxcoe_volume_name']); $e = $this->response->html->a(); $e->title = $this->lang['action_edit']; $e->label = $this->lang['action_edit']; $e->handler = 'onclick="wait();"'; $e->css = 'edit'; $e->href = '/openqrm/base/index.php?base=image&image_action=edit&image_id=' . $local_image->id; $body[] = array('icon' => $d['icon'], 'linuxcoe_volume_id' => $v['linuxcoe_volume_id'], 'linuxcoe_volume_name' => $v['linuxcoe_volume_name'], 'linuxcoe_volume_root' => $v['linuxcoe_volume_root'], 'description' => $v['linuxcoe_volume_description'], 'clone' => $c, 'edit' => $e); } } $h['icon']['title'] = ' '; $h['icon']['sortable'] = false; $h['linuxcoe_volume_id']['title'] = $this->lang['table_id']; $h['linuxcoe_volume_name']['title'] = $this->lang['table_name']; $h['linuxcoe_volume_root']['title'] = $this->lang['table_root']; $h['description']['title'] = $this->lang['table_description']; $h['description']['sortable'] = false; $h['clone']['title'] = ' '; $h['clone']['sortable'] = false; $h['edit']['title'] = ' '; $h['edit']['sortable'] = false; $table->id = 'Tabelle'; $table->css = 'htmlobject_table'; $table->border = 1; $table->cellspacing = 0; $table->cellpadding = 3; $table->form_action = $this->response->html->thisfile; $table->max = count($linuxcoe_volume_arr); $table->head = $h; $table->body = $body; $table->identifier = 'linuxcoe_volume_name'; $table->identifier_name = $this->identifier_name; $table->identifier_disabled = $identifier_disabled; $table->actions_name = $this->actions_name; $table->actions = array(array('remove' => $this->lang['action_remove'])); $d['table'] = $table->get_string(); return $d; } else { return false; } }