Table des matières

Gandi Hosting XML-RPC API specification (OBSOLETE)

Documents version: 1.0

Cette API n'existe plus, la documentation de la nouvelle API cloud est disponible à l'adresse http://doc.rpc.gandi.net/

Table of contents

Introduction

XML Methods


Introduction

Description

Gandi hosting API XML will allow you to remotely manage your servers. It is freely available to all of Gandi's resellers.

User Cases

Creation of a Gandi server:

XML methods

Session methods

login

Signature

string login(string login, string password [, boolean safe])

Description

Log in to the XML-RPC interface and retrieve a session id.

Sessions ID are sensitive information and therefore must be kept secret. If a session ID was to be disclosed a malicious user would be able to execute commands with your credentials during 12 hours.

Parameters

Optional parameter

Returns

The XML-RPC response will contain a session id (string) if the login procedure is successful or a fault describing the problem. Possible faults are described in section Error Codes Format.

Sample code

import sys 
import xmlrpclib
proxy  = xmlrpclib.ServerProxy("https://api.gandi.net/hosting/")
try:
    session  = proxy.login("AA1234-GANDI", "mypassword", True)
except xmlrpclib.Fault, e:
    print "could not login because: " + e.faultString
    sys.exit(67)
<?php
require_once("xmlrpc.inc");
 
$proxy  = new xmlrpc_client("https://api.gandi.net/hosting/");
$msg  = new xmlrpcmsg(
    "login",
    array(new xmlrpcval("AA1234-GANDI"),
    new xmlrpcval("mypassword"),
    new xmlrpcval(True, "boolean"))
);
 
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    echo "could not login because: " . $reply->faultString() . "\n";
    exit(67);
}
$session  = $reply->value();
?>
my $safe_mode  = XMLRPC::Data->type('boolean')->value(1);
my $proxy  = XMLRPC::Lite->proxy("https://api.gandi.net/hosting/");
my $reply  = $proxy->call("login", "AA1234-GANDI", "mypassword", $safe_mode);
my $session  = $reply->result();
 
die "could not login because: " . $reply->faultstring . "\n" unless defined $session;



Account methods

account_currency

Signature

string account_currency(string session)

Description

Retrieve the currency name used with this prepaid account.

Parameters

Returns

The XML-RPC response will contain the ISO 4217 currency name (string) used for this account. Possible faults are described in section Error Codes Format

Sample code

print "prepaid account currency: %s" % proxy.account_currency(session)
$msg  = new xmlrpcmsg("account_currency", array($session));
$reply  = $proxy->send($msg);
$val  = $reply->value();
$val  = $val->scalarval();
print "prepaid account currency: " . $val . "\n";
my $reply  = $proxy->call("account_currency", $session);
my $currency  = $reply->result();
print "prepaid account currency: " . $currency . "\n";



account_balance

Signature

double account_balance(string session)

Description

Retrieve the prepaid account balance.

Parameters

Returns

The XML-RPC response will contain the balance of the account (double). Possible faults are described in section Error Codes Format.

Sample code

print "prepaid account balance: %d"  % proxy.account_balance(session)
$msg  = new xmlrpcmsg("account_balance", array($session));
$reply  = $proxy->send($msg);
$val  = $reply->value();
$val  = $val->scalarval();
print "prepaid account currency: " . $val . "\n";
my $reply  = $proxy->call("account_balance", $session);
my $balance  = $reply->result();
print "prepaid account balance: " . $balance . "\n";

Hosting account methods

hosting_account_info

Signature

struct hosting_account_info(string session)

Description

Return the informations linked to the user hosting account (number of shares, used shares, etc.).

Parameters

Returns

The XML-RPC response will be the informations for this account. Possible faults are described in section Error Codes Format

Sample code

import pprint
 
try:
    info  = proxy.hosting_account_info(session)
    pprint.pprint(info)
