X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=scripts%2Fvsys_vnet_admin.py;h=52cdd960779195023f6b57e738c10161c0e60ffb;hb=HEAD;hp=54805d314acc30bf19b98eefdf9b2fc128edced7;hpb=35901273dc9fed4f12d59bce7a59da41906bfc8a;p=infrastructure.git diff --git a/scripts/vsys_vnet_admin.py b/scripts/vsys_vnet_admin.py index 54805d3..52cdd96 100755 --- a/scripts/vsys_vnet_admin.py +++ b/scripts/vsys_vnet_admin.py @@ -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 -p -l --show --assign -b -n " + usage = """Usage: + %prog : displays and check current assignments +or %prog -a -S : assigns a range to slice """ 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) -