Since I recently had to delve into the subtleties of using PlanetLab, I decided to share an example script to automatically add-delete nodes. Perhaps this will shorten the time for someone in the future.

I will describe briefly what is at stake. PlanetLab is a network widely used to test new network services or modify existing ones. PlanetLab nodes (there are about 1024's) are distributed in different countries and access to them is obtained only by employees of those institutions that host PlanetLab nodes. A more detailed article on PlanetLab is
here .
')
If you are developing distributed applications, it will be difficult to manage without PlanetLab. When testing a distributed application, you will most likely have to deal with a large number of nodes (Nodes). The problem is that in PlanetLab the nodes often go offline. Accordingly, these nodes need to be removed from your account (slice) and connect new ones instead. It is certainly possible to do it through the web interface by hand. However, the process is tedious, so the best way to use the script. This is the script that I want to share with you. It is written on python.
A description of all the API methods of PlanetLab can be found at
www.planet-lab.eu/doc/api . The script itself has tried to provide sufficient number of comments so that it is clear what is happening.
#! / usr / bin / env pythonimport xmlrpclib
import sys
plc_host =
'www.planet-lab.eu'auth =
{
'AuthMethod' :
'gpg' ,
'name' :
'your user name' ,
'signature' :
'GnuPG signature' ,
}
slice_name =
'tudresdenple_backup'api_url = "
% s : 443 / PLCAPI /"% plc_host
#api_url = "
% s / PLCAPI "% plc_host
plc_api = xmlrpclib.ServerProxy (api_url, allow_none = True)
#get list of all nodes
print “nodes:"nodes = plc_api.GetNodes (auth, {}, [
'node_id' ,
'hostname' ,
'boot_state' ])
#get ids the slice
attached_nodes_ids = plc_api.GetSlices (auth, [slice_name], [
'node_ids' ]) [0] [
'node_ids' ]
#obtain nodes hostnames, which will look like {'hostname': ''}
attached_nodes = plc_api.GetNodes (auth, attached_nodes_ids, [
'hostname' ,
'boot_state' ])
#extract hostname only
have_nodes = []
for node
in attached_nodes:
have_nodes.append (node [
'hostname' ])
for node
in have_nodes:
print node
#Filter all the nodes that have been in the boot state and therefor
print "Searching for non-boot nodes slice:"to_delete = []
for node_record
in attached_nodes:
if node_record [
'boot_state' ]! =
'boot' :
to_delete.append (node_record [
'hostname' ])
for node_record
in to_delete:
print node_record
#delete those nodes
num_of_deleted =
len (to_delete)
if num_of_deleted> 0:
success = plc_api.DeleteSliceFromNodes (auth, slice_name, to_delete)
if success == 1:
print "Successfullly detached non-booted nodes"else :
print "Deleting of the non-booted nodes has failed!"sys.exit ()
else :
print "Nothing to delete or add"
sys.exit ()
#add as the number of deleted ones
print "Adding new booted nodes"to_add = []
for node_record
in nodes:
if num_of_deleted> 0:
num_of_deleted - = num_of_deleted
else :
break
if (node_record [
'hostname' ]
not in have_nodes) and node_record [
'boot_state' ] ==
'boot' :
to_add.append (node_record [
'hostname' ])
if len (to_add)> 0:
success = plc_api.AddSliceToNodes (auth, slice_name, to_add)
if success == 1:
print "Successfullly attached new nbooted nodes"else :
print "Addint of the booted nodes has failed!"sys.exit ()
print "The following nodes were added:"for node_record
in to_add:
print node_record