gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r23011 - gnunet-planetlab/planetlab-api


From: gnunet
Subject: [GNUnet-SVN] r23011 - gnunet-planetlab/planetlab-api
Date: Tue, 31 Jul 2012 10:46:21 +0200

Author: wachs
Date: 2012-07-31 10:46:21 +0200 (Tue, 31 Jul 2012)
New Revision: 23011

Added:
   gnunet-planetlab/planetlab-api/getallnodes.py
Removed:
   gnunet-planetlab/planetlab-api/getnodes.py
Modified:
   gnunet-planetlab/planetlab-api/addnodes.py
   gnunet-planetlab/planetlab-api/getmynodes.py
Log:
some checks

Modified: gnunet-planetlab/planetlab-api/addnodes.py
===================================================================
--- gnunet-planetlab/planetlab-api/addnodes.py  2012-07-31 07:57:48 UTC (rev 
23010)
+++ gnunet-planetlab/planetlab-api/addnodes.py  2012-07-31 08:46:21 UTC (rev 
23011)
@@ -1,14 +1,8 @@
+#!/usr/bin/python
 
+# Add all available nodes in state "booted" to slice 
 
-'''
-Created on Jan 24, 2012
-Good information:
-http://www.planet-lab.org/doc/plc_api
-http://www.planet-lab.org/doc/plcapitut
address@hidden: mwachs
-'''
 
-#!/usr/bin/python
 import sys, os, urllib, xmlrpclib, socket
 
 user = ''
@@ -28,10 +22,14 @@
 if (arg[5] == '-s'):
     slice = arg[6]
 
-# the PL Central API
-apiurl = 'https://www.planet-lab.org/PLCAPI/'
-server = xmlrpclib.ServerProxy(apiurl)
 
+# PlanetLab Europe
+api_url = "https://www.planet-lab.eu/PLCAPI/";
+# Planetlab Central
+#api_url = https://www.planet-lab.org/PLCAPI/
+
+server = xmlrpclib.ServerProxy(api_url)
+
 # the auth struct
 auth = {}
 auth['Username'] = user
@@ -39,29 +37,33 @@
 auth['AuthMethod'] = "password"
 
 # request all sites on PL
-sys.stdout.write('Retrieving PL sites list... ')
-sys.stdout.flush()
-sites = server.GetSites(auth,{},['site_id','name','latitude','longitude'])
-nsites = len(sites)
-sys.stdout.write('got ' + str(nsites) + ' sites\n\n')
-sys.stdout.flush()
+try:
+    sys.stdout.write('Retrieving PL sites list... ')
+    sys.stdout.flush()
+    sites = server.GetSites(auth,{},['site_id','name','latitude','longitude'])
+    nsites = len(sites)
+    sys.stdout.write('Received ' + str(nsites) + ' sites\n\n')
+    sys.stdout.flush()
+except Exception as e:
+    print "Error while retrieving nodes list: " + str(e) 
 
-node_str = []
 
 # request all nodes on PL
 sys.stdout.write('Retrieving PL nodes list for sites')
 sys.stdout.flush()
 filter_dict = {"boot_state":"boot"}
-nodes = 
server.GetNodes(auth,filter_dict,['site_id','node_id','hostname','boot_state'])
-nnodes = len(nodes)
-sys.stdout.write('... got ' +str(nnodes)+ ' nodes \n\n')
+try:
+    nodes = 
server.GetNodes(auth,filter_dict,['site_id','node_id','hostname','boot_state'])
+    nnodes = len(nodes)
+    sys.stdout.write('... got ' +str(nnodes)+ ' nodes \n\n')
 
-for node in nodes:
-    node_str.append(node.get('hostname'))
+    for node in nodes:
+        node_str.append(node.get('hostname'))
     
-res =server.AddSliceToNodes(auth,slice,node_str)
+    res = server.AddSliceToNodes(auth,slice,node_str)
+    if (res == 1):
+        print 'Added ' +str(nnodes)+ ' to slice ' + slice      
+        sys.stdout.flush()
+except Exception as e:
+    print "Error while adding nodes to list: " + str(e) 
 
-if (res == 1):
-    print 'Added ' +str(nnodes)+ ' to slice ' + slice      
-sys.stdout.flush()
-

Copied: gnunet-planetlab/planetlab-api/getallnodes.py (from rev 22851, 
gnunet-planetlab/planetlab-api/getnodes.py)
===================================================================
--- gnunet-planetlab/planetlab-api/getallnodes.py                               
(rev 0)
+++ gnunet-planetlab/planetlab-api/getallnodes.py       2012-07-31 08:46:21 UTC 
(rev 23011)
@@ -0,0 +1,56 @@
+#!/usr/bin/python
+
+# List all available nodes in state "booted" to slice 
+
+
+import sys, os, urllib, xmlrpclib, socket
+
+user = ''
+password = ''
+slice = ''
+
+arg = sys.argv
+size = len(arg)
+if (len(arg) < 6):
+    print 'usage: -u <username> -p <password> -s <slice>'
+    exit()
+
+if (arg[1] == '-u'):
+    user = arg[2]
+if (arg[3] == '-p'):
+    password = arg[4]
+if (arg[5] == '-s'):
+    slice = arg[6]
+
+
+# PlanetLab Europe
+api_url = "https://www.planet-lab.eu/PLCAPI/";
+# Planetlab Central
+#api_url = https://www.planet-lab.org/PLCAPI/
+
+server = xmlrpclib.ServerProxy(api_url)
+
+# the auth struct
+auth = {}
+auth['Username'] = user
+auth['AuthString'] = password
+auth['AuthMethod'] = "password"
+
+# request all sites on PL
+try:
+    sites = server.GetSites(auth,{},['site_id','name','latitude','longitude'])
+    nsites = len(sites)
+except Exception as e:
+    print "Error while retrieving site list: " + str(e) 
+
+
+# request all nodes on PL
+filter_dict = {"boot_state":"boot"}
+try:
+    nodes = 
server.GetNodes(auth,filter_dict,['site_id','node_id','hostname','boot_state'])
+    nnodes = len(nodes)
+    for node in nodes:
+        print node.get('hostname')
+except Exception as e:
+    print "Error while retrieving node list: " + str(e) 
+       
\ No newline at end of file

