API state vm

The API state vm is are post requests, to manage VMs that help integrate with other applications.

State

vm state changes.
Url: host/api/vm/state

Note!

API does not work without authorization.

Parameters

  • vmId: vm Id (90E450FE-6386-4EA0-86AA-DFE2656CB2E5)
  • state: selection state (1-11)

state

    2- unpause and turn on
    3- reboot
    4- save
    9- Pause
    11- Checkpoint

Examples

PHP


header('Content-type: text/html; charset=utf-8');
require 'phpQuery.php';

$url_auth = 'http://127.0.0.1:8117/login';
$url = 'http://127.0.0.1:8117/api/vm/state';

//authorization
$auth_data = [
    'usr' => 'administrator',
    'pwd' => 'admin',
];
//state
$data = '{
        "vmId": "90E450FE-6386-4EA0-86AA-DFE2656CB2E5",
		"state": 9
      }';


function post_auth($url, $data = []){
	$ch = curl_init($url);

	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
	curl_setopt($ch, CURLOPT_COOKIEJAR, __DIR__ . '/cookie.txt');
	
	$res = curl_exec($ch);
	curl_close($ch);
	return $res;
}


function post_state($url, $data){
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_COOKIEFILE, __DIR__ . '/cookie.txt');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
	
	$res = curl_exec($ch);
	curl_close($ch);
	return $res;
}

//authorization
post_auth($url_auth, $auth_data);

//state
post_state($url, $data);