HighAvailabilityClusterService.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Services\Cloud;
  3. use MGProvision\Proxmox\v2\models\HaResource;
  4. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  5. use ModulesGarden\ProxmoxAddon\Core\UI\Traits\WhmcsParams;
  6. use function ModulesGarden\ProxmoxAddon\Core\Helper\sl;
  7. class HighAvailabilityClusterService
  8. {
  9. use ProductService;
  10. use ApiService;
  11. use WhmcsParams;
  12. public function delete()
  13. {
  14. $haResurce = new HaResource();
  15. $haResurce->setSid(sl('Vm')->getVm()->getVmid())
  16. ->setType(sl('Vm')->getVm()->getVirtualization() == "lxc" ? "ct" : "vm");
  17. $haResurce->setApi($this->api());
  18. if ($haResurce->exist())
  19. {
  20. $haResurce->delete();
  21. }
  22. return $this;
  23. }
  24. public function create()
  25. {
  26. $haResurce = new HaResource();
  27. $haResurce->setSid(sl('Vm')->getVm()->getVmid())
  28. ->setState($this->configuration()->getClusterState())
  29. ->setType(sl('Vm')->getVm()->getVirtualization() == "lxc" ? "ct" : "vm")
  30. ->setGroup($this->configuration()->getClusterGroup())
  31. ->setMaxRelocate($this->configuration()->getClusterMaxRelocate())
  32. ->setMaxRestart($this->configuration()->getClusterMaxRestart())
  33. ->create();
  34. }
  35. public function exist(){
  36. $haResurce = new HaResource();
  37. $haResurce->setSid(sl('Vm')->getVm()->getVmid())
  38. ->setType(sl('Vm')->getVm()->getVirtualization() == "lxc" ? "ct" : "vm");
  39. $haResurce->setApi($this->api());
  40. return $haResurce->exist();
  41. }
  42. public function isConfigured(){
  43. return $this->configuration()->getClusterState() &&
  44. is_numeric($this->configuration()->getClusterMaxRelocate()) &&
  45. is_numeric($this->configuration()->getClusterMaxRestart());
  46. }
  47. }