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 KvmNetworkDevice * * @author Pawel Kopec * @version 1.0.0 */ class NetworkDeviceKvm extends AbstractObject { protected $id; protected $model; protected $macAddress; protected $bridge; protected $firewall; protected $linkDown; protected $queues; protected $rate; protected $tag; protected $trunks; protected $node; protected $vmid; public function __construct($id=null, $config = null) { $this->id = $id; if ($config !== null) { $config = self::asArray($config); $model = array_search(current($config), $config); $this->setBridge($config['bridge']) ->setRate($config['rate']) ->setMacAddress($config) ->setModel($model) ->setTag($config['tag']) ->setTrunks($config['trunks']) ->setFirewall($config['firewall']) ->setQueues($config['queues']); } } public function getId() { return $this->id; } public function getModel() { return $this->model; } public function getMacAddress() { return $this->macAddress; } public function getBridge() { return $this->bridge; } public function getFirewall() { return $this->firewall; } public function getLinkDown() { return $this->linkDown; } public function getQueues() { return $this->queues; } public function getRate() { return $this->rate; } public function getTag() { return $this->tag; } public function getNode() { return $this->node; } public function getVmid() { return $this->vmid; } public function setId($id) { $this->id = $id; return $this; } public function setModel($model) { $this->model = $model; return $this; } public function setMacAddress($macAddress) { if (is_array($macAddress)) { $models = array('e1000', 'i82551', 'i82557b', 'i82559er', 'ne2k_isa', 'ne2k_pci', 'pcnet', 'rtl8139', 'virtio', 'vmxnet3'); $config = $macAddress; foreach ($config as $k => $v) { foreach ($models as $model) { if (preg_match("/{$model}/", $k)) { $macAddress = $v; break; } } } } if($macAddress =="auto"){ $macAddress = null; } if ($macAddress && !preg_match("/^[0-9a-fA-F]{2}(?=([:;.]?))(?:\\1[0-9a-fA-F]{2}){5}$/", $macAddress)) throw new \MGProvision\Proxmox\v2\ProxmoxApiException(sprintf("Invalid MAC Address ('%s') ", $macAddress)); $this->macAddress = $macAddress; return $this; } public function setBridge($bridge) { $this->bridge = $bridge; return $this; } public function setFirewall($firewall) { $this->firewall = $firewall; return $this; } public function setLinkDown($linkDown) { $this->linkDown = $linkDown; return $this; } public function setQueues($queues) { $this->queues = $queues; return $this; } public function setRate($rate) { $this->rate = $rate; return $this; } public function setTag($tag) { $this->tag = $tag; return $this; } public function setNode($node) { $this->node = $node; return $this; } public function setVmid($vmid) { $this->vmid = $vmid; return $this; } public function getTrunks() { return $this->trunks; } public function setTrunks($trunks) { $this->trunks = $trunks; return $this; } public function asConfig() { $config = array(); if ($this->macAddress) $config[] = $this->model . "=" . $this->macAddress; else if ($this->model) $config[] = $this->model; if ($this->bridge) $config[] = "bridge=" . $this->bridge; if ($this->firewall) $config[] = "firewall=1"; if (!empty($this->linkDown)) $config[] = 'link_down=' . $this->linkDown; if (!empty($this->tag)) $config[] = 'tag=' . $this->tag; if (!empty($this->trunks)) $config[] = 'trunks=' . $this->trunks; if ($this->rate) $config[] = "rate=" . $this->rate; if(!empty($this->queues)){ $config[] = "queues=" . $this->queues; } return implode(",", $config); } public function getRateMbps() { return $this->rate * 8; } public function getAttributes(){ return [ "id" => $this->getId(), "bridge" => $this->getBridge(), "firewall" => $this->getFirewall(), "tag" => $this->getTag(), "macAddress" => $this->getMacAddress(), "rate" => $this->getRate(), "queues" => $this->getQueues() ]; } }