[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25720 - gnunet-planetlab/gplmt/scripts
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25720 - gnunet-planetlab/gplmt/scripts |
Date: |
Tue, 8 Jan 2013 18:43:26 +0100 |
Author: wachs
Date: 2013-01-08 18:43:26 +0100 (Tue, 08 Jan 2013)
New Revision: 25720
Modified:
gnunet-planetlab/gplmt/scripts/gplmt-api.py
Log:
merge
Modified: gnunet-planetlab/gplmt/scripts/gplmt-api.py
===================================================================
--- gnunet-planetlab/gplmt/scripts/gplmt-api.py 2013-01-08 17:25:08 UTC (rev
25719)
+++ gnunet-planetlab/gplmt/scripts/gplmt-api.py 2013-01-08 17:43:26 UTC (rev
25720)
@@ -1,5 +1,5 @@
#!/usr/bin/python
-import sys, xmlrpclib, getopt, getpass
+import sys, os, xmlrpclib, getopt, getpass
def usage():
@@ -9,8 +9,9 @@
-p, --user= Planetlab username\n\
-p. --password= Planetlab password\n\
-s, --slice= Planetlab slice\n\
+ -n, --nodes= Files containing nodes\n\
-h, --help print this help\n\
- -o, --operation= all,my\n\
+ -o, --operation= all,my,add_nodes_file\n\
Report bugs to address@hidden \n\
GNUnet home page: http://www.gnu.org/software/gnunet/ \n\
General help using GNU software: http://www.gnu.org/gethelp/"
@@ -20,6 +21,7 @@
pl_password = None
pl_slicename = None
cfgfile = None
+nodesfile = None
op = None
def parse_arg ():
@@ -28,8 +30,9 @@
global pl_password
global pl_slicename
global op
+ global nodesfile
try:
- opts, args = getopt.getopt(sys.argv[1:], "hc:u:p:s:o:", ["help",
"config", "pl_user=", "pl_password=", "slice=", "operation="])
+ opts, args = getopt.getopt(sys.argv[1:], "hc:u:p:s:o:n:", ["help",
"config", "pl_user=", "pl_password=", "slice=", "operation=", "nodes="])
except getopt.GetoptError, err:
# print help information and exit:
print str(err) # will print something like "option -a not recognized"
@@ -47,11 +50,15 @@
cfgfile = a
elif o in ("-s", "--slice"):
pl_slicename = a
+ elif o in ("-n", "--nodes"):
+ nodesfile = a
elif o in ("-o", "--operation"):
if (a == "all"):
op = "all"
elif (a == "my"):
op = "my"
+ elif (a == "add_nodes_file"):
+ op = "add_nodes_file"
else:
usage()
sys.exit()
@@ -68,6 +75,18 @@
if (None != pl_password):
configuration.pl_password = pl_password
+def load_nodes (filename):
+ if (False == os.path.exists(filename)):
+ return None
+ fobj = open (filename, "r")
+ nodes = list()
+ for line in fobj:
+ line = line.strip()
+ print "Found node '" + line + "'"
+ nodes.append(line)
+ return nodes
+
+
def list_my_nodes (configuration):
# PlanetLab XML RPC server
server = xmlrpclib.ServerProxy(configuration.pl_api_url)
@@ -118,7 +137,32 @@
except Exception as e:
print "Error while retrieving node list: " + str(e)
+def add_to_nodes (configuration, nodes):
+ server = xmlrpclib.ServerProxy(configuration.pl_api_url)
+ # PlanetLab auth struct
+ auth = {}
+ auth['Username'] = configuration.pl_username
+ auth['AuthString'] = configuration.pl_password
+ auth['AuthMethod'] = "password"
+ # PlanetLab Slice data
+ slice_data = {}
+ slice_data['name'] = configuration.pl_slicename
+
+ # request nodes assigned to slice
+ try:
+ res = server.AddSliceToNodes (auth, configuration.pl_slicename, nodes)
+ if (res == 1):
+ print "Added slice '" + configuration.pl_slicename+ "' to nodes :"
+ str(nodes)
+ sys.stdout.flush()
+ else:
+ print "Failed to add nodes " + str(nodes)
+ sys.stdout.flush()
+ except Exception as e:
+ print "Failed to add node :" + str(e)
+
+
def main():
+ global nodesfile
global cfgfile
global op
#import gplmt
@@ -143,10 +187,22 @@
print "Please enter PlanetLab password:"
configuration.pl_password = getpass.getpass()
+ if (None != nodesfile):
+ nodes = load_nodes(nodesfile)
+ if (None == nodes):
+ print "Nodes file " +nodesfile+ "not found"
+ sys.exit(1)
+ else:
+ nodes = None
+
if (op == "all"):
list_all_nodes (configuration)
elif (op == "my"):
list_my_nodes (configuration)
+ elif (op == "my"):
+ list_my_nodes (configuration)
+ elif ((None != nodes) and (op == "add_nodes_file")):
+ add_to_nodes(configuration, nodes)
else:
usage()
sys.exit()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25720 - gnunet-planetlab/gplmt/scripts,
gnunet <=