function remove() { $response = $this->get_response(); $lvols = $response->html->request()->get($this->identifier_name); $form = $response->form; if ($lvols !== '') { $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 ($lvols 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()) { $name = $this->openqrm->admin()->name; $pass = $this->openqrm->admin()->password; $storage = new storage(); $resource = new resource(); $deployment = new deployment(); $storage->get_instance_by_id($this->response->html->request()->get('storage_id')); $resource->get_instance_by_id($storage->resource_id); $deployment->get_instance_by_id($storage->type); $errors = array(); $message = array(); foreach ($lvols as $key => $lvol) { // check if an appliance is still using the volume as an image $image = new image(); $image->get_instance_by_name($lvol); // 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_vm_image_still_in_use'], $lvol, $image->id, $appliances_using_resource_str); } else { $command = $this->openqrm->get('basedir') . '/plugins/kvm/bin/openqrm-kvm remove'; $command .= ' -n ' . $lvol; $command .= ' -v ' . $this->volgroup; $command .= ' -t ' . $deployment->type; $command .= ' -u ' . $name . ' -p ' . $pass; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $file = $this->openqrm->get('basedir') . '/plugins/kvm/web/storage/' . $resource->id . '.' . $this->volgroup . '.lv.stat'; if ($this->file->exists($file)) { $this->file->remove($file); } $resource->send_command($resource->ip, $command); while (!$this->file->exists($file)) { usleep(10000); // sleep 10ms to unload the CPU clearstatcache(); } $form->remove($this->identifier_name . '[' . $key . ']'); $message[] = sprintf($this->lang['msg_removed'], $lvol); // remove the image of the volume $image->remove_by_name($lvol); } } 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 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; }