model = VmModel::class; } public function read() { $this->vmModel = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVmModel(); $this->data = $this->vmModel->toArray(); $vm = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVm(); $config = $vm->config(); $this->data['password'] = $this->vmModel->getPassword(); $this->data['description'] = html_entity_decode($config['description']); $this->data['searchdomain'] = $config['searchdomain']; $ns = explode(" ",$config['nameserver']); $this->data['nameserver[0]'] = $ns[0]; $this->data['nameserver[1]'] = $ns[1]; /** * @deprecated $this->data['ipv4'] = $this->vmModel->ipv4Addresses->count(); $this->data['ipv6'] = $this->vmModel->ipv6Addresses->count(); */ //Boot order if($vm instanceof Kvm){ $bootOrder = $vm->getBootOrder(); $this->data['bootDevice'] = $bootOrder[0]; $options = [ 0 => sl("lang")->tr("None"), "scsi0" => sl("lang")->tr("Disk"), "ide2" => sl("lang")->tr("CD-ROM"), "net0" => sl("lang")->tr("Network"), ]; $this->availableValues['bootDevice'] = $options; } //sshkeys $this->data['sshkeys'] = rawurldecode($vm->config()['sshkeys']); //cpu Priority if($this->configuration()->hasCpuPriority()){ for($i=1; $i<=5; $i++){ $cpuunits = $this->configuration()->get('cpuunitsPriority'.$i); $cpulimit = $this->configuration()->get('cpulimitPriority'.$i); if($this->vmModel->cpulimit >= $cpulimit){ $this->data['cpuPriority'] = $i; } if($this->vmModel->cpuunits >= $cpuunits){ $this->data['cpuPriority'] = $i; } } } //iso if ($this->configuration()->isQemu() && $this->configuration()->isPermissionIsoImage()) { $this->availableValues['iso'] = ["none" => sl('lang')->abtr("None")]; $storageRepository = new StorageRepository(); $storageRepository->findByNodes([$vm->getNode()]) ->findEnabed(); $storages = $storageRepository->fetchAsArray(); $isoRepository = new FileRepository(); $isoRepository->findByNodes([$vm->getNode()]) ->findByStorages($storages); $isoRepository->findIso(); foreach ($isoRepository->fetch() as $entity) { if ($this->configuration()->isPermissionIsoImages() && !in_array($entity->getVolid(), $this->configuration()->getPermissionIsoImages())) { continue; } $this->availableValues['iso'][$entity->getVolid()] = $entity->getFriendlyName(); } if( $vm->getCdRomRepository()->first()){ $this->data['iso']= $vm->getCdRomRepository()->first()->getLocation(); } } } public function update() { $this->vmModel = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVmModel(); $vm = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVm(); $this->networkService = new NetworkService(); $networkService = new NetworkService(); /** * @deprecated * $ipv4 = (int) $this->formData['ipv4'] - (int) $this->vmModel->ipv4Addresses->count(); * $ipv6 = (int) $this->formData['ipv6'] - (int) $this->vmModel->ipv6Addresses->count(); * $networkService->hasIp($ipv4, $ipv6, $this->vmModel->node); * $networkService->addIp($ipv4, $ipv6, $this->vmModel->node); * $networkService->unassignIpAddressesAndDeleteNetwork($ipv4, $ipv6); */ //load data $this->getFormDataValues(); if ($vm instanceof Kvm) { //iso if ($vm->cdrom()) { $vm->updateCdrom($this->formData['iso']); } //Boot Device //order=scsi0;ide0;ide1;net0 logModuleCall( 'proxmoxCloud', __FUNCTION__, $this->formData, 'Debug', $this->data ); $vm->updateConfig(['boot' => 'order=' . $this->formData['bootDevice']]); //sshkeys if($this->configuration()->isPermissionSshkeys()){ if ($this->formData['sshkeys']) { $vm->updateConfig(["sshkeys" => rawurlencode($this->formData['sshkeys'])]); } else if($vm->config()['sshkeys']) { $vm->deleteConfig('sshkeys'); } } } try{ Api::beginTransaction(); DB::beginTransaction(); $this->fillVmModel(); if($this->getFormDataValues()['password']){ $this->vmModel->setPassword($this->getFormDataValues()['password']); } if($this->configuration()->isCalculateSocketsAndCores()){ $this->calculateSocketsAndCores(); } $this->vmModel->save(); if($this->configuration()->isQemu()){ fire(new QemuUpdateEvent($this->vmModel, $this->formData)); } if($this->configuration()->isLxc()){ fire(new LxcUpdateEvent($this->vmModel, $this->formData)); } $agentEnabled = (new AgentService())->isEnabled(); if($agentEnabled && $this->configuration()->isAgentConfigureNetwork()){ queue(ConfigureNetworkJob::class, ['hostingId' => $this->getWhmcsParamByKey('serviceid')], null, "hosting", $this->getWhmcsParamByKey("serviceid"), $this->vmModel->id ); } if($agentEnabled && $this->configuration()->isAgentPassword()){ queue(ChangePasswordJob::class, ['hostingId' => $this->getWhmcsParamByKey('serviceid')], null, "hosting", $this->getWhmcsParamByKey("serviceid"), $this->vmModel->id ); } DB::commit(); return (new HtmlDataJsonResponse()) ->setMessageAndTranslate('Server has been updated') ->setCallBackFunction('pcVmUpdatedAjaxDone') ->addRefreshTargetId('serviceInformationDataTable') ->setCallBackFunction('mgLocationReload'); }catch (\Exception $ex){ DB::rollBack(); Api::commit(); return (new HtmlDataJsonResponse()) ->setStatusError() ->setMessageAndTranslate($ex->getMessage()); } } }