Gandi hosting API XML will allow you to remotely manage your servers. It is freely available to all of Gandi's resellers.
Creation of a Gandi server:
string login(string login, string password [, boolean safe])
Log in to the XML-RPC interface and retrieve a session id.
Note :
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.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.
import sys import xmlrpclib proxy = xmlrpclib.ServerProxy("https://api.gandi.net/xmlrpc/") 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/xmlrpc/"); $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/xmlrpc/"); 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;
string account_currency(string session)
Retrieve the currency name used with this prepaid account.
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
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";
double account_balance(string session)
Retrieve the prepaid account balance.
The XML-RPC response will contain the balance of the account (double). Possible faults are described in section Error Codes Format.
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";
struct hosting_account_info(string session)
Return the informations linked to the user hosting account (number of shares, used shares, etc.).
The XML-RPC response will be the informations for this account. Possible faults are described in section Error Codes Format
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); }
int hosting_account_product_add(string session, string product_name, int quantity, string duration)
Create a 'hosting_account_product_add' operation that will add a hosting product to the logged user hosting account.
The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format
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; }
int hosting_account_product_renew(string session, int product_id, string duration)
Create a 'hosting_account_product_renew' operation that will renew a hosting product for a specified duration.
The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format
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; }
int hosting_account_product_remove(string session, int product_id)
Create a 'hosting_account_product_remove' operation that will remove a hosting product from the user hosting account.
The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format
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; }
int hosting_account_product_update(string session, int product_id, int quantity)
Create a 'hosting_account_product_update' operation that will update the quantity of a hosting product.
The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format
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; }
int vm_create(string session, string hostname, string password, int os_id, int shares, int cpu, struct specs)
Create a 'vm_create' operation that will create a VM and return its id.
The XML-RPC response will be a VM ID. Possible faults are described in section Error Codes Format
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; }
struct vm_info(string session, int vm_id)
Return the informations of the specified VM.
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); }
array vm_list(string session)
Return the list of VMs associated to a hosting account.
The XML-RPC response will be an array of VM ids. Possible faults are described in section Error Codes Format
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); }
int vm_update(string session, int vm_id, struct specs)
Create a 'vm_update' operation that will update a VM and returns the operation id.
The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format
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; }
int vm_delete(string session, int vm_id)
Create a 'vm_delete' operation to delete a stopped VM, and return the operation id.
The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format
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; }
int vm_start(string session, int vm_id)
Create a 'vm_start' operation that will start (boot or unpause) a VM and returns the operation id.
The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format
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; }
int vm_stop(string session, int vm_id)
Create a 'vm_stop' operation that will shutdown a VM and returns the operation id.
The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format
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; }
int vm_reboot(string session, int vm_id)
Create a 'vm_reboot' operation that will reboot (soft) a VM and returns the operation id.
The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format
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; }
int disk_create(string session, struct specs)
Create a 'disk_create' operation that will create a disk on the hosting side and returns the ID of the disk created.
The XML-RPC response will be a disk ID. Possible faults are described in section Error Codes Format
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; }
struct disk_info(string session, int disk_id)
Return the informations of the specified disk.
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); }
int disk_delete(string session, int disk_id)
Create a 'disk_delete' operation to delete an unattached disk and return the operation id.
The XML-RPC response will be an operation id. Possible faults are described in section Error Codes Format
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<