ConfigureNetworkJob.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Jobs\Vps\Agent;
  3. use MGProvision\Proxmox\v2\ProxmoxApiException;
  4. use ModulesGarden\ProxmoxAddon\App\Jobs\Vps\BaseJob;
  5. use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
  6. class ConfigureNetworkJob extends BaseJob
  7. {
  8. use ProductService;
  9. public function handle($text = null)
  10. {
  11. $this->initParams();
  12. $this->initServices();
  13. $this->setHostingId($this->getWhmcsParamByKey("serviceid"));
  14. try{
  15. if(!$this->vm()->isRunning()){
  16. $this->log->info(sprintf("VM %s - Start", $this->vm()->getVmid()));
  17. $this->vm()->start();
  18. $this->sleep(40);
  19. return false;
  20. }
  21. $this->vm()->agent()->ping();
  22. $this->agentService->configureNetwork();
  23. }catch (ProxmoxApiException $ex){
  24. if(preg_match("/not running/", $ex->getMessage())){
  25. $this->log->info($ex->getMessage());
  26. }else{
  27. $this->log->error($ex->getMessage());
  28. }
  29. //sleep
  30. $this->sleep(30);
  31. return false;
  32. }
  33. }
  34. }