except xmlrpclib.Fault, e:
    print "could not get information for hosting account: %s" % (e.faultString,)
$msg  = new xmlrpcmsg("hosting_account_info", array($session));
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not get information for hosting account: %s\n", $reply->faultString());
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    print_r($val);
}
my $reply  = $proxy->call("hosting_account_info", $session);
my $info  = $reply->result();
unless (defined $opid) {
    printf "could not get information for hosting account: %s\n", $reply->faultstring;
}
else {
    print Dumper($info);
}



hosting_account_product_add

Signature

int hosting_account_product_add(string session, string product_name, int quantity, string duration)

Description

Create a 'hosting_account_product_add' operation that will add a hosting product to the logged user hosting account.

Parameters

Returns

The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format

Sample code

try:
    opid  = proxy.hosting_account_product_add(session, 'shares', 4, '1m')
    print "created operation#%s" % (opid,)
except xmlrpclib.Fault, e:
    print "could not create a hosting_account_product_add operation: %s" % (e.faultString,)
$msg  = new xmlrpcmsg("hosting_account_product_add", array($session, new xmlrpcval("shares"), new xmlrpcval(4), new xmlrpcval("1m")));
 
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not create a hosting_account_product_add operation because: %s\n", $reply->faultString()); 
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    printf("created operation#%s\n", $val);
}
my $reply  = $proxy->call("hosting_account_product_add", $session, "shares", 4, "1m");
my $opid  = $reply->result();
unless (defined $opid) {
    printf "could not create a hosting_account_product_add operation because: %s\n", $reply->faultstring;
}
else {
    printf "created operation#%s\n", $opid;
}



hosting_account_product_renew

Signature

int hosting_account_product_renew(string session, int product_id, string duration)

Description

Create a 'hosting_account_product_renew' operation that will renew a hosting product for a specified duration.

Parameters

Returns

The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format

Sample code

try:
    opid  = proxy.hosting_account_product_renew(session, 1234, '1m')
    print "created operation#%s" % (opid,)
except xmlrpclib.Fault, e:
    print "could not create a hosting_account_product_renew operation: %s" % (e.faultString,)
$msg  = new xmlrpcmsg("hosting_account_product_renew", array($session, new xmlrpcval(1234), new xmlrpcval("1m")));
 
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not create a hosting_account_product_renew operation because: %s\n", $reply->faultString()); 
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    printf("created operation#%s\n", $val);
}
my $reply  = $proxy->call("hosting_account_product_renew", $session, 1234, "1m");
my $opid  = $reply->result();
unless (defined $opid) {
    printf "could not create a hosting_account_product_renew operation because: %s\n", $reply->faultstring;
}
else {
    printf "created operation#%s\n", $opid;
}



hosting_account_product_remove

Signature

int hosting_account_product_remove(string session, int product_id)

Description

Create a 'hosting_account_product_remove' operation that will remove a hosting product from the user hosting account.

Parameters

Returns

The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format

Sample code

try:
    opid  = proxy.hosting_account_product_remove(session, 1234)
    print "created operation#%s" % (opid,)
except xmlrpclib.Fault, e:
    print "could not create a hosting_account_product_remove operation: %s" % (e.faultString,)
$msg  = new xmlrpcmsg("hosting_account_product_remove", array($session, new xmlrpcval(1234)));
 
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not create a hosting_account_product_remove operation because: %s\n", $reply->faultString()); 
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    printf("created operation#%s\n", $val);
}
my $reply  = $proxy->call("hosting_account_product_remove", $session, 1234);
my $opid  = $reply->result();
unless (defined $opid) {
    printf "could not create a hosting_account_product_remove operation because: %s\n", $reply->faultstring;
}
else {
    printf "created operation#%s\n", $opid;
}



hosting_account_product_update

Signature

int hosting_account_product_update(string session, int product_id, int quantity)

Description

Create a 'hosting_account_product_update' operation that will update the quantity of a hosting product.

