| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- <?php
- /* * ********************************************************************
- * ProxmoxVPS product developed. (2016-12-14)
- * *
- *
- * 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;
- /**
- * Description of NetworkDeviceLxc
- *
- * @author Pawel Kopec <pawelk@modulesgarden.com>
- * @version 1.0.0
- */
- class NetworkDeviceLxc extends AbstractObject
- {
- protected $id;
- protected $name;
- protected $bridge;
- protected $firewall;
- protected $gw;
- protected $gw6;
- protected $hwaddr;
- protected $ip;
- protected $cidr;
- protected $ip6;
- protected $cidr6;
- protected $tag;
- protected $trunks;
- protected $type;
- protected $rate;
- public function __construct($id=null, $config = null)
- {
- $this->id = $id;
- if ($config !== null)
- {
- $config = self::asArray($config);
- if ($config['ip'] && preg_match("/\\//", $config['ip']))
- {
- list($ip, $cidr) = explode("/", $config['ip']);
- $config['ip'] = $ip;
- $config['cidr'] = $cidr;
- }
- if ($config['ip6'] && preg_match("/\//", $config['ip6']))
- {
- list($ip, $cidr) = explode("/", $config['ip6']);
- $config['ip6'] = $ip;
- $config['cidr6'] = $cidr;
- }
- $this->setAttributes($config);
- }
- }
- public function getId()
- {
- return $this->id;
- }
- public function getName()
- {
- return $this->name;
- }
- public function getBridge()
- {
- return $this->bridge;
- }
- public function getFirewall()
- {
- return $this->firewall;
- }
- public function getGw()
- {
- return $this->gw;
- }
- public function getHwaddr()
- {
- return $this->hwaddr;
- }
- public function getIp()
- {
- return $this->ip;
- }
- public function getTag()
- {
- return $this->tag;
- }
- public function getType()
- {
- return $this->type;
- }
- public function setId($id)
- {
- $this->id = $id;
- return $this;
- }
- public function setName($name)
- {
- $this->name = $name;
- return $this;
- }
- public function setBridge($bridge)
- {
- $this->bridge = $bridge;
- return $this;
- }
- public function setFirewall($firewall)
- {
- $this->firewall = $firewall;
- return $this;
- }
- public function setGw($gw)
- {
- $this->gw = $gw;
- return $this;
- }
- public function setHwaddr($hwaddr)
- {
- $this->hwaddr = $hwaddr;
- return $this;
- }
- public function setIp($ip)
- {
- $this->ip = $ip;
- return $this;
- }
- public function setTag($tag)
- {
- $this->tag = $tag;
- return $this;
- }
- public function setType($type)
- {
- $this->type = $type;
- return $this;
- }
- public function getGw6()
- {
- return $this->gw6;
- }
- public function getIp6()
- {
- return $this->ip6;
- }
- public function setGw6($gw6)
- {
- $this->gw6 = $gw6;
- return $this;
- }
- public function setIp6($ip6)
- {
- $this->ip6 = $ip6;
- return $this;
- }
- public function getTrunks()
- {
- return $this->trunks;
- }
- public function setTrunks($trunks)
- {
- $this->trunks = $trunks;
- return $this;
- }
- public function asConfig()
- {
- $config = array();
- if ($this->name)
- $config[] = "name=" . $this->name;
- if ($this->bridge)
- $config[] = "bridge=" . $this->bridge;
- if (!empty($this->hwaddr) && $this->hwaddr != 'auto')
- $config[] = 'hwaddr=' . $this->hwaddr;
- if ($this->firewall)
- $config[] = "firewall=1";
- if (!empty($this->tag))
- $config[] = 'tag=' . $this->tag;
- if (!empty($this->trunks))
- $config[] = 'trunks=' . $this->trunks;
- if ($this->ip && $this->ip != "dhcp")
- {
- $config[] = "ip=" . $this->ip . '/' . $this->getCidr();
- }
- else if ($this->ip && $this->ip == "dhcp")
- {
- $config[] = "ip=" . $this->ip;
- }
- if ($this->ip6 && $this->ip6 != "dhcp")
- {
- $config[] = "ip6=" . $this->ip6 . '/' . $this->getCidr6();
- }
- else if ($this->ip6 && $this->ip6 == "dhcp")
- {
- $config[] = "ip6=" . $this->ip6;
- }
- if ($this->gw && filter_var($this->gw, FILTER_VALIDATE_IP))
- $config[] = "gw=" . $this->gw;
- if ($this->gw6 && filter_var($this->gw6, FILTER_VALIDATE_IP))
- $config[] = "gw6=" . $this->gw6;
- if ($this->rate)
- $config[] = "rate=" . $this->rate;
- return implode(",", $config);
- }
- public function getRate()
- {
- return $this->rate;
- }
- public function setRate($rate)
- {
- $this->rate = $rate;
- return $this;
- }
- public function getCidr()
- {
- return $this->cidr;
- }
- public function getCidr6()
- {
- return $this->cidr6;
- }
- public function setCidr($cidr)
- {
- $this->cidr = $cidr;
- return $this;
- }
- public function setCidr6($cidr6)
- {
- $this->cidr6 = $cidr6;
- return $this;
- }
- public function getRateMbps()
- {
- return $this->rate * 8;
- }
- public function remove($ip)
- {
- if (!preg_match('/\:/', $ip) && $this->getIp() == $ip)
- {//v4
- $this->setIp(null)
- ->setCidr(null)
- ->setGw(null);
- return true;
- }
- else if ($this->getIp6() == $ip)
- {//v6
- $this->setIp6(null)
- ->setCidr6(null)
- ->setGw6(null);
- return true;
- }
- }
- public function getAttributes(){
- return [
- "id" => $this->getId(),
- "name" => $this->getName(),
- "bridge" => $this->getBridge(),
- "firewall" => $this->getFirewall(),
- "hwaddr" => $this->getHwaddr(),
- "ip" => $this->getIp(),
- "cidr" => $this->getCidr(),
- "gw" => $this->getGw(),
- "ip6" => $this->getIp6(),
- "cidr6" => $this->getCidr6(),
- "gw6" => $this->getGw6(),
- "tag" => $this->getTag(),
- "rate" => $this->getRate(),
- ];
- }
- public function isEmpty()
- {
- return ( ($this->getIp() === null || $this->getIp() === 'dhcp' ) && ( $this->getIp6() === null || $this->getIp6() === 'dhcp' ) );
- }
- }
|