api(); $clusterResurces = new ClusterResourcesRepository(); $clusterResurces->findVm(); //qemu or lxc $this->configuration()->isQemu() ? $clusterResurces->findQemu() : $clusterResurces->findLxc(); foreach ($clusterResurces->fetch() as $resource){ if($resource->getTemplate()){ continue; } if(VmModel::where("vmid", $resource->getVmid())->count()){ continue; } if(Hosting::ofCustomFielVmid($resource->getVmid())->count()){ continue; } $this->availableValues['vmid'][$resource->getVmid()] = sprintf("VMID: %s (%s)", $resource->getVmid(), $resource->getName()); } } public function update() { } public function delete() { } public function import() { $this->api(); $clusterResurces = new ClusterResourcesRepository(); $clusterResurces->findVm(); $clusterResurces->findVmid($this->getFormDataValues()['vmid']); $resurce = $clusterResurces->firstOrFail(); $vm = $resurce->getVm(); $vmModel = new VmModel(); $vmModel->hosting_id = $this->getWhmcsParamByKey('serviceid'); $vmModel->vmid = $vm->getVmid(); $vmModel->node = $vm->getNode(); $vmModel->name = $resurce->getName(); $vmModel->virtualization = $this->configuration()->getVirtualization(); $vmModel->password = encrypt($this->getFormDataValues()['password']); $vmModel->cores = $vm->config()['cores']; $vmModel->sockets = (int) $vm->config()['sockets']; $vmModel->vcpus = (int) $vm->config()['vcpus']; $vmModel->cpulimit = $vm->config()['cpulimit']; $vmModel->cpuunits = $vm->config()['cpuunits']; $vmModel->memory = $vm->config()['memory']; $vmModel->swap = (int) $vm->config()['swap']; $vmModel->disk = (int) $vm->getMasterHddSize(); if($this->configuration()->isQemu()){ $vmModel->disks = (int) $vm->getHardDiskRepostiory()->additionalSize(); } if($this->configuration()->isLxc()){ $vmModel->disks = (int) $vm->getMounPoints()->additionalSize(); } $this->userUpdatePermission([$vmModel->vmid]); $vmModel->save(); return (new HtmlDataJsonResponse()) ->setStatusSuccess() ->setMessageAndTranslate('The Virtual Machine has been imported successfully'); } }