| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- /* * ********************************************************************
- * ProxmoxVPS product developed. (2016-10-11)
- * *
- *
- * 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;
- /**
- * Description of StorageRepository
- *
- * @author Pawel Kopec <pawelk@modulesgarden.com>
- * @version 1.0.0
- */
- class StorageRepository extends AbstractRepository
- {
- protected $nodes = array();
- private $enabled;
- protected $filterPattern;
- public function findEnabed()
- {
- $this->enabled = 1;
- return $this;
- }
- public function findContent($content)
- {
- $this->content = $content;
- return $this;
- }
- public function findIso()
- {
- $this->content = 'iso';
- return $this;
- }
- public function findSnippets(){
- $this->filterPattern = "/snippets/";
- }
- /**
- * @return \MGProvision\Proxmox\v2\models\Storage[]
- */
- public function fetch()
- {
- $request = $this->content ? array("content" => $this->content) : array();
- if (!is_null($this->enabled))
- {
- $request['enabled'] = $this->enabled;
- }
- $data = array();
- foreach ($this->nodes as $node)
- {
- $storages = $this->api()->get("/nodes/{$node}/storage", $request);
- foreach ($storages as $storage)
- {
- if ($this->enabled && (!$storage['enabled'] && version_compare($this->api()->getVersion(), "5.0", '>') ))
- {
- continue;
- }
- $storageObj = new \MGProvision\Proxmox\v2\models\Storage();
- $storageObj->setAttributes($storage);
- $data[] = $storageObj;
- }
- }
- if(empty($this->nodes)){
- $storages = $this->api()->get("/storage", $request);
- foreach ($storages as $storage)
- {
- if($this->filterPattern && !preg_match($this->filterPattern, $storage['content'])){
- continue;
- }
- $storageObj = new \MGProvision\Proxmox\v2\models\Storage();
- $storageObj->setAttributes($storage);
- $data[] = $storageObj;
- }
- }
- return $data;
- }
- public function fetchAsArray()
- {
- $data = array();
- foreach ($this->fetch() as $storage)
- {
- $data[] = $storage->getStorage();
- }
- return $data;
- }
- public function findByNodes(array $nodes)
- {
- $this->nodes = $nodes;
- return $this;
- }
- }
|