"""A&AI mock application.""" """ 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 flask import Flask from flask_restful import Resource, Api from resources.cloud_region import ( CloudRegion, CloudRegionList, CloudRegionRelationshipList, CloudRegionRelationship, Tenant, TenantList, ) from resources.complex import Complex, ComplexList from resources.customer import ( Customer, CustomerList, ServiceSubscription, ServiceSubscriptionInstance, ServiceSubscriptionList, ServiceSubscriptionRelationship, ServiceSubscriptionRelationshipList, ServiceSubscriptionInstanceList, ServiceSubscriptionInstanceRelationshipList, ) from resources.network import Network from resources.vnf import Vnf, VfModule, VfModuleList app = Flask(__name__) api = Api(app) API_VERSIONS_SUPPORTED = ["v16", "v20", "v23", "v26"] def generate_urls_for_all_versions(endpoint_pattern: str) -> list: """Helper function. Generates list of endpoints by replacing pattern for each supported API version. Args: endpoint_pattern (str): url pattern with tag to be replaced Returns: list: List of string values reporesenting endpoints that are currently supported """ return [endpoint_pattern.replace("", api_version) for api_version in API_VERSIONS_SUPPORTED] @app.route("/reset") def reset() -> str: """Reset endpoint. Reset all resources. Returns: str: Empty string, it has to returns anything """ CloudRegion.reset() Complex.reset() Customer.reset() Network.reset() Vnf.reset() return "" # Cloud region resource api.add_resource(CloudRegionList, *generate_urls_for_all_versions("/aai//cloud-infrastructure/cloud-regions")) api.add_resource( CloudRegion, *generate_urls_for_all_versions("/aai//cloud-infrastructure/cloud-regions/cloud-region//"), ) api.add_resource( CloudRegionRelationshipList, *generate_urls_for_all_versions("/aai//cloud-infrastructure/cloud-regions/cloud-region///relationship-list"), ) api.add_resource( CloudRegionRelationship, *generate_urls_for_all_versions("/aai//cloud-infrastructure/cloud-regions/cloud-region///relationship-list/relationship"), ) api.add_resource( TenantList, *generate_urls_for_all_versions("/aai//cloud-infrastructure/cloud-regions/cloud-region///tenants"), ) api.add_resource( Tenant, *generate_urls_for_all_versions("/aai//cloud-infrastructure/cloud-regions/cloud-region///tenants/tenant/"), ) # Complex resource api.add_resource(ComplexList, *generate_urls_for_all_versions("/aai//cloud-infrastructure/complexes")) api.add_resource( Complex, *generate_urls_for_all_versions("/aai//cloud-infrastructure/complexes/complex/") ) # Customer resource api.add_resource(CustomerList, *generate_urls_for_all_versions("/aai//business/customers")) api.add_resource(Customer, *generate_urls_for_all_versions("/aai//business/customers/customer/")) api.add_resource( ServiceSubscriptionList, *generate_urls_for_all_versions("/aai//business/customers/customer//service-subscriptions"), ) api.add_resource( ServiceSubscription, *generate_urls_for_all_versions("/aai//business/customers/customer//service-subscriptions/service-subscription/"), ) api.add_resource( ServiceSubscriptionRelationshipList, *generate_urls_for_all_versions("/aai//business/customers/customer//service-subscriptions/service-subscription//relationship-list"), ) api.add_resource( ServiceSubscriptionRelationship, *generate_urls_for_all_versions("/aai//business/customers/customer//service-subscriptions/service-subscription//relationship-list/relationship"), ) api.add_resource( ServiceSubscriptionInstance, *generate_urls_for_all_versions("/aai//business/customers/customer//service-subscriptions/service-subscription//service-instances/service-instance/"), ) api.add_resource( ServiceSubscriptionInstanceList, *generate_urls_for_all_versions("/aai//business/customers/customer//service-subscriptions/service-subscription//service-instances"), ) api.add_resource( ServiceSubscriptionInstanceRelationshipList, *generate_urls_for_all_versions("/aai//business/customers/customer//service-subscriptions/service-subscription//service-instances/service-instance//relationship-list"), ) # VNF resource api.add_resource(Vnf, *generate_urls_for_all_versions("/aai//network/generic-vnfs/generic-vnf/")) api.add_resource( VfModule, *generate_urls_for_all_versions("/aai//network/generic-vnfs/generic-vnf//vf-modules/"), ) api.add_resource( VfModuleList, *generate_urls_for_all_versions("/aai//network/generic-vnfs/generic-vnf//vf-modules"), ) api.add_resource( Network, *generate_urls_for_all_versions("/aai//network/l3-networks/l3-network/") ) if __name__ == "__main__": app.run(host="0.0.0.0", debug=True)