|
@@ -63,7 +63,8 @@ class BaseJob extends Job
|
|
|
*/
|
|
*/
|
|
|
protected $additionalMountPointService;
|
|
protected $additionalMountPointService;
|
|
|
|
|
|
|
|
- protected function initServices() {
|
|
|
|
|
|
|
+ protected function initServices()
|
|
|
|
|
+ {
|
|
|
$this->emailService = new EmailService();
|
|
$this->emailService = new EmailService();
|
|
|
$this->containerService = new ContainerService();
|
|
$this->containerService = new ContainerService();
|
|
|
$this->agentService = new AgentService();
|
|
$this->agentService = new AgentService();
|
|
@@ -72,7 +73,8 @@ class BaseJob extends Job
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function initParams() {
|
|
|
|
|
|
|
+ public function initParams()
|
|
|
|
|
+ {
|
|
|
if (!$this->model->rel_id)
|
|
if (!$this->model->rel_id)
|
|
|
{
|
|
{
|
|
|
new \InvalidArgumentException(sprintf("Job model: #%s rel_id cannot be empty", $this->model->id));
|
|
new \InvalidArgumentException(sprintf("Job model: #%s rel_id cannot be empty", $this->model->id));
|
|
@@ -88,13 +90,15 @@ class BaseJob extends Job
|
|
|
return $this;
|
|
return $this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function sleep($seconds = 60) {
|
|
|
|
|
|
|
+ protected function sleep($seconds = 60)
|
|
|
|
|
+ {
|
|
|
$this->model->setWaiting();
|
|
$this->model->setWaiting();
|
|
|
$this->model->setRetryAfter(date("Y-m-d H:i:s", strtotime("+{$seconds} seconds")));
|
|
$this->model->setRetryAfter(date("Y-m-d H:i:s", strtotime("+{$seconds} seconds")));
|
|
|
$this->model->increaseRetryCount();
|
|
$this->model->increaseRetryCount();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function vmidExistInWhmcs($vmid) {
|
|
|
|
|
|
|
+ protected function vmidExistInWhmcs($vmid)
|
|
|
|
|
+ {
|
|
|
//vps
|
|
//vps
|
|
|
$cfv = 'tblcustomfieldsvalues';
|
|
$cfv = 'tblcustomfieldsvalues';
|
|
|
$cfn = 'tblcustomfields';
|
|
$cfn = 'tblcustomfields';
|
|
@@ -105,7 +109,8 @@ class BaseJob extends Job
|
|
|
->where("{$cfn}.fieldname", "like", "vmid%")
|
|
->where("{$cfn}.fieldname", "like", "vmid%")
|
|
|
->where("{$cfv}.value", $vmid)
|
|
->where("{$cfv}.value", $vmid)
|
|
|
->whereIn("{$h}.domainstatus", ['Active', "Suspended"]);
|
|
->whereIn("{$h}.domainstatus", ['Active', "Suspended"]);
|
|
|
- if ($query->count()) {
|
|
|
|
|
|
|
+ if ($query->count())
|
|
|
|
|
+ {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
//cloud
|
|
//cloud
|
|
@@ -120,31 +125,41 @@ class BaseJob extends Job
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function findFreeVmid($vmid) {
|
|
|
|
|
- for ($i = $vmid; $i <= 1000000; $i++) {
|
|
|
|
|
- if ($this->vmidExistInWhmcs($i)) {
|
|
|
|
|
|
|
+ protected function findFreeVmid($vmid)
|
|
|
|
|
+ {
|
|
|
|
|
+ for ($i = $vmid; $i <= 1000000; $i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($this->vmidExistInWhmcs($i))
|
|
|
|
|
+ {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- try {
|
|
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
$res = $this->api()->get("/cluster/nextid", ['vmid' => $i]);
|
|
$res = $this->api()->get("/cluster/nextid", ['vmid' => $i]);
|
|
|
- } catch (\Exception $ex) {
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (\Exception $ex)
|
|
|
|
|
+ {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- if ($res == $i) {
|
|
|
|
|
|
|
+ if ($res == $i)
|
|
|
|
|
+ {
|
|
|
return $i;
|
|
return $i;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
throw new \Exception("Unable to obtain vmid");
|
|
throw new \Exception("Unable to obtain vmid");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function isVmRange(){
|
|
|
|
|
- if (RangeVm::ofServerId($this->getWhmcsParamByKey("serverid"))->count()) {
|
|
|
|
|
|
|
+ protected function isVmRange()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (RangeVm::ofServerId($this->getWhmcsParamByKey("serverid"))->count())
|
|
|
|
|
+ {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
return Configuration::where("setting", "proxmoxVPSMinimumVMID")->count() > 0;
|
|
return Configuration::where("setting", "proxmoxVPSMinimumVMID")->count() > 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function nextVmid() {
|
|
|
|
|
|
|
+ protected function nextVmid()
|
|
|
|
|
+ {
|
|
|
$data = $this->api()->get("/cluster/nextid", []);
|
|
$data = $this->api()->get("/cluster/nextid", []);
|
|
|
$vmid = (int)$data ? (int)$data : 100;
|
|
$vmid = (int)$data ? (int)$data : 100;
|
|
|
$vmid = $this->findFreeVmid($vmid);
|
|
$vmid = $this->findFreeVmid($vmid);
|
|
@@ -157,7 +172,9 @@ class BaseJob extends Job
|
|
|
if (!$rageVm->has() && !$rageVm->getMin())
|
|
if (!$rageVm->has() && !$rageVm->getMin())
|
|
|
{
|
|
{
|
|
|
return $vmid;
|
|
return $vmid;
|
|
|
- } else {
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
if (!$rageVm->getMax() && $rageVm->getMin())
|
|
if (!$rageVm->getMax() && $rageVm->getMin())
|
|
|
{
|
|
{
|
|
|
$from = (int)$rageVm->getMin();
|
|
$from = (int)$rageVm->getMin();
|
|
@@ -291,18 +308,23 @@ class BaseJob extends Job
|
|
|
return $task->getExitstatus() && $task->getExitstatus() != "OK";
|
|
return $task->getExitstatus() && $task->getExitstatus() != "OK";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function failed($error) {
|
|
|
|
|
|
|
+ protected function failed($error)
|
|
|
|
|
+ {
|
|
|
|
|
|
|
|
- if ((int)$this->model->retry_count != 21) {
|
|
|
|
|
|
|
+ if ((int)$this->model->retry_count != 21)
|
|
|
|
|
+ {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if (!preg_match("/Create/", $this->model->job) || preg_match("/Clone/", $this->model->job)) {
|
|
|
|
|
|
|
+ if (!preg_match("/Create/", $this->model->job) || preg_match("/Clone/", $this->model->job))
|
|
|
|
|
+ {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
//create new entery on to do list
|
|
//create new entery on to do list
|
|
|
- if ($this->configuration()->isToDoList()) {
|
|
|
|
|
|
|
+ if ($this->configuration()->isToDoList())
|
|
|
|
|
+ {
|
|
|
$title = sprintf('Creation Failed - Service ID: %s', $this->getWhmcsParamByKey('serviceid'));
|
|
$title = sprintf('Creation Failed - Service ID: %s', $this->getWhmcsParamByKey('serviceid'));
|
|
|
- if (ToDoList::ofTitle($title)->pending()->count()) {
|
|
|
|
|
|
|
+ if (ToDoList::ofTitle($title)->pending()->count())
|
|
|
|
|
+ {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
$entity = new ToDoList();
|
|
$entity = new ToDoList();
|
|
@@ -350,17 +372,21 @@ class BaseJob extends Job
|
|
|
/**
|
|
/**
|
|
|
* @return \ModulesGarden\ProxmoxAddon\App\Models\Job:
|
|
* @return \ModulesGarden\ProxmoxAddon\App\Models\Job:
|
|
|
*/
|
|
*/
|
|
|
- protected function getParentModel() {
|
|
|
|
|
- if (is_null($this->model->parent_id)) {
|
|
|
|
|
|
|
+ protected function getParentModel()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (is_null($this->model->parent_id))
|
|
|
|
|
+ {
|
|
|
throw new \InvalidArgumentException("The Parent Id is not valid");
|
|
throw new \InvalidArgumentException("The Parent Id is not valid");
|
|
|
}
|
|
}
|
|
|
- if ($this->parent) {
|
|
|
|
|
|
|
+ if ($this->parent)
|
|
|
|
|
+ {
|
|
|
return $this->parent;
|
|
return $this->parent;
|
|
|
}
|
|
}
|
|
|
return $this->parent = \ModulesGarden\ProxmoxAddon\App\Models\Job::ofId($this->model->parent_id)->firstOrFail();
|
|
return $this->parent = \ModulesGarden\ProxmoxAddon\App\Models\Job::ofId($this->model->parent_id)->firstOrFail();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function getParentModelData() {
|
|
|
|
|
|
|
+ protected function getParentModelData()
|
|
|
|
|
+ {
|
|
|
return unserialize($this->getParentModel()->data);
|
|
return unserialize($this->getParentModel()->data);
|
|
|
}
|
|
}
|
|
|
|
|
|