Parameters

Returns

The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format

Sample code

try:
    opid  = proxy.hosting_account_product_update(session, 1234, 5)
    print "created operation#%s" % (opid,)
except xmlrpclib.Fault, e:
    print "could not create a hosting_account_product_update operation: %s" % (e.faultString,)
$msg  = new xmlrpcmsg("hosting_account_product_update", array($session, new xmlrpcval(1234), new xmlrpcval(5)));
 
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not create a hosting_account_product_update operation because: %s\n", $reply->faultString()); 
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    printf("created operation#%s\n", $val);
}
my $reply  = $proxy->call("hosting_account_product_update", $session, 1234, 5);
my $opid  = $reply->result();
unless (defined $opid) {
    printf "could not create a hosting_account_product_update operation because: %s\n", $reply->faultstring;
}
else {
    printf "created operation#%s\n", $opid;
}



VM methods

vm_create

Signature

int vm_create(string session, string hostname, string password, int os_id, int shares, int cpu, struct specs)

Description

Create a 'vm_create' operation that will create a VM and return its id.

Parameters

Returns

The XML-RPC response will be a VM ID. Possible faults are described in section Error Codes Format

Sample code

hostname  = 'vmtest1'
password  = 'my_password'
os_id  = 111
shares  = 4
cpu  = 1
specs = {'login': 'gandi'}
 
try:
    vm_id  = proxy.vm_create(session, hostname, password, os_id, shares, cpu, specs)
    print "creating VM#%d" % (vm_id,)
except xmlrpclib.Fault, e:
    print "could not create VM because: %s" % (e.faultString,)
$hostname  = new xmlrpcval("vmtest1");
$password  = new xmlrpcval("my_password");
$os_id  = new xmlrpcval(111);
$shares  = new xmlrpcval(4);
$cpu  = new xmlrpcval(1);
$specs["login"]  = new xmlrpcval("gandi");
$specs  = php_xmlrpc_encode($specs);
 
$msg  = new xmlrpcmsg("vm_create", array($session, $hostname, $password, $os_id, $shares, $cpu, $specs));
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not create VM because: %s\n", $reply->faultString());
}
else {
    $val  = $reply->value();
    $val  = $val->scalarval();
    printf("creating VM#%d\n", $val);
}
my $hostname  = "vmtest1";
my $password  = "my_password";
my $os_id  = 111;
my $shares  = 4;
my $cpu  = 1;
my $specs = {};
$specs["login"]  = "gandi";
 
my $reply  = $proxy->call("vm_create", $session, $hostname, $password, $os_id, $shares, $cpu, $specs);
 
my $vm_id  = $reply->result();
unless (defined $opid) {
    printf "could not create VM because: %s\n", $reply->faultstring;
}
else {
    printf "creating VM#%d\n", $vm_id;
}



vm_info

Signature

struct vm_info(string session, int vm_id)

Description

Return the informations of the specified VM.

Parameters

Returns

The XML-RPC response will be the informations for the specified VM. Possible faults are described in section Error Codes Format

import pprint
vm_id  = 456
try:
    vm_info  = proxy.vm_info(session, vm_id)
    print "informations for VM#%s" % (vm_id,)
    pprint.pprint(vm_info)
except xmlrpclib.Fault, e:
    print "could not retrieve informations of VM#%s because: %s" % (vm_id, e.faultString)
$vm_id  = 456;
$msg  = new xmlrpcmsg("vm_info", array($session, new xmlrpcval($vm_id)));
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not retrieve informations of VM#%s because: %s\n", $vm_id, $reply->faultString());
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    printf("informations for VM#%s\n", $vm_id);
    print_r($val);
}
my $vm_id  = 456;
my $reply  = $proxy->call("vm_info", $session, $vm_id);
my $info  = $reply->result();
unless (defined $info) {
    printf "could not retrieve informations of VM#%s because: %s\n", $vm_id, $reply->faultstring;
}
else {
    printf "informations for VM#%s\n", $vm_id;
    print Dumper($info);
}



