On 19/01/2015 19:49, Christy Perez wrote:
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
recieve an error. However, this is not an error condition.
This patch avoids reporting the exception on the GET if the object
should to ignore it.
---
src/kimchi/control/base.py | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py
index 97e789f..8048370 100644
--- a/src/kimchi/control/base.py
+++ b/src/kimchi/control/base.py
@@ -63,7 +63,8 @@ def _redirect(self, ident, code=303):
uri_params += [urllib2.quote(ident.encode('utf-8'),
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,
+ ignore_not_found=False):
def _render_element(self, ident):
self._redirect(ident)
uri_params = []
@@ -75,7 +76,7 @@ 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)
+ ignore_not_found, action_args)
def generate_action_handler_task(self, action_name, action_args=None):
def _render_task(self, task):
@@ -86,7 +87,7 @@ def _render_task(self, task):
action_args)
def _generate_action_handler_base(self, action_name, render_fn,
- action_args=None):
+ ignore_not_found, action_args=None):
def wrapper(*args, **kwargs):
validate_method(('POST'), self.role_key, self.admin_methods)
try:
@@ -111,7 +112,11 @@ def wrapper(*args, **kwargs):
except UnauthorizedError, e:
raise cherrypy.HTTPError(403, e.message)
except NotFoundError, e:
- raise cherrypy.HTTPError(404, e.message)
+ if ignore_not_found is True:
+ # Should something be returned instead?
I don't think so.
You can change the if statement to only raise the exception when
ignore_not_found is False.
if not ignore_not_found:
raise NotFoundError()
+ pass
+ else:
+ raise cherrypy.HTTPError(404, e.message)
except OperationFailed, e:
raise cherrypy.HTTPError(500, e.message)
except KimchiException, e: