HaResource.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS product developed. (2016-11-14)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace MGProvision\Proxmox\v2\models;
  20. /**
  21. * Description of HaResource
  22. *
  23. * @author Pawel Kopec <pawelk@modulesgarden.com>
  24. * @version 1.0.0
  25. */
  26. class HaResource extends AbstractObject
  27. {
  28. protected $sid;
  29. protected $type;
  30. protected $state;
  31. protected $group;
  32. protected $max_restart;
  33. protected $max_relocate;
  34. public function __construct($sid = null)
  35. {
  36. if ($sid)
  37. $this->setSid($sid);
  38. }
  39. public function getSid()
  40. {
  41. return $this->sid;
  42. }
  43. public function getType()
  44. {
  45. return $this->type;
  46. }
  47. public function getState()
  48. {
  49. return $this->state;
  50. }
  51. public function setSid($sid)
  52. {
  53. $this->sid = str_replace(array("ct:", "vm:"), "", $sid);
  54. return $this;
  55. }
  56. public function setType($type)
  57. {
  58. $this->type = $type;
  59. return $this;
  60. }
  61. public function setState($state)
  62. {
  63. $this->state = $state;
  64. return $this;
  65. }
  66. public function create()
  67. {
  68. if (empty($this->sid))
  69. throw new \MGProvision\Proxmox\v2\ProxmoxApiException("Resource Id is empty");
  70. $parameters = array(
  71. "sid" => $this->sid,
  72. "state" => $this->getState(),
  73. "type" => $this->getType(),
  74. "max_relocate" => $this->max_relocate,
  75. "max_restart" => $this->max_restart
  76. );
  77. if ($this->group)
  78. {
  79. $parameters['group'] = $this->group;
  80. }
  81. return $this->api()->post("/cluster/ha/resources", $parameters);
  82. }
  83. public function delete()
  84. {
  85. if (empty($this->sid))
  86. throw new \MGProvision\Proxmox\v2\ProxmoxApiException("Resource Id is empty");
  87. return $this->api()->delete("/cluster/ha/resources/{$this->type}:" . $this->sid);
  88. }
  89. public function get()
  90. {
  91. return $this->api()->get("/cluster/ha/resources/{$this->type}:" . $this->sid);
  92. }
  93. public function exist()
  94. {
  95. if (empty($this->sid) || !$this->type)
  96. throw new \MGProvision\Proxmox\v2\ProxmoxApiException("Resource Id is empty");
  97. try
  98. {
  99. return is_array($this->get());
  100. }
  101. catch (\Exception $ex)
  102. {// http 401
  103. }
  104. return false;
  105. }
  106. public function getGroup()
  107. {
  108. return $this->group;
  109. }
  110. public function getMaxRestart()
  111. {
  112. return $this->max_restart;
  113. }
  114. public function getMaxRelocate()
  115. {
  116. return $this->max_relocate;
  117. }
  118. public function setGroup($group)
  119. {
  120. $this->group = $group;
  121. return $this;
  122. }
  123. public function setMaxRestart($maxRestart)
  124. {
  125. $this->max_restart = $maxRestart;
  126. return $this;
  127. }
  128. public function setMaxRelocate($maxRelocate)
  129. {
  130. $this->max_relocate = $maxRelocate;
  131. return $this;
  132. }
  133. }