f37 -> f39
[infrastructure.git] / scripts / vsys_vnet_admin.py
index 54805d3..52cdd96 100755 (executable)
@@ -30,11 +30,9 @@ def get_next_available(assigned, base, prefix):
     net = ipaddr.IPNetwork(base)
     iter_sub = net.iter_subnets(new_prefix=prefix)
 
-    print assigned
     try:
         while True:
             sub = iter_sub.next()
-            print sub
             if not [ s for s in map(ipaddr.IPNetwork, assigned.keys()) \
                     if sub == s or s in sub or sub in s]:
                return sub.exploded 
@@ -52,17 +50,20 @@ if __name__ == "__main__":
     pl_url = "https://www.planet-lab.eu:443/PLCAPI/"
     pl_slice = os.environ.get('PL_SLICE')
 
-    usage = "usage: %prog -u <user> -p <password> -l <url>  --show --assign -b <base_address> -n <prefix>"
+    usage = """Usage: 
+   %prog : displays and check current assignments
+or %prog -a -S <slicename> : assigns a range to slice <slicename>"""
     parser = OptionParser(usage=usage)
     parser.add_option("-u", "--user", dest="pl_user", help="PlanetLab account user name", default=pl_user)
     parser.add_option("-p", "--password", dest="pl_pwd", help="PlanetLab account password", default=pl_pwd)
     parser.add_option("-l", "--url", dest="pl_url", help="PlanetLab XMLRPC url", default=pl_url)
-    parser.add_option("-b", "--base", dest="basenet", help="Base network address to perform assignment (defaults to 10.0.0.0/8)", default="10.0.0.0/8")
+    parser.add_option("-b", "--base", dest="basenet",
+                      help="Base network address to perform assignment (defaults to 10.0.0.0/8)", default="10.0.0.0/8")
     parser.add_option("-n", "--prefix", dest="prefix", help="Network prefix for segments (defaults to 21)", default = "21")
-    parser.add_option("-s", "--show", action="store_false", dest="show", default=True,
-        help="Show all assigned vsys_vnet tags")
     parser.add_option("-a", "--assign", action="store_true", dest="assign", default=False,
-        help="Assign next available network segment as a vsys_vnet tag to the user slice")
+                      help="If specified, assign next available network segment as a vsys_vnet tag to the target slice")
+    parser.add_option("-S", "--slice", dest="pl_slice", default=pl_slice,
+                      help="target PlanetLab slice name, for --assign", )
 
     (options, args) = parser.parse_args()
    
@@ -84,12 +85,13 @@ if __name__ == "__main__":
         print "The next available network segment is %s." % vsys_vnet
         proceed = raw_input ("Do you wish to proceed with the assignment of the vsys_vnet tag? [y/N] ")
         if proceed.lower() in ['yes', 'y']:
+            pl_slice = options.pl_slice
             if not pl_slice:
                 pl_slice = raw_input ("Please, enter your slice name \n")
 
-                if pl_slice in assigned.values():
-                    print "Error: This slice already has a tag vsys_vnet assigned!!!"
-                    sys.exit(1)
+            if pl_slice in assigned.values():
+                print "Error: This slice already has a tag vsys_vnet assigned!!!"
+                sys.exit(1)
 
             slice_tag_id = assign_vsys_vent(api, auth, vsys_vnet, pl_slice)
 
@@ -103,4 +105,3 @@ if __name__ == "__main__":
         pp.pprint(assigned)
 
 
-