raise EngineException("missing 'password'", HTTPStatus.UNPROCESSABLE_ENTITY)
if not indata.get("projects"):
raise EngineException("missing 'projects'", HTTPStatus.UNPROCESSABLE_ENTITY)
- # check username not exist
+ # check username not exists
if self.db.get_one(item, {"username": indata.get("username")}, fail_on_empty=False, fail_on_more=False):
- raise EngineException("username '{}' exist".format(indata["username"]), HTTPStatus.CONFLICT)
+ raise EngineException("username '{}' exists".format(indata["username"]), HTTPStatus.CONFLICT)
elif item == "projects":
if not indata.get("name"):
raise EngineException("missing 'name'")
- # check name not exist
+ # check name not exists
if self.db.get_one(item, {"name": indata.get("name")}, fail_on_empty=False, fail_on_more=False):
- raise EngineException("name '{}' exist".format(indata["name"]), HTTPStatus.CONFLICT)
+ raise EngineException("name '{}' exists".format(indata["name"]), HTTPStatus.CONFLICT)
elif item in ("vnfds", "nsds"):
filter = {"id": indata["id"]}
if id:
# TODO add admin to filter, validate rights
self._add_read_filter(session, item, filter)
if self.db.get_one(item, filter, fail_on_empty=False):
- raise EngineException("{} with id '{}' already exist for this tenant".format(item[:-1], indata["id"]),
+ raise EngineException("{} with id '{}' already exists for this tenant".format(item[:-1], indata["id"]),
HTTPStatus.CONFLICT)
# TODO validate with pyangbind
pass
elif item == "vim_accounts" or item == "sdns":
if self.db.get_one(item, {"name": indata.get("name")}, fail_on_empty=False, fail_on_more=False):
- raise EngineException("name '{}' already exist for {}".format(indata["name"], item),
+ raise EngineException("name '{}' already exists for {}".format(indata["name"], item),
HTTPStatus.CONFLICT)
def _format_new_data(self, session, item, indata):
:return: True package has is completely uploaded or False if partial content has been uplodaed.
Raise exception on error
"""
- # Check that _id exist and it is valid
+ # Check that _id exists and it is valid
current_desc = self.get_item(session, item, _id)
content_range_text = headers.get("Content-Range")
_format = None
method = "DONE"
engine_item = None
+ rollback = None
try:
if not topic or not version or not item:
raise NbiException("URL must contain at least 'topic/version/item'", HTTPStatus.METHOD_NOT_ALLOWED)
_id = cherrypy.request.headers.get("Transaction-Id")
if not _id:
_id = self.engine.new_item(session, engine_item, {}, None, cherrypy.request.headers)
+ rollback = {"session": session, "item": engine_item, "_id": _id, "force": True}
completed = self.engine.upload_content(session, engine_item, _id, indata, kwargs, cherrypy.request.headers)
if completed:
self._set_location_header(topic, version, item, _id)
outdata = {"id": _id}
elif item == "ns_instances_content":
_id = self.engine.new_item(session, engine_item, indata, kwargs)
+ rollback = {"session": session, "item": engine_item, "_id": _id, "force": True}
self.engine.ns_action(session, _id, "instantiate", {}, None)
self._set_location_header(topic, version, item, _id)
outdata = {"id": _id}
cherrypy.response.status = HTTPStatus.OK.value
else: # len(args) > 1
if item == "ns_instances_content":
- self.engine.ns_action(session, _id, "terminate", {"autoremove": True}, None)
+ opp_id = self.engine.ns_action(session, _id, "terminate", {"autoremove": True}, None)
+ outdata = {"_id": opp_id}
cherrypy.response.status = HTTPStatus.ACCEPTED.value
else:
force = kwargs.get("FORCE")
raise NbiException("Method {} not allowed".format(method), HTTPStatus.METHOD_NOT_ALLOWED)
return self._format_out(outdata, session, _format)
except (NbiException, EngineException, DbException, FsException, MsgException) as e:
- if hasattr(outdata, "close"): # is an open file
- outdata.close()
cherrypy.log("Exception {}".format(e))
cherrypy.response.status = e.http_code.value
+ if hasattr(outdata, "close"): # is an open file
+ outdata.close()
+ if rollback:
+ try:
+ self.engine.del_item(**rollback)
+ except Exception as e2:
+ cherrypy.log("Rollback Exception {}: {}".format(rollback, e2))
error_text = str(e)
if isinstance(e, MsgException):
error_text = "{} has been '{}' but other modules cannot be informed because an error on bus".format(