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\models; use \MGProvision\Proxmox\v2\ProxmoxApiException; use \MGProvision\Proxmox\v2\repository\IpCidrRepository; /** * Description of IpSet * * @author Pawel Kopec */ class IpSet extends AbstractObject { const DEFAULT_PATH = 'firewall/ipset'; private $path; protected $name; protected $comment; private $ipCidr; function __construct($path = null) { if (!is_null($path)) { $this->setPath($path); } } public function getName() { return $this->name; } public function getComment() { return $this->comment; } public function setName($name) { $this->name = $name; return $this; } public function setComment($comment) { $this->comment = $comment; return $this; } /** * * @param string $path /api2/json/nodes/{node}/qemu/{vmid}/firewall/ipset * @throws proxmox\ProxmoxApiException */ public function setPath($path) { if (!preg_match('/ipset/', $path)) { throw new ProxmoxApiException(sprintf("IpSet path ('%s') is not valid", $path)); } $this->path = $path; return $this; } public function create() { if (empty($this->path)) { throw new ProxmoxApiException("IpSet path is empty"); } $this->api()->post($this->path, ['name' => $this->name, "comment" => $this->comment]); $this->setPath($this->path . "/{$this->name}"); return $this; } public function delete() { if (empty($this->path)) { throw new ProxmoxApiException("IpSet path is empty"); } $this->api()->delete($this->path); return $this; } public function getPath() { return $this->path; } /** * * @return IpCidr[] */ public function getIpCidr() { if ($this->ipCidr) { return $this->ipCidr; } $this->ipCidr = (new IpCidrRepository())->findByPath($this->getPath())->fetch(); return $this->ipCidr; } }