From: Thierry Parmentelat Date: Thu, 12 Jul 2012 10:08:34 +0000 (+0200) Subject: add option to specify target slice with -a X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=d3cf8f77b30ede116dcb11debefb60ff04b26847;p=infrastructure.git add option to specify target slice with -a --- diff --git a/scripts/vsys_vnet_admin.py b/scripts/vsys_vnet_admin.py index 54805d3..8786f80 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,16 @@ 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 -u -p -l -S --assign -b -n " 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("-S", "--slice", dest="pl_slice", help="PlanetLab slice name", default=pl_slice) 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("-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 user slice") (options, args) = parser.parse_args() @@ -84,6 +81,7 @@ 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") @@ -103,4 +101,3 @@ if __name__ == "__main__": pp.pprint(assigned) -