Client SDK

Overview

The API enables you to interact with Virtualizor programatically via HTTP requests. The client API can be disabled at any time and access is only granted with a key pair.

Initializing and Authentication

<?php
    require_once('Virtualizor_Enduser_API.php');

    $v = new Virtualizor_Enduser_API('HOST_SERVER_IP', '16_BIT_API_KEY', '32_BIT_API_PASS');
?>

This will load the Class in $v with the paramaters:

  • HOST_SERVER_IP is the Host server IP where your VPS is installed.
  • 16_BIT_API_KEY is the API key.
  • 32_BIT_API_PASS is the API password.

These parameters are required for authentication, as without authentication you will not be able to use Client API.

Note: If you do not have API Key and API Password click here to know how to get the API Key 
and Password.

List of Functions

Here is the list of functions available for the developers:

FunctionDescriptionParameters
function listvs() List the Virtual Servers in your account. Returns array containing a list of Virtual Servers one has in their account.  
function start($vid) START a Virtual Server. Returns TRUE on success or FALSE on failure. int $vid The VMs ID
function stop($vid) STOP a Virtual Server. Returns TRUE on success or FALSE on failure. int $vid The VMs ID
function restart($vid) POWER OFF a Virtual Server. Returns TRUE on success or FALSE on failure. int $vid The VMs ID
function poweroff($vid) RESTART a Virtual Server. Returns TRUE on success or FALSE on failure. int $vid The VMs ID
function status($vid) Returns 1 if the VM is ON, 0 if its OFF. int $vid The VMs ID
function hostname($vid, $newhostname = NULL) GET or SET the hostname of a VM. To get the current hostname dont pass the $newhostname parameter. The CURRENT hostname is returned if $newhostname is NULL. FALSE is returned if there was an error while setting the new hostname 'onboot' is returned if the new hostname will be set when the VPS is STOPPED and STARTED 'done' is returned if the new hostname has been set right now - Mainly OpenVZ. int $vid The VMs ID

string $newhostname The new HOSTNAME of the virtual server.

function cpu($vid) GET the CPU details of a VM. Incase of Xen / KVM, only information is available as usage cannot be sensed. An array containing the details is returned. Usage details is available only in case of OpenVZ. int $vid The VMs ID
function ram($vid) GET the RAM details of a VM. Incase of Xen / KVM, only information is available as usage cannot be sensed. An array containing the details is returned. Usage details is available only in case of OpenVZ. int $vid The VMs ID
function disk($vid) GET the Disk details of a VM. Incase of Xen / KVM, only information is available as usage cannot be sensed. An array containing the details is returned. Usage details is available only in case of OpenVZ. int $vid The VMs ID
function bandwidth($vid, $month = 0) GET the Bandwidth Usage of a VM.Returns an array of Bandwidth Information for the Month GIVEN. By Default the CURRENT MONTH details are returned. int $vid The VMs ID

int $month The month in the format YYYYMM e.g. 201205 is for the Month of May, 2012

function processes($vid) List the Processes in a VPS - Only OpenVZ. An array containing all the processes is returned. int $vid The VMs ID
function services($vid) List the Services in a VPS - Only OpenVZ. An array containing all the services is returned. int $vid The VMs ID
function changepassword($vid, $pass) Changes the root password of a VPS. FALSE is returned if there was an error while setting the new password 'onboot' is returned if the new password will be set when the VPS is STOPPED and STARTED 'done' is returned if the new password has been set right now - Mainly OpenVZ. int $vid The VMs ID

string $pass The new password to set

function vnc($vid) Get the VNC Details like PORT, IP, VNC Password. Only available in case of Xen and KVM VPS if VNC is enabled. Returns an array containing all the VNC Details. int $vid The VMs ID
function vncpass($vid, $pass) Change the VNC Password. Only available in case of Xen and KVM VPS if VNC is enabled. FALSE is returned if there was an error while setting the new password 'onboot' is returned if the new password will be set when the VPS is STOPPED and STARTED. int $vid The VMs ID

string $pass The new password to set

function ostemplate($vid, $newosid = NULL, $newpass = NULL) Re-installs a VPS if the $newosid is specified. If the $newosid is not passed, then this function will return an array of available templates. FALSE is returned if there was an error while setting the new password string 'onboot' is returned if the new password will be set when the VPS is STOPPED and STARTED string 'done' is returned if the new password has been set right now - Mainly OpenVZ array An array of the list of avvailable OS Templates is returned if $newosid is NULL int $vid The VMs ID

int $newosid The Operating System ID (you got from the list) that will be installed on the VPS.

string $newpass The new root password to set.

function controlpanel($vid, $panel) Install a Control Panel. FALSE is returned if there was an error while installing the control panel 'onboot' is returned if the control panel will be installed when the VPS is STOPPED and STARTED 'done' is returned if the control panel has been installed right now - Mainly OpenVZ int $vid The VMs ID

string $panel The Name of the Panel you want to install. Options - cpanel, plesk, webuzo, kloxo, webmin

 

List VPS via the API (Example code)

funtion listvs()
  • This function has no parameters, it will get you the list of VPS.

eg:

