| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- <?php
- /* * ********************************************************************
- * ProxmoxVPS product developed. (2016-12-08)
- * *
- *
- * 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 KvmNetworkDevice
- *
- * @author Pawel Kopec <pawelk@modulesgarden.com>
- * @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()
- ];
- }
- }
|