Task.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS product developed. (2016-11-15)
  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 Task
  22. *
  23. * @author Pawel Kopec <pawelk@modulesgarden.com>
  24. * @version 1.0.0
  25. */
  26. class Task extends AbstractObject
  27. {
  28. protected $starttime;
  29. protected $pstart;
  30. protected $id;
  31. protected $exitstatus;
  32. protected $pid;
  33. protected $user;
  34. protected $node;
  35. protected $upid;
  36. protected $type;
  37. protected $status;
  38. protected $endtime;
  39. private $path;
  40. public function getStarttime()
  41. {
  42. return $this->starttime;
  43. }
  44. public function getPstart()
  45. {
  46. return $this->pstart;
  47. }
  48. public function getId()
  49. {
  50. return $this->id;
  51. }
  52. public function getExitstatus()
  53. {
  54. return $this->exitstatus;
  55. }
  56. public function getPid()
  57. {
  58. return $this->pid;
  59. }
  60. public function getUser()
  61. {
  62. return $this->user;
  63. }
  64. public function getNode()
  65. {
  66. return $this->node;
  67. }
  68. public function getUpid()
  69. {
  70. return $this->upid;
  71. }
  72. public function getType()
  73. {
  74. return $this->type;
  75. }
  76. public function getStatus()
  77. {
  78. return $this->status;
  79. }
  80. public function isRunning()
  81. {
  82. return $this->status === "running";
  83. }
  84. public function isFalied()
  85. {
  86. return $this->exitstatus && $this->exitstatus !== "OK";
  87. }
  88. public function isDone()
  89. {
  90. return $this->exitstatus === "OK";
  91. }
  92. public function setStarttime($starttime)
  93. {
  94. $this->starttime = $starttime;
  95. return $this;
  96. }
  97. public function setPstart($pstart)
  98. {
  99. $this->pstart = $pstart;
  100. return $this;
  101. }
  102. public function setId($id)
  103. {
  104. $this->id = $id;
  105. return $this;
  106. }
  107. public function setExitstatus($exitstatus)
  108. {
  109. $this->exitstatus = $exitstatus;
  110. return $this;
  111. }
  112. public function setPid($pid)
  113. {
  114. $this->pid = $pid;
  115. return $this;
  116. }
  117. public function setUser($user)
  118. {
  119. $this->user = $user;
  120. return $this;
  121. }
  122. public function setNode($node)
  123. {
  124. $this->node = $node;
  125. return $this;
  126. }
  127. public function setUpid($upid)
  128. {
  129. $this->upid = $upid;
  130. return $this;
  131. }
  132. public function setType($type)
  133. {
  134. $this->type = $type;
  135. return $this;
  136. }
  137. public function setStatus($status)
  138. {
  139. $this->status = $status;
  140. return $this;
  141. }
  142. public function getEndtime()
  143. {
  144. return $this->endtime;
  145. }
  146. public function setEndtime($endtime)
  147. {
  148. $this->endtime = $endtime;
  149. return $this;
  150. }
  151. public function getStartDate()
  152. {
  153. return date('Y-m-d H:i:s', $this->starttime);
  154. }
  155. public function getEndDate()
  156. {
  157. return date('Y-m-d H:i:s', $this->endtime);
  158. }
  159. public function setPath($path)
  160. {
  161. if (!preg_match('/\/tasks\//', $path))
  162. {
  163. throw new proxmox\ProxmoxApiException(sprintf("Task Path ('%s') is not valid", $path));
  164. }
  165. $this->path = $path;
  166. }
  167. public function delete()
  168. {
  169. if (empty($this->path))
  170. throw new proxmox\ProxmoxApiException('Task [path] - property is missing and it is not optional');
  171. return $this->api()->delete($this->path);
  172. }
  173. public function description()
  174. {
  175. return ucwords(str_replace(array("vz", "qm"), array("VM {$this->getId()} - ", "CT {$this->getId()} - "), $this->getType()));
  176. }
  177. public function getAttributes(){
  178. return [
  179. "id" => $this->getId(),
  180. "starttime" => $this->getStarttime(),
  181. "endtime" => $this->getEndtime(),
  182. "pstart" => $this->getPstart(),
  183. "exitstatus" => $this->getExitstatus(),
  184. "pid" => $this->getPid(),
  185. "node" => $this->getNode(),
  186. "upid"=> $this->getUpid(),
  187. "type" => $this->getType(),
  188. "status" => $this->getStatus(),
  189. ];
  190. }
  191. }