<?php
    $host_ip  = 'xxx.xxx.xxx.xxx';
    $key      = 'A3TNS71Z4OWXXXXX';
    $key_pass = 'ifxzfx52cigahzzwn3avhoskxxxxxxxx';
    
    $v = new Virtualizor_Enduser_API($host_ip, $key, $key_pass);
    
    $vps_list = $v->listvs();

    print_r($vps_list);
?>
  • Will give you the output :
Array
(
    [1003] => Array
        (
            [vpsid] => 1003
            [vps_name] => 1028
            [serid] => 0
            [time] => 1399300794
            [edittime] => 1399563718
            [virt] => kvm
            [uid] => 1
            [plid] => 6
            [hostname] => testt
            [osid] => 187
            [iso] => 
            [sec_iso] => 
            [boot] => cda
            [space] => 5
            [inodes] => 0
            [ram] => 1024
            [burst] => 0
            [swap] => 1024
            [cpu] => 1000
            [cores] => 4
            [cpu_percent] => 100.00
            [bandwidth] => 0
            [network_speed] => 0
            [io] => 0
            [ubc] => 
            [acpi] => 1
            [apic] => 1
            [pae] => 1
            [shadow] => 0
            [vnc] => 1
            [hvm] => 0
            [suspended] => 0
            [rescue] => 0
            [band_suspend] => 0
            [tuntap] => 0
            [ppp] => 0
            [ploop] => 0
            [dns_nameserver] => a:2:{i:0;s:7:"4.2.2.1";i:1;s:7:"4.2.2.2";}
            [osreinstall_limit] => 0
            [preferences] => 
            [nic_type] => default
            [vif_type] => 
            [virtio] => 0
            [disk] => 
            [kvm_cache] => 0
            [io_mode] => 0
            [vnc_keymap] => en-us
            [routing] => 0
            [mg] => 
            [server_name] => 
            [status] => 0
            [ips] => Array
                (
                    [3516] => 192.168.12.19
                    [3733] => 192.168.1.2
                    [3749] => 192.168.1.19
                    [3735] => 192.168.1.5
                )
        ),
    .
    .
    .
    .
)

Start the VPS via the API (Example code)

function start($vid)
  • This function takes $vid as parameter which is the VPS ID for the VPS to be started.

Parameters :

  • $vid is the VPS ID to be started.

Return Values :

  • TRUE on success or FALSE on failure

eg:

<?php
    $host_ip  = 'xxx.xxx.xxx.xxx';
    $key      = 'A3TNS71Z4OWXXXXX';
    $key_pass = 'ifxzfx52cigahzzwn3avhoskxxxxxxxx';
    
    $v = new Virtualizor_Enduser_API($host_ip, $key, $key_pass);
    
    $vid = 1003;
    $ret = $v->start($vid);
    
    if($ret == True){
        echo "VPS started successfully";
    }
?>
  • Will give you the output :
 VPS started sucessfully

Stop the VPS via the API (Example code)

function stop($vid)
  • This function takes $vid as parameter which is the VPS ID for the VPS to be shutdown.

Parameters :

  • $vid is the VPS ID to be shutted down.

Return Values :

  • TRUE on success or FALSE on failure

eg:

<?php
    $host_ip  = 'xxx.xxx.xxx.xxx';
    $key      = 'A3TNS71Z4OWXXXXX';
    $key_pass = 'ifxzfx52cigahzzwn3avhoskxxxxxxxx';
    
    $v = new Virtualizor_Enduser_API($host_ip, $key, $key_pass);
    
    $vid = 1003;
    $ret = $v->stop($vid);
    
    if($ret == True){
        echo "VPS is shutting down";
    }
?>
  • Will give you the output :
 VPS is shutting down

VNC details of the VPS via the API (Example code)

function vnc($vid)
  • This function takes $vid as parameter which is the VPS ID for the VPS.

Parameters :

  • $vid is the VPS ID.

Return Values :

  • An array containing all the VNC details is returned

eg:

<?php
    $host_ip  = 'xxx.xxx.xxx.xxx';
    $key      = 'A3TNS71Z4OWXXXXX';
    $key_pass = 'ifxzfx52cigahzzwn3avhoskxxxxxxxx';
    
    $v = new Virtualizor_Enduser_API($host_ip, $key, $key_pass);
    
    $vid = 1003;
    $ret = $v->vnc($vid);
    
    print_r($ret);
?>
  • Will give you the output :
     Array
    (
        [port] => 5928
        [ip] => XXX.XXX.XXX.XXX
        [password] => feuvupyxxx
     )

Poweroff the VPS via the API (Example code)

function poweroff($vid)
  • This function takes $vid as parameter which is the VPS ID for the VPS.

Parameters :

  • $vid is the VPS ID.

Return Values :

  • TRUE on success or FALSE on failure

eg:

<?php
    $host_ip  = 'xxx.xxx.xxx.xxx';
    $key      = 'A3TNS71Z4OWXXXXX';
    $key_pass = 'ifxzfx52cigahzzwn3avhoskxxxxxxxx';
    
    $v = new Virtualizor_Enduser_API($host_ip, $key, $key_pass);
    
    $vid = 1003;
    $ret = $v->poweroff($vid);
    
    if($ret == TRUE){
        echo 'VPS poweroff sucessfull.'
    }

?>
  • Will give you the output :
VPS poweroff sucessfull.