UpgradeVmJob.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Jobs\Vps\LoadBalancer;
  3. use ModulesGarden\ProxmoxAddon\App\Events\Vps\LxcUpdateEvent;
  4. use ModulesGarden\ProxmoxAddon\App\Events\Vps\QemuUpdateEvent;
  5. use ModulesGarden\ProxmoxAddon\App\Jobs\Vps\BaseJob;
  6. use ModulesGarden\ProxmoxAddon\App\Services\Vps\HighAvailabilityClusterService;
  7. use ModulesGarden\ProxmoxAddon\App\Services\Vps\IpSetIpFilterService;
  8. use ModulesGarden\ProxmoxAddon\App\Services\Vps\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->highAvailabilityClusterService = new HighAvailabilityClusterService();
  23. $this->ipSetIpFilterService = new IpSetIpFilterService();
  24. //Upgrade
  25. if ($this->configuration()->isQemu())
  26. {
  27. $evnet = new QemuUpdateEvent($this->vm());
  28. $evnet->isChangeVmPassword(false);
  29. fire($evnet);
  30. }
  31. elseif ($this->configuration()->isLxc())
  32. {
  33. fire(new LxcUpdateEvent($this->vm()));
  34. }
  35. //createHaResource
  36. if ($this->highAvailabilityClusterService->isConfigured() )
  37. {
  38. $this->highAvailabilityClusterService->create();
  39. }
  40. //ip set filter
  41. if ($this->configuration()->isIpsetIpFilter())
  42. {
  43. $this->ipSetIpFilterService->create();
  44. }
  45. //start vm
  46. if (!$this->vm()->isRunning())
  47. {
  48. $this->vm()->start();
  49. }
  50. }
  51. }