Successful build of server. Ready for testing.

This commit is contained in:
2023-09-10 23:32:59 -04:00
parent bb2e8ac538
commit b25530f063
4 changed files with 161 additions and 77 deletions

View File

@@ -116,4 +116,38 @@ class ConfigureService extends Module
return isset($response['msg']) && $response['msg'] === "ext_relation_id not found" ? null : $response['data'];
}
/**
* @param int $id
* @param array $vars
* @return bool
*/
public function initServerBuild(int $id, array $vars): bool
{
$request = $this->initCurl($this->cp['token']);
// Generate a random 8 character hostname
$hostname = substr(str_shuffle('abcdefghijklmnopqrstuvwxyz'), 0, 8);
$inputData = [
"operatingSystemId" => $vars['customfields']['Initial Operating System'],
"name" => $hostname,
"sshKeys" => [
$vars['customfields']['Initial SSH Key']
],
'email' => true
];
if (empty($vars['customfields']['Initial SSH Key'])) {
unset($inputData['sshKeys']);
}
$request->addOption(CURLOPT_POSTFIELDS, json_encode($inputData));
$request->post(
sprintf("%s/servers/%d/build", $this->cp['url'], $id)
);
return true;
}
}

View File

@@ -163,6 +163,10 @@ class ModuleFunctions extends Module
Database::systemOnServerCreate($params['serviceid'], $data);
$this->updateWhmcsServiceParamsOnServerObject($params['serviceid'], $data);
// If the server is created successfully, we can initialize the server build.
$cs = new ConfigureService();
$cs->initServerBuild($data->data->id, $params);
/**
*
* Server was created successfully.