| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- /* * ********************************************************************
- * ProxmoxVPS product developed. (2016-10-06)
- * *
- *
- * 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 Node
- *
- * @author Pawel Kopec <pawelk@modulesgarden.com>
- * @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);
- }
- }
|