http://modulesgarden.com * CONTACT -> contact@modulesgarden.com * * * This software is furnished under a license and may be used and copied * only in accordance with the terms of such license and with the * inclusion of the above copyright notice. This software or any other * copies thereof may not be provided or otherwise made available to any * other person. No title to and ownership of the software is hereby * transferred. * * * ******************************************************************** */ namespace ModulesGarden\ProxmoxAddon\App\UI\VmCleaner\Providers; use MGProvision\Proxmox\v2 as proxmox; use ModulesGarden\ProxmoxAddon as main; use ModulesGarden\ProxmoxAddon\Core\UI\Interfaces\AdminArea; use ModulesGarden\ProxmoxAddon\Core\UI\ResponseTemplates\HtmlDataJsonResponse; use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Forms\DataProviders\BaseDataProvider; /** * * Description of RangeVmProvider * * @author Pawel Kopec */ class VmProvider extends BaseDataProvider implements AdminArea { use main\App\Services\BaseService; public function read() { if (!$this->actionElementId) { return false; } $this->data = json_decode(base64_decode($this->actionElementId), true); $this->data['serverId'] = $this->getRequestValue('id'); } public function delete() { $this->setServerId($this->formData['serverId']); $this->getApi()->setInstance(); $vm = $this->getVm($this->formData['node'], $this->formData['vmid'], $this->formData['type']); $haResurce = new proxmox\models\HaResource(); $haResurce->setSid($vm->getVmid()) ->setType($vm->getVirtualization() == "lxc" ? "ct" : "vm"); if ($haResurce->exist()) { $haResurce->delete(); } $vm->delete(); main\Core\ServiceLocator::call('lang')->addReplacementConstant('vmid', $this->formData['vmid']); sleep(1); return (new HtmlDataJsonResponse())->setMessageAndTranslate('Deleting Virtual Machine :vmid: in progress'); } private function getVm($node, $vmid, $type) { switch ($type) { case 'qemu' : $vm = new proxmox\models\Kvm($node, $vmid); break; case 'lxc': $vm = new proxmox\models\Lxc($node, $vmid); break; default : throw new \Exception(sprintf("Unkown virtualization %s type", $type)); } return $vm; } public function deleteMass() { if (!$this->getRequestValue('massActions')) { return (new HtmlDataJsonResponse())->setMessageAndTranslate('Bug no massActions data!')->setStatusError(); return; } $this->setServerId($this->getRequestValue('id')); $this->getApi()->setInstance(); foreach ($this->getRequestValue('massActions') as $id) { $data = json_decode(base64_decode($id), true); $this->getVm($data['node'], $data['vmid'], $data['type'])->delete(); } sleep(1); return (new HtmlDataJsonResponse())->setMessageAndTranslate('Deleting the selected Virtual Machines in progress'); } public function update() { } }