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 */ 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(), ]; } }