@@ -97,9 +97,9 @@ def wrapper_outer(function):
9797 def wrapper_inner (** kwargs ):
9898 '''Inner, worker function'''
9999 ctx = kwargs ['ctx' ]
100+ _ , _ , _ , operation_name = ctx .operation .name .split ('.' )
100101 props = ctx .node .properties
101102 runtime_instance_properties = ctx .instance .runtime_properties
102-
103103 # Override the resource ID if needed
104104 resource_id = kwargs .get (EXT_RES_ID )
105105 if resource_id and not \
@@ -178,11 +178,11 @@ def wrapper_inner(**kwargs):
178178 kwargs ['resource_config' ] = \
179179 runtime_instance_properties ['resource_config' ]
180180 resource_config = kwargs ['resource_config' ]
181-
181+ resource_id = utils .get_resource_id (
182+ node = ctx .node ,
183+ instance = ctx .instance )
182184 # Check if using external
183185 if ctx .node .properties .get ('use_external_resource' , False ):
184- resource_id = utils .get_resource_id (
185- node = ctx .node , instance = ctx .instance )
186186 ctx .logger .info ('%s ID# "%s" is user-provided.'
187187 % (resource_type , resource_id ))
188188 if not kwargs .get ('force_operation' , False ):
@@ -192,7 +192,6 @@ def wrapper_inner(**kwargs):
192192 # Set "resource_config" and "EXT_RES_ID"
193193 ctx .instance .runtime_properties [
194194 'resource_config' ] = resource_config
195- _ , _ , _ , operation_name = ctx .operation .name .split ('.' )
196195 ctx .instance .runtime_properties [EXT_RES_ID ] = resource_id
197196 if operation_name not in ['delete' , 'create' ] and \
198197 not kwargs ['iface' ].verify_resource_exists ():
@@ -361,3 +360,42 @@ def wrapper(**kwargs):
361360
362361 return func (** kwargs )
363362 return wrapper
363+
364+
365+ def tag_resources (fn ):
366+ def wrapper (** kwargs ):
367+ result = fn (** kwargs )
368+ ctx = kwargs .get ('ctx' )
369+ iface = kwargs .get ('iface' )
370+ resource_id = utils .get_resource_id (
371+ node = ctx .node ,
372+ instance = ctx .instance )
373+ tags = utils .get_tags_list (
374+ ctx .node .properties .get ('Tags' ),
375+ ctx .instance .runtime_properties .get ('Tags' ),
376+ kwargs .get ('Tags' ))
377+ if iface and tags and resource_id :
378+ iface .tag ({
379+ 'Tags' : tags ,
380+ 'Resources' : [resource_id ]})
381+ return result
382+ return wrapper
383+
384+
385+ def untag_resources (fn ):
386+ def wrapper (** kwargs ):
387+ ctx = kwargs .get ('ctx' )
388+ iface = kwargs .get ('iface' )
389+ resource_id = utils .get_resource_id (
390+ node = ctx .node ,
391+ instance = ctx .instance )
392+ tags = utils .get_tags_list (
393+ ctx .node .properties .get ('Tags' ),
394+ ctx .instance .runtime_properties .get ('Tags' ),
395+ kwargs .get ('Tags' ))
396+ if iface and tags and resource_id :
397+ iface .untag ({
398+ 'Tags' : tags ,
399+ 'Resources' : [resource_id ]})
400+ return fn (** kwargs )
401+ return wrapper
0 commit comments