vm_list

Signature

array vm_list(string session)

Description

Return the list of VMs associated to a hosting account.

Parameters

Returns

The XML-RPC response will be an array of VM ids. Possible faults are described in section Error Codes Format

Sample code

import pprint
try:
    vms  = proxy.vm_list(session)
    print "VMs:"
    pprint.pprint(vms)
except xmlrpclib.Fault, e:
    print "could not retrieve the list of VMs because: %s" % (e.faultString,)
$msg  = new xmlrpcmsg("vm_list", array($session));
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not retrieve the list of VMs because: %s\n", $reply->faultString()); 
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    print_r($val);
}
my $reply  = $proxy->call("vm_list", $session);
my $vms  = $reply->result();
unless (defined $vms) {
    print "could not retrieve the list of VMs because: " . $reply->faultstring . "\n";
}
else {
    print Dumper($vms);
}



vm_update

Signature

int vm_update(string session, int vm_id, struct specs)

Description

Create a 'vm_update' operation that will update a VM and returns the operation id.

Parameters

Returns

The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format

Sample code

vm_id  = 1234
shares  = 5
 
try:
    opid  = proxy.vm_update(session, vm_id, {'shares': shares})
    print "updating VM#%d is operation id#%s" % (vm_id, opid)
except xmlrpclib.Fault, e:
    print "could not update VM#%s because: %s" % (opid, e.faultString,)
$vm_id  = 1234;
$specs["shares"]  = new xmlrpcval(5);
$specs  = php_xmlrpc_encode($specs);
 
$msg  = new xmlrpcmsg("vm_update", array($session, new xmlrpcval($vm_id), $specs));
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not update VM#%s because: %s\n", $vm_id, $reply->faultString());
}
else {
    $val  = $reply->value();
    $val  = $val->scalarval();
    printf("updating VM#%d is operation id#%s\n", $vm_id, $val);
}
my $vm_id  = 1234;
my $specs = {};
$specs["shares"]  = 5;
 
my $reply  = $proxy->call("vm_update", $session, $vm_id, $specs);
 
my $opid  = $reply->result();
unless (defined $opid) {
    printf "could not update VM#%s because: %s\n", $vm_id, $reply->faultstring;
}
else {
    printf "updating VM#%d is operation id#%s\n", $vm_id, $opid;
}



vm_delete

Signature

int vm_delete(string session, int vm_id)

Description

Create a 'vm_delete' operation to delete a stopped VM, and return the operation id.

Parameters

Returns

The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format

Sample code

vm_id = 9876
try:
    opid  = proxy.vm_delete(session, vm_id)
    print "created operation#%s" % (opid,)
except xmlrpclib.Fault, e:
    print "could not create a vm_delete operation for VM#%s because: %s" % (vm_id, e.faultString,)
$vm_id = 9876;
$msg  = new xmlrpcmsg("vm_delete", array($session, new xmlrpcval($vm_id)));
 
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not create a vm_delete operation for VM#%d because: %s\n", $vm_id, $reply->faultString()); 
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    printf("created operation#%s\n", $val);
}
my $vm_id = 9876;
my $reply  = $proxy->call("vm_delete", $session, $vm_id);
my $opid  = $reply->result();
unless (defined $opid) {
    printf "could not create a vm_delete for VM#%s operation because: %s\n", $vm_id, $reply->faultstring;
}
else {
    printf "created operation#%s\n", $opid;
}



vm_start

Signature

int vm_start(string session, int vm_id)

Description

Create a 'vm_start' operation that will start (boot or unpause) a VM and returns the operation id.

Parameters

Returns

The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format

Sample code

vm_id = 9876
try:
    opid  = proxy.vm_start(session, vm_id)
    print "created operation#%s" % (opid,)
