new global setting PLC_VSYS_DEFAULTS
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Mon, 17 Dec 2012 09:45:45 +0000 (10:45 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Mon, 17 Dec 2012 09:45:45 +0000 (10:45 +0100)
utility script to check/apply this on older slices

bin/check-hrns.py
bin/check-vsys-default-tags.py [new file with mode: 0755]
default_config.xml

index f92d412..777d258 100755 (executable)
@@ -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 (executable)
index 0000000..47a9ea0
--- /dev/null
@@ -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()
index c9f3bab..0500795 100644 (file)
@@ -835,6 +835,7 @@ Copyright (C) 2006 The Trustees of Princeton University
         </variable>
       </variablelist>
     </category>
+
     <category id="myslice">
       <name>MySlice</name>
       <description>MySlice configuration parameters</description>
@@ -856,6 +857,17 @@ Copyright (C) 2006 The Trustees of Princeton University
        </variable>
       </variablelist>
     </category>
+
+    <category id="plc_vsys">
+      <name>vsys</name>
+      <description>Default vsys tags</description>
+      <variablelist>
+       <variable id="defaults" type="string">
+         <name>vsys tags set by default</name>
+         <description>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.</description>
+       </variable>
+      </variablelist>
+    </category>
   </variables>
 
   <comps>