Commands.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxVps\Core\Models;
  3. /**
  4. * Class Commands
  5. * @property $uuid
  6. * @property $name
  7. * @property $parent_uuid
  8. * @property $status
  9. * @property $action
  10. * @package ModulesGarden\Servers\ProxmoxVps\Core\Models
  11. */
  12. class Commands extends ExtendedEloquentModel
  13. {
  14. const STATUS_STOPPED = 'stopped';
  15. const STATUS_RUNNING = 'running';
  16. const STATUS_ERROR = 'error';
  17. const STATUS_SLEEPING = 'sleeping';
  18. const ACTION_START = 'start';
  19. const ACTION_STOP = 'stop';
  20. const ACTION_REBOOT = 'reboot';
  21. const ACTION_NONE = 'none';
  22. /**
  23. * Table name
  24. *
  25. * @var string
  26. */
  27. protected $table = 'Commands';
  28. /**
  29. * @var string
  30. */
  31. protected $primaryKey = 'name';
  32. /**
  33. * @return bool
  34. */
  35. public function isStopped()
  36. {
  37. return $this->status === self::STATUS_STOPPED;
  38. }
  39. /**
  40. * @return bool
  41. */
  42. public function isRunning()
  43. {
  44. return $this->status === self::STATUS_RUNNING;
  45. }
  46. public function isSleeping()
  47. {
  48. return $this->status === self::STATUS_SLEEPING;
  49. }
  50. /**
  51. * @return $this
  52. */
  53. public function setRunning()
  54. {
  55. $this->setStatus(self::STATUS_RUNNING);
  56. return $this;
  57. }
  58. /**
  59. * @return $this
  60. */
  61. public function setStopped()
  62. {
  63. $this->setStatus(self::STATUS_STOPPED);
  64. return $this;
  65. }
  66. /**
  67. * @return $this
  68. */
  69. public function setSleeping()
  70. {
  71. $this->setStatus(self::STATUS_SLEEPING);
  72. return $this;
  73. }
  74. /**
  75. * @param $status
  76. * @return $this
  77. */
  78. public function setStatus($status)
  79. {
  80. $this->status = $status;
  81. $this->save();
  82. return $this;
  83. }
  84. /**
  85. * @return $this
  86. */
  87. public function start()
  88. {
  89. $this->setAction(self::ACTION_START);
  90. return $this;
  91. }
  92. /**
  93. * @return $this
  94. */
  95. public function stop()
  96. {
  97. $this->setAction(self::ACTION_STOP);
  98. return $this;
  99. }
  100. /**
  101. * @return $this
  102. */
  103. public function reboot()
  104. {
  105. $this->setAction(self::ACTION_REBOOT);
  106. return $this;
  107. }
  108. /**
  109. *
  110. */
  111. public function ping()
  112. {
  113. $this->save();
  114. }
  115. /**
  116. * @return $this
  117. */
  118. public function clearAction()
  119. {
  120. $this->setAction(self::ACTION_NONE);
  121. return $this;
  122. }
  123. /**
  124. * @param $action
  125. * @return $this
  126. */
  127. public function setAction($action)
  128. {
  129. $this->action = $action;
  130. $this->save();
  131. return $this;
  132. }
  133. /**
  134. * @return bool
  135. */
  136. public function shouldBeStopped()
  137. {
  138. return $this->action === self::ACTION_STOP;
  139. }
  140. public function shouldBeRestared()
  141. {
  142. return $this->action === self::ACTION_REBOOT;
  143. }
  144. }