Set Site/Slice HRN when new Site/Slice is created
[plcapi.git] / PLC / Methods / AddSlice.py
index a7fb5b9..bcae122 100644 (file)
@@ -1,5 +1,3 @@
-# $Id$
-# $URL$
 import re
 
 from PLC.Faults import *
@@ -92,6 +90,10 @@ class AddSlice(Method):
         slice['site_id'] = site['site_id']
         slice.sync()
 
+        # Set Slice HRN
+        root_auth = self.api.config.PLC_HRN_ROOT
+        tags['hrn'] = '.'.join([root_auth, login_base, name.split("_")[1]])
+
         for (tagname,value) in tags.iteritems():
             # the tagtype instance is assumed to exist, just check that
             if not TagTypes(self.api,{'tagname':tagname}):
@@ -102,6 +104,15 @@ class AddSlice(Method):
             else:
                 UpdateSliceTag(self.api).__call__(auth,slice_tags[0]['slice_tag_id'],value)
 
+        # take PLC_VSYS_DEFAULTS into account for convenience
+        try:
+            values= [ y for y in [ x.strip() for x in self.api.config.PLC_VSYS_DEFAULTS.split(',') ] if y ]
+            for value in values:
+                AddSliceTag(self.api).__call__(auth,slice['slice_id'],'vsys',value)
+        except:
+            print "Could not set vsys tags as configured in PLC_VSYS_DEFAULTS"
+            import traceback
+            traceback.print_exc()
         self.event_objects = {'Slice': [slice['slice_id']]}
         self.message = "Slice %d created" % slice['slice_id']