| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- /* * ********************************************************************
- * ProxmoxVPS product developed. (2016-11-14)
- * *
- *
- * 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 HaResource
- *
- * @author Pawel Kopec <pawelk@modulesgarden.com>
- * @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;
- }
- }
|