diff options
Diffstat (limited to 'tutorials/ApacheCNF/automation')
-rw-r--r-- | tutorials/ApacheCNF/automation/Pipfile | 4 | ||||
-rw-r--r-- | tutorials/ApacheCNF/automation/__init__.py | 1 | ||||
-rw-r--r-- | tutorials/ApacheCNF/automation/healthcheck.py | 69 | ||||
-rw-r--r-- | tutorials/ApacheCNF/automation/instantiate.py | 22 | ||||
-rw-r--r-- | tutorials/ApacheCNF/automation/k8s_client.py | 59 | ||||
-rw-r--r-- | tutorials/ApacheCNF/automation/onap_settings.py | 33 | ||||
-rw-r--r-- | tutorials/ApacheCNF/automation/onap_settings_tnap.py | 106 |
7 files changed, 187 insertions, 107 deletions
diff --git a/tutorials/ApacheCNF/automation/Pipfile b/tutorials/ApacheCNF/automation/Pipfile index a8e79269..c8d35a7f 100644 --- a/tutorials/ApacheCNF/automation/Pipfile +++ b/tutorials/ApacheCNF/automation/Pipfile @@ -6,9 +6,9 @@ verify_ssl = true [dev-packages] [packages] -onapsdk = "==9.3.0" +onapsdk = "==10.1.0" markupsafe = "==2.0.1" -kubernetes = "*" +click = "==8.1.3" [requires] python_version = "3.8" diff --git a/tutorials/ApacheCNF/automation/__init__.py b/tutorials/ApacheCNF/automation/__init__.py index 9525040e..e3af8050 100644 --- a/tutorials/ApacheCNF/automation/__init__.py +++ b/tutorials/ApacheCNF/automation/__init__.py @@ -16,4 +16,3 @@ # ============LICENSE_END========================================================= from .config import Config -from .k8s_client import K8sClient diff --git a/tutorials/ApacheCNF/automation/healthcheck.py b/tutorials/ApacheCNF/automation/healthcheck.py index aee101dd..9c33375e 100644 --- a/tutorials/ApacheCNF/automation/healthcheck.py +++ b/tutorials/ApacheCNF/automation/healthcheck.py @@ -14,14 +14,14 @@ # limitations under the License. # # ============LICENSE_END========================================================= -#todo update when onapsdk > 9.3.0 import logging +import os import zipfile +from io import BytesIO from onapsdk.aai.business import Customer from onapsdk.cds.blueprint import Workflow, Blueprint - -from config import Config +from config import Config, VariablesDict #FIXME remove from global scope logger = logging.getLogger("") @@ -32,29 +32,24 @@ fh.setFormatter(fh_formatter) logger.addHandler(fh) -def resolve_hc_inputs(): +def resolve_hc_inputs(config: Config): logger.info("******** Check Customer *******") - customer = None - for found_customer in list(Customer.get_all()): - logger.debug("Customer %s found", found_customer.subscriber_name) - if found_customer.subscriber_name == Config.GLOBAL_CUSTOMER_ID: - logger.info("Customer %s found", found_customer.subscriber_name) - customer = found_customer - break + customer_id = config.service_instance["customer_id"] + customer = Customer.get_by_global_customer_id(customer_id) if customer is None: - raise Exception("Customer %s wasn't found in ONAP" % Config.GLOBAL_CUSTOMER_ID) + raise Exception("Customer %s wasn't found in ONAP" % customer_id) logger.info("******** Check Service Subscription *******") service_subscription = None for service_sub in customer.service_subscriptions: logger.debug("Service subscription %s is found", service_sub.service_type) - if service_sub.service_type == Config.SERVICENAME: - logger.info("Service %s subscribed", Config.SERVICENAME) + if service_sub.service_type == config.service_model["model_name"]: + logger.info("Service %s subscribed", config.service_model["model_name"]) service_subscription = service_sub break logger.info("******** Retrieve Service Metadata *******") service_instance = None for single_service in service_subscription.service_instances: - if single_service.instance_name == Config.SERVICE_INSTANCE_NAME: + if single_service.instance_name == config.service_instance["instance_name"]: service_instance = single_service break service_id = service_instance.instance_id @@ -67,26 +62,32 @@ def resolve_hc_inputs(): return service_id, vnf_id def main(): - blueprint = None - with zipfile.ZipFile(Config.VSPFILE, 'r') as package: - with package.open("CBA.zip", 'r') as cba: - blueprint = Blueprint(cba.read()) + mypath = os.path.dirname(os.path.realpath(__file__)) + config = Config(env_dict=VariablesDict.env_variable) + for vnf in config.service_model["vnfs"]: + file = vnf["vsp"]["vsp_file"] + file_path = os.path.join(mypath, file) + with zipfile.ZipFile(file_path, 'r') as package: + cba_io = BytesIO(package.read("CBA.zip")) + cba_io.seek(0) + blueprint = Blueprint(cba_io.read()) + + healthcheck: Workflow = blueprint.get_workflow_by_name('health-check') + serv_id, vnf_id = resolve_hc_inputs(config) + cds_input = {"health-check-properties": + { + "service-instance-id": serv_id, + "vnf-id": vnf_id + } + } - healthcheck = Workflow('health-check', None, blueprint) - serv_id, vnf_id = resolve_hc_inputs() - cds_input = {"health-check-properties": - { - "service-instance-id": serv_id, - "vnf-id": vnf_id - } - } - logger.info("Requesting Healthcheck for CBA %s:%s with inputs:\n%s", - blueprint.metadata.template_name, - blueprint.metadata.template_version, - cds_input) - result = healthcheck.execute(cds_input) - logger.info("Healthcheck process completed with result: %s", result) - logger.info("Please check cds-blueprints-processor logs to see exact status") + logger.info("Requesting Healthcheck for CBA %s:%s with inputs:\n%s", + blueprint.metadata.template_name, + blueprint.metadata.template_version, + cds_input) + result = healthcheck.execute(cds_input) + logger.info("Healthcheck process completed with result: %s", result) + logger.info("Please check cds-blueprints-processor logs to see exact status") if __name__ == "__main__": main() diff --git a/tutorials/ApacheCNF/automation/instantiate.py b/tutorials/ApacheCNF/automation/instantiate.py index 0d9dc5ef..ecbeaa41 100644 --- a/tutorials/ApacheCNF/automation/instantiate.py +++ b/tutorials/ApacheCNF/automation/instantiate.py @@ -1,5 +1,6 @@ # ============LICENSE_START======================================================= # Copyright (C) 2021 Orange +# Modification Copyright (C) 2022 Deutsche Telekom AG # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -32,7 +33,6 @@ from onapsdk.so.instantiation import ( ServiceInstantiation, InstantiationParameter, SoService, SoServiceVnf) from onapsdk.sdc.service import Service -# from onapsdk.vid import LineOfBusiness, OwningEntity, Platform, Project from onapsdk.so.so_element import OrchestrationRequest from onapsdk.aai.service_design_and_creation import Service as AaiService @@ -203,7 +203,7 @@ def get_aai_service(service_type): def instantiate_service_macro(config, service, cloud_region, tenant, customer, owning_entity, - vid_project, vid_line_of_business, vid_platform): + project, line_of_business, platform): service_instance_name = config.service_instance["instance_name"] so_input = config.so_input for vnf in so_input["vnfs"]: @@ -232,9 +232,9 @@ def instantiate_service_macro(config, service, cloud_region, tenant, customer, o tenant=tenant, customer=customer, owning_entity=owning_entity, - project=vid_project, - line_of_business=vid_line_of_business, - platform=vid_platform, + project=project, + line_of_business=line_of_business, + platform=platform, service_instance_name=service_instance_name, aai_service=aai_service, so_service=so_service @@ -347,7 +347,7 @@ def get_properties(vnf): def instantiate_service_alacarte(config, service_subscription, service_model, cloud_region, tenant, customer, owning_entity, - vid_project, vid_line_of_business, vid_platform): + project, line_of_business, platform): raise NotImplementedError("Not supported since 2022") service_instance_name = config.service_instance["instance_name"] @@ -358,7 +358,7 @@ def instantiate_service_alacarte(config, service_subscription, service_model, cl tenant=tenant, customer=customer, owning_entity=owning_entity, - project=vid_project, + project=project, service_instance_name=service_instance_name ) check_orchestration_status(service_instantiation) @@ -375,8 +375,8 @@ def instantiate_service_alacarte(config, service_subscription, service_model, cl # TODO: instance name vnf_instantiation = service_instance.add_vnf( vnf=vnf, - line_of_business=vid_line_of_business, - platform=vid_platform, + line_of_business=line_of_business, + platform=platform, vnf_parameters=vnf_parameters ) check_orchestration_status(vnf_instantiation) @@ -443,8 +443,8 @@ def main(): logger.info("******** Business Objects (OE, P, Pl, LoB) *******") project = "Project-Demonstration" platform = "Platform-test" - line_of_business = "Orange-LOB" - owning_entity = add_owning_entity("Orange") + line_of_business = config.user_params["company_name"] + "-LOB" + owning_entity = add_owning_entity(config.user_params["company_name"]) logger.info("******** Delete old profiles ********") delete_old_profiles(service, config.service_instance) diff --git a/tutorials/ApacheCNF/automation/k8s_client.py b/tutorials/ApacheCNF/automation/k8s_client.py deleted file mode 100644 index 98b451bc..00000000 --- a/tutorials/ApacheCNF/automation/k8s_client.py +++ /dev/null @@ -1,59 +0,0 @@ -# ============LICENSE_START======================================================= -# Copyright (C) 2021 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. -# -# ============LICENSE_END========================================================= - -import os -from pprint import pprint - -import oyaml as yaml -from kubernetes import config, client -from kubernetes.client import OpenApiException - - -class K8sClient: - def __init__(self, kubeconfig_path): - self.mypath = os.path.dirname(os.path.realpath(__file__)) - config.load_kube_config(config_file=os.path.join(self.mypath, kubeconfig_path)) - self.api_instance = client.CustomObjectsApi() - - def read_custom_object_file(self, file_path): - with open(file_path) as crd_file: - crd_body = yaml.load(crd_file, Loader=yaml.FullLoader) - return crd_body - - def get_custom_object_details(self, crd_body): - group = crd_body["apiVersion"].split("/")[0] - version = crd_body["apiVersion"].split("/")[1] - plural = crd_body["kind"].lower() + "s" - #name = crd_body["metadata"]["name"] - - return group, version, plural #, name - - def create_custom_object(self, file_path): - crd_body = self.read_custom_object_file(file_path) - #group, version, plural, name = self.get_custom_object_details(crd_body) - group, version, plural = self.get_custom_object_details(crd_body) - api_response = None - try: - api_response = self.api_instance.create_cluster_custom_object(group=group, - version=version, - plural=plural, - body=crd_body, - pretty="true") - except OpenApiException as error: - print(str(error.status) + " " + error.reason) - pprint(error.body) - return api_response diff --git a/tutorials/ApacheCNF/automation/onap_settings.py b/tutorials/ApacheCNF/automation/onap_settings.py index e0bad35d..414685e0 100644 --- a/tutorials/ApacheCNF/automation/onap_settings.py +++ b/tutorials/ApacheCNF/automation/onap_settings.py @@ -24,6 +24,39 @@ # ONAP SERVICES URLS # # # ###################### +import logging.config + +LOG_CONFIG = { + "version": 1, + "disable_existing_loggers": False, + "formatters": { + "default": { + "class": "logging.Formatter", + "format": "%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s" + } + }, + "handlers": { + "console": { + "level": "DEBUG", + "class": "logging.StreamHandler", + "formatter": "default" + }, + "file": { + "level": "DEBUG", + "class": "logging.FileHandler", + "formatter": "default", + "filename": "/tmp/pythonsdk.debug.log", + "mode": "w" + } + }, + "root": { + "level": "DEBUG", + "handlers": ["console", "file"] + } +} + +logging.config.dictConfig(LOG_CONFIG) + AAI_URL = "https://aai.api.sparky.simpledemo.onap.org:30233" AAI_API_VERSION = "v23" diff --git a/tutorials/ApacheCNF/automation/onap_settings_tnap.py b/tutorials/ApacheCNF/automation/onap_settings_tnap.py new file mode 100644 index 00000000..90455ec1 --- /dev/null +++ b/tutorials/ApacheCNF/automation/onap_settings_tnap.py @@ -0,0 +1,106 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2021 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. +# +# ============LICENSE_END========================================================= + +"""Global settings module.""" # pylint: disable=bad-whitespace +# uncomment if socks is used +#from onapsdk.onap_service import OnapService + +###################### +# # +# ONAP SERVICES URLS # +# # +###################### + +import logging.config + +LOG_CONFIG = { + "version": 1, + "disable_existing_loggers": False, + "formatters": { + "default": { + "class": "logging.Formatter", + "format": "%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s" + } + }, + "handlers": { + "console": { + "level": "DEBUG", + "class": "logging.StreamHandler", + "formatter": "default" + }, + "file": { + "level": "DEBUG", + "class": "logging.FileHandler", + "formatter": "default", + "filename": "/tmp/pythonsdk.debug.log", + "mode": "w" + } + }, + "root": { + "level": "DEBUG", + "handlers": ["console", "file"] + } +} + +logging.config.dictConfig(LOG_CONFIG) +TNAP_ENV = "onap.local:81" +AAI_URL = f"http://{TNAP_ENV}/aai-api" +AAI_API_VERSION = "v23" +AAI_AUTH = "Basic QUFJOkFBSQ==" +CDS_URL = "http://portal.api.simpledemo.onap.org:30449" +CDS_AUTH = ("ccsdkapps", "ccsdkapps") +MSB_URL = f"http://{TNAP_ENV}/msb" +SDC_BE_URL = f"http://{TNAP_ENV}/sdc-be" +SDC_FE_URL = f"http://{TNAP_ENV}/sdc-fe" +SDC_AUTH = "Basic YWFpOktwOGJKNFNYc3pNMFdYbGhhazNlSGxjc2UyZ0F3ODR2YW9HR21KdlV5MlU=" +SDNC_URL = "https://sdnc.api.simpledemo.onap.org:30267" +SDNC_AUTH = "Basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ==" +SO_URL = f"http://{TNAP_ENV}/so" +SO_API_VERSION = "v7" +SO_AUTH = "Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==" +SO_CAT_DB_AUTH = "Basic YnBlbDpwYXNzd29yZDEk" +VID_URL = "https://vid.api.simpledemo.onap.org:30200" +VID_API_VERSION = "/vid" +CLAMP_URL = "https://clamp.api.simpledemo.onap.org:30258" +CLAMP_AUTH = "Basic ZGVtb0BwZW9wbGUub3NhYWYub3JnOmRlbW8xMjM0NTYh" +VES_URL = "http://ves.api.simpledemo.onap.org:30417" +DMAAP_URL = "http://dmaap.api.simpledemo.onap.org:3904" +NBI_URL = "https://nbi.api.simpledemo.onap.org:30274" +NBI_API_VERSION = "/nbi/api/v4" +DCAEMOD_URL = "" +HOLMES_URL = "https://aai.api.sparky.simpledemo.onap.org:30293" +POLICY_URL = "" + +## GUI +AAI_GUI_URL = "https://aai.api.sparky.simpledemo.onap.org:30220" +AAI_GUI_SERVICE = f"{AAI_GUI_URL}/services/aai/webapp/index.html#/browse" +CDS_GUI_SERVICE = f"{CDS_URL}/" +SO_MONITOR_GUI_SERVICE = f"{SO_URL}/" +SDC_GUI_SERVICE = f"{SDC_FE_URL}/sdc1/portal" +SDNC_DG_GUI_SERVICE = f"{SDNC_URL}/nifi/" +SDNC_ODL_GUI_SERVICE = f"{SDNC_URL}/odlux/index.html" + +DCAEMOD_GUI_SERVICE = f"{DCAEMOD_URL}/" +HOLMES_GUI_SERVICE = f"{HOLMES_URL}/iui/holmes/default.html" +POLICY_GUI_SERVICE = f"{POLICY_URL}/onap/login.html" +POLICY_CLAMP_GUI_SERVICE = f"{CLAMP_URL}/" + +# uncomment if socks is used +#OnapService.set_proxy({'http': 'socks5h://127.0.0.1:8081', 'https': 'socks5h://127.0.0.1:8081'}) + +# execute in the shell to apply these settings +# export ONAP_PYTHON_SDK_SETTINGS="onap_settings" |