aboutsummaryrefslogtreecommitdiffstats
path: root/heat/vFW_CNF_CDS/automation
diff options
context:
space:
mode:
Diffstat (limited to 'heat/vFW_CNF_CDS/automation')
-rwxr-xr-xheat/vFW_CNF_CDS/automation/Pipfile4
-rwxr-xr-xheat/vFW_CNF_CDS/automation/README.md20
-rwxr-xr-xheat/vFW_CNF_CDS/automation/__init__.py3
-rw-r--r--heat/vFW_CNF_CDS/automation/artifacts/cluster_kubeconfig1
-rwxr-xr-xheat/vFW_CNF_CDS/automation/config.py124
-rwxr-xr-xheat/vFW_CNF_CDS/automation/create_cloud_regions.py232
-rw-r--r--heat/vFW_CNF_CDS/automation/create_k8s_region.py126
-rwxr-xr-xheat/vFW_CNF_CDS/automation/delete.py123
-rwxr-xr-xheat/vFW_CNF_CDS/automation/instantiate.py550
-rwxr-xr-xheat/vFW_CNF_CDS/automation/k8s_client.py2
-rwxr-xr-xheat/vFW_CNF_CDS/automation/onap_settings.py19
-rwxr-xr-xheat/vFW_CNF_CDS/automation/onboard.py201
-rwxr-xr-xheat/vFW_CNF_CDS/automation/so_db_adapter.py95
-rwxr-xr-xheat/vFW_CNF_CDS/automation/update_cba.py54
-rwxr-xr-xheat/vFW_CNF_CDS/automation/update_connectivity_info.py2
-rw-r--r--heat/vFW_CNF_CDS/automation/vsp/.gitkeep (renamed from heat/vFW_CNF_CDS/automation/vsp/.keep)0
16 files changed, 992 insertions, 564 deletions
diff --git a/heat/vFW_CNF_CDS/automation/Pipfile b/heat/vFW_CNF_CDS/automation/Pipfile
index 7c21af18..0fd8924d 100755
--- a/heat/vFW_CNF_CDS/automation/Pipfile
+++ b/heat/vFW_CNF_CDS/automation/Pipfile
@@ -6,8 +6,8 @@ verify_ssl = true
[dev-packages]
[packages]
-onapsdk = "<=7.3.0"
-kubernetes = "<=12.0.1"
+onapsdk = "8.1.2"
+kubernetes = "*"
[requires]
python_version = "3.8"
diff --git a/heat/vFW_CNF_CDS/automation/README.md b/heat/vFW_CNF_CDS/automation/README.md
index a37ec9db..41eb4f06 100755
--- a/heat/vFW_CNF_CDS/automation/README.md
+++ b/heat/vFW_CNF_CDS/automation/README.md
@@ -1,20 +1,24 @@
-# vFW_CNF_CDS use case automation
+# CNF automation
0. Make sure you have python 3.8.x installed and default interpreter, what is required by onap-pythonsdk
1. Install required packages with pipenv `pipenv install`
2. Run virtual environment `pipenv shell`. In case of problems use `--fancy` option
**In case of problems with pipenv:** `venv` can be used as well. In that case, please install all required python packages in correct version according the list in `Pipfile`
-3. Add kubeconfig file for k8s cluster that will host vFW
+3. Add kubeconfig file for k8s cluster that will host your CNF
- `artifacts/cluster_kubeconfig`
4. Prepare onboarding packages `cd ../templates/ && make && cd ../automation/`
5. Modify `config.py`:
- NATIVE - enables native helm orchestration path in SO
- - CLOUD_REGION
+ - SKIP_POST_INSTANTIATION - whether post instantiation configuration should be run
+ - MACRO_INSTANTIATION - instantiation method used: macro or a'la carte
+ - K8S_NAMESPACE - k8s namespace to use for deployment of CNF
+ - K8S_VERSION - version of the k8s cluster
+ - K8S_REGION - name of the k8s region from the CLOUD_REGIONS
+ - CLOUD_REGIONS - configuration of k8s or Openstack regions
- GLOBAL_CUSTOMER_ID
- VENDOR
- SERVICENAME
- - CUSTOMER_RESOURCE_DEFINITIONS - add list of CRDs to be installed on non KUD k8s cluster
- VNF_PARAM_LIST - list of parameters to pass for VNF creation process
- VF_MODULE_PARAM_LIST - list of parameters to pass for VF Module creation
6. __Important:__ Before running python scripts, some settings for `onapsdk` with information about ONAP endpoints (and socks) have to be exported.
@@ -22,8 +26,8 @@
```shell
(automation) ubuntu@onap:~/automation$ export ONAP_PYTHON_SDK_SETTINGS="onap_settings"
```
-7. Run script `python create_k8s_region.py` in order to create **k8s cloud region**
-8. Onboard **vFW** `python onboard.py`
-9. Instantiate **vFW** `python instantiate.py`
-10. Once test is done, **vFW** service instance can be deleted with `python delete.py` command
+7. Run script `python create_cloud_regions.py` in order to create **k8s or openstack cloud region**
+8. Onboard CNF `python onboard.py`
+9. Instantiate CNF `python instantiate.py`
+10. Once test is done, CNF service instance can be deleted with `python delete.py` command
diff --git a/heat/vFW_CNF_CDS/automation/__init__.py b/heat/vFW_CNF_CDS/automation/__init__.py
index c9ad83e5..9525040e 100755
--- a/heat/vFW_CNF_CDS/automation/__init__.py
+++ b/heat/vFW_CNF_CDS/automation/__init__.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (C) 2020 Orange
+# 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.
@@ -16,5 +16,4 @@
# ============LICENSE_END=========================================================
from .config import Config
-from .so_db_adapter import SoDBAdapter
from .k8s_client import K8sClient
diff --git a/heat/vFW_CNF_CDS/automation/artifacts/cluster_kubeconfig b/heat/vFW_CNF_CDS/automation/artifacts/cluster_kubeconfig
index 8b137891..e69de29b 100644
--- a/heat/vFW_CNF_CDS/automation/artifacts/cluster_kubeconfig
+++ b/heat/vFW_CNF_CDS/automation/artifacts/cluster_kubeconfig
@@ -1 +0,0 @@
-
diff --git a/heat/vFW_CNF_CDS/automation/config.py b/heat/vFW_CNF_CDS/automation/config.py
index 82536960..c0f7b1b4 100755
--- a/heat/vFW_CNF_CDS/automation/config.py
+++ b/heat/vFW_CNF_CDS/automation/config.py
@@ -14,6 +14,8 @@
# limitations under the License.
#
# ============LICENSE_END=========================================================
+from uuid import uuid4
+
class Config:
SCENARIO = 1
@@ -22,25 +24,14 @@ class Config:
# 3 - extra ssh service that comes from config + verification of the CNF status
# change requires new onboarding
- #### REGION DETAILS ####
- COMPLEX_ID = "complex"
- CLOUD_OWNER = "k8sCloudOwner"
- CLOUD_REGION = "kud-1"
- AVAILABILITY_ZONE_NAME = "k8s-availability-zone"
- HYPERVISOR_TYPE = "k8s"
- TENANT_NAME = "kud-1"
K8S_NAMESPACE = "vfirewall"
K8S_VERSION = "1.18.9"
- CUSTOMER_RESOURCE_DEFINITIONS = []
-# Uncomment, if you want to run on non KUD k8s cluster
-# CUSTOMER_RESOURCE_DEFINITIONS = ["crds/crd1",
-# "crds/crd2"]
-
- CLUSTER_KUBECONFIG_PATH = "artifacts/cluster_kubeconfig"
+ K8S_REGION = "kud"
#### SERVICE DETAILS ####
- NATIVE = True
+ NATIVE = True # False for old dummy-heat based orchestration path
SKIP_POST_INSTANTIATION = True
+ MACRO_INSTANTIATION = True # A-la-carte instantiation if False
GLOBAL_CUSTOMER_ID = "customer_cnf"
VSPFILE = "vsp/vfw_k8s_demo.zip"
if NATIVE:
@@ -51,10 +42,10 @@ class Config:
RELEASE_NAME = "vfw-1"
VENDOR = "vendor_cnf"
- SERVICENAME = "vfw_k8s_demo_CNF_KUD" + "_" + str(SCENARIO)
+ SERVICENAME = "vfw_k8s_demo_CNF" + "_" + str(SCENARIO)
VSPNAME = "VSP_" + SERVICENAME
VFNAME = "VF_" + SERVICENAME
- SERVICE_INSTANCE_NAME = "INSTANCE_" + SERVICENAME + "_1"
+ SERVICE_INSTANCE_NAME = "INSTANCE_" + SERVICENAME
SDNC_ARTIFACT_NAME = "vnf"
# INSERT PARAMS FOR VNF HERE AS "name" : "value" PAIR
@@ -69,26 +60,48 @@ class Config:
VF_MODULE_PARAM_LIST = {
VF_MODULE_PREFIX + "base_template": {
- "k8s-rb-profile-name": PROFILE_NAME,
- "k8s-rb-profile-source": PROFILE_SOURCE,
- "k8s-rb-instance-release-name": RELEASE_NAME + "-base"
+ "instantiation_parameters": {
+ "k8s-rb-profile-name": PROFILE_NAME,
+ "k8s-rb-profile-source": PROFILE_SOURCE,
+ "k8s-rb-instance-release-name": RELEASE_NAME + "-base",
+ "k8s-rb-profile-namespace": K8S_NAMESPACE
+ },
+ "cloud_configuration": K8S_REGION
},
VF_MODULE_PREFIX + "vfw": {
- "k8s-rb-profile-name": PROFILE_NAME,
- "k8s-rb-profile-source": PROFILE_SOURCE,
- "k8s-rb-instance-release-name": RELEASE_NAME + "-vfw"
+ "instantiation_parameters": {
+ "k8s-rb-profile-name": PROFILE_NAME,
+ "k8s-rb-profile-source": PROFILE_SOURCE,
+ "k8s-rb-instance-release-name": RELEASE_NAME + "-vfw",
+ "k8s-rb-profile-namespace": K8S_NAMESPACE
+ },
+ "cloud_configuration": K8S_REGION
},
VF_MODULE_PREFIX + "vpkg": {
- "k8s-rb-profile-name": PROFILE_NAME,
- "k8s-rb-profile-source": PROFILE_SOURCE,
- "k8s-rb-instance-release-name": RELEASE_NAME + "-vpkg"
+ "instantiation_parameters": {
+ "k8s-rb-profile-name": PROFILE_NAME,
+ "k8s-rb-profile-source": PROFILE_SOURCE,
+ "k8s-rb-instance-release-name": RELEASE_NAME + "-vpkg",
+ "k8s-rb-profile-namespace": K8S_NAMESPACE
+ },
+ "cloud_configuration": K8S_REGION
},
VF_MODULE_PREFIX + "vsn": {
- "k8s-rb-profile-name": PROFILE_NAME,
- "k8s-rb-profile-source": PROFILE_SOURCE,
- "k8s-rb-instance-release-name": RELEASE_NAME + "-vsn"
+ "instantiation_parameters": {
+ "k8s-rb-profile-name": PROFILE_NAME,
+ "k8s-rb-profile-source": PROFILE_SOURCE,
+ "k8s-rb-instance-release-name": RELEASE_NAME + "-vsn",
+ "k8s-rb-profile-namespace": K8S_NAMESPACE
+ },
+ "cloud_configuration": K8S_REGION
}
}
+ ######## PNF DETAILS ########
+ ADD_PNF = False
+ if ADD_PNF:
+ PNF_VSP_FILE = "vsp/pnf_package.csar"
+ PNF_NAME = "PNF_example"
+ PNF_VSP_NAME = "VSP_" + PNF_NAME
######## DEFAULT VALUES ########
OWNING_ENTITY = "OE-Demonstration"
@@ -96,27 +109,60 @@ class Config:
PLATFORM = "test"
LINE_OF_BUSINESS = "LOB-Demonstration"
+ #### REGION DETAILS ####
+ CLOUD_REGIONS = {
+ K8S_REGION: {
+ "complex_id": "k8s-complex1",
+ "cloud_owner": "K8sCloudOwner",
+ "cloud_type": "k8s",
+ "availability_zone": "k8s-availability-zone",
+ "tenant": {
+ "id": str(uuid4()),
+ "name": K8S_REGION + "-tenant"
+ },
+ "customer_resource_definitions": [
+ # Uncomment lines below, if you want to run on non KUD k8s cluster
+ # "crds/crd1",
+ # "crds/crd2"
+ ],
+ "cluster_kubeconfig_file": "artifacts/kud_kubeconfig"
+ # },
+ # "openstack-region-test-1": {
+ # "complex_id": "complex1",
+ # "cloud_owner": "CloudOwner",
+ # "cloud_type": "openstack",
+ # "availability_zone": "Main",
+ # "identity_url": "http://test:5000/v4",
+ # "mso_id": "test_use",
+ # "mso_pass": "test_password",
+ # "identity_server_type": "KEYSTONE_V3",
+ # "tenant": {
+ # "id": "5117085204e84027a8d1a0cf34abb0ba",
+ # "name": "onap-dev"
+ # }
+ }
+ }
######## SCENARIOS #############
######## 1 #############
if SCENARIO == 1:
SKIP_POST_INSTANTIATION = True
- VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["k8s-rb-profile-name"] = PROFILE_NAME
- VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["k8s-rb-profile-source"] = PROFILE_SOURCE
+ VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["instantiation_parameters"]["k8s-rb-profile-name"] = PROFILE_NAME
+ VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["instantiation_parameters"]["k8s-rb-profile-source"] = PROFILE_SOURCE
######## 2 #############
elif SCENARIO == 2:
SKIP_POST_INSTANTIATION = True
- VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["k8s-rb-profile-name"] = "vfw-cnf-cds-vpkg-profile"
- VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["k8s-rb-profile-source"] = "vfw-cnf-cds-vpkg-profile"
- VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["vpg-management-port"] = "31922"
+ VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["instantiation_parameters"]["k8s-rb-profile-name"] = "vfw-cnf-cds-vpkg-profile"
+ VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["instantiation_parameters"]["k8s-rb-profile-source"] = "vfw-cnf-cds-vpkg-profile"
+ VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["instantiation_parameters"]["vpg-management-port"] = "31922"
######## 3 #############
elif SCENARIO == 3:
SKIP_POST_INSTANTIATION = False
- VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["k8s-rb-profile-name"] = PROFILE_NAME
- VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["k8s-rb-profile-source"] = PROFILE_SOURCE
- VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["k8s-rb-config-template-name"] = "ssh-service-config"
- VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["k8s-rb-config-template-source"] = "ssh-service-config"
- VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["k8s-rb-config-name"] = "ssh-service-config"
- VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["k8s-rb-config-value-source"] = "ssh-service-config"
+ VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["instantiation_parameters"]["k8s-rb-profile-name"] = PROFILE_NAME
+ VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["instantiation_parameters"]["k8s-rb-profile-source"] = PROFILE_SOURCE
+ VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["instantiation_parameters"]["k8s-rb-config-template-name"] = "ssh-service-config"
+ VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["instantiation_parameters"]["k8s-rb-config-template-source"] = "ssh-service-config"
+ VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["instantiation_parameters"]["k8s-rb-config-name"] = "ssh-service-config"
+ VF_MODULE_PARAM_LIST[VF_MODULE_PREFIX + "vpkg"]["instantiation_parameters"]["k8s-rb-config-value-source"] = "ssh-service-config"
else:
raise Exception("Not Implemented Scenario")
diff --git a/heat/vFW_CNF_CDS/automation/create_cloud_regions.py b/heat/vFW_CNF_CDS/automation/create_cloud_regions.py
new file mode 100755
index 00000000..d4b318f9
--- /dev/null
+++ b/heat/vFW_CNF_CDS/automation/create_cloud_regions.py
@@ -0,0 +1,232 @@
+# ============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 logging
+import os
+
+from onapsdk.so.so_db_adapter import SoDbAdapter, IdentityService
+
+from config import Config
+from k8s_client import K8sClient
+from onapsdk.exceptions import ResourceNotFound, APIError
+from onapsdk.aai.business import Customer
+from onapsdk.aai.cloud_infrastructure import Complex, CloudRegion
+from onapsdk.msb.k8s import ConnectivityInfo
+
+logger = logging.getLogger("")
+logger.setLevel(logging.DEBUG)
+fh = logging.StreamHandler()
+fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s')
+fh.setFormatter(fh_formatter)
+logger.addHandler(fh)
+
+MYPATH = os.path.dirname(os.path.realpath(__file__))
+
+
+def create_complex(region_id):
+ #### Create complex if not exists ####
+ logger.info("******** Complex *******")
+ complex_id = Config.CLOUD_REGIONS[region_id]["complex_id"]
+ try:
+ region_complex = next(Complex.get_all(physical_location_id=complex_id))
+ logger.info("Complex exists")
+ except ResourceNotFound:
+ logger.info("Complex does not exist")
+ region_complex = Complex.create(physical_location_id=complex_id,
+ name=complex_id,
+ physical_location_type="office",
+ street1="DummyStreet 1",
+ city="DummyCity",
+ postal_code="00-000",
+ country="DummyCountry",
+ region="DummyRegion")
+ logger.info("Complex created")
+ return region_complex
+ return region_complex
+
+
+def create_cloud_region(region_id):
+ #### Create cloud region if not exists ####
+ logger.info("******** Cloud Region *******")
+ cloud_owner = Config.CLOUD_REGIONS[region_id]["cloud_owner"]
+ cloud_type = Config.CLOUD_REGIONS[region_id]["cloud_type"]
+ complex_id = Config.CLOUD_REGIONS[region_id]["complex_id"]
+ cloud_region_version = "1.0" if cloud_type == "k8s" else "v2.5"
+ try:
+ region = next(CloudRegion.get_all(cloud_owner=cloud_owner, cloud_region_id=region_id))
+ logger.info("Cloud region exists")
+ except ResourceNotFound:
+ logger.info("Cloud region does not exist")
+ region = CloudRegion.create(cloud_owner=cloud_owner,
+ cloud_region_id=region_id,
+ cloud_type=cloud_type,
+ owner_defined_type="t1",
+ cloud_region_version=cloud_region_version,
+ complex_name=complex_id,
+ cloud_zone="CloudZone",
+ sriov_automation="false",
+ orchestration_disabled=False,
+ in_maint=False)
+ logger.info("Cloud region created")
+ return region
+ return region
+
+
+def link_region_to_complex(cloud_region, complx):
+ logger.info("******** Cloud region <-> Complex *******")
+ cloud_region.link_to_complex(complex_object=complx)
+
+
+def add_availability_zone(cloud_region):
+ logger.info("******** Availability zone *******")
+ region_id = cloud_region.cloud_region_id
+ availability_zone_name = Config.CLOUD_REGIONS[region_id]["availability_zone"]
+ cloud_type = Config.CLOUD_REGIONS[region_id]["cloud_type"]
+ try:
+ cloud_region.get_availability_zone_by_name(availability_zone_name)
+ logger.info("Availability zone exists")
+ except ResourceNotFound:
+ logger.info("Availability zone does not exist")
+ cloud_region.add_availability_zone(availability_zone_name=availability_zone_name,
+ availability_zone_hypervisor_type=cloud_type)
+ logger.info("Availability zone added to region")
+
+
+def add_tenant(cloud_region):
+ logger.info("******** Tenant *******")
+ region_id = cloud_region.cloud_region_id
+ tenant_id = Config.CLOUD_REGIONS[region_id]["tenant"]["id"]
+ tenant_name = Config.CLOUD_REGIONS[region_id]["tenant"]["name"]
+
+ try:
+ cloud_region.get_tenant(tenant_id)
+ logger.info("Tenant exists")
+ except ResourceNotFound:
+ logger.info("Tenant does not exist")
+ cloud_region.add_tenant(tenant_id=tenant_id,
+ tenant_name=tenant_name)
+ logger.info("Tenant added to region")
+
+
+def create_customer():
+ #### Create customer if not exists ####
+ logger.info("******** Customer *******")
+ try:
+ Customer.get_by_global_customer_id(Config.GLOBAL_CUSTOMER_ID)
+ logger.info("Customer exists")
+ except ResourceNotFound:
+ logger.info("Customer does not exist")
+ Customer.create(Config.GLOBAL_CUSTOMER_ID, Config.GLOBAL_CUSTOMER_ID, "INFRA")
+ logger.info("Customer created")
+
+
+def update_connectivity_info(region_id):
+ #### Update or create connectivity info ####
+ logger.info("******** Connectivity Info *******")
+ cluster_kubeconfig_path = Config.CLOUD_REGIONS[region_id]["cluster_kubeconfig_file"]
+ cloud_owner = Config.CLOUD_REGIONS[region_id]["cloud_owner"]
+ with open(os.path.join(MYPATH, cluster_kubeconfig_path), 'rb') as kubeconfig_file:
+ kubeconfig = kubeconfig_file.read()
+ try:
+ connectivity_info = ConnectivityInfo.get_connectivity_info_by_region_id(cloud_region_id=region_id)
+ logger.info("Connectivity Info exists ")
+ logger.info("Delete Connectivity Info ")
+ connectivity_info.delete()
+ ConnectivityInfo.create(cloud_region_id=region_id,
+ cloud_owner=cloud_owner,
+ kubeconfig=kubeconfig)
+ logger.info("Connectivity Info created ")
+ except (APIError, ResourceNotFound):
+ logger.info("Connectivity Info does not exists ")
+ ConnectivityInfo.create(cloud_region_id=region_id,
+ cloud_owner=cloud_owner,
+ kubeconfig=kubeconfig)
+ logger.info("Connectivity Info created ")
+
+
+def add_custom_resource_definitions(region_id):
+ #### Add Custom Resource Definitions ####
+ logger.info("******** Custom Resource Definitions *******")
+ cluster_kubeconfig_path = Config.CLOUD_REGIONS[region_id]["cluster_kubeconfig_file"]
+ k8s_client = K8sClient(kubeconfig_path=cluster_kubeconfig_path)
+ for crd in Config.CLOUD_REGIONS[region_id]["customer_resource_definitions"]:
+ k8s_client.create_custom_object(crd)
+
+
+def add_region_to_so_db(region):
+ #### Add region to SO db ####
+ logger.info("******** SO Database *******")
+ if is_k8s_region(region.cloud_region_id):
+ identity_service = IdentityService(identity_id="Keystone_K8s",
+ url="http://test:5000/v3",
+ mso_id="onapsdk_user",
+ mso_pass="mso_pass_onapsdk",
+ project_domain_name="NULL",
+ user_domain_name="NULL",
+ identity_server_type="KEYSTONE")
+
+ SoDbAdapter.add_cloud_site(cloud_region_id=region.cloud_region_id,
+ complex_id=region.complex_name,
+ identity_service=identity_service,
+ orchestrator="multicloud")
+ else:
+ identity_url = Config.CLOUD_REGIONS[region.cloud_region_id]["identity_url"]
+ mso_id = Config.CLOUD_REGIONS[region.cloud_region_id]["mso_id"]
+ mso_pass = Config.CLOUD_REGIONS[region.cloud_region_id]["mso_pass"]
+ identity_server_type = Config.CLOUD_REGIONS[region.cloud_region_id]["identity_server_type"]
+ identity_service = IdentityService(identity_id=region.cloud_region_id + "_KEYSTONE",
+ url=identity_url,
+ mso_id=mso_id,
+ mso_pass=mso_pass,
+ project_domain_name="Default",
+ user_domain_name="Default",
+ identity_server_type=identity_server_type)
+
+ SoDbAdapter.add_cloud_site(cloud_region_id=region.cloud_region_id,
+ complex_id=region.complex_name,
+ identity_service=identity_service,
+ orchestrator="NULL")
+
+
+def is_k8s_region(region_id):
+ is_k8s = False
+ if Config.CLOUD_REGIONS[region_id]["cloud_type"] == "k8s":
+ is_k8s = True
+ return is_k8s
+
+
+########################################################################################################################
+def main():
+ create_customer()
+
+ for cloud_region_id in Config.CLOUD_REGIONS:
+
+ complx = create_complex(cloud_region_id)
+ cloud_region = create_cloud_region(cloud_region_id)
+ link_region_to_complex(cloud_region, complx)
+ add_availability_zone(cloud_region)
+ add_tenant(cloud_region)
+
+ if is_k8s_region(cloud_region_id):
+ update_connectivity_info(cloud_region_id)
+ add_custom_resource_definitions(cloud_region_id)
+
+ add_region_to_so_db(cloud_region)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/heat/vFW_CNF_CDS/automation/create_k8s_region.py b/heat/vFW_CNF_CDS/automation/create_k8s_region.py
deleted file mode 100644
index ca680cf1..00000000
--- a/heat/vFW_CNF_CDS/automation/create_k8s_region.py
+++ /dev/null
@@ -1,126 +0,0 @@
-# ============LICENSE_START=======================================================
-# Copyright (C) 2020 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 logging
-import os
-from uuid import uuid4
-
-from config import Config
-from k8s_client import K8sClient
-from so_db_adapter import SoDBUpdate
-from onapsdk.aai.business import Customer
-from onapsdk.aai.cloud_infrastructure import Complex, CloudRegion
-from onapsdk.msb.k8s import ConnectivityInfo
-
-logger = logging.getLogger("")
-logger.setLevel(logging.DEBUG)
-fh = logging.StreamHandler()
-fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s')
-fh.setFormatter(fh_formatter)
-logger.addHandler(fh)
-
-MYPATH = os.path.dirname(os.path.realpath(__file__))
-
-#### Create complex if not exists ####
-logger.info("******** Complex *******")
-try:
- complex = list(Complex.get_all(physical_location_id=Config.COMPLEX_ID))[0]
- logger.info("Complex exists")
-except IndexError:
- logger.info("Complex does not exists")
- complex = Complex.create(physical_location_id=Config.COMPLEX_ID,
- name=Config.COMPLEX_ID,
- physical_location_type="office",
- street1="DummyStreet 1",
- city="DummyCity",
- postal_code="00-000",
- country="DummyCountry",
- region="DummyRegion")
- logger.info("Complex created")
-
-#### Create cloud region if not exists ####
-logger.info("******** Cloud Region *******")
-try:
- cloud_region = list(CloudRegion.get_all(cloud_owner=Config.CLOUD_OWNER, cloud_region_id=Config.CLOUD_REGION))[0]
- logger.info("Cloud region exists")
-except IndexError:
- logger.info("Cloud region does not exists")
- cloud_region = CloudRegion.create(cloud_owner=Config.CLOUD_OWNER,
- cloud_region_id=Config.CLOUD_REGION,
- cloud_type="k8s",
- owner_defined_type="t1",
- cloud_region_version="1.0",
- complex_name=complex.physical_location_id,
- cloud_zone="CloudZone",
- sriov_automation="false",
- orchestration_disabled=False,
- in_maint=False)
- logger.info("Cloud region created")
-
-logger.info("******** Cloud regiongion <-> Complex *******")
-cloud_region.link_to_complex(complex)
-
-logger.info("******** Availability zone *******")
-cloud_region.add_availability_zone(availability_zone_name=Config.AVAILABILITY_ZONE_NAME,
- availability_zone_hypervisor_type=Config.HYPERVISOR_TYPE)
-
-logger.info("******** Tenant *******")
-cloud_region.add_tenant(str(uuid4()), Config.TENANT_NAME)
-
-#### Update or create connectivity info ####
-logger.info("******** Connectivity Info *******")
-with open(os.path.join(MYPATH, Config.CLUSTER_KUBECONFIG_PATH), 'rb') as kubeconfig_file:
- kubeconfig = kubeconfig_file.read()
-try:
- connectivity_info = ConnectivityInfo.get_connectivity_info_by_region_id(cloud_region_id=Config.CLOUD_REGION)
- logger.info("Connectivity Info exists ")
- logger.info("Delete Connectivity Info ")
- connectivity_info.delete()
- connectivity_info = ConnectivityInfo.create(cloud_region_id=Config.CLOUD_REGION,
- cloud_owner=Config.CLOUD_OWNER,
- kubeconfig=kubeconfig)
- logger.info("Connectivity Info created ")
-except:
- logger.info("Connectivity Info does not exists ")
- connectivity_info = ConnectivityInfo.create(cloud_region_id=Config.CLOUD_REGION,
- cloud_owner=Config.CLOUD_OWNER,
- kubeconfig=kubeconfig)
- logger.info("Connectivity Info created ")
-
-#### Add Custom Resource Definitions ####
-k8s_client = K8sClient(kubeconfig_path=Config.CLUSTER_KUBECONFIG_PATH)
-for crd in Config.CUSTOMER_RESOURCE_DEFINITIONS:
- k8s_client.create_custom_object(crd)
-
-#### Create customer if not exists ####
-logger.info("******** Customer *******")
-try:
- customer = Customer.get_by_global_customer_id(Config.GLOBAL_CUSTOMER_ID)
- logger.info("Customer exists")
-except:
- logger.info("Customer exists")
- customer = Customer.create(Config.GLOBAL_CUSTOMER_ID, Config.GLOBAL_CUSTOMER_ID, "INFRA")
- logger.info("Customer created")
-
-#### Add region to SO db ####
-logger.info("******** SO Database *******")
-result = SoDBUpdate.add_region_to_so_db(cloud_region_id=Config.CLOUD_REGION,
- complex_id=Config.COMPLEX_ID)
-if result.status_code == 201:
- logger.info("Region in SO db created successfully")
-else:
- logger.error("Creating region in SO db failed")
diff --git a/heat/vFW_CNF_CDS/automation/delete.py b/heat/vFW_CNF_CDS/automation/delete.py
index c5ac334a..09f2856d 100755
--- a/heat/vFW_CNF_CDS/automation/delete.py
+++ b/heat/vFW_CNF_CDS/automation/delete.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (C) 2020 Orange
+# 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.
@@ -16,13 +16,11 @@
# ============LICENSE_END=========================================================
import logging
-from time import sleep
-
-from onapsdk.aai.business import Customer
-from onapsdk.so.so_element import OrchestrationRequest
from config import Config
+from instantiate import get_customer, check_orchestration_status, get_service_model
+
logger = logging.getLogger("")
logger.setLevel(logging.DEBUG)
fh = logging.StreamHandler()
@@ -30,40 +28,81 @@ fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filenam
fh.setFormatter(fh_formatter)
logger.addHandler(fh)
-logger.info("******** Get Customer *******")
-customer = None
-try:
- customer = Customer.get_by_global_customer_id(Config.GLOBAL_CUSTOMER_ID)
-except:
- logger.error("Customer not found")
- exit(1)
-
-logger.info("******** Check Service Subscription *******")
-service_subscription = None
-for service_sub in customer.service_subscriptions:
- if service_sub.service_type == Config.SERVICENAME:
- logger.info("Service %s subscribed", Config.SERVICENAME)
- service_subscription = service_sub
- break
-if not service_subscription:
- logger.error("Service Subscription not found")
- exit(1)
-
-logger.info("******** Get Service Instance details *******")
-service_instance = None
-for service in service_subscription.service_instances:
- if service.instance_name == Config.SERVICE_INSTANCE_NAME:
- service_instance = service
- break
-if not service_instance:
- logger.error("Service Instance not found")
- exit(1)
-
-logger.info("******** Delete Service %s *******", service_instance.instance_name)
-service_deletion = service_instance.delete()
-status = None
-while not (status == OrchestrationRequest.StatusEnum.COMPLETED
- or status == OrchestrationRequest.StatusEnum.FAILED):
- sleep(10)
- status = service_deletion.status
- logger.info(f"Orchestration status is: {status.value}")
+
+def get_service_subscription(customer, service_name):
+ try:
+ service_subscription = next(
+ service_sub for service_sub in customer.service_subscriptions if service_sub.service_type == service_name)
+ except StopIteration:
+ logger.error("Service Subscription not found")
+ exit(1)
+ return service_subscription
+
+
+def get_service_instance(service_subscription, service_instance_name):
+ try:
+ service_instance = next(instance for instance in service_subscription.service_instances
+ if instance.instance_name == service_instance_name)
+ except StopIteration:
+ logger.error("Service Instance not found")
+ exit(1)
+ return service_instance
+
+
+def delete_service_macro(service_instance):
+ service_deletion = service_instance.delete(a_la_carte=False)
+ check_orchestration_status(service_deletion)
+
+
+def delete_service_alacarte(service_instance):
+ for vnf in service_instance.vnf_instances:
+ for vf_module in vnf.vf_modules:
+ vf_module_deletion = vf_module.delete()
+ check_orchestration_status(vf_module_deletion)
+ vnf_deletion = vnf.delete()
+ check_orchestration_status(vnf_deletion)
+ service_deletion = service_instance.delete()
+ check_orchestration_status(service_deletion)
+
+
+def delete_service_alacarte2(service_instance, service_model):
+ for vnf in service_instance.vnf_instances:
+ for label in sorted(Config.VF_MODULE_PARAM_LIST, reverse=True):
+ vf_module_model = next(vfmodule for vfmodule in service_model.vf_modules
+ if vfmodule.properties["vf_module_label"] == label)
+ vfModuleModelInvariantUUID = vf_module_model.metadata["vfModuleModelInvariantUUID"]
+ vf_module = next(vfmodule for vfmodule in vnf.vf_modules if vfmodule.model_invariant_id == vfModuleModelInvariantUUID)
+ vf_module_deletion = vf_module.delete()
+ check_orchestration_status(vf_module_deletion)
+
+ vnf_deletion = vnf.delete()
+ check_orchestration_status(vnf_deletion)
+ service_deletion = service_instance.delete()
+ check_orchestration_status(service_deletion)
+
+
+def main():
+ logger.info("*******************************")
+ logger.info("**** SERVICE DELETION ****")
+ logger.info("*******************************")
+
+ logger.info("******** GET Customer *******")
+ customer = get_customer(Config.GLOBAL_CUSTOMER_ID)
+
+ logger.info("******** Check Service Subscription *******")
+ service_subscription = get_service_subscription(customer, Config.SERVICENAME)
+
+ logger.info("******** Get Service Instance details *******")
+ service_instance = get_service_instance(service_subscription, Config.SERVICE_INSTANCE_NAME)
+
+ service_model = get_service_model(Config.SERVICENAME)
+
+ logger.info("******** Delete Service %s *******", service_instance.instance_name)
+ if Config.MACRO_INSTANTIATION:
+ delete_service_macro(service_instance)
+ else:
+ delete_service_alacarte2(service_instance, service_model)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/heat/vFW_CNF_CDS/automation/instantiate.py b/heat/vFW_CNF_CDS/automation/instantiate.py
index a626bd09..7468c7a2 100755
--- a/heat/vFW_CNF_CDS/automation/instantiate.py
+++ b/heat/vFW_CNF_CDS/automation/instantiate.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (C) 2020 Orange
+# 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.
@@ -19,18 +19,19 @@ import logging
import zipfile
from io import BytesIO
from time import sleep
-from uuid import uuid4
+import os
import oyaml as yaml
from config import Config
from onapsdk.aai.cloud_infrastructure import (
- CloudRegion,
+ CloudRegion
)
from onapsdk.aai.business import (
Customer,
OwningEntity as AaiOwningEntity
)
+from onapsdk.exceptions import ResourceNotFound, APIError
from onapsdk.msb.k8s import Definition
from onapsdk.so.instantiation import (
@@ -39,6 +40,7 @@ from onapsdk.so.instantiation import (
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
logger = logging.getLogger("")
logger.setLevel(logging.DEBUG)
@@ -47,171 +49,206 @@ fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filenam
fh.setFormatter(fh_formatter)
logger.addHandler(fh)
-logger.info("*******************************")
-logger.info("**** SERVICE INSTANTIATION ****")
-logger.info("*******************************")
-
-logger.info("******** Create 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
-if not customer:
- customer = Customer.create(Config.GLOBAL_CUSTOMER_ID, Config.GLOBAL_CUSTOMER_ID, "INFRA")
-
-logger.info("******** Find Service in SDC *******")
-service = None
-services = Service.get_all()
-for found_service in services:
- logger.debug("Service %s is found, distribution %s", found_service.name, found_service.distribution_status)
- if found_service.name == Config.SERVICENAME:
- logger.info("Found Service %s in SDC", found_service.name)
- service = found_service
- break
-
-if not service:
- logger.error("Service %s not found in SDC", Config.SERVICENAME)
- exit(1)
-
-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)
- service_subscription = service_sub
- break
-
-if not service_subscription:
- logger.info("******** Subscribe Service *******")
- customer.subscribe_service(service)
-
-logger.info("******** Get Tenant *******")
-cloud_region = CloudRegion(cloud_owner=Config.CLOUD_OWNER, cloud_region_id=Config.CLOUD_REGION,
- orchestration_disabled=True, in_maint=False)
-tenant = None
-for found_tenant in cloud_region.tenants:
- logger.debug("Tenant %s found in %s_%s", found_tenant.name, cloud_region.cloud_owner, cloud_region.cloud_region_id)
- if found_tenant.name == Config.TENANT_NAME:
- logger.info("Found my Tenant %s", found_tenant.name)
- tenant = found_tenant
- break
-
-if not tenant:
- logger.error("tenant %s not found", Config.TENANT_NAME)
- exit(1)
-
-logger.info("******** Connect Service to Tenant *******")
-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)
- service_subscription = service_sub
- break
-
-if not service_subscription:
- logger.error("Service subscription %s is not found", Config.SERVICENAME)
- exit(1)
-
-service_subscription.link_to_cloud_region_and_tenant(cloud_region, tenant)
-
-logger.info("******** Add Business Objects (OE, P, Pl, LoB) in VID *******")
-vid_owning_entity = OwningEntity.create(Config.OWNING_ENTITY)
-vid_project = Project.create(Config.PROJECT)
-vid_platform = Platform.create(Config.PLATFORM)
-vid_line_of_business = LineOfBusiness.create(Config.LINE_OF_BUSINESS)
-
-logger.info("******** Add Owning Entity in AAI *******")
-owning_entity = None
-for oe in AaiOwningEntity.get_all():
- if oe.name == vid_owning_entity.name:
- owning_entity = oe
- break
-if not owning_entity:
- logger.info("******** Owning Entity not existing: create *******")
- owning_entity = AaiOwningEntity.create(vid_owning_entity.name, str(uuid4()))
-
-logger.info("******** Delete old profiles ********")
-for vnf in service.vnfs:
- for vf_module in vnf.vf_modules:
- definition = Definition.get_definition_by_name_version(vf_module.metadata["vfModuleModelInvariantUUID"],
- vf_module.metadata["vfModuleModelUUID"])
- vf_module_label = vf_module.properties["vf_module_label"]
- if vf_module_label == "base_template_dummy_ignore":
- continue
- profile_name = Config.VF_MODULE_PARAM_LIST[vf_module_label]["k8s-rb-profile-name"]
- try:
- profile = definition.get_profile_by_name(profile_name)
- namespace = None
- if "k8s-rb-profile-namespace" in Config.VNF_PARAM_LIST:
- namespace = Config.VNF_PARAM_LIST["k8s-rb-profile-namespace"]
- if "k8s-rb-profile-namespace" in Config.VF_MODULE_PARAM_LIST[vf_module_label]:
- namespace = Config.VF_MODULE_PARAM_LIST[vf_module_label]["k8s-rb-profile-namespace"]
- if namespace != None and profile.namespace != namespace:
- profile.delete()
- logger.info("Profile: " + profile_name + " for " + vf_module.name + " deleted")
- else:
- logger.info("No need to delete Profile " + profile_name +
- " for " + vf_module.name + ". Namespace is fine")
- except ValueError:
- logger.info("Profile: " + profile_name + " for " + vf_module.name + " not found")
-
-
-# Read SDNC MODEL NAME and VERSION from CBA.zip
-logger.info("*******************************")
-logger.info("Retrieving SDNC MODEL NAME and VERSION")
-logger.info("*******************************")
-with zipfile.ZipFile(Config.VSPFILE, 'r') as package:
- cba_io = BytesIO(package.read("CBA.zip"))
- with zipfile.ZipFile(cba_io) as cba:
- with cba.open('TOSCA-Metadata/TOSCA.meta') as meta_file:
- tosca_meta = yaml.load(meta_file, Loader=yaml.FullLoader)
- SDNC_MODEL_NAME = tosca_meta.get("Template-Name")
- SDNC_MODEL_VERSION = tosca_meta.get("Template-Version")
-
-logger.info("******** Instantiate Service *******")
-service_instance = None
-service_instantiation = None
-for se in service_subscription.service_instances:
- if se.instance_name == Config.SERVICE_INSTANCE_NAME:
- service_instance = se
- break
-if not service_instance:
- logger.info("******** Service Instance not existing: Instantiate *******")
- # Instantiate service
- vfmodules_list = Config.VF_MODULE_PARAM_LIST
- vnf_param_list = Config.VNF_PARAM_LIST
-
- vnf_param = [
- InstantiationParameter(name="sdnc_model_name", value=SDNC_MODEL_NAME),
- InstantiationParameter(name="sdnc_model_version", value=SDNC_MODEL_VERSION),
- InstantiationParameter(name="sdnc_artifact_name", value=Config.SDNC_ARTIFACT_NAME)]
+
+def get_customer(global_customer_id):
+ try:
+ customer = Customer.get_by_global_customer_id(global_customer_id)
+ logger.info(f"Customer {customer.subscriber_name} found")
+ return customer
+ except ResourceNotFound:
+ logger.error("Customer not exists. Check if region creation was successfully finished")
+ exit(1)
+
+
+def get_service_model(service_type):
+ try:
+ service_model = next(model for model in Service.get_all() if model.name == service_type)
+ logger.info(
+ f"Found Service {service_model.name} in SDC, distribution status: {service_model.distribution_status}")
+ return service_model
+ except StopIteration:
+ logger.error(f"Service model {service_type} not found in SDC")
+ exit(1)
+
+
+def check_service_customer_subscription(customer, service):
+ try:
+ next(subscription for subscription in customer.service_subscriptions
+ if subscription.service_type == service.name)
+ except StopIteration:
+ return False
+
+ logger.info(f"Customer {customer.subscriber_name} subscribed for {service.name}")
+ return True
+
+
+def subscribe_service_customer(customer, service):
+ if not check_service_customer_subscription(customer, service):
+ logger.info("******** Subscribe Service *******")
+ customer.subscribe_service(service)
+
+
+def get_cloud_region(cloud_owner, cloud_region):
+ return CloudRegion(cloud_owner=cloud_owner, cloud_region_id=cloud_region,
+ orchestration_disabled=True, in_maint=False)
+
+
+def get_tenant(cloud_region, tenant_name):
+ try:
+ tenant = next(tenant for tenant in cloud_region.tenants if tenant.name == tenant_name)
+ return tenant
+ except StopIteration:
+ logger.error(f"Tenant {tenant_name} not found")
+ exit(1)
+
+
+def add_business_objects(owning_entity, project, platform, line_of_business):
+ vid_owning_entity = OwningEntity.create(Config.OWNING_ENTITY)
+ vid_project = Project.create(project)
+ vid_platform = Platform.create(platform)
+ vid_line_of_business = LineOfBusiness.create(line_of_business)
+ logger.info("******** Business objects added to VID *******")
+
+ logger.info("******** Add Owning Entity to AAI *******")
+ try:
+ aai_owning_entity = AaiOwningEntity.get_by_owning_entity_name(owning_entity)
+ except ResourceNotFound:
+ logger.info("******** Owning Entity not existing: create *******")
+ aai_owning_entity = AaiOwningEntity.create(vid_owning_entity.name)
+
+ return vid_project, vid_platform, vid_line_of_business, aai_owning_entity
+
+
+def delete_old_profiles(service):
+ for vnf in service.vnfs:
+ for vf_module in vnf.vf_modules:
+ vf_module_label = vf_module.properties["vf_module_label"]
+ if vf_module_label == "base_template_dummy_ignore":
+ continue
+ if "k8s-rb-profile-name" not in Config.VF_MODULE_PARAM_LIST[vf_module_label]["instantiation_parameters"]:
+ continue
+ try:
+ definition = Definition.get_definition_by_name_version(
+ rb_name=vf_module.metadata["vfModuleModelInvariantUUID"],
+ rb_version=vf_module.metadata["vfModuleModelCustomizationUUID"])
+ except APIError:
+ definition = Definition.get_definition_by_name_version(
+ rb_name=vf_module.metadata["vfModuleModelInvariantUUID"],
+ rb_version=vf_module.metadata["vfModuleModelUUID"])
+ profile_name = Config.VF_MODULE_PARAM_LIST[vf_module_label]["instantiation_parameters"][
+ "k8s-rb-profile-name"]
+ try:
+ profile = definition.get_profile_by_name(profile_name)
+ namespace = None
+ if "k8s-rb-profile-namespace" in Config.VNF_PARAM_LIST:
+ namespace = Config.VNF_PARAM_LIST["k8s-rb-profile-namespace"]
+ if "k8s-rb-profile-namespace" in Config.VF_MODULE_PARAM_LIST[vf_module_label]["instantiation_parameters"]:
+ namespace = Config.VF_MODULE_PARAM_LIST[vf_module_label]["instantiation_parameters"]["k8s-rb-profile-namespace"]
+ if namespace != None and profile.namespace != namespace:
+ profile.delete()
+ logger.info("Profile: " + profile_name + " for " + vf_module.name + " deleted")
+ else:
+ logger.info("No need to delete Profile " + profile_name +
+ " for " + vf_module.name + ". Namespace is fine")
+ except ResourceNotFound:
+ logger.info("Profile: " + profile_name + " for " + vf_module.name + " not found")
+
+
+def read_sdnc_model_details(file):
+ mypath = os.path.dirname(os.path.realpath(__file__))
+ file_path = os.path.join(mypath, file)
+ with zipfile.ZipFile(file_path, 'r') as package:
+ cba_io = BytesIO(package.read("CBA.zip"))
+ with zipfile.ZipFile(cba_io) as cba:
+ with cba.open('TOSCA-Metadata/TOSCA.meta') as meta_file:
+ tosca_meta = yaml.load(meta_file, Loader=yaml.FullLoader)
+ sdnc_model_name = tosca_meta.get("Template-Name")
+ sdnc_model_version = tosca_meta.get("Template-Version")
+ return sdnc_model_name, sdnc_model_version
+
+
+def check_service_instance_exists(service_subscription, service_instance_name):
+ try:
+ service_instance = next((instance for instance in service_subscription.service_instances
+ if instance.instance_name == service_instance_name), None)
+ return service_instance
+ except ResourceNotFound:
+ return None
+
+
+def get_vfmodule_parameters(vf_module, vf_module_instantiation_parameters, sdnc_model_name, sdnc_model_version):
+ base_parameters = [
+ InstantiationParameter(name="sdnc_model_name", value=sdnc_model_name),
+ InstantiationParameter(name="sdnc_model_version", value=sdnc_model_version),
+ InstantiationParameter(name="vf_module_label", value=vf_module)]
+
+ for instantiation_parameter_key, instantiation_parameter_value in vf_module_instantiation_parameters:
+ base_parameters.append(InstantiationParameter(name=instantiation_parameter_key,
+ value=instantiation_parameter_value))
+
+ return VfmoduleParameters(vf_module, base_parameters)
+
+
+def get_vnf_parameters(sdnc_model_name, sdnc_model_version, sdnc_artifact_name, vnf_param_list):
+ vnf_parameters = [
+ InstantiationParameter(name="sdnc_model_name", value=sdnc_model_name),
+ InstantiationParameter(name="sdnc_model_version", value=sdnc_model_version),
+ InstantiationParameter(name="sdnc_artifact_name", value=sdnc_artifact_name)]
for vnf_param_name, vnf_param_value in vnf_param_list.items():
- vnf_param.append(
+ vnf_parameters.append(
InstantiationParameter(name=vnf_param_name, value=vnf_param_value)
)
- vfmodules_param = []
- for vfmodule in vfmodules_list:
- params = [
- InstantiationParameter(name="sdnc_model_name", value=SDNC_MODEL_NAME),
- InstantiationParameter(name="sdnc_model_version", value=SDNC_MODEL_VERSION),
- InstantiationParameter(name="vf_module_label", value=vfmodule)]
+ return vnf_parameters
+
+
+def check_orchestration_status(instantiation):
+ status = None
+ while not (status == OrchestrationRequest.StatusEnum.COMPLETED
+ or status == OrchestrationRequest.StatusEnum.FAILED):
+ sleep(10)
+ status = instantiation.status
+ logger.info(f"Orchestration status is: {status.value}")
+
+ if status == OrchestrationRequest.StatusEnum.FAILED:
+ logger.error("Orchestration was failed!")
+ exit(1)
+ else:
+ logger.info("Orchestration was succeed")
+ return
+
+
+def get_aai_service(service_type):
+ logging.info("******** Retrieve product family for service *******")
+ try:
+ aai_service = next(service for service in AaiService.get_all() if service.service_id == service_type)
+ except (ResourceNotFound, StopIteration):
+ logging.info("******** Service design and creation in AAI not existing: create *******")
+ AaiService.create(service_id=service_type, service_description=service_type)
+ aai_service = next(service for service in AaiService.get_all() if service.service_id == service_type)
+
+ return aai_service
- for vfmodule_param_name, vfmodule_param_value in vfmodules_list[vfmodule].items():
- params.append(
- InstantiationParameter(name=vfmodule_param_name, value=vfmodule_param_value)
- )
- vfmodules_param.append(VfmoduleParameters(vfmodule, params))
+def instantiate_service_macro(service_instance_name,
+ sdnc_model_name, sdnc_model_version, sdnc_artifact_name, vf_name, vnf_param_list,
+ vf_module_list, service, cloud_region, tenant, customer, owning_entity,
+ vid_project, vid_line_of_business, vid_platform):
+ # TODO: support for multiple vnf should be added BEGINING of the loop
+ vnf_parameters = get_vnf_parameters(sdnc_model_name, sdnc_model_version, sdnc_artifact_name, vnf_param_list)
- vnf_params = VnfParameters(name=Config.VFNAME, vnf_parameters=vnf_param, vfmodule_parameters=vfmodules_param)
+ vfmodule_parameters = []
+ for vfmodule in vf_module_list:
+ vf_module_instantiation_parameters = vf_module_list[vfmodule]["instantiation_parameters"].items()
+ vfmodule_parameters.append(get_vfmodule_parameters(vfmodule, vf_module_instantiation_parameters,
+ sdnc_model_name, sdnc_model_version))
+ vnf_instantiation_parameters = VnfParameters(name=vf_name,
+ vnf_parameters=vnf_parameters,
+ vfmodule_parameters=vfmodule_parameters)
+ # END of the loop
+ aai_service = get_aai_service(service.name)
service_instantiation = ServiceInstantiation.instantiate_macro(
sdc_service=service,
cloud_region=cloud_region,
@@ -221,14 +258,189 @@ if not service_instance:
project=vid_project,
line_of_business=vid_line_of_business,
platform=vid_platform,
- service_instance_name=Config.SERVICE_INSTANCE_NAME,
- vnf_parameters=[vnf_params]
+ service_instance_name=service_instance_name,
+ vnf_parameters=[vnf_instantiation_parameters],
+ aai_service=aai_service
)
- logger.info("Instantiation request ID: %s", service_instantiation.request_id)
- logger.info("Service Instance ID: %s", service_instantiation.instance_id)
- status = None
- while not (status == OrchestrationRequest.StatusEnum.COMPLETED
- or status == OrchestrationRequest.StatusEnum.FAILED):
- sleep(10)
- status = service_instantiation.status
- logger.info(f"Orchestration status is: {status.value}")
+ check_orchestration_status(service_instantiation)
+
+
+def get_base_vf_module(vf_modules):
+ base_vf_module = next(vf_module for vf_module in vf_modules if vf_module.properties["isBase"])
+ return base_vf_module
+
+
+def is_base(vf_module):
+ if vf_module.properties["isBase"]:
+ return True
+ return False
+
+
+def instantiate_vf_module(vf_module, vf_module_param_list, vnf_instance, sdnc_model_name, sdnc_model_version):
+ vf_module_label = vf_module.properties["vf_module_label"]
+ region_id = vf_module_param_list[vf_module_label]["cloud_configuration"]
+ cloud_region = get_cloud_region(
+ Config.CLOUD_REGIONS[region_id]["cloud_owner"],
+ region_id)
+ tenant = get_tenant(cloud_region, Config.CLOUD_REGIONS[region_id]["tenant"]["name"])
+
+ vfmodule_instantiation_parameters = vf_module_param_list[vf_module_label]["instantiation_parameters"].items()
+
+ base_parameters = [
+ InstantiationParameter(name="sdnc_model_name", value=sdnc_model_name),
+ InstantiationParameter(name="sdnc_model_version", value=sdnc_model_version),
+ InstantiationParameter(name="vf_module_label", value=vf_module_label)]
+
+ for instantiation_parameter_key, instantiation_parameter_value in vfmodule_instantiation_parameters:
+ base_parameters.append(InstantiationParameter(name=instantiation_parameter_key,
+ value=instantiation_parameter_value))
+
+ vf_module_instantiation = vnf_instance.add_vf_module(
+ vf_module=vf_module,
+ cloud_region=cloud_region,
+ tenant=tenant,
+ vnf_parameters=base_parameters,
+ use_preload=False
+ )
+ check_orchestration_status(vf_module_instantiation)
+
+
+def check_vf_module_list_correct(vf_modules, vf_module_param_list):
+ labels = set()
+ for vf_module in vf_modules:
+ labels.add(vf_module.properties["vf_module_label"])
+ if vf_module_param_list.keys() == labels:
+ return True
+ else:
+ return False
+
+
+def instantiate_service_alacarte(service_subscription, service_instance_name,
+ sdnc_model_name, sdnc_model_version, sdnc_artifact_name, vnf_param_list,
+ vf_module_param_list, service, cloud_region, tenant, customer, owning_entity,
+ vid_project, vid_line_of_business, vid_platform):
+ # Tworzenie Serwisu
+ service_instantiation = ServiceInstantiation.instantiate_ala_carte(
+ sdc_service=service,
+ cloud_region=cloud_region,
+ tenant=tenant,
+ customer=customer,
+ owning_entity=owning_entity,
+ project=vid_project,
+ service_instance_name=service_instance_name
+ )
+ check_orchestration_status(service_instantiation)
+ # Koniec tworzenia Serwisu
+
+ service_instance = service_subscription.get_service_instance_by_name(service_instance_name)
+ # Dodawanie VNFs (VF) do Serwisu
+ for vnf in service.vnfs:
+ vnf_parameters = get_vnf_parameters(sdnc_model_name, sdnc_model_version, sdnc_artifact_name, vnf_param_list)
+ vnf_instantiation = service_instance.add_vnf(
+ # vnf_instance_name=vf_name, TODO: support for multiple vnf in config file
+ vnf=vnf,
+ line_of_business=vid_line_of_business,
+ platform=vid_platform,
+ vnf_parameters=vnf_parameters
+ )
+ check_orchestration_status(vnf_instantiation)
+
+ # Dodawanie VF Modulow
+ vnf_type = service.name + "/" + vnf.name
+ vnf_instance = next((vnf for vnf in service_instance.vnf_instances if vnf.vnf_type == vnf_type), None)
+
+ if check_vf_module_list_correct(vnf.vf_modules, vf_module_param_list):
+ for vf_module_label in vf_module_param_list:
+ vf_module = next(
+ vf_module for vf_module in vnf.vf_modules if
+ vf_module.properties["vf_module_label"] == vf_module_label)
+ instantiate_vf_module(vf_module, vf_module_param_list, vnf_instance, sdnc_model_name,
+ sdnc_model_version)
+ else:
+ logger.error("VF_MODULE_PARAM_LIST error. ")
+ # Koniec dodawania VF Modulow
+ # Koniec dodawania VNFs
+
+ # # Dodanie base
+ # base_vf_module = get_base_vf_module(vnf.vf_modules)
+ # instantiate_vf_module(base_vf_module, vf_module_param_list, vnf_instance, sdnc_model_name, sdnc_model_version)
+ # # Dodanie reszty
+ # for vf_module in vnf.vf_modules:
+ # if not is_base(vf_module):
+ # instantiate_vf_module(vf_module, vf_module_param_list, vnf_instance, sdnc_model_name,
+ # sdnc_model_version)
+
+
+def main():
+ logger.info("*******************************")
+ logger.info("**** SERVICE INSTANTIATION ****")
+ logger.info("*******************************")
+
+ logger.info("******** GET Customer *******")
+ customer = get_customer(Config.GLOBAL_CUSTOMER_ID)
+
+ logger.info("******** GET Service Model from SDC *******")
+ service = get_service_model(Config.SERVICENAME)
+
+ logger.info("******** Subscribe Customer for Service *******")
+ subscribe_service_customer(customer, service)
+
+ logger.info("******** Get Tenant *******")
+ basic_cloud_region_name = next(iter(Config.CLOUD_REGIONS.keys()))
+ cloud_region = get_cloud_region(Config.CLOUD_REGIONS[basic_cloud_region_name]["cloud_owner"],
+ basic_cloud_region_name)
+ tenant = get_tenant(cloud_region,
+ Config.CLOUD_REGIONS[basic_cloud_region_name]["tenant"]["name"])
+
+ ######
+ logger.info("******** Connect Service to Tenant *******")
+ 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)
+ service_subscription = service_sub
+ break
+
+ if not service_subscription:
+ logger.error("Service subscription %s is not found", Config.SERVICENAME)
+ exit(1)
+
+ service_subscription.link_to_cloud_region_and_tenant(cloud_region, tenant)
+ ####
+
+ logger.info("******** Add Business Objects (OE, P, Pl, LoB) *******")
+ vid_project, vid_platform, vid_line_of_business, owning_entity = add_business_objects(Config.OWNING_ENTITY,
+ Config.PROJECT,
+ Config.PLATFORM,
+ Config.LINE_OF_BUSINESS)
+
+ logger.info("******** Delete old profiles ********")
+ delete_old_profiles(service)
+
+ logger.info("******** Read SDNC MODEL NAME and VERSION from CBA.zip ********")
+ sdnc_model_name, sdnc_model_version = read_sdnc_model_details(Config.VSPFILE)
+
+ logger.info("******** Instantiate Service *******")
+ service_instance = check_service_instance_exists(service_subscription, Config.SERVICE_INSTANCE_NAME)
+ if service_instance:
+ logger.info("******** Service Instance exists, do not instantiate *******")
+ else:
+ logger.info("******** Service Instance not existing: Instantiate *******")
+ if Config.MACRO_INSTANTIATION:
+ instantiate_service_macro(Config.SERVICE_INSTANCE_NAME, sdnc_model_name,
+ sdnc_model_version, Config.SDNC_ARTIFACT_NAME, Config.VFNAME,
+ Config.VNF_PARAM_LIST,
+ Config.VF_MODULE_PARAM_LIST,
+ service, cloud_region, tenant, customer, owning_entity, vid_project,
+ vid_line_of_business, vid_platform)
+ else:
+ instantiate_service_alacarte(service_subscription, Config.SERVICE_INSTANCE_NAME, sdnc_model_name,
+ sdnc_model_version, Config.SDNC_ARTIFACT_NAME, Config.VNF_PARAM_LIST,
+ Config.VF_MODULE_PARAM_LIST,
+ service, cloud_region, tenant, customer, owning_entity, vid_project,
+ vid_line_of_business, vid_platform)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/heat/vFW_CNF_CDS/automation/k8s_client.py b/heat/vFW_CNF_CDS/automation/k8s_client.py
index 7b0b634f..98b451bc 100755
--- a/heat/vFW_CNF_CDS/automation/k8s_client.py
+++ b/heat/vFW_CNF_CDS/automation/k8s_client.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (C) 2020 Orange
+# 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.
diff --git a/heat/vFW_CNF_CDS/automation/onap_settings.py b/heat/vFW_CNF_CDS/automation/onap_settings.py
index dda6006c..55a246f4 100755
--- a/heat/vFW_CNF_CDS/automation/onap_settings.py
+++ b/heat/vFW_CNF_CDS/automation/onap_settings.py
@@ -1,3 +1,20 @@
+# ============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
@@ -20,7 +37,7 @@ SO_API_VERSION = "v7"
VID_URL = "https://vid.api.simpledemo.onap.org:30200"
VID_API_VERSION = "/vid"
CLAMP_URL = "https://clamp.api.simpledemo.onap.org:30258"
-VES_URL = "http://ves.api.simpledemo.onap.org:30417"
+VES_URL = "https://ves.api.simpledemo.onap.org:30417"
DMAAP_URL = "http://dmaap.api.simpledemo.onap.org:3904"
# uncomment if socks is used
diff --git a/heat/vFW_CNF_CDS/automation/onboard.py b/heat/vFW_CNF_CDS/automation/onboard.py
index 0abd2660..357f980c 100755
--- a/heat/vFW_CNF_CDS/automation/onboard.py
+++ b/heat/vFW_CNF_CDS/automation/onboard.py
@@ -18,17 +18,15 @@
import logging
import time
-import zipfile
-from io import BytesIO
-
-import oyaml as yaml
+from instantiate import read_sdnc_model_details
from config import Config
import onapsdk.constants as const
from onapsdk.sdc.vendor import Vendor
from onapsdk.sdc.vsp import Vsp
from onapsdk.sdc.vf import Vf
+from onapsdk.sdc.pnf import Pnf
from onapsdk.sdc.service import Service, ServiceInstantiationType
import os
@@ -40,76 +38,125 @@ fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filenam
fh.setFormatter(fh_formatter)
logger.addHandler(fh)
-# Read SDNC MODEL NAME and VERSION from CBA.zip
-logger.info("*******************************")
-logger.info("Retrieving SDNC MODEL NAME and VERSION")
-logger.info("*******************************")
-with zipfile.ZipFile(Config.VSPFILE, 'r') as package:
- cba_io = BytesIO(package.read("CBA.zip"))
- with zipfile.ZipFile(cba_io) as cba:
- with cba.open('TOSCA-Metadata/TOSCA.meta') as meta_file:
- tosca_meta = yaml.load(meta_file, Loader=yaml.FullLoader)
- SDNC_MODEL_NAME = tosca_meta.get("Template-Name")
- SDNC_MODEL_VERSION = tosca_meta.get("Template-Version")
-
-logger.info("*******************************")
-logger.info("******** SERVICE DESIGN *******")
-logger.info("*******************************")
-
-logger.info("******** Onboard Vendor *******")
-vendor = Vendor(name=Config.VENDOR)
-vendor.onboard()
-
-logger.info("******** Onboard VSP *******")
-mypath = os.path.dirname(os.path.realpath(__file__))
-myvspfile = os.path.join(mypath, Config.VSPFILE)
-vsp = Vsp(name=Config.VSPNAME, vendor=vendor, package=open(myvspfile, 'rb'))
-vsp.onboard()
-
-logger.info("******** Onboard VF *******")
-vf = Vf(name=Config.VFNAME)
-vf.vsp = vsp
-vf.create()
-vf.onboard()
-
-logger.info("******** Onboard Service *******")
-svc = Service(name=Config.SERVICENAME,
- instantiation_type=ServiceInstantiationType.MACRO)
-svc.create()
-
-if svc.status == const.DRAFT:
- svc.add_resource(vf)
-
- logger.info("******** Set SDNC properties for VF ********")
- component = svc.get_component(vf)
- prop = component.get_property("sdnc_model_version")
- prop.value = SDNC_MODEL_VERSION
- prop = component.get_property("sdnc_artifact_name")
- prop.value = Config.SDNC_ARTIFACT_NAME
- prop = component.get_property("sdnc_model_name")
- prop.value = SDNC_MODEL_NAME
- prop = component.get_property("controller_actor")
- prop.value = "CDS"
- prop = component.get_property("skip_post_instantiation_configuration")
- prop.value = Config.SKIP_POST_INSTANTIATION
-
- logger.info("******** Onboard Service *******")
- svc.checkin()
- svc.onboard()
-
-logger.info("******** Check Service Distribution *******")
-distribution_completed = False
-nb_try = 0
-nb_try_max = 10
-while distribution_completed is False and nb_try < nb_try_max:
- distribution_completed = svc.distributed
- if distribution_completed is True:
- logger.info("Service Distribution for %s is successfully finished", svc.name)
- break
- logger.info("Service Distribution for %s ongoing, Wait for 60 s", svc.name)
- time.sleep(60)
- nb_try += 1
-
-if distribution_completed is False:
- logger.error("Service Distribution for %s failed !!", svc.name)
- exit(1)
+
+def retrieve_service(service_name: str):
+ logger.info("Retrieve service from SDC before onboarding")
+ services = Service.get_all()
+
+ for found_service in services:
+ if found_service.name == service_name:
+ logging.info(f"Service {found_service.name} found in SDC, onboarding will not be executed")
+ exit(0)
+ return
+
+
+def onboard_vendor(vendor_name: str = "demo_vendor"):
+ logger.info("******** Onboard Vendor *******")
+ vendor = Vendor(vendor_name)
+ vendor.onboard()
+ return vendor
+
+
+def onboard_vsp(vsp_name, vsp_file, vendor):
+ logger.info(f"******** Onboard VSP - {vsp_name} *******")
+ mypath = os.path.dirname(os.path.realpath(__file__))
+ vsp_path = os.path.join(mypath, vsp_file)
+ vsp = None
+ try:
+ vsp = Vsp(name=vsp_name, vendor=vendor, package=open(vsp_path, 'rb'))
+ except FileNotFoundError:
+ logger.error(f"No vsp file was found for {vsp_name}!")
+ exit(1)
+ vsp.onboard()
+ return vsp
+
+
+def onboard_pnf(pnf_name, vsp_name, vsp_file, vendor):
+ logger.info(f"******** Onboard PNF - {pnf_name} *******")
+ pnf_vsp = onboard_vsp(vsp_name=vsp_name, vsp_file=vsp_file, vendor=vendor)
+ pnf = Pnf(name=pnf_name, vsp=pnf_vsp)
+ pnf.onboard()
+ return pnf
+
+
+def onboard_vnf(vnf_name, vsp_name, vsp_file, vendor):
+ logger.info(f"******** Onboard VNF - {vnf_name} *******")
+ vnf_vsp = onboard_vsp(vsp_name=vsp_name, vsp_file=vsp_file, vendor=vendor)
+ vnf = Vf(name=vnf_name, vsp=vnf_vsp)
+ vnf.create()
+ vnf.onboard()
+ return vnf
+
+
+def create_service(service_name, is_macro: bool = True):
+ logger.info("******** Create Service *******")
+ if is_macro:
+ svc = Service(name=service_name,
+ instantiation_type=ServiceInstantiationType.MACRO)
+ else:
+ svc = Service(name=service_name,
+ instantiation_type=ServiceInstantiationType.A_LA_CARTE)
+ svc.create()
+ return svc
+
+
+def set_properties(service, xnf):
+ sdnc_model_name, sdnc_model_version = read_sdnc_model_details(Config.VSPFILE)
+ if service.status == const.DRAFT:
+ logger.info("******** Set SDNC properties for VF ********")
+ component = service.get_component(xnf)
+ prop = component.get_property("sdnc_model_version")
+ prop.value = sdnc_model_version
+ prop = component.get_property("sdnc_artifact_name")
+ prop.value = Config.SDNC_ARTIFACT_NAME
+ prop = component.get_property("sdnc_model_name")
+ prop.value = sdnc_model_name
+ prop = component.get_property("controller_actor")
+ prop.value = "CDS"
+ prop = component.get_property("skip_post_instantiation_configuration")
+ prop.value = Config.SKIP_POST_INSTANTIATION
+
+
+def check_distribution_status(service):
+ logger.info("******** Check Service Distribution *******")
+ distribution_completed = False
+ nb_try = 0
+ nb_try_max = 10
+ while distribution_completed is False and nb_try < nb_try_max:
+ distribution_completed = service.distributed
+ if distribution_completed is True:
+ logger.info(f"Service Distribution for {service.name} is successfully finished")
+ break
+ logger.info(f"Service Distribution for {service.name} ongoing, Wait for 60 s")
+ time.sleep(60)
+ nb_try += 1
+
+ if distribution_completed is False:
+ logger.error(f"Service Distribution for {service.name} failed !!", )
+ exit(1)
+
+
+def main():
+ retrieve_service(service_name=Config.SERVICENAME)
+ logger.info("******** SERVICE DESIGN *******")
+ vendor = onboard_vendor(vendor_name=Config.VENDOR)
+ service = create_service(Config.SERVICENAME, Config.MACRO_INSTANTIATION)
+ if Config.ADD_PNF:
+ pnf = onboard_pnf(pnf_name=Config.PNF_NAME,
+ vsp_name=Config.PNF_VSP_NAME,
+ vsp_file=Config.PNF_VSP_FILE,
+ vendor=vendor)
+ service.add_resource(pnf)
+ vnf = onboard_vnf(vnf_name=Config.VFNAME,
+ vsp_name=Config.VSPNAME,
+ vsp_file=Config.VSPFILE,
+ vendor=vendor)
+ service.add_resource(vnf)
+ set_properties(service, vnf)
+ service.checkin()
+ service.onboard()
+ check_distribution_status(service)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/heat/vFW_CNF_CDS/automation/so_db_adapter.py b/heat/vFW_CNF_CDS/automation/so_db_adapter.py
deleted file mode 100755
index 621decb1..00000000
--- a/heat/vFW_CNF_CDS/automation/so_db_adapter.py
+++ /dev/null
@@ -1,95 +0,0 @@
-# ============LICENSE_START=======================================================
-# Copyright (C) 2020 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=========================================================
-
-from abc import ABC
-from onapsdk.so.so_element import SoElement
-from onapsdk.onap_service import OnapService
-from onapsdk.utils.headers_creator import headers_so_creator
-
-
-class SoDBUpdate(SoElement, ABC):
-
- @classmethod
- def add_region_to_so_db(cls,
- cloud_region_id: str,
- complex_id: str,
- identity_service_id: str = None,
- **kwargs
- ):
- """Method to add cloud_site data with identity_service to SO db.
-
- Args:
- cloud_region_id: the name of cloud region
- complex_id: name of complex
- identity_service_id: optional - id of identity service
- **kwargs: keyword arguments with parameters for identity service creation, like below
-
- Important:
- identity_services data will be overwrite, but in the same time
- cloud_sites data will not (shouldn't) be overwrite!
-
- Return:
- response object
- """
-
- if not identity_service_id:
- identity_service_id = 'Keystone_K8s'
-
- # params for identity_service creation
- orchestrator = kwargs.get('orchestrator', 'multicloud')
- identity_url = kwargs.get('identity_url', "http://1.2.3.4:5000/v2.0")
- mso_id = kwargs.get('mso_id', 'onapsdk_user')
- mso_pass = kwargs.get('mso_pass', 'mso_pass_onapsdk')
- project_domain_name = kwargs.get("project_domain_name", None)
- user_domain_name = kwargs.get("user_domain_name", None)
- member_role = kwargs.get('member_role', 'admin')
- admin_tenant = kwargs.get('admin_tenant', 'service')
- identity_server_type = kwargs.get('identity_server_type', 'KEYSTONE')
- identity_authentication_type = kwargs.get('identity_authentication_type', 'USERNAME_PASSWORD')
-
- data = {
- "id": cloud_region_id,
- "region_id": cloud_region_id,
- "aic_version": "2.5",
- "clli": complex_id,
- "orchestrator": orchestrator,
- "identityService": {
- "id": identity_service_id,
- "identityServerTypeAsString": "KEYSTONE",
- "hibernateLazyInitializer": {},
- "identity_url": identity_url,
- "mso_id": mso_id,
- "mso_pass": mso_pass,
- "project_domain_name": project_domain_name,
- "user_domain_name": user_domain_name,
- "admin_tenant": admin_tenant,
- "member_role": member_role,
- "tenant_metadata": True,
- "identity_server_type": identity_server_type,
- "identity_authentication_type": identity_authentication_type
- }
- }
-
- response = cls.send_message(
- "POST",
- "Create a region in SO db",
- f"{cls.base_url}/cloudSite",
- json=data,
- headers=headers_so_creator(OnapService.headers),
- exception=ValueError)
-
- return response
diff --git a/heat/vFW_CNF_CDS/automation/update_cba.py b/heat/vFW_CNF_CDS/automation/update_cba.py
new file mode 100755
index 00000000..8d23b3c7
--- /dev/null
+++ b/heat/vFW_CNF_CDS/automation/update_cba.py
@@ -0,0 +1,54 @@
+# ============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 logging
+import os
+import zipfile
+from io import BytesIO
+
+from onapsdk.cds import Blueprint
+
+from config import Config
+
+logger = logging.getLogger("")
+logger.setLevel(logging.DEBUG)
+fh = logging.StreamHandler()
+fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s')
+fh.setFormatter(fh_formatter)
+logger.addHandler(fh)
+
+
+def update_cba(file):
+ mypath = os.path.dirname(os.path.realpath(__file__))
+ file_path = os.path.join(mypath, file)
+ try:
+ with zipfile.ZipFile(file_path, 'r') as package:
+ cba_io = BytesIO(package.read("CBA.zip"))
+
+ blueprint = Blueprint(cba_io)
+ blueprint.publish()
+ except FileNotFoundError:
+ logger.error("Error - File Not Found")
+ exit(1)
+
+
+def main():
+ update_cba(Config.VSPFILE)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/heat/vFW_CNF_CDS/automation/update_connectivity_info.py b/heat/vFW_CNF_CDS/automation/update_connectivity_info.py
index 2a341f21..fb166386 100755
--- a/heat/vFW_CNF_CDS/automation/update_connectivity_info.py
+++ b/heat/vFW_CNF_CDS/automation/update_connectivity_info.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (C) 2020 Orange
+# 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.
diff --git a/heat/vFW_CNF_CDS/automation/vsp/.keep b/heat/vFW_CNF_CDS/automation/vsp/.gitkeep
index e69de29b..e69de29b 100644
--- a/heat/vFW_CNF_CDS/automation/vsp/.keep
+++ b/heat/vFW_CNF_CDS/automation/vsp/.gitkeep