From a19ad195de060a360697afef71c7383e616b32fb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bar=C4=B1=C5=9F=20Metin?= Date: Fri, 9 Jul 2010 17:15:00 +0200 Subject: [PATCH 1/1] unify handling calls in before and after aspects. check method's return value before proceeding with the aspect's actions. --- aspects/omfaspects.py | 46 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/aspects/omfaspects.py b/aspects/omfaspects.py index 6612ca4..32eb364 100644 --- a/aspects/omfaspects.py +++ b/aspects/omfaspects.py @@ -15,6 +15,8 @@ class BaseOMF(object): def __init__(self): self.config = Config("/etc/planetlab/plc_config") + self.slice = None + # this was only for debugging, no need to log all method calls here -baris # self.log = open("/var/log/omf/plc_slice_calls.log", "a") self.log = None @@ -90,27 +92,6 @@ class BaseOMF(object): slice_name_or_id = None node_ids = None - # DeleteSlice shall be handled before the actual method call; - # after the call we won't be able to acess the slice. - if api_method_name == "DeleteSlice": - slice_name_or_id = args[1] - else: # ignore the rest - return - - slice = self.get_slice(wobj.api, slice_name_or_id) - if not slice: - return - - if api_method_name == "DeleteSlice": - self.delete_slice(slice['name']) - - self.logit(wobj.name, args, kwargs, data, slice) - - # aspect method - def after(self, wobj, data, *args, **kwargs): - api_method_name = wobj.name - slice_name_or_id = None - node_ids = None if api_method_name == "AddSlice": slice_name_or_id = args[1]['name'] elif api_method_name == "AddSliceToNodes" or api_method_name == "DeleteSliceFromNodes": @@ -118,20 +99,38 @@ class BaseOMF(object): node_ids = args[2] elif api_method_name == "AddSliceTag": slice_name_or_id = args[1] + elif api_method_name == "DeleteSlice": + slice_name_or_id = args[1] else: # ignore the rest #self.logit(wobj.name, args, kwargs, data, "SLICE") + self.slice = None + return + + self.slice = self.get_slice(wobj.api, slice_name_or_id) + + self.logit(wobj.name, args, kwargs, data, slice) + + # aspect method + def after(self, wobj, data, *args, **kwargs): + if not self.slice: return - slice = self.get_slice(wobj.api, slice_name_or_id) - if not slice: + if data.has_key("method_return_value") and data['method_return_value'] == 1: + # return value 1 means that API call was successful, we can go on. + pass + else: return + api_method_name = wobj.name + if api_method_name == "AddSlice": self.create_slice(slice['name']) elif api_method_name == "AddSliceToNodes": for node_id in node_ids: node_hostname = self.get_node_hostname(wobj.api, node_id) self.add_resource(slice['name'], node_hostname) + elif api_method_name == "DeleteSlice": + self.delete_slice(slice['name']) elif api_method_name == "DeleteSliceFromNodes": for node_id in node_ids: node_hostname = self.get_node_hostname(wobj.api, node_id) @@ -149,7 +148,6 @@ class BaseOMF(object): slice_tag['value'] = u'dotsshmount' slice_tag.sync() - self.logit(wobj.name, args, kwargs, data, slice) -- 2.43.0