except xmlrpclib.Fault, e:
    print "could not create a vm_start operation for VM#%s because: %s" % (vm_id, e.faultString,)
$vm_id = 9876;
$msg  = new xmlrpcmsg("vm_start", array($session, new xmlrpcval($vm_id)));
 
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not create a vm_start operation for VM#%d because: %s\n", $vm_id, $reply->faultString()); 
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    printf("created operation#%s\n", $val);
}
my $vm_id = 9876;
my $reply  = $proxy->call("vm_start", $session, $vm_id);
my $opid  = $reply->result();
unless (defined $opid) {
    printf "could not create a vm_start for VM#%s operation because: %s\n", $vm_id, $reply->faultstring;
}
else {
    printf "created operation#%s\n", $opid;
}



vm_stop

Signature

int vm_stop(string session, int vm_id)

Description

Create a 'vm_stop' operation that will shutdown a VM and returns the operation id.

Parameters

Returns

The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format

Sample code

vm_id = 9876
try:
    opid  = proxy.vm_stop(session, vm_id)
    print "created operation#%s" % (opid,)
except xmlrpclib.Fault, e:
    print "could not create a vm_stop operation for VM#%s because: %s" % (vm_id, e.faultString,)
$vm_id = 9876;
$msg  = new xmlrpcmsg("vm_stop", array($session, new xmlrpcval($vm_id)));
 
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not create a vm_stop operation for VM#%d because: %s\n", $vm_id, $reply->faultString()); 
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    printf("created operation#%s\n", $val);
}
my $vm_id = 9876;
my $reply  = $proxy->call("vm_stop", $session, $vm_id);
my $opid  = $reply->result();
unless (defined $opid) {
    printf "could not create a vm_stop for VM#%s operation because: %s\n", $vm_id, $reply->faultstring;
}
else {
    printf "created operation#%s\n", $opid;
}



vm_reboot

Signature

int vm_reboot(string session, int vm_id)

Description

Create a 'vm_reboot' operation that will reboot (soft) a VM and returns the operation id.

Parameters

Returns

The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format

Sample code

vm_id = 9876
try:
    opid  = proxy.vm_reboot(session, vm_id)
    print "created operation#%s" % (opid,)
except xmlrpclib.Fault, e:
    print "could not create a vm_reboot operation for VM#%s because: %s" % (vm_id, e.faultString,)
$vm_id = 9876;
$msg  = new xmlrpcmsg("vm_reboot", array($session, new xmlrpcval($vm_id)));
 
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not create a vm_reboot operation for VM#%d because: %s\n", $vm_id, $reply->faultString()); 
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    printf("created operation#%s\n", $val);
}
my $vm_id = 9876;
my $reply  = $proxy->call("vm_reboot", $session, $vm_id);
my $opid  = $reply->result();
unless (defined $opid) {
    printf "could not create a vm_reboot for VM#%s operation because: %s\n", $vm_id, $reply->faultstring;
}
else {
    printf "created operation#%s\n", $opid;
}



Disk methods

disk_create

Signature

int disk_create(string session, struct specs)

Description

Create a 'disk_create' operation that will create a disk on the hosting side and returns the ID of the disk created.

Parameters

Returns

The XML-RPC response will be a disk ID. Possible faults are described in section Error Codes Format

Sample code

size = 2048
name = 'disk2GB'
fstype = 'ext3'
 
try:
    disk_id  = proxy.disk_create(session, {'size': size, 'name': name, 'fstype': fstype})
    print "creating disk#%d" % (disk_id,)
except xmlrpclib.Fault, e:
    print "could not create disk because: %s" % (e.faultString,)
$specs["size"]  = new xmlrpcval("2048");
$specs["name"]  = new xmlrpcval("disk2GB");
$specs["fstype"]  = new xmlrpcval("ext3");
$specs  = php_xmlrpc_encode($specs);
 
