gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r25715 - gnunet-planetlab/gplmt/scripts


From: gnunet
Subject: [GNUnet-SVN] r25715 - gnunet-planetlab/gplmt/scripts
Date: Tue, 8 Jan 2013 17:46:37 +0100

Author: wachs
Date: 2013-01-08 17:46:37 +0100 (Tue, 08 Jan 2013)
New Revision: 25715

Modified:
   gnunet-planetlab/gplmt/scripts/getmynodes.py
Log:
unified with gplmt to use configuration


Modified: gnunet-planetlab/gplmt/scripts/getmynodes.py
===================================================================
--- gnunet-planetlab/gplmt/scripts/getmynodes.py        2013-01-08 16:45:53 UTC 
(rev 25714)
+++ gnunet-planetlab/gplmt/scripts/getmynodes.py        2013-01-08 16:46:37 UTC 
(rev 25715)
@@ -1,74 +1,114 @@
 #!/usr/bin/python
-import sys, xmlrpclib,  getopt
+import sys, xmlrpclib, getopt, getpass
 
+
 def usage():
     print "GNUnet PlanetLab deployment and automation toolset\n\
 Arguments mandatory for long options are also mandatory for short options.\n\
-  -u, --user=      Planetlab username\n\
-  -p, --password=       Planetlab password\n\
+  -c, --config=    configuration file\n\
+  -p, --user=      Planetlab username\n\
+  -p. --password=       Planetlab password\n\
   -s, --slice=       Planetlab slice\n\
-  -f, --file=                  file containing nodes\n\
   -h, --help                 print this help\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/";
 
-user = None
-password = None
-plslice = None
-filename = None
+# configuration
+pl_user = None
+pl_password = None
+pl_slicename = None
+cfgfile = None
 
-# Parse command line arguments
+def parse_arg ():
+    global cfgfile
+    global pl_user
+    global pl_password
+    global pl_slicename
 
-try:
-    opts, args = getopt.getopt(sys.argv[1:], "hu:p:s:", ["help", "user=", 
"password=", "slice="])
-except getopt.GetoptError, err:
-    # print help information and exit:
-    print str(err) # will print something like "option -a not recognized"
-    usage()
-    sys.exit(2)
-for o, a in opts:
-    if o in ("-h", "--help"):
+    
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "hc:u:p:s:", ["help", 
"config", "pl_user=", "pl_password=", "slice="])
+    except getopt.GetoptError, err:
+        # print help information and exit:
+        print str(err) # will print something like "option -a not recognized"
         usage()
-        sys.exit()
-    elif o in ("-u", "--user"):
-        user = a
-    elif o in ("-p", "--password"):
-        password = a
-    elif o in ("-s", "--slice"):
-        plslice = a                                                 
-        filename = a                                 
-    else:
-        assert False, "unhandled option"
-        
-if (((user == None) or (password == None) or (slice == None))):
-    usage ()
-    sys.exit (2)
+        sys.exit(2)
+    for o, a in opts:
+        if o in ("-h", "--help"):
+            usage()
+            sys.exit()
+        elif o in ("-u", "--pl_user"):
+            pl_username = a
+        elif o in ("-p", "--pl_password"):
+            pl_password = a
+        elif o in ("-c", "--config"):
+            cfgfile = a          
+        elif o in ("-s", "--slice"):
+            pl_slicename = a                                                   
                     
+        else:
+            assert False, "unhandled option"
+            
+def update_conf (configuration):
+    if (None != pl_user):
+        configuration.pl_user = pl_user
+    if (None != pl_password):
+        configuration.pl_password = pl_password
+    if (None != pl_slicename):
+        configuration.pl_slicename = pl_slicename
+    if (None != pl_password):
+        configuration.pl_password = pl_password         
 
+def run_pl_api (configuration):
+    # PlanetLab XML RPC server
+    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:
+        node_ids = server.GetSlices(auth, [slice_data['name']], 
['node_ids'])[0]['node_ids']
+        node_hostnames = [node['hostname'] for node in server.GetNodes(auth, 
node_ids, ['hostname'])]
+    
+        for node in node_hostnames:
+            print node
+    except Exception as e:
+        print "Error while retrieving node list: " + str(e) 
+    
 
-# PlanetLab Europe
-api_url = "https://www.planet-lab.eu/PLCAPI/";
-# Planetlab Central
-#api_url = https://www.planet-lab.org/PLCAPI/
+def main():
+    global cfgfile
+    #import gplmt
+    import gplmt.Configuration as Configuration
+    import gplmt.Util as Util
+    
+    logger = Util.Logger (True)
+    # Parse command line arguments
+    parse_arg ()
+    configuration = Configuration.Configuration (cfgfile, logger)
+    configuration.load ()
+    update_conf (configuration)
 
-server = xmlrpclib.ServerProxy(api_url)
+    if ((configuration.pl_username == "") or 
+         (configuration.pl_slicename == "")):
+        #usage ()
+        sys.exit (2)
+    if (configuration.pl_api_url == ""):
+        # PlanetLab Europe
+        configuration.pl_api_url = "https://www.planet-lab.eu/PLCAPI/";
+    if (configuration.pl_password == ""):
+        print "Please enter PlanetLab password:"            
+        configuration.pl_password = getpass.getpass()    
 
-# the auth struct
-auth = {}
-auth['Username'] = user
-auth['AuthString'] = password
-auth['AuthMethod'] = "password"
-
-slice_data = {}
-slice_data['name'] = plslice
-
-# request nodes assigned to slice
-try:
-    node_ids = server.GetSlices(auth, [slice_data['name']], 
['node_ids'])[0]['node_ids']
-    node_hostnames = [node['hostname'] for node in server.GetNodes(auth, 
node_ids, ['hostname'])]
-
-    for node in node_hostnames:
-        print node
-except Exception as e:
-    print "Error while retrieving node list: " + str(e) 
-       
+    run_pl_api (configuration)
+    
+if (__name__ == "__main__"):
+    # Modify search path to include gplmt
+    sys.path.append('../')
+    main ()




reply via email to

[Prev in Thread] Current Thread [Next in Thread]