| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- /* * ********************************************************************
- * ProxmoxAddon product developed. (Aug 23, 2018)
- * *
- *
- * CREATED BY MODULESGARDEN -> 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 <pawelk@modulesgardne.com>
- */
- 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()
- {
- }
- }
|