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 Node * * @author Pawel Kopec * @version 1.0.0 */ class Node extends AbstractObject { protected $node; function __construct($node) { $this->node = $node; } function getNode() { return $this->node; } function setNode($node) { $this->node = $node; } /** * * @param string $upid * @return \MGProvision\Proxmox\v2\models\Task * @throws \MGProvision\Proxmox\v2\ProxmoxApiException */ public function task($upid) { if (empty($upid)) throw new \MGProvision\Proxmox\v2\ProxmoxApiException("Task Id is empty"); if (!is_string($upid)) { throw new \MGProvision\Proxmox\v2\ProxmoxApiException(sprintf("Task Id is invalid '%s'", $upid)); } $attributes = $this->api()->get("/nodes/{$this->node}/tasks/{$upid}/status"); $task = new Task(); $task->setAttributes($attributes); return $task; } public function hasKvm($vmid) { if (empty($vmid)) throw new \MGProvision\Proxmox\v2\ProxmoxApiException("Parameter ('vmid') is empty"); try { $res = $this->api()->get("/nodes/{$this->node}/qemu/{$vmid}"); return true; } catch (\MGProvision\Proxmox\v2\ProxmoxApiException $ex) { return false; } } public function getFreeSpace($storage = null) { $result = $res = $this->api()->get("/nodes/{$this->node}/status"); $limits = array( "memory" => $result['memory']['free'], "swap" => $result['swap']['free'], ); if ($storage) { $result2 = $this->api()->get("/nodes/{$this->node}/storage/{$storage}/status", array()); $limits['storage'] = $result2['avail']; } return $limits; } /** * * @return \MGProvision\Proxmox\v2\models\Kvm */ public function kvm() { return new Kvm($this->node); } /** * * @return \MGProvision\Proxmox\v2\models\Lxc */ public function lxc() { return new Lxc($this->node); } public function getPath() { return "/nodes/{$this->node}"; } public function getMainIpAddress() { $repository = new \MGProvision\Proxmox\v2\repository\NetworkRepository(); $repository->findByPath($this->getPath() . "/network") ->findTypeBridge(); foreach ($repository->fetch() as $n) { if ($n->getIface() == 'vmbr0') { if ($n->getAddress()) { return $n->getAddress(); } } } throw new ProxmoxApiException(sprintf("IP Addres for node '%s' not found", $this->getNode())); } public function getStatus() { return $this->api()->get("/nodes/{$this->node}/status", array()); } public function getSubscription() { return $this->api()->get("/nodes/{$this->node}/subscription"); } public function getDns() { return $this->api()->get("/nodes/{$this->node}/dns"); } public function rrdData($parameters) { return $this->api()->get("/nodes/{$this->node}/rrddata", $parameters); } }