From 02d3482536dbd282f3eb7acc6920c8f320c63859 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Mon, 17 Dec 2012 10:45:45 +0100 Subject: [PATCH] new global setting PLC_VSYS_DEFAULTS utility script to check/apply this on older slices --- bin/check-hrns.py | 7 +++- bin/check-vsys-default-tags.py | 71 ++++++++++++++++++++++++++++++++++ default_config.xml | 12 ++++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100755 bin/check-vsys-default-tags.py diff --git a/bin/check-hrns.py b/bin/check-hrns.py index f92d412..777d258 100755 --- a/bin/check-hrns.py +++ b/bin/check-hrns.py @@ -42,7 +42,12 @@ def handle_persons (sites,sites_by_id, dry_run,verbose): def main(): - parser = OptionParser() + usage="""Usage: %prog + Checks that the hrn tags are correctly set +Example: + %prog -- -p -nv +""" + parser = OptionParser(usage=usage) parser.add_option("-p", "--person", action = "store_true", default = False, dest='persons',help="run on persons") parser.add_option("-n", "--node", action = "store_true", default = False, diff --git a/bin/check-vsys-default-tags.py b/bin/check-vsys-default-tags.py new file mode 100755 index 0000000..47a9ea0 --- /dev/null +++ b/bin/check-vsys-default-tags.py @@ -0,0 +1,71 @@ +#!/usr/bin/env plcsh +import sys +from optparse import OptionParser + +try: + vsys_tag_type=GetSliceTags({'tagname':'vsys'})[0] +except: + print "Can't find tag vsys - exiting" + sys.exit(1) + +def add_value (slice, value, options): + (slice_id, slice_name ) = (slice['slice_id'], slice['name']) + if options.dry_run: + print "Would add vsys=%s to slice %s (%d)"%(value,slice_name,slice_id) + return + if options.verbose: + print "Adding vsys=%s to slice %s (%d)"%(value,slice_name,slice_id) + AddSliceTag (slice_id, 'vsys', value) + + +def check (options): + # retrieve applicable slices + filter={} + if options.pattern: filter['name']=options.pattern + if not options.all: filter['peer_id']=None + slices=GetSlices(filter) + # find list of values + if options.tags: + values=options.tags + else: + config_tags=api.config.PLC_VSYS_DEFAULTS + values= [ value for value in config_tags.split(',') if value ] + # let's go + for value in values: + slice_tags=GetSliceTags({'tagname':'vsys','value':value}) + names_with_tag = [ st['name'] for st in slice_tags ] + counter=0 + for slice in slices: + if slice['name'] not in names_with_tag: + add_value (slice,value,options) + counter+=1 + if options.verbose: + print "Found %d slices for which %s is missing"%(counter,value) + +def main (): + usage="""Usage: %prog + Checks that a set of slices has a set of vsys tags set +Example: + %prog -- -p 'inria*' -t promisc -t fd_tuntap -vn +""" + parser = OptionParser(usage=usage) + parser.add_option("-t","--tag",action='append',default=[],dest='tags', + help="ignore PLC config and provide tags on the command line - can be repeated") + parser.add_option("-a","--all",action='store_true',default=False, + dest='all',help="Apply on foreign slices as well (default is local only)") + parser.add_option("-p","--pattern",action='store',default=None, + dest='pattern',help="Apply on slices whose name matches pattern") + parser.add_option("-v", "--verbose", action = "store_true", default = False, + dest='verbose', help="be verbose") + parser.add_option("-n", "--dry-run", action = "store_true", default = False, + dest='dry_run', help="don't actually do it") + (options, args) = parser.parse_args() + + if args: + parser.print_help() + sys.exit(1) + + check (options) + +if __name__ == "__main__": + main() diff --git a/default_config.xml b/default_config.xml index c9f3bab..0500795 100644 --- a/default_config.xml +++ b/default_config.xml @@ -835,6 +835,7 @@ Copyright (C) 2006 The Trustees of Princeton University + MySlice MySlice configuration parameters @@ -856,6 +857,17 @@ Copyright (C) 2006 The Trustees of Princeton University + + + vsys + Default vsys tags + + + vsys tags set by default + Comma-separated list of vsys script names that all newly created slices will have as their vsys tags. For older slices, see the check-vsys-default-tags.py script as part of the myplc package. + + + -- 2.43.0