| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- /* * ********************************************************************
- * ProxmoxAddon product developed. (May 28, 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 MGProvision\Proxmox\v2\repository;
- use MGProvision\Proxmox\v2\models\CdRom;
- use MGProvision\Proxmox\v2\models\CloudInitDrive;
- use \MGProvision\Proxmox\v2\ProxmoxApiException;
- use \MGProvision\Proxmox\v2\models\IpConfig;
- /**
- * Description of IpConfigRepository
- *
- * @author Pawel Kopec <pawelk@modulesgardne.com>
- */
- class CdRomRepository extends AbstractRepository
- {
- protected $path;
- public function findByPath($path)
- {
- if (!preg_match('/config/', $path))
- {
- throw new ProxmoxApiException(sprintf("CdRom path ('%s') is not valid", $path));
- }
- $this->path = $path;
- return $this;
- }
- /**
- *
- * @return CdRom[]
- * @throws ProxmoxApiException
- */
- public function fetch()
- {
- if ($this->fetch)
- {
- return $this->fetch;
- }
- if (empty($this->path))
- {
- throw new ProxmoxApiException("CdRom path is empty");
- }
- $this->fetch = [];
- $get = $this->api()->get($this->path);
- foreach ($get as $id => $config)
- {
- if (preg_match('/media\=cdrom/', $config) && !preg_match('/cloudinit/', $config))
- {
- $entity = new CdRom($id, $config);
- $entity->setPath($this->path);
- $entity->setApi($this->api);
- $this->fetch[] = $entity;
- }
- }
- return $this->fetch;
- }
- /**
- * @return CdRom
- * @throws ProxmoxApiException
- */
- public function first(){
- return $this->fetch()[0];
- }
- public function hasCloudInit()
- {
- if (empty($this->path))
- {
- throw new ProxmoxApiException("CdRom path is empty");
- }
- if (!$this->fetch)
- {
- $this->fetch = $this->api()->get($this->path);
- }
- foreach ($this->fetch as $id => $config)
- {
- if (preg_match('/cloudinit/', $config))
- {
- return true;
- }
- }
- return false;
- }
- /**
- * @return CloudInitDrive
- * @throws ProxmoxApiException
- */
- public function getCloudInitDrive(){
- if (empty($this->path))
- {
- throw new ProxmoxApiException("CdRom path is empty");
- }
- if (!$this->fetch)
- {
- $this->fetch = $this->api()->get($this->path);
- }
- foreach ($this->fetch as $id => $config)
- {
- if (preg_match('/cloudinit/', $config))
- {
- $entity = new CloudInitDrive($id, $config);
- $entity->setPath($this->path);
- $entity->setApi($this->api);
- return $entity;
- }
- }
- throw new ProxmoxApiException("Cloud Init Drive not found");
- }
- }
|