$msg  = new xmlrpcmsg("disk_create", array($session, $specs));
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not create disk because: %s\n", $reply->faultString());
}
else {
    $val  = $reply->value();
    $val  = $val->scalarval();
    printf("creating disk#%d\n", $val);
}
my $specs = {};
$specs["size"]  = 2048;
$specs["name"]  = "disk2GB";
$specs["fstype"]  = "ext3";
 
my $reply  = $proxy->call("disk_create", $session, $specs);
 
my $disk_id  = $reply->result();
unless (defined $opid) {
    printf "could not create disk because: %s\n", $reply->faultstring;
}
else {
    printf "creating disk#%d\n", $disk_id;
}



disk_info

Signature

struct disk_info(string session, int disk_id)

Description

Return the informations of the specified disk.

Parameters

Returns

The XML-RPC response will be the informations for the specified disk. Possible faults are described in section Error Codes Format

import pprint
disk_id  = 123
try:
    disk_info  = proxy.disk_info(session, disk_id)
    print "informations for disk#%s" % (disk_id,)
    pprint.pprint(disk_info)
except xmlrpclib.Fault, e:
    print "could not retrieve informations for disk#%s because: %s" % (disk_id, e.faultString)
$disk_id  = 123;
$msg  = new xmlrpcmsg("disk_info", array($session, new xmlrpcval($disk_id)));
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not retrieve informations of disk#%s because: %s\n", $disk_id, $reply->faultString());
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    printf("informations for disk#%s\n", $disk_id);
    print_r($val);
}
my $disk_id  = 123;
my $reply  = $proxy->call("disk_info", $session, $disk_id);
my $info  = $reply->result();
unless (defined $info) {
    printf "could not retrieve informations of disk#%s because: %s\n", $disk_id, $reply->faultstring;
}
else {
    printf "informations for disk#%s\n", $disk_id;
    print Dumper($info);
}



disk_delete

Signature

int disk_delete(string session, int disk_id)

Description

Create a 'disk_delete' operation to delete an unattached disk and return the operation id.

Parameters

Returns

The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format

Sample code

disk_id = 1928
try:
    opid  = proxy.disk_delete(session, disk_id)
    print "created operation#%s" % (opid,)
except xmlrpclib.Fault, e:
    print "could not create a disk_delete operation for disk#%s because: %s" % (disk_id, e.faultString,)
$disk_id = 1928;
$msg  = new xmlrpcmsg("disk_delete", array($session, new xmlrpcval($disk_id)));
 
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not create a disk_delete operation for disk#%d because: %s\n", $disk_id, $reply->faultString()); 
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    printf("created operation#%s\n", $val);
}
my $disk_id = 1928;
my $reply  = $proxy->call("disk_delete", $session, $disk_id);
my $opid  = $reply->result();
unless (defined $opid) {
    printf "could not create a disk_delete for disk#%s operation because: %s\n", $disk_id, $reply->faultstring;
}
else {
    printf "created operation#%s\n", $opid;
}



disk_attach

Signature

int disk_attach(string session, int disk_id, int vm_id)

Description

Create a 'disk_attach' operation to attach a disk to a VM and return the operation id.

Parameters

Returns

The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format

Sample code

disk_id = 1928
vm_id = 9876
try:
    opid  = proxy.disk_attach(session, disk_id, vm_id)
    print "created operation#%s" % (opid,)
except xmlrpclib.Fault, e:
    print "could not create a disk_attach operation for disk#%s on VM#%s because: %s" % (disk_id, vm_id, e.faultString,)
