diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2023-03-13 11:00:21 +0000 |
---|---|---|
committer | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2023-03-14 14:25:16 +0000 |
commit | 870ff702088b89549bc21631eb48443fff0bcd71 (patch) | |
tree | 5d52aca25035644bdc2ac687275ed858ba524e7e /mock-aai/resources/vnf.py | |
parent | 98e0e65ba145ab4c85c301118d4a0d02940221ec (diff) |
Migrate mock applications from Orange GitLab
Move from Orange repositories into ONAP one.
Issue-ID: INT-2208
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Change-Id: I6e165da5144c28a6ff151e02e32f5ae89ce124e3
Diffstat (limited to 'mock-aai/resources/vnf.py')
-rw-r--r-- | mock-aai/resources/vnf.py | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/mock-aai/resources/vnf.py b/mock-aai/resources/vnf.py new file mode 100644 index 0000000..3a49f01 --- /dev/null +++ b/mock-aai/resources/vnf.py @@ -0,0 +1,108 @@ +"""Vnf resources module.""" +""" + Copyright 2023 Deutsche Telekom AG, Orange + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +""" +from typing import Dict, List +from uuid import uuid4 + +from flask_restful import Resource, request + + +VNFS = {} + + +class Vnf(Resource): + """Vnf resource.""" + + @staticmethod + def reset(): + """Reset resource for tests. + + Create new, empty VNFS dictionary + + """ + global VNFS + VNFS = {} + + def get(self, vnf_instance_id: str) -> Dict[str, List]: + """Get vnf instance data. + + Get data from VNFS dictionary + + Args: + vnf_instance_id (str): Vnf instance id key value + + Returns: + Dict[str, List]: Vnf instance data dictionary + + """ + try: + return VNFS[vnf_instance_id] + except KeyError: + VNFS[vnf_instance_id] = {"vnf-id": vnf_instance_id, "model-version-id": str(uuid4())} + return VNFS[vnf_instance_id] + + +class VfModule(Resource): + """Vf module resource.""" + + def delete(self, vnf_instance_id: str, vf_module_instance_id: str) -> None: + """Delete vf module. + + Removes vf module data from VNFS dictionary. + + Args: + vnf_instance_id (str): Vnf instance id key value + vf_module_instance_id (str): Vf module instance id key value + + """ + del VNFS[vnf_instance_id]["vf_modules"][vf_module_instance_id] + + +class VfModuleList(Resource): + """Vf module list resource.""" + + def post(self, vnf_instance_id: str) -> None: + """Create vf module. + + Add vf module data into VNFS dictionary. + + Args: + vnf_instance_id (str): Vnf instance id key value + + """ + vf_module_data = request.get_json() + vf_module_dict = {vf_module_data["vf-module-id"]: vf_module_data} + try: + VNFS[vnf_instance_id]["vf_modules"].update(vf_module_dict) + except KeyError: + VNFS[vnf_instance_id]["vf_modules"] = vf_module_dict + + def get(self, vnf_instance_id: str) -> Dict[str, List]: + """Get Vnf instance Vf modules list. + + Get data from VNFS dictionary + + Args: + vnf_instance_id (str): Vnf instance id key value + + Returns: + Dict[str, List]: Vnf instance vf modules dictionary + """ + return { + "vf-module": [ + data for vf_module_id, data in VNFS[vnf_instance_id].get("vf_modules", {}).items() + ] + } |