| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?php
- /* * ********************************************************************
- * ProxmoxAddon product developed. (May 25, 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;
- /**
- * Description of IpConfig
- *
- * @author Pawel Kopec <pawelk@modulesgardne.com>
- */
- class IpConfig extends AbstractObject
- {
- protected $id;
- protected $path;
- protected $ip;
- protected $gw;
- protected $cidr;
- protected $ip6;
- protected $gw6;
- protected $cidr6;
- public function __construct($id, $config = null)
- {
- $this->id = $id;
- if ($config)
- {
- $config = self::asArray($config);
- $this->setAttributes($config);
- }
- }
- public function asConfig()
- {
- $config = null;
- if ($this->getIp())
- {
- $config[] = "ip={$this->getIp()}/{$this->getCidr()}";
- }
- if ($this->getGw())
- {
- $config[] = "gw={$this->getGw()}";
- }
- if ($this->getIp6())
- {
- $config[] = "ip6={$this->getIp6()}/{$this->getCidr6()}";
- }
- if ($this->getGw6())
- {
- $config[] = "gw6={$this->getGw6()}";
- }
- return implode(",", $config);
- }
- public function getId()
- {
- return $this->id;
- }
- public function getPath()
- {
- return $this->path;
- }
- public function getIp($cird=true)
- {
- if(!$cird){
- $ex = explode("/", $this->ip);
- return $ex[0];
- }
- return $this->ip;
- }
- public function getGw()
- {
- return $this->gw;
- }
- public function getCidr()
- {
- return $this->cidr;
- }
- public function getIp6()
- {
- return $this->ip6;
- }
- public function getGw6()
- {
- return $this->gw6;
- }
- public function getCidr6()
- {
- return $this->cidr6;
- }
- public function setId($id)
- {
- $this->id = $id;
- return $this;
- }
- public function setPath($path)
- {
- $this->path = $path;
- return $this;
- }
- public function setIp($ip)
- {
- $ip = explode("\/", $ip);
- $this->ip = $ip['0'];
- $this->setCidr($ip['1']);
- return $this;
- }
- public function setGw($gw)
- {
- $this->gw = $gw;
- return $this;
- }
- public function setCidr($cidr)
- {
- $this->cidr = $cidr;
- return $this;
- }
- public function setIp6($ip6)
- {
- $ip6 = explode("\/", $ip6);
- $this->ip6 = $ip6['0'];
- $this->setCidr6($ip6['1']);
- return $this;
- }
- public function setGw6($gw6)
- {
- $this->gw6 = $gw6;
- return $this;
- }
- public function setCidr6($cidr6)
- {
- $this->cidr6 = $cidr6;
- return $this;
- }
- public function getAttributes(){
- return [
- "ip" => $this->getIp(),
- "ip6" => $this->getIp6(),
- "gw" => $this->getGw(),
- "gw6" => $this->getGw6(),
- ];
- }
- }
|