X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Fnbi.py;h=c5262a8568de55ebdaaf6cdf0d1f4d0d955d5806;hp=4a5b0cc63939c55cdcf6c024521712663861806e;hb=36ec86019fa668dddbbe0cf9d9ec53b9ea6569cf;hpb=d985a8dbd3c2a0ae7e1b6a28b12b6c0297c888b8 diff --git a/osm_nbi/nbi.py b/osm_nbi/nbi.py index 4a5b0cc..c5262a8 100644 --- a/osm_nbi/nbi.py +++ b/osm_nbi/nbi.py @@ -14,6 +14,7 @@ import sys from authconn import AuthException from auth import Authenticator from engine import Engine, EngineException +from validation import ValidationError from osm_common.dbbase import DbException from osm_common.fsbase import FsException from osm_common.msgbase import MsgException @@ -92,6 +93,10 @@ URL: /osm GET POST query string: Follows SOL005 section 4.3.2 It contains extra METHOD to override http method, FORCE to force. + simpleFilterExpr := ["."]*["."]"="[","]* + filterExpr := ["&"]* + op := "eq" | "neq" (or "ne") | "gt" | "lt" | "gte" | "lte" | "cont" | "ncont" + attrName := string For filtering inside array, it must select the element of the array, or add ANYINDEX to apply the filtering over any item of the array, that is, pass if any item of the array pass the filter. It allows both ne and neq for not equal @@ -188,7 +193,7 @@ class Server(object): "": {"METHODS": ("GET", "PUT", "DELETE")} }, "ns_descriptors": {"METHODS": ("GET", "POST"), - "": {"METHODS": ("GET", "DELETE"), "TODO": "PATCH", + "": {"METHODS": ("GET", "DELETE", "PATCH"), "nsd_content": {"METHODS": ("GET", "PUT")}, "nsd": {"METHODS": "GET"}, # descriptor inside package "artifacts": {"*": {"METHODS": "GET"}} @@ -259,9 +264,11 @@ class Server(object): if "application/json" in cherrypy.request.headers["Content-Type"]: error_text = "Invalid json format " indata = json.load(self.reader(cherrypy.request.body)) + cherrypy.request.headers.pop("Content-File-MD5", None) elif "application/yaml" in cherrypy.request.headers["Content-Type"]: error_text = "Invalid yaml format " indata = yaml.load(cherrypy.request.body) + cherrypy.request.headers.pop("Content-File-MD5", None) elif "application/binary" in cherrypy.request.headers["Content-Type"] or \ "application/gzip" in cherrypy.request.headers["Content-Type"] or \ "application/zip" in cherrypy.request.headers["Content-Type"] or \ @@ -281,9 +288,11 @@ class Server(object): # 'application/yaml' for input format are available") error_text = "Invalid yaml format " indata = yaml.load(cherrypy.request.body) + cherrypy.request.headers.pop("Content-File-MD5", None) else: error_text = "Invalid yaml format " indata = yaml.load(cherrypy.request.body) + cherrypy.request.headers.pop("Content-File-MD5", None) if not indata: indata = {} @@ -597,7 +606,7 @@ class Server(object): if not main_topic or not version or not topic: raise NbiException("URL must contain at least 'main_topic/version/topic'", HTTPStatus.METHOD_NOT_ALLOWED) - if main_topic not in ("admin", "vnfpkgm", "nsd", "nslcm"): + if main_topic not in ("admin", "vnfpkgm", "nsd", "nslcm", "pdu"): raise NbiException("URL main_topic '{}' not supported".format(main_topic), HTTPStatus.METHOD_NOT_ALLOWED) if version != 'v1': @@ -732,7 +741,8 @@ class Server(object): raise NbiException("Method {} not allowed".format(method), HTTPStatus.METHOD_NOT_ALLOWED) return self._format_out(outdata, session, _format) except Exception as e: - if isinstance(e, (NbiException, EngineException, DbException, FsException, MsgException, AuthException)): + if isinstance(e, (NbiException, EngineException, DbException, FsException, MsgException, AuthException, + ValidationError)): http_code_value = cherrypy.response.status = e.http_code.value http_code_name = e.http_code.name cherrypy.log("Exception {}".format(e)) @@ -746,7 +756,11 @@ class Server(object): rollback.reverse() for rollback_item in rollback: try: - self.engine.del_item(**rollback_item, session=session, force=True) + if rollback_item.get("operation") == "set": + self.engine.db.set_one(rollback_item["topic"], {"_id": rollback_item["_id"]}, + rollback_item["content"], fail_on_empty=False) + else: + self.engine.del_item(**rollback_item, session=session, force=True) except Exception as e2: rollback_error_text = "Rollback Exception {}: {}".format(rollback_item, e2) cherrypy.log(rollback_error_text)