| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- /* * ********************************************************************
- * ProxmoxVPS product developed. (2016-12-13)
- * *
- *
- * 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 MGProvision\Proxmox\v2\repository;
- use MGProvision\Proxmox\v2\interfaces\VmInterface;
- use MGProvision\Proxmox\v2\models\BackupSchedule;
- use ModulesGarden\ProxmoxAddon\App\Models\VmModel;
- /**
- * Description of BackupSchedule
- *
- * @author Pawel Kopec <pawelk@modulesgarden.com>
- * @version 1.0.0
- */
- class BackupScheduleRepository extends AbstractRepository
- {
- protected $vmids = array();
- protected $nodes = array();
- public function findByVm(VmInterface $vm)
- {
- $this->findByVmids(array($vm->getVmid()));
- return $this;
- }
- public function findByVmids(array $vmids)
- {
- $this->vmids = $vmids;
- return $this;
- }
- public function findByNodes(array $nodes)
- {
- $this->nodes = $nodes;
- return $this;
- }
- /**
- *
- * @return BackupSchedule[]
- */
- public function fetch()
- {
- if (!empty($this->fetch))
- {
- return $this->fetch;
- }
- $path = "/cluster/backup";
- $res = $this->api()->get($path);
- $this->fetch = array();
- foreach ($res as $job)
- {
- if ((!$job['vmid'] && $this->vmids) || ($job['vmid'] && $this->vmids && !in_array($job['vmid'], $this->vmids)))
- {
- continue;
- }
- if ((!$job['node'] && $this->nodes) || ( $job['node'] && $this->nodes && !in_array($job['node'], $this->nodes)))
- {
- continue;
- }
- $backupShedule = new BackupSchedule();
- $backupShedule->setAttributes($job);
- $backupShedule->setPath(sprintf("{$path}/%s", $job['id']));
- $this->fetch[] = $backupShedule;
- }
- return $this->fetch;
- }
- /**
- *
- * @param VmModel[] $vservers
- */
- public function findByVmModel($vservers)
- {
- foreach ($vservers as $vserver)
- {
- if (!$vserver instanceof VmModel)
- {
- throw new \MGProvision\Proxmox\v2\ProxmoxApiException("Ukown object: " . get_class($vserver));
- }
- $this->vmids[] = $vserver->vmid;
- }
- return $this;
- }
- public function count()
- {
- return count($this->fetch());
- }
- public function delete()
- {
- for ($i = 0; $i <= 100; $i++)
- {
- $this->reset();
- $backups = $this->fetch();
- if (empty($backups))
- break;
- foreach ($backups as $b)
- {
- $b->delete();
- break;
- }
- }
- }
- }
|