X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Fnbi.py;h=a8f891d006d225e08f349ea738f99968742dd0fe;hp=99f90aa9eef286d3bd64af27c9137ed31026a676;hb=0ffaa99c277d76ca49fdbe4d4b6b9df4d7484857;hpb=f27c79b67671934005fa1691158c363e2b686e77;ds=sidebyside diff --git a/osm_nbi/nbi.py b/osm_nbi/nbi.py index 99f90aa..a8f891d 100644 --- a/osm_nbi/nbi.py +++ b/osm_nbi/nbi.py @@ -10,6 +10,7 @@ import logging from engine import Engine, EngineException from dbbase import DbException from fsbase import FsException +from msgbase import MsgException from base64 import standard_b64decode #from os import getenv from http import HTTPStatus @@ -18,8 +19,11 @@ from codecs import getreader from os import environ __author__ = "Alfonso Tierno " -__version__ = "0.2" -version_date = "Mar 2018" + +# TODO consider to remove and provide version using the static version file +__version__ = "0.1.3" +version_date = "Apr 2018" +database_version = '1.0' """ North Bound Interface (O: OSM specific; 5,X: SOL005 not implemented yet; O5: SOL005 implemented) @@ -39,6 +43,8 @@ URL: /osm GET POST / 5 X /vnfpkgm/v1 + /vnf_packages_content O O + / O O /vnf_packages O5 O5 / O5 O5 5 /package_content O5 O5 @@ -53,10 +59,16 @@ URL: /osm GET POST / O O /ns_instances 5 5 / 5 5 - TO BE COMPLETED + instantiate O5 + terminate O5 + action O + scale O5 + heal 5 /ns_lcm_op_occs 5 5 / 5 5 5 TO BE COMPLETED 5 5 + /vnfrs O + / O /subscriptions 5 5 / 5 X /admin/v1 @@ -66,6 +78,10 @@ URL: /osm GET POST / O O /projects O O / O O + /vims_accounts (also vims for compatibility) O O + / O O O + /sdns O O + / O O O query string. [....]*[.]=[,...]&... @@ -123,14 +139,23 @@ class Server(object): self.valid_methods = { # contains allowed URL and methods "admin": { "v1": { - "tokens": { "METHODS": ("GET", "POST", "DELETE"), + "tokens": {"METHODS": ("GET", "POST", "DELETE"), "": { "METHODS": ("GET", "DELETE")} }, - "users": { "METHODS": ("GET", "POST"), + "users": {"METHODS": ("GET", "POST"), "": {"METHODS": ("GET", "POST", "DELETE")} }, - "projects": { "METHODS": ("GET", "POST"), - "": {"METHODS": ("GET", "POST", "DELETE")} + "projects": {"METHODS": ("GET", "POST"), + "": {"METHODS": ("GET", "DELETE")} + }, + "vims": {"METHODS": ("GET", "POST"), + "": {"METHODS": ("GET", "DELETE")} + }, + "vim_accounts": {"METHODS": ("GET", "POST"), + "": {"METHODS": ("GET", "DELETE")} + }, + "sdns": {"METHODS": ("GET", "POST"), + "": {"METHODS": ("GET", "DELETE")} }, } }, @@ -140,7 +165,7 @@ class Server(object): "": {"METHODS": ("GET", "PUT", "DELETE")} }, "ns_descriptors": { "METHODS": ("GET", "POST"), - "": { "METHODS": ("GET", "DELETE"), "TODO": "PATCH", + "": {"METHODS": ("GET", "DELETE"), "TODO": "PATCH", "nsd_content": { "METHODS": ("GET", "PUT")}, "nsd": {"METHODS": "GET"}, # descriptor inside package "artifacts": {"*": {"METHODS": "GET"}} @@ -182,9 +207,20 @@ class Server(object): "ns_instances_content": {"METHODS": ("GET", "POST"), "": {"METHODS": ("GET", "DELETE")} }, - "ns_instances": {"TODO": ("GET", "POST"), - "": {"TODO": ("GET", "DELETE")} - } + "ns_instances": {"METHODS": ("GET", "POST"), + "": {"TODO": ("GET", "DELETE"), + "scale": {"TODO": "POST"}, + "terminate": {"METHODS": "POST"}, + "instantiate": {"METHODS": "POST"}, + "action": {"METHODS": "POST"}, + } + }, + "ns_lcm_op_occs": {"METHODS": "GET", + "": {"METHODS": "GET"}, + }, + "vnfrs": {"METHODS": ("GET"), + "": {"METHODS": ("GET")} + }, } }, } @@ -317,8 +353,11 @@ class Server(object): :param _format: The format to be set as Content-Type ir data is a file :return: None """ + accept = cherrypy.request.headers.get("Accept") if data is None: - cherrypy.response.status = HTTPStatus.NO_CONTENT.value + if accept and "text/html" in accept: + return html.format(data, cherrypy.request, cherrypy.response, session) + # cherrypy.response.status = HTTPStatus.NO_CONTENT.value return elif hasattr(data, "read"): # file object if _format: @@ -329,8 +368,7 @@ class Server(object): cherrypy.response.headers["Content-Type"] = 'text/plain' # TODO check that cherrypy close file. If not implement pending things to close per thread next return data - if "Accept" in cherrypy.request.headers: - accept = cherrypy.request.headers["Accept"] + if accept: if "application/json" in accept: cherrypy.response.headers["Content-Type"] = 'application/json; charset=utf-8' a = json.dumps(data, indent=4) + "\n" @@ -366,6 +404,25 @@ class Server(object): cherrypy.response.status = e.http_code.value return self._format_out("Welcome to OSM!", session) + @cherrypy.expose + def version(self, *args, **kwargs): + # TODO consider to remove and provide version using the static version file + global __version__, version_date + try: + if cherrypy.request.method != "GET": + raise NbiException("Only method GET is allowed", HTTPStatus.METHOD_NOT_ALLOWED) + elif args or kwargs: + raise NbiException("Invalid URL or query string for version", HTTPStatus.METHOD_NOT_ALLOWED) + return __version__ + " " + version_date + except NbiException as e: + cherrypy.response.status = e.http_code.value + problem_details = { + "code": e.http_code.name, + "status": e.http_code.value, + "detail": str(e), + } + return self._format_out(problem_details, None) + @cherrypy.expose def token(self, method, token_id=None, kwargs=None): session = None @@ -390,6 +447,7 @@ class Server(object): outdata = self.engine.new_token(session, indata, cherrypy.request.remote) session = outdata cherrypy.session['Authorization'] = outdata["_id"] + self._set_location_header("admin", "v1", "tokens", outdata["_id"]) # cherrypy.response.cookie["Authorization"] = outdata["id"] # cherrypy.response.cookie["Authorization"]['expires'] = 3600 elif method == "DELETE": @@ -399,6 +457,7 @@ class Server(object): session = self._authorization() token_id = session["_id"] outdata = self.engine.del_token(token_id) + oudata = None session = None cherrypy.session['Authorization'] = "logout" # cherrypy.response.cookie["Authorization"] = token_id @@ -416,19 +475,12 @@ class Server(object): } return self._format_out(problem_details, session) - @cherrypy.expose - def test2(self, args0=None, args1=None, args2=None, args3=None, *args, **kwargs): - return_text = ( - "
\n{} {} {} {} {} {} \n".format(args0, args1, args2, args3, args, kwargs))
-        return_text += "
" - return return_text - @cherrypy.expose def test(self, *args, **kwargs): thread_info = None if args and args[0] == "help": return "
\ninit\nfile/  download file\ndb-clear/table\nprune\nlogin\nlogin2\n"\
-                    "sleep/
" + "sleep/