UpgradeVmJob.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Jobs\Cloud\LoadBalancer;
  3. use ModulesGarden\ProxmoxAddon\App\Events\Cloud\LxcUpdateEvent;
  4. use ModulesGarden\ProxmoxAddon\App\Events\Cloud\QemuUpdateEvent;
  5. use ModulesGarden\ProxmoxAddon\App\Jobs\BaseJob;
  6. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\HighAvailabilityClusterService;
  7. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\IpSetIpFilterService;
  8. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  9. use function ModulesGarden\ProxmoxAddon\Core\Helper\fire;
  10. class UpgradeVmJob extends BaseJob
  11. {
  12. use ProductService;
  13. /**
  14. * @var HighAvailabilityClusterService
  15. */
  16. protected $highAvailabilityClusterService;
  17. protected $ipSetIpFilterService;
  18. public function handle($text = null)
  19. {
  20. $this->initParams();
  21. $this->initServices();
  22. $this->initVm();
  23. $this->highAvailabilityClusterService = new HighAvailabilityClusterService();
  24. $this->ipSetIpFilterService = new IpSetIpFilterService();
  25. //Upgrade
  26. if ($this->configuration()->isQemu())
  27. {
  28. $evnet = new QemuUpdateEvent($this->getVmModel());
  29. $evnet->isChangeVmPassword(false);
  30. fire($evnet);
  31. }
  32. elseif ($this->configuration()->isLxc())
  33. {
  34. fire(new LxcUpdateEvent($this->getVmModel()));
  35. }
  36. //createHaResource
  37. if ($this->highAvailabilityClusterService->isConfigured() )
  38. {
  39. $this->highAvailabilityClusterService->create();
  40. }
  41. //ip set filter
  42. if ($this->configuration()->isIpsetIpFilter())
  43. {
  44. $this->ipSetIpFilterService->create();
  45. }
  46. //start vm
  47. if (!sl('Vm')->getVm()->isRunning())
  48. {
  49. sl('Vm')->getVm()->start();
  50. }
  51. }
  52. }