$disk_id = 1928;
$vm_id = 9876;
$msg  = new xmlrpcmsg("disk_attach", array($session, new xmlrpcval($disk_id), new xmlrpcval($vm_id)));
 
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not create a disk_attach operation for disk#%d on VM#%s because: %s\n", $disk_id, $vm_id, $reply->faultString()); 
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    printf("created operation#%s\n", $val);
}
my $disk_id = 1928;
my $vm_id = 9876;
my $reply  = $proxy->call("disk_attach", $session, $disk_id, $vm_id);
my $opid  = $reply->result();
unless (defined $opid) {
    printf "could not create a disk_attach for disk#%s on VM#%s operation because: %s\n", $disk_id, $vm_id, $reply->faultstring;
}
else {
    printf "created operation#%s\n", $opid;
}



disk_detach

Signature

int disk_detach(string session, int disk_id, int vm_id)

Description

Create a 'disk_detach' operation to detach a disk from a VM and return the operation id.

Parameters

Returns

The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format

Sample code

disk_id = 1928
vm_id = 9876
try:
    opid  = proxy.disk_detach(session, disk_id, vm_id)
    print "created operation#%s" % (opid,)
except xmlrpclib.Fault, e:
    print "could not create a disk_detach operation for disk#%s on VM#%s because: %s" % (disk_id, vm_id, e.faultString,)
$disk_id = 1928;
$vm_id = 9876;
$msg  = new xmlrpcmsg("disk_detach", array($session, new xmlrpcval($disk_id), new xmlrpcval($vm_id)));
 
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not create a disk_detach operation for disk#%d on VM#%s because: %s\n", $disk_id, $vm_id, $reply->faultString()); 
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    printf("created operation#%s\n", $val);
}
my $disk_id = 1928;
my $vm_id = 9876;
my $reply  = $proxy->call("disk_detach", $session, $disk_id, $vm_id);
my $opid  = $reply->result();
unless (defined $opid) {
    printf "could not create a disk_detach operation for disk#%s on VM#%s operation because: %s\n", $disk_id, $vm_id, $reply->faultstring;
}
else {
    printf "created operation#%s\n", $opid;
}



disk_list

Signature

array disk_list(string session)

Description

Return the list of disks associated to a hosting account.

Parameters

Returns

The XML-RPC response will be an array of disk ids. Possible faults are described in section Error Codes Format

Sample code

import pprint
try:
    disks  = proxy.disk_list(session)
    print "disks:"
    pprint.pprint(disks)
except xmlrpclib.Fault, e:
    print "could not retrieve the list of disks because: %s" % (e.faultString,)
$msg  = new xmlrpcmsg("disk_list", array($session));
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not retrieve the list of disks because: %s\n", $reply->faultString()); 
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    print_r($val);
}
my $reply  = $proxy->call("disk_list", $session);
my $disks  = $reply->result();
unless (defined $disks) {
    print "could not retrieve the list of disks because: " . $reply->faultstring . "\n";
}
else {
    print Dumper($disks);
}



OS methods

os_list

Signature

array os_list(string session)

Description

Return the list of OS images that can be installed on a VM.

Parameters

Returns

The XML-RPC response will be an array of struct, describing the OS images. Possible faults are described in section Error Codes Format

Sample code

import pprint
try:
    oslst  = proxy.os_list(session)
    print "OS images:"
    pprint.pprint(oslst)
except xmlrpclib.Fault, e:
    print "could not retrieve the list of OS images because: %s" % (e.faultString,)
$msg  = new xmlrpcmsg("os_list", array($session));
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not retrieve the list of OS images because: %s\n", $reply->faultString()); 
}
else {
    $val  = php_xmlrpc_decode($reply->value());
    print_r($val);
}
my $reply  = $proxy->call("os_list", $session);
my $oslst  = $reply->result();
unless (defined $oslst) {
    print "could not retrieve the list of OS images because: " . $reply->faultstring . "\n";
}
else {
    print Dumper($oslst);
}



Operations methods

operation_list

Signature

array operation_list(string session [, struct filter ])

Description

Retrieves the last 300 operation IDs matching the specified criterias.

Parameters

Returns

The XML-RPC response will contain an array of operations IDs (int) or a fault describing the problem. Possible faults are described in section Error Codes Format.

