X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Fnbi.py;h=0a4c4027ef1165a81bbeb0f89549c915c3c102c9;hp=262e34981afc0e638788ae6fc1ecaa767caacb8a;hb=cb83c941ebdf6a8807ffe3b1c3346c61e085b0bf;hpb=2f98821b1da7d26fd54f631330bc8e1aa1e8f631 diff --git a/osm_nbi/nbi.py b/osm_nbi/nbi.py index 262e349..0a4c402 100644 --- a/osm_nbi/nbi.py +++ b/osm_nbi/nbi.py @@ -11,6 +11,7 @@ import logging.handlers import getopt import sys +from authconn import AuthException from auth import Authenticator from engine import Engine, EngineException from osm_common.dbbase import DbException @@ -26,6 +27,7 @@ __author__ = "Alfonso Tierno " __version__ = "0.1.3" version_date = "Apr 2018" database_version = '1.0' +auth_database_version = '1.0' """ North Bound Interface (O: OSM specific; 5,X: SOL005 not implemented yet; O5: SOL005 implemented) @@ -73,6 +75,9 @@ URL: /osm GET POST / O /subscriptions 5 5 / 5 X + /pdu/v1 + /pdu_descriptor O O + / O O O O /admin/v1 /tokens O O / O O @@ -146,7 +151,7 @@ class Server(object): def __init__(self): self.instance += 1 self.engine = Engine() - self.authenticator = Authenticator(self.engine) + self.authenticator = Authenticator() self.valid_methods = { # contains allowed URL and methods "admin": { "v1": { @@ -170,6 +175,13 @@ class Server(object): }, } }, + "pdu": { + "v1": { + "pdu_descriptors": {"METHODS": ("GET", "POST"), + "": {"METHODS": ("GET", "POST", "DELETE", "PATCH", "PUT")} + }, + } + }, "nsd": { "v1": { "ns_descriptors_content": {"METHODS": ("GET", "POST"), @@ -371,7 +383,7 @@ class Server(object): return self._format_out(outdata, session) - except EngineException as e: + except (EngineException, AuthException) as e: cherrypy.log("index Exception {}".format(e)) cherrypy.response.status = e.http_code.value return self._format_out("Welcome to OSM!", session) @@ -436,7 +448,7 @@ class Server(object): else: raise NbiException("Method {} not allowed for token".format(method), HTTPStatus.METHOD_NOT_ALLOWED) return self._format_out(outdata, session) - except (NbiException, EngineException, DbException) as e: + except (NbiException, EngineException, DbException, AuthException) as e: cherrypy.log("tokens Exception {}".format(e)) cherrypy.response.status = e.http_code.value problem_details = { @@ -622,6 +634,8 @@ class Server(object): engine_item = "nslcmops" if item == "vnfrs" or item == "vnf_instances": engine_item = "vnfrs" + elif topic == "pdu": + engine_item = "pdus" if engine_item == "vims": # TODO this is for backward compatibility, it will remove in the future engine_item = "vim_accounts" @@ -705,7 +719,7 @@ class Server(object): else: 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: + except (NbiException, EngineException, DbException, FsException, MsgException, AuthException) as e: cherrypy.log("Exception {}".format(e)) cherrypy.response.status = e.http_code.value if hasattr(outdata, "close"): # is an open file @@ -764,12 +778,13 @@ def _start_service(): update_dict['server.socket_host'] = v elif k1 in ("server", "test", "auth", "log"): update_dict[k1 + '.' + k2] = v - elif k1 in ("message", "database", "storage"): + elif k1 in ("message", "database", "storage", "authentication"): # k2 = k2.replace('_', '.') - if k2 == "port": + if k2 in ("port", "db_port"): engine_config[k1][k2] = int(v) else: engine_config[k1][k2] = v + except ValueError as e: cherrypy.log.error("Ignoring environ '{}': " + str(e)) except Exception as e: @@ -821,9 +836,11 @@ def _start_service(): logger_module.setLevel(engine_config[k1]["loglevel"]) # TODO add more entries, e.g.: storage cherrypy.tree.apps['/osm'].root.engine.start(engine_config) + cherrypy.tree.apps['/osm'].root.authenticator.start(engine_config) try: cherrypy.tree.apps['/osm'].root.engine.init_db(target_version=database_version) - except EngineException: + cherrypy.tree.apps['/osm'].root.authenticator.init_db(target_version=auth_database_version) + except (EngineException, AuthException): pass # getenv('OSMOPENMANO_TENANT', None)