X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=osm_nbi%2Fnbi.py;h=ff2f6decbc33783cdba4f2f13e31857334c7d9f7;hb=e47b913f0500837d7caa2ee25c0b476f58884859;hp=bec0cfa04a3e97c6eb308494c2c7eb55c4fec6f5;hpb=4568a372eb5a204e04d917213de03ec51f9110c1;p=osm%2FNBI.git diff --git a/osm_nbi/nbi.py b/osm_nbi/nbi.py index bec0cfa..ff2f6de 100644 --- a/osm_nbi/nbi.py +++ b/osm_nbi/nbi.py @@ -86,6 +86,7 @@ URL: /osm GET POST action O scale O5 heal 5 + update 05 /ns_lcm_op_occs 5 5 / 5 5 5 TO BE COMPLETED 5 5 @@ -447,6 +448,10 @@ valid_url_methods = { "METHODS": ("POST",), "ROLE_PERMISSION": "ns_instances:id:action:", }, + "update": { + "METHODS": ("POST",), + "ROLE_PERMISSION": "ns_instances:id:update:", + }, }, }, "ns_lcm_op_occs": { @@ -477,6 +482,31 @@ valid_url_methods = { }, } }, + "vnflcm": { + "v1": { + "vnf_instances": {"METHODS": ("GET", "POST"), + "ROLE_PERMISSION": "vnflcm_instances:", + "": {"METHODS": ("GET", "DELETE"), + "ROLE_PERMISSION": "vnflcm_instances:id:", + "scale": {"METHODS": ("POST",), + "ROLE_PERMISSION": "vnflcm_instances:id:scale:" + }, + "terminate": {"METHODS": ("POST",), + "ROLE_PERMISSION": "vnflcm_instances:id:terminate:" + }, + "instantiate": {"METHODS": ("POST",), + "ROLE_PERMISSION": "vnflcm_instances:id:instantiate:" + }, + } + }, + "vnf_lcm_op_occs": {"METHODS": ("GET",), + "ROLE_PERMISSION": "vnf_instances:opps:", + "": {"METHODS": ("GET",), + "ROLE_PERMISSION": "vnf_instances:opps:id:" + }, + }, + } + }, "nst": { "v1": { "netslice_templates_content": { @@ -569,6 +599,16 @@ valid_url_methods = { }, }, }, + "nsfm": { + "v1": { + "alarms": {"METHODS": ("GET", "PATCH"), + "ROLE_PERMISSION": "alarms:", + "": {"METHODS": ("GET", "PATCH"), + "ROLE_PERMISSION": "alarms:id:", + }, + } + }, + }, } @@ -823,6 +863,91 @@ class Server(object): if token_info.get("id"): cherrypy.request.login += ";session=" + token_info["id"][0:12] + # NS Fault Management + @cherrypy.expose + def nsfm(self, version=None, topic=None, uuid=None, project_name=None, ns_id=None, *args, **kwargs): + if topic == 'alarms': + try: + method = cherrypy.request.method + role_permission = self._check_valid_url_method(method, "nsfm", version, topic, None, None, *args) + query_string_operations = self._extract_query_string_operations(kwargs, method) + + self.authenticator.authorize(role_permission, query_string_operations, None) + + # to handle get request + if cherrypy.request.method == 'GET': + # if request is on basis of uuid + if uuid and uuid != 'None': + try: + alarm = self.engine.db.get_one("alarms", {"uuid": uuid}) + alarm_action = self.engine.db.get_one("alarms_action", {"uuid": uuid}) + alarm.update(alarm_action) + vnf = self.engine.db.get_one("vnfrs", {"nsr-id-ref": alarm["tags"]["ns_id"]}) + alarm["vnf-id"] = vnf["_id"] + return self._format_out(str(alarm)) + except Exception: + return self._format_out("Please provide valid alarm uuid") + elif ns_id and ns_id != 'None': + # if request is on basis of ns_id + try: + alarms = self.engine.db.get_list("alarms", {"tags.ns_id": ns_id}) + for alarm in alarms: + alarm_action = self.engine.db.get_one("alarms_action", {"uuid": alarm['uuid']}) + alarm.update(alarm_action) + return self._format_out(str(alarms)) + except Exception: + return self._format_out("Please provide valid ns id") + else: + # to return only alarm which are related to given project + project = self.engine.db.get_one("projects", {"name": project_name}) + project_id = project.get('_id') + ns_list = self.engine.db.get_list("nsrs", {"_admin.projects_read": project_id}) + ns_ids = [] + for ns in ns_list: + ns_ids.append(ns.get("_id")) + alarms = self.engine.db.get_list("alarms") + alarm_list = [alarm for alarm in alarms if alarm["tags"]["ns_id"] in ns_ids] + for alrm in alarm_list: + action = self.engine.db.get_one("alarms_action", {"uuid": alrm.get("uuid")}) + alrm.update(action) + return self._format_out(str(alarm_list)) + # to handle patch request for alarm update + elif cherrypy.request.method == 'PATCH': + data = yaml.load(cherrypy.request.body, Loader=yaml.SafeLoader) + try: + # check if uuid is valid + self.engine.db.get_one("alarms", {"uuid": data.get("uuid")}) + except Exception: + return self._format_out("Please provide valid alarm uuid.") + if data.get("is_enable") is not None: + if data.get("is_enable"): + alarm_status = 'ok' + else: + alarm_status = 'disabled' + self.engine.db.set_one("alarms", {"uuid": data.get("uuid")}, + {"alarm_status": alarm_status}) + else: + self.engine.db.set_one("alarms", {"uuid": data.get("uuid")}, + {"threshold": data.get("threshold")}) + return self._format_out("Alarm updated") + except Exception as e: + cherrypy.response.status = e.http_code.value + if isinstance(e, (NbiException, EngineException, DbException, FsException, MsgException, AuthException, + ValidationError, AuthconnException)): + http_code_value = cherrypy.response.status = e.http_code.value + http_code_name = e.http_code.name + cherrypy.log("Exception {}".format(e)) + else: + http_code_value = cherrypy.response.status = HTTPStatus.BAD_REQUEST.value # INTERNAL_SERVER_ERROR + cherrypy.log("CRITICAL: Exception {}".format(e), traceback=True) + http_code_name = HTTPStatus.BAD_REQUEST.name + problem_details = { + "code": http_code_name, + "status": http_code_value, + "detail": str(e), + } + return self._format_out(problem_details) + @cherrypy.expose def token(self, method, token_id=None, kwargs=None): token_info = None @@ -858,7 +983,12 @@ class Server(object): self._set_location_header("admin", "v1", "tokens", outdata["_id"]) # for logging self._format_login(token_info) - + # password expiry check + if self.authenticator.check_password_expiry(outdata): + outdata = {"id": outdata["id"], + "message": "change_password", + "user_id": outdata["user_id"] + } # cherrypy.response.cookie["Authorization"] = outdata["id"] # cherrypy.response.cookie["Authorization"]['expires'] = 3600 elif method == "DELETE": @@ -1193,6 +1323,7 @@ class Server(object): "nst", "nsilcm", "nspm", + "vnflcm", ): raise NbiException( "URL main_topic '{}' not supported".format(main_topic), @@ -1247,6 +1378,9 @@ class Server(object): engine_topic = "nslcmops" if topic == "vnfrs" or topic == "vnf_instances": engine_topic = "vnfrs" + elif main_topic == "vnflcm": + if topic == "vnf_lcm_op_occs": + engine_topic = "vnflcmops" elif main_topic == "nst": engine_topic = "nsts" elif main_topic == "nsilcm": @@ -1297,9 +1431,10 @@ class Server(object): if item == "reports": # TODO check that project_id (_id in this context) has permissions _id = args[0] - outdata = self.engine.get_item( - engine_session, engine_topic, _id, True - ) + filter_q = None + if "vcaStatusRefresh" in kwargs: + filter_q = {"vcaStatusRefresh": kwargs["vcaStatusRefresh"]} + outdata = self.engine.get_item(engine_session, engine_topic, _id, filter_q, True) elif method == "POST": cherrypy.response.status = HTTPStatus.CREATED.value @@ -1403,6 +1538,13 @@ class Server(object): "_links": link, } cherrypy.response.status = HTTPStatus.CREATED.value + elif topic == "vnf_instances" and item: + indata["lcmOperationType"] = item + indata["vnfInstanceId"] = _id + _id, _ = self.engine.new_item(rollback, engine_session, "vnflcmops", indata, kwargs) + self._set_location_header(main_topic, version, "vnf_lcm_op_occs", _id) + outdata = {"id": _id} + cherrypy.response.status = HTTPStatus.ACCEPTED.value else: _id, op_id = self.engine.new_item( rollback,