112 lines
3.9 KiB
PHP
Executable File
112 lines
3.9 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Webservices; // Assuming a Webservices namespace
|
|
|
|
use App\Core\Api; // Assuming Api class for calling Java backend
|
|
use App\Core\Controller; // Or a base Webservice class if it exists
|
|
|
|
// Placeholder for OVH.php (PHP Webservice)
|
|
// This class will be called by the frontend (e.g., AJAX from views) to trigger backend actions.
|
|
class OVH extends Controller // Or extends a base Webservice class
|
|
{
|
|
/**
|
|
* Creates OVHcloud instances by calling the Java backend.
|
|
* Expects parameters via POST request, typically from an AJAX call.
|
|
*/
|
|
public function createInstances()
|
|
{
|
|
// Input validation should ideally happen in the controller before calling this,
|
|
// or add more robust validation here.
|
|
$requiredParams = [
|
|
'ovh_account_id',
|
|
'number_of_instances',
|
|
'base_hostname',
|
|
'flavor_id',
|
|
'region',
|
|
'image_id',
|
|
'ssh_key_id',
|
|
'domain_for_rdns'
|
|
];
|
|
|
|
foreach ($requiredParams as $param) {
|
|
if (!isset($_POST[$param]) || empty($_POST[$param])) {
|
|
$this->jsonResponse(['success' => false, 'message' => "Missing required parameter: {$param}"]);
|
|
return;
|
|
}
|
|
}
|
|
|
|
$params = [
|
|
"ovhAccountId" => $_POST["ovh_account_id"],
|
|
"numberOfInstances" => (int)$_POST["number_of_instances"],
|
|
"baseHostname" => $_POST["base_hostname"],
|
|
"flavorId" => $_POST["flavor_id"],
|
|
"region" => $_POST["region"],
|
|
"imageId" => $_POST["image_id"],
|
|
"sshKeyId" => $_POST["ssh_key_id"],
|
|
"rootPassword" => $_POST["root_password"] ?? null,
|
|
"domainForRdns" => $_POST["domain_for_rdns"]
|
|
];
|
|
|
|
$response = Api::call("tech.iresponse.webservices.OVH", "createInstances", $params);
|
|
$this->jsonResponse($response);
|
|
}
|
|
|
|
/**
|
|
* Executes actions (start, stop, reboot, rebuild, delete) on an OVHcloud instance.
|
|
* Expects parameters via POST request.
|
|
*/
|
|
public function executeInstanceAction()
|
|
{
|
|
$requiredParams = ['ovh_account_id', 'instance_db_id', 'action'];
|
|
foreach ($requiredParams as $param) {
|
|
if (!isset($_POST[$param]) || empty($_POST[$param])) {
|
|
$this->jsonResponse(['success' => false, 'message' => "Missing required parameter: {$param}"]);
|
|
return;
|
|
}
|
|
}
|
|
|
|
$params = [
|
|
"ovhAccountId" => $_POST["ovh_account_id"],
|
|
"instanceDbId" => (int)$_POST["instance_db_id"],
|
|
"action" => strtoupper($_POST["action"]),
|
|
"newImageId" => $_POST["new_image_id"] ?? null // For REBUILD action
|
|
];
|
|
|
|
$response = Api::call("tech.iresponse.webservices.OVH", "executeInstancesActions", $params);
|
|
$this->jsonResponse($response);
|
|
}
|
|
|
|
/**
|
|
* Stops ongoing instance creation/management processes.
|
|
* Expects 'process_id' via POST.
|
|
*/
|
|
public function stopInstancesProcess()
|
|
{
|
|
if (!isset($_POST['process_id']) || empty($_POST['process_id'])) {
|
|
$this->jsonResponse(['success' => false, 'message' => 'Missing required parameter: process_id']);
|
|
return;
|
|
}
|
|
|
|
$params = [
|
|
"processId" => (int)$_POST["process_id"]
|
|
];
|
|
|
|
$response = Api::call("tech.iresponse.webservices.OVH", "stopInstancesProcesses", $params);
|
|
$this->jsonResponse($response);
|
|
}
|
|
|
|
// Helper to send JSON response
|
|
private function jsonResponse($data, $statusCode = 200)
|
|
{
|
|
header_remove(); // Remove any existing headers
|
|
header("Content-Type: application/json");
|
|
http_response_code($statusCode);
|
|
echo json_encode($data);
|
|
exit();
|
|
}
|
|
|
|
// Placeholder for getAccountDomains if needed, similar to Linode.php webservice
|
|
// public function getAccountDomains() { ... }
|
|
}
|
|
|