import pprint
try:
    updated_after  = xmlrpclib.DateTime("2006-01-01")
    updated_before  = xmlrpclib.DateTime("2006-02-01")
    state  = "DONE"
    type  = "vm_create"
    filter  = { "updated_after": updated_after, "updated_before": updated_before, "state": state, "type": vm_create }
    oplist  = proxy.operation_list(session, filter)
    print "operations list:"
 
    pprint.pprint(oplist)
except xmlrpclib.Fault, e:
    print "could not retrieve operations list because: %s" % e.faultString
$filter  = new xmlrpcval(array(
    "updated_after"  => new xmlrpcval("20060101T00:00:00", "dateTime.iso8601"),
    "updated_before"  => new xmlrpcval("20060201T00:00:00", "dateTime.iso8601"),
    "state"  => new xmlrpcval("DONE"),
    "type"  => new xmlrpcval("vm_create"),
    ), "struct");
 
$msg  = new xmlrpcmsg("operation_list", array($session, $filter));
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
   printf("could not retrieve operations list because: %s\n", $reply->faultString());
}
else {
   $val  = php_xmlrpc_decode($reply->value());
    print("operations list:\n");
    print_r($val);
}
my $filter  = {}
$filter["updated_after"]  = XMLRPC::Data->type("datetime")->value("20060101T00:00:00");
$filter["updated_before"]  = XMLRPC::Data->type("datetime")->value("20060201T00:00:00");
$filter["state"]  = "DONE";
$filter["type"]  = "vm_create";
my $reply  = $proxy->call("operation_list", $session, $filter);
my $oplist  = $reply->result();
unless (defined $oplist) {
    printf "could not retrieve operations list because: %s\n", $reply->faultstring;
}
else {
    print "operations list:\n";
    print Dumper($oplist);
}



operation_details

Signature

struct operation_details(string session, int opid)

Description

Retrieve an operation details.

Parameters

Returns

The XML-RPC response will contain an operation details (struct) or a fault describing the problem. The returned struct contains the following keys:

Possible faults are described in section Error Codes Format.

import pprint
opid  = 1234
try:
    opdetails  = proxy.operation_details(session, opid)
    pprint.pprint(opdetails)
except xmlrpclib.Fault, e:
    print "could not retrieve operation #%d details because: %s" % (opid, e.faultString)
$opid  = 1234;
$msg  = new xmlrpcmsg("operation_details", array($session, new xmlrpcval($opid, "int")));
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
   printf("could not retrieve operation #%d details because: %s\n", ($opid, $reply->faultString()));
}
else {
   $val  = php_xmlrpc_decode($reply->value());
    print_r($val);
}
my $opid  = 1234;
my $reply  = $proxy->call("operation_details", $session, $opid);
my $opdetails  = $reply->result();
unless (defined $opdetails) {
    printf "could not retrieve operation #%d details because: %s\n", $opid, $reply->faultstring;
}
else {
    print Dumper($opdetails);
}



operation_cancel

Signature

boolean operation_cancel(string session, int opid)

Description

Cancel an operation.

Parameters

Returns

The XML-RPC response will return True (boolean) or a fault describing the problem. Possible faults are described in section Error Codes Format.

opid  = 1234
try:
    proxy.operation_cancel(session, opid)
except xmlrpclib.Fault, e:
    print "could not cancel operation #%d because: %s" % (opid, e.faultString)
$opid  = 1234;
$msg  = new xmlrpcmsg("operation_cancel", array($session, new xmlrpcval($opid, "int")));
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    printf("could not cancel operation #%d because: %s\n", $opid, $reply->faultString());
}
my $opid  = 1234;
my $reply  = $proxy->call("operation_cancel", $session, $opid);
my $result  = $reply->result();
unless (defined $result) {
    printf "could not cancel operation #%d because: %s\n", $opid, $reply->faultstring;
}