X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=PLC%2FMethods%2FAddSlice.py;h=51918f41602241db1a754d26eddf48bea2c508d1;hb=13901cd4465288b634103c1997a5653500f2b5cc;hp=9644e6d5255e627a5e72b891710d0716e3210bb7;hpb=d39ed0538a3ad7090d8188a691849ab07733d784;p=plcapi.git diff --git a/PLC/Methods/AddSlice.py b/PLC/Methods/AddSlice.py index 9644e6d..51918f4 100644 --- a/PLC/Methods/AddSlice.py +++ b/PLC/Methods/AddSlice.py @@ -1,5 +1,3 @@ -# $Id$ -# $URL$ import re from PLC.Faults import * @@ -14,7 +12,8 @@ from PLC.TagTypes import TagTypes from PLC.SliceTags import SliceTags from PLC.Methods.AddSliceTag import AddSliceTag from PLC.Methods.UpdateSliceTag import UpdateSliceTag -from PLC.SFA import SFA + +from PLC.Debug import log can_update = ['name', 'instantiation', 'url', 'description', 'max_nodes'] @@ -64,7 +63,7 @@ class AddSlice(Method): # 3. Then single underscore after login_base. # 4. Then letters, numbers, or underscores. name = slice_fields['name'] - good_name = r'^[a-z0-9]+_[a-zA-Z0-9_]+$' + good_name = r'^[a-z0-9\.]+_[a-zA-Z0-9_\.]+$' if not name or \ not re.match(good_name, name): raise PLCInvalidArgument, "Invalid slice name" @@ -85,14 +84,18 @@ class AddSlice(Method): "Site %s has reached (%d) its maximum allowable slice count (%d)"%(site['name'], len(site['slice_ids']), site['max_slices']) - if not site['enabled']: - raise PLCInvalidArgument, "Site %s is disabled and can cannot create slices" % (site['name']) - + if not site['enabled']: + raise PLCInvalidArgument, "Site %s is disabled and can cannot create slices" % (site['name']) + slice = Slice(self.api, native) slice['creator_person_id'] = self.caller['person_id'] 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}): @@ -103,9 +106,16 @@ 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 >> log, "Could not set vsys tags as configured in PLC_VSYS_DEFAULTS" + import traceback + traceback.print_exc(file=log) self.event_objects = {'Slice': [slice['slice_id']]} self.message = "Slice %d created" % slice['slice_id'] - - sfa = SFA(self.api) - sfa.update_record(slice, 'slice', site['login_base']) + return slice['slice_id']