| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- /* * ********************************************************************
- * ProxmoxAddon product developed. (Mar 9, 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\models;
- use \MGProvision\Proxmox\v2\ProxmoxApiException;
- use \MGProvision\Proxmox\v2\repository\IpCidrRepository;
- /**
- * Description of IpSet
- *
- * @author Pawel Kopec <pawelk@modulesgardne.com>
- */
- 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;
- }
- }
|