If a transient (or non-persistent) object (e.g. VM, network or
storage pool) is created outside of Kimchi, it will (expectedly)
be deleted when shutdown. Since Kimchi calls a GET after
shutdown and other POST requests, the GET fails, and a user will
receive an error. However, this is not an error condition.
This patch does not call the GET function for transient objects
if the function will delete the object (as indicated by a new
parameter passed to generate_action_handler).
Signed-off-by: Christy Perez <christy(a)linux.vnet.ibm.com>
---
src/kimchi/control/base.py | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py
index 484e9b9..b50ea5c 100644
--- a/src/kimchi/control/base.py
+++ b/src/kimchi/control/base.py
@@ -71,7 +71,8 @@ def _redirect(self, action_result, code=303):
safe="")]
raise cherrypy.HTTPRedirect(self.uri_fmt % tuple(uri_params), code)
- def generate_action_handler(self, action_name, action_args=None):
+ def generate_action_handler(self, action_name, action_args=None,
+ destructive=False):
def _render_element(self, ident):
self._redirect(ident)
uri_params = []
@@ -83,7 +84,8 @@ def _render_element(self, ident):
raise internal_redirect(self.uri_fmt % tuple(uri_params))
return self._generate_action_handler_base(action_name, _render_element,
- action_args)
+ destructive=destructive,
+ action_args=action_args)
def generate_action_handler_task(self, action_name, action_args=None):
def _render_task(self, task):
@@ -91,10 +93,10 @@ def _render_task(self, task):
return kimchi.template.render('Task', task)
return self._generate_action_handler_base(action_name, _render_task,
- action_args)
+ action_args=action_args)
def _generate_action_handler_base(self, action_name, render_fn,
- action_args=None):
+ destructive=False, action_args=None):
def wrapper(*args, **kwargs):
validate_method(('POST'), self.role_key, self.admin_methods)
try:
@@ -109,7 +111,10 @@ def wrapper(*args, **kwargs):
action_fn = getattr(self.model, model_fn(self, action_name))
action_result = action_fn(*model_args)
- return render_fn(self, action_result)
+ if destructive is False or \
+ ('persistent' in self.info.keys()
+ and self.info['persistent'] is True):
+ return render_fn(self, action_result)
except MissingParameter, e:
raise cherrypy.HTTPError(400, e.message)
except InvalidParameter, e:
--
1.9.3