initParams(); $this->initServices(); //create task validation if ($this->isDone()) { $this->initVm(); $this->qemuUpdate(); if ($this->agentUpdate()) { fire(new VmCreatedEvent($this->getVmModel())); return true; } return false; } elseif ($this->isTaskRunning()) { //sleep $this->sleep(5); return false; } try { Api::beginTransaction(); DB::beginTransaction(); list($backupNode, $volid) = explode(":", $this->getModelData()['archive'], 2); //vmid $vmid = $this->nextVmid(); $vm = new Kvm($backupNode,$vmid); $vmModel = $this->getVmModel(); $vmModel->vmid = $vmid; $vmModel->node = $backupNode; $vmModel->save(); sl('Vm')->setVm(null); sl('Vm')->setVmModel( $vmModel); $vm->setApi($this->api()); $container = [ 'vmid' => $vmid, 'archive' => $volid ]; $taskId = $vm->create($container); DB::commit(); } catch (\Exception $ex) { DB::rollBack(); Api::commit(); $this->failed($ex->getMessage()); throw $ex; } //task history $this->createTaskHistory($taskId, "Create"); //save task id $this->putModelDataAndSave(["taskId" => $taskId, "node" => $backupNode]); //sleep $this->sleep(); return false; } }