StatusProvider.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS Product developed. (27.03.19)
  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 ModulesGarden\Servers\ProxmoxVps\App\UI\Home\Providers;
  20. use ModulesGarden\ProxmoxAddon\App\Jobs\Vps\RebootVmJob;
  21. use ModulesGarden\ProxmoxAddon\App\Models\Job;
  22. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  23. use ModulesGarden\ProxmoxAddon\App\Services\Vps\HighAvailabilityClusterService;
  24. use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
  25. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\ClientArea;
  26. use ModulesGarden\Servers\ProxmoxVps\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
  27. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
  28. use function ModulesGarden\ProxmoxAddon\Core\Helper\queue;
  29. class StatusProvider extends BaseDataProvider implements ClientArea
  30. {
  31. use ProductService;
  32. use ApiService;
  33. public function start()
  34. {
  35. $this->vm()->start();
  36. return (new HtmlDataJsonResponse())
  37. ->setStatusSuccess()
  38. ->setMessageAndTranslate('The container has been booted successfully')
  39. ->addData('refreshState', 'serverinformationTable')
  40. ->addRefreshTargetId('serviceInformationDataTable');
  41. }
  42. public function reboot()
  43. {
  44. $ha = new HighAvailabilityClusterService();
  45. if ($ha->exist())
  46. {
  47. //reboot
  48. if (!Job::waiting()->ofJob(RebootVmJob::class)->ofHostingId($this->getWhmcsParamByKey("serviceid"))->count())
  49. {
  50. queue(RebootVmJob::class, [], null, "hosting", $this->getWhmcsParamByKey("serviceid"));
  51. }
  52. return (new HtmlDataJsonResponse())
  53. ->setStatusSuccess()
  54. ->setMessageAndTranslate('Rebooting container in progress')
  55. ->addData('refreshState', 'serverinformationTable')
  56. ->addRefreshTargetId('serviceInformationDataTable');
  57. }
  58. else
  59. {
  60. $this->vm()->restart();
  61. return (new HtmlDataJsonResponse())
  62. ->setStatusSuccess()
  63. ->setMessageAndTranslate('The container has been rebooted successfully')
  64. ->addData('refreshState', 'serverinformationTable')
  65. ->addRefreshTargetId('serviceInformationDataTable');
  66. }
  67. }
  68. public function stop()
  69. {
  70. $this->vm()->stop();
  71. return (new HtmlDataJsonResponse())
  72. ->setStatusSuccess()
  73. ->setMessageAndTranslate('The container has been stopped successfully')
  74. ->addData('refreshState', 'serverinformationTable')
  75. ->addRefreshTargetId('serviceInformationDataTable');
  76. }
  77. public function shutdown()
  78. {
  79. $this->vm()->shutdown();
  80. return (new HtmlDataJsonResponse())
  81. ->setStatusSuccess()
  82. ->setMessageAndTranslate('The container has been shut down successfully')
  83. ->addData('refreshState', 'serverinformationTable')
  84. ->addRefreshTargetId('serviceInformationDataTable');
  85. }
  86. public function read()
  87. {
  88. }
  89. public function update()
  90. {
  91. }
  92. }