Skip to content

Examples

API_KEY and HASH are used for the authentication on SolusVM. It is required to browse to Reseller UI > y Account > and configure API Access Settings.

Create a virtual server

<?php

// Url to the reseller API endpoint
$url = "https://IP_ADDRESS:5656/api/reseller";
$postfields["key"] = "API_KEY";
$postfields["hash"] = "HASH";
$postfields["action"] = "vserver-create";
$postfields["type"]="kvm";
$postfields["nodegroup"] = "1";
$postfields["hostname"] = "my.virtualserver.tld";
$postfields["plan"] = "service1";
$postfields["template"] = "linux-centos-7-x86_64-minimal-latest";
$postfields["password"] = "qwerty123";
$postfields["username"] = "johndoe";
$postfields["ips"] = "1";
$postfields["randomipv4"] = "true";

// Send the query to the solusvm master
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . "/command.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:"));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);

// Print the result
print_r($data.PHP_EOL, false);

echo "";

Template name should be a file name of the template without extension, e.g. linux-centos-7-x86_64-minimal-latest instead of linux-centos-7-x86_64-minimal-latest.gz

If the execution of the script takes too much time and fails with time out error, consider tuning CURLOPT_TIMEOUT option

Reboot the virtual server

<?php
// Url to the reseller API endpoint
$url = "https://\<MASTER IP>:5656/api/reseller";
$postfields["key"] = "API_KEY";
$postfields["hash"] = "HASH";
$postfields["action"] = "vserver-reboot";
$postfields["vserverid"] = "VSERVER_ID";

// Send the query to the solusvm master
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . "/command.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:"));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);

// Print the result
print_r($data.PHP_EOL, false);

echo "";
Back to top