| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- /* * ********************************************************************
- * ProxmoxVPS Product developed. (27.03.19)
- * *
- *
- * 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\Servers\ProxmoxVps\App\UI\Snapshot\Providers;
- use MGProvision\Proxmox\v2\models\Snapshot;
- use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
- use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
- use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\ClientArea;
- use ModulesGarden\Servers\ProxmoxVps\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
- use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
- class SnapshotProvider extends BaseDataProvider implements ClientArea
- {
- use ProductService;
- use ApiService;
- public function read()
- {
- if ($this->actionElementId)
- {
- $this->data = json_decode(base64_decode($this->actionElementId), true);
- }
- }
- public function create()
- {
- $this->acl()->snapshot();
- $this->resourceGuard()->snapshotLimit();
- $snapshot = new Snapshot();
- $snapshot->setApi($this->api());
- $snapshot->setPath($this->vm()->getPath() . "/snapshot");
- $snapshot->setAttributes([
- "name" => $this->formData['name'],
- "description" => $this->formData['description'],
- ]);
- if ($this->formData['vmstate'])
- {
- $snapshot->setVmstate($this->formData['vmstate'] == "on" ? 1 : 0);
- }
- $taskId = $snapshot->create();
- sleep(1);
- $task = $this->vm()->node()->task($taskId);
- if($task->isFalied()){
- return (new HtmlDataJsonResponse())
- ->setStatusError()
- ->setMessageAndTranslate($task->getExitstatus());
- }
- return (new HtmlDataJsonResponse())
- ->setStatusSuccess()
- ->setMessageAndTranslate('The snapshot has been created successfully')
- ->addData('createButtonStatus', $this->resourceGuard()->hasSnapshotLimit())
- ->setCallBackFunction('pmToggleButton');
- }
- public function update()
- {
- $this->acl()->snapshot();
- $snapshot = new Snapshot();
- $snapshot->setApi($this->api());
- $snapshot->setPath($this->vm()->getPath() . "/snapshot/" . $this->formData['name']);
- $snapshot->setAttributes([
- "name" => $this->formData['name'],
- "description" => $this->formData['description'],
- ]);
- $snapshot->update();
- return (new HtmlDataJsonResponse())
- ->setStatusSuccess()
- ->setMessageAndTranslate('The snapshot has been updated successfully');
- }
- public function delete()
- {
- $this->acl()->snapshot();
- $snapshot = new Snapshot();
- $snapshot->setApi($this->api());
- $snapshot->setPath($this->vm()->getPath() . "/snapshot/" . $this->formData['name']);
- $snapshot->delete();
- sleep(1);
- return (new HtmlDataJsonResponse())
- ->setStatusSuccess()
- ->setMessageAndTranslate('The snapshot has been deleted successfully')
- ->addData('createButtonStatus', $this->resourceGuard()->hasSnapshotLimit())
- ->setCallBackFunction('pmToggleButton');
- }
- public function deleteMass()
- {
- $this->acl()->snapshot();
- $snapshot = new Snapshot();
- $snapshot->setApi($this->api());
- foreach ($this->request->get('massActions') as $id)
- {
- $data = json_decode(base64_decode($id), true);
- $name = $data['name'];
- $snapshot->setPath($this->vm()->getPath() . "/snapshot/" . $name);
- $snapshot->delete();
- sleep(1);
- }
- return (new HtmlDataJsonResponse())
- ->setStatusSuccess()
- ->setMessageAndTranslate('The snapshots have been deleted successfully')
- ->addData('createButtonStatus', $this->resourceGuard()->hasSnapshotLimit())
- ->setCallBackFunction('pmToggleButton');
- }
- public function rollback()
- {
- $this->acl()->snapshot();
- $snapshot = new Snapshot();
- $snapshot->setApi($this->api());
- $snapshot->setPath($this->vm()->getPath() . "/snapshot/" . $this->formData['name']);
- $snapshot->rollback();
- return (new HtmlDataJsonResponse())
- ->setStatusSuccess()
- ->setMessageAndTranslate('The snapshot has been rolled back successfully');
- }
- }
|