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 * @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; } }