BackupSchedule.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS product developed. (2016-12-13)
  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. use MGProvision\Proxmox\v2 as proxmox;
  21. /**
  22. * Description of BackupSchedule
  23. *
  24. * @author Pawel Kopec <pawelk@modulesgarden.com>
  25. * @version 1.0.0
  26. */
  27. class BackupSchedule extends AbstractObject
  28. {
  29. protected $path;
  30. protected $starttime;
  31. protected $enabled;
  32. protected $mailto;
  33. protected $dow;
  34. protected $vmid;
  35. protected $storage;
  36. protected $quiet;
  37. protected $id;
  38. protected $remove;
  39. protected $compress;
  40. protected $mode;
  41. protected $maxfiles;
  42. protected $node;
  43. public function getStarttime()
  44. {
  45. return $this->starttime;
  46. }
  47. public function getEnabled()
  48. {
  49. return $this->enabled;
  50. }
  51. public function getMailto()
  52. {
  53. return $this->mailto;
  54. }
  55. public function getDow()
  56. {
  57. return $this->dow;
  58. }
  59. public function getVmid()
  60. {
  61. return $this->vmid;
  62. }
  63. public function getStorage()
  64. {
  65. return $this->storage;
  66. }
  67. public function getQuiet()
  68. {
  69. return $this->quiet;
  70. }
  71. public function getId()
  72. {
  73. return $this->id;
  74. }
  75. public function getRemove()
  76. {
  77. return $this->remove;
  78. }
  79. public function getCompress()
  80. {
  81. return $this->compress;
  82. }
  83. public function getMode()
  84. {
  85. return $this->mode;
  86. }
  87. public function getMaxfiles()
  88. {
  89. return $this->maxfiles;
  90. }
  91. public function getNode()
  92. {
  93. return $this->node;
  94. }
  95. public function setStarttime($starttime)
  96. {
  97. $this->starttime = $starttime;
  98. return $this;
  99. }
  100. public function setEnabled($enabled)
  101. {
  102. $this->enabled = $enabled;
  103. return $this;
  104. }
  105. public function setMailto($mailto)
  106. {
  107. $this->mailto = $mailto;
  108. return $this;
  109. }
  110. public function setDow($dow)
  111. {
  112. $this->dow = $dow;
  113. return $this;
  114. }
  115. public function setVmid($vmid)
  116. {
  117. $this->vmid = $vmid;
  118. return $this;
  119. }
  120. public function setStorage($storage)
  121. {
  122. $this->storage = $storage;
  123. return $this;
  124. }
  125. public function setQuiet($quiet)
  126. {
  127. $this->quiet = $quiet;
  128. return $this;
  129. }
  130. public function setId($id)
  131. {
  132. $this->id = $id;
  133. return $this;
  134. }
  135. public function setRemove($remove)
  136. {
  137. $this->remove = $remove;
  138. return $this;
  139. }
  140. public function setCompress($compress)
  141. {
  142. $this->compress = $compress;
  143. return $this;
  144. }
  145. public function setMode($mode)
  146. {
  147. $this->mode = $mode;
  148. return $this;
  149. }
  150. public function setMaxfiles($maxfiles)
  151. {
  152. $this->maxfiles = $maxfiles;
  153. return $this;
  154. }
  155. public function setNode($node)
  156. {
  157. $this->node = $node;
  158. return $this;
  159. }
  160. public function setPath($path)
  161. {
  162. $this->path = $path;
  163. return $this;
  164. }
  165. public function delete()
  166. {
  167. if (empty($this->id))
  168. throw new proxmox\ProxmoxApiException('Backup Schedule [id] - property is missing and it is not optional');
  169. return $this->api()->delete("/cluster/backup/".$this->getId());
  170. }
  171. private function fill()
  172. {
  173. $data = array(
  174. "vmid" => $this->getVmid(),
  175. "starttime" => $this->getStarttime(),
  176. );
  177. if($this->getMaxfiles()){
  178. $data['maxfiles'] = (int) $this->getMaxfiles();
  179. }
  180. if ($this->getStorage())
  181. $data['storage'] = $this->getStorage();
  182. if ($this->getRemove())
  183. $data['remove'] = $this->getRemove();
  184. if ($this->getDow())
  185. $data['dow'] = $this->getDow();
  186. if (!is_null($this->mode))
  187. $data['mode'] = $this->getMode();
  188. if (!is_null($this->compress))
  189. $data['compress'] = $this->getCompress();
  190. if ($this->getMailto())
  191. $data['mailto'] = $this->getMailto();
  192. return $data;
  193. }
  194. public function create()
  195. {
  196. $data = $this->fill();
  197. return $this->api()->post("/cluster/backup", $data);
  198. }
  199. public function update()
  200. {
  201. $data = $this->fill();
  202. return $this->api()->put("/cluster/backup/" . $this->getId(), $data);
  203. }
  204. public function getAttributes()
  205. {
  206. return array(
  207. 'displayId' => preg_replace('/^(.*):/', '', $this->getId()),
  208. "starttime" => $this->getStarttime(),
  209. "days" => explode(",", $this->dow),
  210. "compress" => $this->getCompress(),
  211. "mode" => $this->getMode(),
  212. "mailto" => $this->getMailto(),
  213. "id" => $this->getId(),
  214. "dow" => $this->getDow()
  215. );
  216. }
  217. }