Modified: gnunet-planetlab/planetlab-api/getmynodes.py
===================================================================
--- gnunet-planetlab/planetlab-api/getmynodes.py        2012-07-31 07:57:48 UTC 
(rev 23010)
+++ gnunet-planetlab/planetlab-api/getmynodes.py        2012-07-31 08:46:21 UTC 
(rev 23011)
@@ -3,7 +3,7 @@
 
 user = ''
 password = ''
-slice = 'tumple_gnunet'
+slice = ''
 
 arg = sys.argv
 size = len(arg)
@@ -11,10 +11,14 @@
     print 'usage: -u <username> -p <password>'
     exit()
 
+
+
 if (arg[1] == '-u'):
     user = arg[2]
 if (arg[3] == '-p'):
     password = arg [4]
+if (arg[5] == '-s'):
+    slice = arg [6]
 
 # the PL Central API
 # apiurl = 'https://www.planet-lab.org/PLCAPI/'
@@ -23,7 +27,7 @@
 apiurl = 'https://www.planet-lab.eu/PLCAPI/'
 server = xmlrpclib.ServerProxy(apiurl)
 slice_data = {}
-slice_data['name'] = 'tumple_gnunet_deployment'
+slice_data['name'] = slice
 
 # the auth struct
 auth = {}
@@ -32,9 +36,55 @@
 auth['AuthMethod'] = "password"
 
 
-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
 
+
+
+#!/usr/bin/python
+
+# Add all available nodes in state "booted" to slice 
+
+
+import sys, os, urllib, xmlrpclib, socket
+
+user = ''
+password = ''
+slice = ''
+
+arg = sys.argv
+size = len(arg)
+if (len(arg) < 6):
+    print 'usage: -u <username> -p <password> -s <slice>'
+    exit()
+
+if (arg[1] == '-u'):
+    user = arg[2]
+if (arg[3] == '-p'):
+    password = arg[4]
+if (arg[5] == '-s'):
+    slice = arg[6]
+
+
+# PlanetLab Europe
+api_url = "https://www.planet-lab.eu/PLCAPI/";
+# Planetlab Central
+#api_url = https://www.planet-lab.org/PLCAPI/
+
+server = xmlrpclib.ServerProxy(api_url)
+
+# the auth struct
+auth = {}
+auth['Username'] = user
+auth['AuthString'] = password
+auth['AuthMethod'] = "password"
+
+# 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) 
+       
\ No newline at end of file

Deleted: gnunet-planetlab/planetlab-api/getnodes.py
===================================================================
--- gnunet-planetlab/planetlab-api/getnodes.py  2012-07-31 07:57:48 UTC (rev 
23010)
+++ gnunet-planetlab/planetlab-api/getnodes.py  2012-07-31 08:46:21 UTC (rev 
23011)
@@ -1,54 +0,0 @@
-#!/usr/bin/python
-import sys, os, urllib, xmlrpclib, socket
-
-user = ''
-password = ''
-
-arg = sys.argv
-size = len(arg)
-if (len(arg) < 4):
-    print 'usage: -u <username> -p <password>'
-    exit()
-
-if (arg[1] == '-u'):
-    user = arg[2]
-if (arg[3] == '-p'):
-    password = arg [4]
-
-# the PL Central API
-# apiurl = 'https://www.planet-lab.org/PLCAPI/'
-
-# Planetlab EU API
-apiurl = 'https://www.planet-lab.eu/PLCAPI/'
-server = xmlrpclib.ServerProxy(apiurl)
-
-# the auth struct
-auth = {}
-auth['Username'] = user
-auth['AuthString'] = password
-auth['AuthMethod'] = "password"
-
-# request all sites on PL
-sys.stdout.write('Retrieving PL sites list... ')
-sys.stdout.flush()
-sites = server.GetSites(auth,{},['site_id','name','latitude','longitude'])
-nsites = len(sites)
-sys.stdout.write('Got ' + str(nsites) + ' sites\n\n')
-sys.stdout.flush()
-
-
-# request all nodes on PL
-sys.stdout.write('Retrieving PL nodes list for sites')
-sys.stdout.flush()
-filter_dict = {"boot_state":"boot"}
-nodes = 
server.GetNodes(auth,filter_dict,['site_id','node_id','hostname','boot_state'])
-nnodes = len(nodes)
-sys.stdout.write('Got ' +str(nnodes)+ 'nodes \n\n')
-f = open('nodes_booted', 'w')
-
-for node in nodes:
-    f.write(node.get('hostname') + '\n')
-    
-f.close()    
-sys.stdout.flush()
-




reply via email to

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