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 HaResource * * @author Pawel Kopec * @version 1.0.0 */ class HaResource extends AbstractObject { protected $sid; protected $type; protected $state; protected $group; protected $max_restart; protected $max_relocate; public function __construct($sid = null) { if ($sid) $this->setSid($sid); } public function getSid() { return $this->sid; } public function getType() { return $this->type; } public function getState() { return $this->state; } public function setSid($sid) { $this->sid = str_replace(array("ct:", "vm:"), "", $sid); return $this; } public function setType($type) { $this->type = $type; return $this; } public function setState($state) { $this->state = $state; return $this; } public function create() { if (empty($this->sid)) throw new \MGProvision\Proxmox\v2\ProxmoxApiException("Resource Id is empty"); $parameters = array( "sid" => $this->sid, "state" => $this->getState(), "type" => $this->getType(), "max_relocate" => $this->max_relocate, "max_restart" => $this->max_restart ); if ($this->group) { $parameters['group'] = $this->group; } return $this->api()->post("/cluster/ha/resources", $parameters); } public function delete() { if (empty($this->sid)) throw new \MGProvision\Proxmox\v2\ProxmoxApiException("Resource Id is empty"); return $this->api()->delete("/cluster/ha/resources/{$this->type}:" . $this->sid); } public function get() { return $this->api()->get("/cluster/ha/resources/{$this->type}:" . $this->sid); } public function exist() { if (empty($this->sid) || !$this->type) throw new \MGProvision\Proxmox\v2\ProxmoxApiException("Resource Id is empty"); try { return is_array($this->get()); } catch (\Exception $ex) {// http 401 } return false; } public function getGroup() { return $this->group; } public function getMaxRestart() { return $this->max_restart; } public function getMaxRelocate() { return $this->max_relocate; } public function setGroup($group) { $this->group = $group; return $this; } public function setMaxRestart($maxRestart) { $this->max_restart = $maxRestart; return $this; } public function setMaxRelocate($maxRelocate) { $this->max_relocate = $maxRelocate; return $this; } }