diff options
author | 2019-08-29 17:01:43 +0530 | |
---|---|---|
committer | 2019-08-29 17:01:43 +0530 | |
commit | 1ac068050203bbe8214b13a267b772a9220a004f (patch) | |
tree | 70e4f16422b1382640358fbe06c0923bf003bc9c /products/onap-dublin/features/integration/src/main | |
parent | 6a4c4e4e9d1db448081deed1466c21262378d98d (diff) |
VNF Tosca Provision
Change-Id: Ib9ab449f00270be85c0a3f608945b2ce0be1c780
Issue-ID: CLI-166
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'products/onap-dublin/features/integration/src/main')
8 files changed, 1063 insertions, 689 deletions
diff --git a/products/onap-dublin/features/integration/src/main/resources/conf/onap-dublin-profile.json b/products/onap-dublin/features/integration/src/main/resources/conf/onap-dublin-profile.json new file mode 100644 index 00000000..24561762 --- /dev/null +++ b/products/onap-dublin/features/integration/src/main/resources/conf/onap-dublin-profile.json @@ -0,0 +1,69 @@ +[ { + "product" : "onap-dublin", + "name" : "sdc.catalog:host-username", + "value" : "cs0008" +}, { + "product" : "onap-dublin", + "name" : "sdc.catalog:service-model-test-accept:host-username", + "value" : "jm0007" +}, { + "product" : "onap-dublin", + "name" : "aai:host-url", + "value" : "https://159.138.8.8:30233" +}, { + "product" : "onap-dublin", + "name" : "sdc.catalog:host-url", + "value" : "http://159.138.8.8:30205" +}, { + "product" : "onap-dublin", + "name" : "sdc.catalog:service-model-add-artifact:host-username", + "value" : "ocomp" +}, { + "product" : "onap-dublin", + "name" : "sdc.catalog:vf-model-add-artifact:host-username", + "value" : "ocomp" +}, { + "product" : "onap-dublin", + "name" : "multicloud:host-url", + "value" : "https://159.138.8.8:30233" +}, { + "product" : "onap-dublin", + "name" : "sdc.onboarding:host-password", + "value" : "demo123456!" +}, { + "product" : "onap-dublin", + "name" : "sdc.onboarding:host-url", + "value" : "http://159.138.8.8:30280" +}, { + "product" : "onap-dublin", + "name" : "sdc.catalog:service-model-test-start:host-username", + "value" : "jm0007" +}, { + "product" : "onap-dublin", + "name" : "sdc.onboarding:host-username", + "value" : "cs0008" +}, { + "product" : "onap-dublin", + "name" : "aai:host-password", + "value" : "AAI" +}, { + "product" : "onap-dublin", + "name" : "sdc.catalog:service-model-approve:host-username", + "value" : "gv0001" +}, { + "product" : "onap-dublin", + "name" : "aai:host-username", + "value" : "AAI" +}, { + "product" : "onap-dublin", + "name" : "vfc:host-url", + "value" : "https://159.138.8.8:30233" +}, { + "product" : "onap-dublin", + "name" : "sdc.catalog:host-password", + "value" : "demo123456!" +}, { + "product" : "onap-dublin", + "name" : "sdc.catalog:service-model-distribute:host-username", + "value" : "op0001" +} ]
\ No newline at end of file diff --git a/products/onap-dublin/features/integration/src/main/resources/conf/ovp-tosca-vnf-provision.json b/products/onap-dublin/features/integration/src/main/resources/conf/ovp-tosca-vnf-provision.json deleted file mode 100644 index f3a5354e..00000000 --- a/products/onap-dublin/features/integration/src/main/resources/conf/ovp-tosca-vnf-provision.json +++ /dev/null @@ -1,141 +0,0 @@ -{ - "open_cli_product" : "onap-dublin", - "open_cli_home" : "/opt/vtp", - "aai_url" : "https://10.12.5.224:30233", - "aai_username" : "AAI", - "aai_password" : "AAI", - - "sdc_onboarding_url" : "http://10.43.89.129:8081", - "sdc_catalog_url" : "http://10.12.5.224:30205", - "sdc_password" : "demo123456!", - "sdc_creator" : "cs0008", - "sdc_tester" : "jm0007", - "sdc_governor" : "gv0001", - "sdc_operator" : "op0001", - "sdc_consumer" : "ocomp", - - "multicloud_url" : "http://10.12.5.224:30280", - - "//" : "#Parameters required to create cloud complex", - "complex_name" : "OVP-LCM", - "street1" : "street1", - "street2" : "street2", - "physical_location" : "phy_type", - "data_center_code" : "ocomp", - "latitude" : "32.89948", - "longitude" : "97.045443", - "lata" : "example-lata-val-28399", - "elevation" : "example-elevation-val-28399", - "region" : "northwest", - "state" : "oregon", - "city" : "hillsboro", - "postal-code" : "00000", - "country" : "USA", - "identity_url" : "http://10.12.11.1:5000/v3", - "service-model-name" : "usn", - "//" : "#Dictionary containing cloud regions and their Parameters", - - "cloud_region_data":{ - "ONAP-POD-01-Rail-05":{ - "cloud-region-version" : "titanium_cloud", - "esr-system-info-id":"5c85ce1f-aa78-4ebf-8d6f-4b62784e9bc7", - "service-url": "http://10.12.11.1:5000/v3", - "user-name":"${cloud-username}", - "password":"${cloud-password}", - "system-type": "VIM", - "ssl-insecure":true, - "cloud-domain":"Default", - "default-tenant":"Integration-HPA", - "tenant-id" : "709ba629fe194f8699b12f9d6ffd86a0", - "cloud-type" : "openstack", - "identity-url": "WillBeUpdatedByMultiCloud", - "system-status":"active" - } - }, - - "//" : "#Parameters to register cloud region", - "cloud-owner" : "CloudOwner", - "owner-defined-type" : "t1", - "cloud-zone" : "CloudZone", - - "service_name" : "USN", - "customer_name" : "ocomp", - "subscriber_name" : "ocomp", - - "//" : "Onboarding parameters", - "vendor-name" : "Huawei", - "entitlement-pool-name" : "ovp-pool", - "entitlement-description" : "ovp-pool", - "start-date" : "08/01/2019", - "expiry-date" : "12/31/2019", - "key-group-name" : "ovp-key", - "key-group-type" : "Universal", - "feature-grp-name" : "ovp-feature", - "feature-grp-desc" : "ovp-feature", - "part-no" : "ovp-part", - "agreement-name" : "ovp-agreement", - "agreement-desc" : "ovp-agreement", - - "onboarding-method" : "NetworkPackage", - - "//" : "Be sure to include single quotes in parameters that have spaces", - "project-code" : "000000", - "service-model-name" : "usn", - "service-model-desc" : "'usn service'", - "icon-id" : "network_l_1-3", - "category-display" : "'Network L1-3'", - "category" : "'network l1-3'", - - "service-test-remarks" : "ovp test", - "service-accept-remarks" : "accepted", - "service-approve-remarks" : "approved", - - "//" : "#Parameters to vfc", - "vfc-url": "http://10.12.5.224:30280", - "vnfs":{ - "usn":{ - "path": "/opt/vtp/data/usn.csar", - "csar-id": "You need change it", - "vsp-name" : "ovp-usn", - "vsp-desc" : "ovp usn", - "vsp-version" : "1.0", - "vf-name" : "ovp-vf", - "vf-description" : "ovp vf", - "vf-remarks" :"ovp test", - "vf-version" : "1.0", - "key": "key2", - "value": "value2" - } - }, - "ns":{ - "csar-id": "You need change it", - "key": "key1", - "value": "value1", - "path": "/opt/vtp/data/usn_service.csar", - "name": "ovp-usn" - }, - "location": "CloudOwner_ONAP-POD-01-Rail-05", - "vnfm_params":{ - "GVNFMDRIVER":{ - "type": "gvnfmdriver", - "vendor": "vfc", - "version": "v1.0", - "url": "http://msb-iag:80/", - "vim-id": "CloudOwner_ONAP-POD-01-Rail-05", - "user-name": "admin", - "user-password": "admin", - "vnfm-version": "v1.0" - }, - "HWVNFMDRIVER":{ - "type": "hwvnfmdriver", - "vendor": "vfc", - "version": "v1.0", - "url": "http://msb-iag:80/", - "vim-id": "CloudOwner_ONAP-POD-01-Rail-05", - "user-name": "admin", - "user-password": "admin", - "vnfm-version": "v1.0" - } - }, - "sdc-controller-id": "2" -} diff --git a/products/onap-dublin/features/integration/src/main/resources/conf/vnf-tosca-provision.json b/products/onap-dublin/features/integration/src/main/resources/conf/vnf-tosca-provision.json new file mode 100644 index 00000000..45aa7d1f --- /dev/null +++ b/products/onap-dublin/features/integration/src/main/resources/conf/vnf-tosca-provision.json @@ -0,0 +1,74 @@ +{ + "ONAP": { + "vlm_id" : null, + "vlm_version": null, + "entitlement_id": null, + "key_group_id": null, + "feature_group_id": null, + "agreement_id": null, + + "vsp_version": null, + "vsp_version_id": null, + "vsp_id": null, + + "vf_id": null, + "vf_uuid": null, + "vf_version": null, + "vf_inputs": null, + + "ns_id": null, + "ns_uuid": null, + "ns_version": null, + "ns_vf_resource_id": null, + + "customer_id": null, + "customer_version": null, + "service_type_id": null, + "service_type_version": null, + "subscription_version": null, + "location_id": null, + "location_version": null, + "cloud_version": null, + "cloud_id": null, + "esr_vnfm_id": null, + "esr_vnfm_version": null, + "tenant_id": null, + "tenant_version": null, + + "ns_instance_id": null + }, + "subscription": { + "customer-name": "ovp", + "service-type": "tosca_vnf_validation" + }, + "vnf": { + "vendor-name" : "vnf-vendor-kanag", + "name": "vgwvnfovpdemo", + "vsp-csar": "C:\\Users\\k00365106\\Desktop\\vtp\\tosca-lcm\\csar\\vgw.csar", + "vnf-csar": "C:\\Users\\k00365106\\Desktop\\vtp\\tosca-lcm\\csar\\vnf_vgw.csar", + "ns-csar": "C:\\Users\\k00365106\\Desktop\\vtp\\tosca-lcm\\csar\\ns.csar", + "vnfm-driver": "hwvnfmdriver" + }, + "cloud": { + "identity-url": "http://10.12.11.1:5000/v3", + "username": "admin", + "password": "password", + "region": "RegionOVP", + "version": "ocata", + "tenant": "ocomp" + }, + "vnfm":{ + "hwvnfmdriver":{ + "version": "v1.0", + "url": "http://159.138.8.8:30280", + "username": "admin", + "password": "password" + }, + "gvnfmdriver":{ + "version": "v1.0", + "url": "http://159.138.8.8:30280", + "username": "admin", + "password": "password" + } + } +} diff --git a/products/onap-dublin/features/integration/src/main/resources/open-cli-sample/vnf-tosca-provision-dublin-schema-sample.yaml b/products/onap-dublin/features/integration/src/main/resources/open-cli-sample/vnf-tosca-provision-dublin-schema-sample.yaml new file mode 100644 index 00000000..46c98327 --- /dev/null +++ b/products/onap-dublin/features/integration/src/main/resources/open-cli-sample/vnf-tosca-provision-dublin-schema-sample.yaml @@ -0,0 +1,43 @@ +open_cli_sample_version: 1.0 +name: vnf-tosca-provision +version: onap-dublin +samples: + sample1: + name: vnf-tosca-provision + input: --mode checkup --vsp c:\Users\k00365106\Desktop\vtp\tosca-lcm\vgw.csar --vnf-csar c:\Users\k00365106\Desktop\vtp\tosca-lcm\vgw.csar --ns-csar c:\Users\k00365106\Desktop\vtp\tosca-lcm\vgw.csar --vnfm-driver hwvnfmdriver --timeout 800000 --vnf-name vgw12345678901 --vnf-vendor-name vnfvendor12345678901 --onap-objects D:\workspace\cli\deployment\zip\target\deployunzip\data\tmp\1234567890-1567065851687_result.json + moco: vnf-tosca-provision-dublin-schema-moco.json + output: | + +------------------+----------------------------------------------------+ + |property |value | + +------------------+----------------------------------------------------+ + |vnf-id | | + +------------------+----------------------------------------------------+ + |vnf-status | | + +------------------+----------------------------------------------------+ + |ns-id |null | + +------------------+----------------------------------------------------+ + |ns-status | | + +------------------+----------------------------------------------------+ + |vnfm-driver |hwvnfmdriver | + +------------------+----------------------------------------------------+ + |onap-objects |{"vf_inputs": null, "vlm_id": null, | + | |"esr_vnfm_version": null, "vlm_version": null, | + | |"vf_id": null, "ns_instance_id": null, | + | |"location_id": null, "service_type_version": | + | |null, "vsp_version": null, "vsp_id": null, | + | |"cloud_id": null, "key_group_id": null, | + | |"ns_version": null, "vf_uuid": null, | + | |"esr_vnfm_id": null, "tenant_version": null, | + | |"vsp_version_id": null, "customer_id": null, | + | |"entitlement_id": null, "service_type_id": null, | + | |"cloud_version": null, "agreement_id": null, | + | |"customer_version": null, "ns_vf_resource_id": | + | |null, "tenant_id": null, "ns_uuid": null, | + | |"vf_version": null, "location_version": null, | + | |"subscription_version": null, "feature_group_id": | + | |null, "ns_id": null}
| + +------------------+----------------------------------------------------+ + |vnf-vendor-name |vnfvendor12345678901 | + +------------------+----------------------------------------------------+ + |vnf-name |vgw12345678901 | + +------------------+----------------------------------------------------+ diff --git a/products/onap-dublin/features/integration/src/main/resources/open-cli-schema/ovp-tosca-vnf-provision.yaml b/products/onap-dublin/features/integration/src/main/resources/open-cli-schema/ovp-tosca-vnf-provision.yaml deleted file mode 100644 index 20c71ec6..00000000 --- a/products/onap-dublin/features/integration/src/main/resources/open-cli-schema/ovp-tosca-vnf-provision.yaml +++ /dev/null @@ -1,96 +0,0 @@ -# Copyright 2019 Huawei Technologies Co., Ltd. -# -# 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. - -open_cli_schema_version: 1.0 -name: tosca-vnf-provision -description: | - Provision TOSCA based VNF using ONAP. - More details: https://wiki.lfnetworking.org/display/LN/TOSCA+VNF+Validation+Planning - NOTE: Before using this command, configure the $OPEN_CLI_HOME/conf/ovp-tosca-vnf-provision.json - -info: - product: onap-dublin - service: vnf-validation - author: ONAP VTP Team onap-discuss@lists.onap.org - -parameters: - - name: config-json - description: Configuration file path - type: string - short_option: x - long_option: config-json - default_value: $s{env:OPEN_CLI_HOME}/conf/ovp-tosca-vnf-provision.json - is_optional: false - - name: vsp - description: Path to the ONAP vendor service product (VSP) for the VNF to provision - type: binary - short_option: y - long_option: vsp - is_optional: false - - name: vnf-csar - description: Path to the TOSCA CSAR for the VNF to provision - type: binary - short_option: r - long_option: vnf-csar - is_optional: false - - name: ns-csar - description: Path to the TOSCA CSAR for the NS service to provision - type: binary - short_option: b - long_option: ns-csar - is_optional: true - default: false - - name: vnfm-driver - description: VNFM driver to use - type: string - short_option: c - long_option: vnfm-driver - is_optional: false - -results: - direction: portrait - attributes: - - name: vnf-id - description: ONAP VNF instance id - scope: short - type: string - - name: vnf-status - description: Onap VNF status - scope: short - type: string - - name: ns-id - description: Onap NS service instance id - scope: short - type: string - - name: ns-status - description: Onap NS status - scope: short - type: string - - name: vnfm-driver - description: VNFM driver used - type: string - scope: short -cmd: - command: - - python $s{env:OPEN_CLI_HOME}/script/ovp-tosca-vnf-provision.py --result-json $s{tmp:result.json} --config-json ${config-json} --vsp ${vsp} --vnf-csar ${vnf-csar} --ns-csar ${ns-csar} --vnfm-driver ${vnfm-driver} - success_codes: - - 0 - working_directory: . - output: $s{tmp:result.json} - result_map: - vnf-id: $o{$.vnf_id} - vnf-status: $o{$.vnf_status} - ns-id: $o{$.ns_id} - ns-status: $o{$.ns_status} - vnfm-driver: ${vnfm-driver}
\ No newline at end of file diff --git a/products/onap-dublin/features/integration/src/main/resources/open-cli-schema/vnf-tosca-provision-dublin-schema.yaml b/products/onap-dublin/features/integration/src/main/resources/open-cli-schema/vnf-tosca-provision-dublin-schema.yaml new file mode 100644 index 00000000..908d33dc --- /dev/null +++ b/products/onap-dublin/features/integration/src/main/resources/open-cli-schema/vnf-tosca-provision-dublin-schema.yaml @@ -0,0 +1,145 @@ +# Copyright 2019 Huawei Technologies Co., Ltd. +# +# 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. + +open_cli_schema_version: 1.0 +name: vnf-tosca-provision +description: | + ONAP TOSCA VNF validation using ONAP CLI and Open Command Platform (OCOMP) + NOTE: Before using this command, configure the $OPEN_CLI_HOME/conf/vnf-tosca-provision.json + + This command runs in 4 mode: + 1. setup: Create requires Vendor, Service Subscription and VNF cloud in ONAP + 2. standup: From the given VSP csar, VNF csar and NS csar, it creates VF Model, NS Model and NS service + 3. cleanup: Remove those entries provided in onap-objects parameter + 4. validate: Run setup -> standup -> cleanup + + On every execution, it reports the ONAP managed object's ids in result onap-objects attribute. so + if requires, these attribute value could be passed in input parameter onap-objects on subsequent + executions to avoid recreation of these ONA managed objects + +info: + product: onap-dublin + service: vnf-validation + author: ONAP VTP Team onap-discuss@lists.onap.org + +parameters: + - name: config-json + description: Configuration file path + type: string + short_option: x + long_option: config-json + default_value: $s{env:OPEN_CLI_HOME}/conf/vnf-tosca-provision.json + is_optional: false + - name: vsp + description: Path to the ONAP vendor service product (VSP) for the VNF to provision + type: binary + short_option: y + long_option: vsp + is_optional: false + - name: vnf-csar + description: Path to the TOSCA CSAR for the VNF to provision + type: binary + short_option: r + long_option: vnf-csar + is_optional: false + - name: ns-csar + description: Path to the TOSCA CSAR for the NS service to provision + type: binary + short_option: b + long_option: ns-csar + is_optional: true + default: false + - name: vnfm-driver + description: VNFM driver to use. One of gvnfmdriver or hwvnfmdriver + type: string + short_option: c + long_option: vnfm-driver + is_optional: false + - name: onap-objects + description: Existing ONAP object ids to use instead of creating them while running this task + type: json + short_option: Z + long_option: onap-objects + is_optional: true + default_value: {} + - name: mode + description: setup or standup or cleanup + type: string + short_option: Y + long_option: mode + is_optional: true + default_value: validate + - name: vnf-name + description: VNF Name + type: string + short_option: A + long_option: vnf-name + is_optional: false + - name: vnf-vendor-name + description: VNF Vendor Name + type: string + short_option: B + long_option: vnf-vendor-name + is_optional: false +results: + direction: portrait + attributes: + - name: vnf-id + description: ONAP VNF instance id + scope: short + type: string + - name: vnf-status + description: Onap VNF status + scope: short + type: string + - name: ns-id + description: Onap NS service instance id + scope: short + type: string + - name: ns-status + description: Onap NS status + scope: short + type: string + - name: vnfm-driver + description: VNFM driver used + type: string + scope: short + - name: onap-objects + description: ONAP object used + type: json + scope: short + - name: vnf-vendor-name + description: VNF Vendor Name + type: string + scope: short + - name: vnf-name + description: VNF Name + type: string + scope: short +cmd: + command: + - python $s{env:OPEN_CLI_HOME}/script/vnf-tosca-provision.py --vendor-name ${vnf-vendor-name} --vnf-name ${vnf-name} --mode ${mode} --result-json $s{tmp:result.json:onap-objects} --conf ${config-json} --vsp ${vsp} --vnf-csar ${vnf-csar} --ns-csar ${ns-csar} --vnfm-driver ${vnfm-driver} + success_codes: + - 0 + working_directory: . + output: $s{tmp:result.json} + result_map: + vnf-id: $o{$.vnf_id} + vnf-status: $o{$.vnf_status} + ns-id: $o{$.ns_instance_id} + ns-status: $o{$.ns_instance_status} + vnfm-driver: ${vnfm-driver} + vnf-name: ${vnf-name} + vnf-vendor-name: ${vnf-vendor-name} + onap-objects: $o{$} diff --git a/products/onap-dublin/features/integration/src/main/resources/script/ovp-tosca-vnf-provision.py b/products/onap-dublin/features/integration/src/main/resources/script/ovp-tosca-vnf-provision.py deleted file mode 100644 index 2141e168..00000000 --- a/products/onap-dublin/features/integration/src/main/resources/script/ovp-tosca-vnf-provision.py +++ /dev/null @@ -1,452 +0,0 @@ -#!/usr/bin/python - -import json -import os -import time -import argparse -import sys -import requests - -def get_parameters(file): - parameters = json.load(file) - return parameters - -def get_out_helper(in_string): - out_list = (((in_string.replace('-','')).replace('|', '')).replace('+', '')).split() - return out_list - -def get_out_helper_2(in_string): - out_list = ((in_string.replace('|', '')).replace('+', '')).split() - return out_list - -def set_open_cli_env(parameters): - os.environ["OPEN_CLI_PRODUCT_IN_USE"] = parameters["open_cli_product"] - os.environ["OPEN_CLI_HOME"] = parameters["open_cli_home"] - -def create_complex(parameters): - complex_create_string = "oclip --request-id {} complex-create --debug -j {} -r {} -x {} -y {} -lt {} -l {} -i {} -lo {} \ - -S {} -la {} -g {} -w {} -z {} -k {} -o {} -q {} -m {} -u {} -p {}".format(request_id, parameters["street2"], \ - parameters["physical_location"], parameters["complex_name"], \ - parameters["data_center_code"], parameters["latitude"], parameters["region"], \ - parameters["street1"], parameters["longitude"], parameters["state"], \ - parameters["lata"], parameters["city"], parameters["postal-code"], \ - parameters["complex_name"], parameters["country"], parameters["elevation"], \ - parameters["identity_url"], parameters["aai_url"], parameters["aai_username"], \ - parameters["aai_password"]) - - os.system(complex_create_string) - -def create_vlm(parameters): - vlm_create_string = "oclip --request-id {} vlm-create --debug -x {} -u {} -p {} -m {}".format(request_id, parameters["vendor-name"], \ - parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"]) - command_out = (os.popen(vlm_create_string)).read() - out_list = get_out_helper(command_out) - vlm_id = out_list[3] - vlm_version = out_list[5] - - entitlement_string = "oclip --request-id {} vlm-entitlement-pool-create --debug -x {} -y {} -e {} -z {} -k {} -g {} -l {} -u {} -p {} -m {}".format(request_id, \ - parameters["entitlement-pool-name"], vlm_id, vlm_version, parameters["entitlement-description"], parameters["vendor-name"], \ - parameters["expiry-date"], parameters["start-date"], parameters["sdc_creator"], parameters["sdc_password"], \ - parameters["sdc_onboarding_url"]) - command_out = (os.popen(entitlement_string)).read() - entitlement_id = (get_out_helper(command_out))[3] - - - key_group_string = "oclip --request-id {} vlm-key-group-create --debug -c {} -e {} -x {} -y {} -u {} -p {} -m {}".format(request_id, vlm_id, vlm_version, \ - parameters["key-group-name"], parameters["key-group-type"], parameters["sdc_creator"], parameters["sdc_password"], \ - parameters["sdc_onboarding_url"]) - command_out = (os.popen(key_group_string)).read() - key_group_id = (get_out_helper(command_out))[3] - - feature_group_string = "oclip --request-id {} vlm-feature-group-create --debug -x {} -y {} -e {} -z {} -g {} -b {} -c {} -u {} -p {} -m {}".format(request_id, - parameters["feature-grp-name"], vlm_id, vlm_version, parameters["feature-grp-desc"], key_group_id, entitlement_id, \ - parameters["part-no"], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"]) - command_out = (os.popen(feature_group_string)).read() - feature_group_id = (get_out_helper(command_out))[3] - - agreement_string = "oclip --request-id {} vlm-aggreement-create --debug -x {} -y {} -e {} -z {} -g {} -u {} -p {} -m {}".format(request_id, parameters["agreement-name"], \ - vlm_id, vlm_version, parameters["agreement-desc"], feature_group_id, parameters["sdc_creator"], parameters["sdc_password"], \ - parameters["sdc_onboarding_url"]) - command_out = (os.popen(agreement_string)).read() - agreement_id = (get_out_helper(command_out))[3] - - submit_string = "oclip --request-id {} vlm-submit --debug -x {} -y {} -u {} -p {} -m {}".format(request_id, vlm_id, vlm_version, parameters["sdc_creator"], \ - parameters["sdc_password"], parameters["sdc_onboarding_url"]) - os.system(submit_string) - - output = [feature_group_id, agreement_id, vlm_version, vlm_id ] - return output - -def create_vsp(parameters, in_list): - vnfs = parameters["vnf"] - vsp_dict = {} - for name, value in vnfs.iteritems(): - create_string = "oclip --request-id {} vsp-create --debug -j {} -o {} -e {} -x {} -y {} -i {} -c {} -g {} -u {} -p {} -m {}".format(request_id, in_list[0], \ - parameters["onboarding-method"], parameters["vendor-name" ], value.get("vsp-name"), value.get("vsp-desc"), in_list[1], \ - in_list[2], in_list[3], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"] ) - command_out = (os.popen(create_string)).read() - out_list = get_out_helper(command_out) - vsp_id = out_list[3] - vsp_version = out_list[5] - - os.system("oclip --request-id {} vsp-add-artifact --debug -x {} -y {} -z {} -u {} -p {} -m {}".format(request_id, vsp_id, vsp_version, value.get("path"), \ - parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"])) - - os.system("oclip --request-id {} vsp-validate --debug -x {} -y {} -u {} -p {} -m {}".format(request_id, vsp_id, vsp_version, parameters["sdc_creator"], \ - parameters["sdc_password"], parameters["sdc_onboarding_url"])) - - os.system("oclip --request-id {} vsp-submit --debug -x {} -y {} -u {} -p {} -m {}".format(request_id, vsp_id, vsp_version, parameters["sdc_creator"], \ - parameters["sdc_password"], parameters["sdc_onboarding_url"])) - - os.system("oclip --request-id {} vsp-package --debug -x {} -y {} -u {} -p {} -m {}".format(request_id, vsp_id, vsp_version, parameters["sdc_creator"], \ - parameters["sdc_password"], parameters["sdc_onboarding_url"])) - - vsp_ids[name] = vsp_id - return vsp_ids - -def create_vf_model(parameters, vsp_dict): - vnfs = parameters["vnfs"] - vf_dict = {} - for name, value in vnfs.iteritems(): - create_string = "oclip --request-id {} vf-model-create --debug -y {} -g {} -x {} -z {} -b {} -u {} -p {} -m {}".format(request_id, value.get("vf-description"), \ - value.get("vsp-version"), value.get("vf-name"), parameters["vendor-name"], vsp_dict[name], \ - parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]) - os.system(create_string) - - output = (os.popen("oclip --request-id {} vf-model-list --debug -m {} -u {} -p {} | grep {}".format(request_id, parameters["sdc_catalog_url"], \ - parameters["sdc_creator"], parameters["sdc_password"], value.get("vf-name")))).read() - output = (get_out_helper_2(output)) - - vf_unique_id = output[1] - - # checkout - output = (os.popen("oclip --request-id {} vf-model-checkout --debug --host-url {} --host-username {} --host-password {} --vf-model-uuid {} --format json".format(request_id, - parameters["sdc_catalog_url"], parameters["sdc_creator"], parameters["sdc_password"], vf_unique_id))).read() - vf_unique_id = (json.loads(output))['ID'] - - # add consumer, if already exist , just ignore, below command would fail simply !! - os.system("oclip --request-id {} sdc-consumer-create --debug --consumer-name {}".format(request_id, parameters["sdc_consumer"])) - - def get_vnf_name(vnf_csar_path): - return vnf_csar_path.replace("_"," ").replace(".", " ").replace("-"," ") - - # add artifact - os.system("oclip --request-id {} vf-model-add-artifact --debug --host-url {} --host-username {} --host-password {} --vf-model-uuid {} --artifact {} --artifact-name {}".format( - request_id, parameters["sdc_catalog_url"], parameters["sdc_consumer"], parameters["sdc_password"], vf_unique_id, vnf_csar, get_vnf_name(vnf_csar))) - - # check-in - os.system("oclip --request-id {} vf-model-checkin --debug --host-url {} --host-username {} --host-password {} --vf-model-uuid {}".format( - request_id, parameters["sdc_catalog_url"], parameters["sdc_creator"], parameters["sdc_password"], vf_unique_id)) - - os.system("oclip --request-id {} vf-model-certify --debug -b {} -r {} -u {} -p {} -m {}".format(vf_unique_id, value.get("vf-remarks"), \ - request_id, parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"])) - - #Check for new parameters after certification - output = (os.popen("oclip --request-id {} vf-model-list --debug -m {} -u {} -p {} | grep {}".format(request_id, parameters["sdc_catalog_url"], \ - parameters["sdc_creator"], parameters["sdc_password"], value.get("vf-name")))).read() - output = (get_out_helper_2(output)) - - vf_dict[name] = output[1] - - return vf_dict - - -def create_service_model(parameters, vf_dict): - vnfs = parameters["vnfs"] - - create_string = "oclip --request-id {} service-model-create --debug -z {} -y {} -e {} -x {} -c {} -b {} -u {} -p {} -m {} |grep ID".format(request_id, parameters["project-code"], \ - parameters["service-model-desc"], parameters["icon-id"], parameters["service-model-name"], parameters["category-display"], \ - parameters["category"],parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]) - - service_model_id = (get_out_helper_2((os.popen(create_string)).read()))[1] - - # checkout - output = (os.popen("oclip --request-id {} service-model-checkout --debug --host-url {} --host-username {} --host-password {} --service-model-uuid {} --format json".format(request_id, - parameters["sdc_catalog_url"], parameters["sdc_creator"], parameters["sdc_password"], service_model_id))).read() - service_model_id = (json.loads(output))['ID'] - - # add consumer, if already exist , just ignore, below command would fail simply !! - os.system("oclip --request-id {} sdc-consumer-create - --debug -consumer-name {}".format(request_id, parameters["sdc_consumer"])) - - for name, value in vnfs.iteritems(): - output = (os.popen("oclip --request-id {} service-model-add-vf --debug -x {} -b {} -y {} -z {} -u {} -p {} -m {}".format(request_id, service_model_id, \ - parameters["vf-version"], vf_dict[name], value.get("vf-name"), parameters["sdc_creator"], \ - parameters["sdc_password"], parameters["sdc_catalog_url"] ))).read() - vf_unique_id = (json.loads(output))['ID'] - vf_uuid = (json.loads(output))['UUID'] - - def get_ns_name(ns_csar_path): - return vnf_csar_path.replace("_"," ").replace(".", " ").replace("-"," ") - - # add artifact - os.system("oclip --request-id {} service-model-add-artifact --debug --host-url {} --host-username {} --host-password {} --service-uniqueId {} --artifact {} --artifact-name {}".format( - request_id, parameters["sdc_catalog_url"], parameters["sdc_consumer"], parameters["sdc_password"], vf_unique_id, ns_csar, get_vnf_name(ns_csar))) - - # set properties - os.system("oclip --request-id {} service-model-set-property --debug --host-url {} --host-username {} --host-password {} --service-uniqueId {} --resource-uuid {} --resource-uniqueId {} --property-name nf_type --property-value {}".format( - request_id, parameters["sdc_catalog_url"], parameters["sdc_consumer"], parameters["sdc_password"], service_model_id , vf_unique_id, vf_uuid, vnfm_driver)) - - # check-in - os.system("oclip --request-id {} service-model-checkin --debug --host-url {} --host-username {} --host-password {} --service-model-uuid {}".format( - request_id, parameters["sdc_catalog_url"], parameters["sdc_creator"], parameters["sdc_password"], service_model_id)) - - - os.system("oclip --request-id {} service-model-test-request --debug -b {} -r {} -u {} -p {} -m {}".format(service_model_id, parameters["service-test-remarks"], \ - request_id, parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"])) - - os.system("oclip --request-id {} service-model-test-start --debug -b {} -u {} -p {} -m {}".format(service_model_id, parameters["sdc_tester"], \ - request_id, parameters["sdc_password"], parameters["sdc_catalog_url"])) - - os.system("oclip --request-id {} service-model-test-accept --debug -b {} -r {} -u {} -p {} -m {}".format(service_model_id, parameters["service-accept-remarks"], \ - request_id, parameters["sdc_tester"], parameters["sdc_password"], parameters["sdc_catalog_url"])) - - #Get uniqueId for the service model - service_model_values = (os.popen("oclip --request-id {} service-model-list --debug -u {} -p {} -m {} |grep {}".format(request_id, parameters["sdc_creator"], \ - parameters["sdc_password"], parameters["sdc_catalog_url"], parameters["service-model-name"]))).read() - service_model_values = get_out_helper_2(service_model_values) - service_model_uniqueId = (service_model_values)[1] - - os.system("oclip --request-id {} service-model-approve --debug -b {} -r {} -u {} -p {} -m {}".format(request_id, service_model_uniqueId, parameters["service-approve-remarks"], \ - parameters["sdc_governor"], parameters["sdc_password"], parameters["sdc_catalog_url"])) - - os.system("oclip --request-id {} service-model-distribute --debug -b {} -u {} -p {} -m {}".format(request_id, service_model_uniqueId, parameters["sdc_operator"], \ - parameters["sdc_password"], parameters["sdc_catalog_url"])) - - return service_model_values - -def register_cloud_helper(cloud_region, values, parameters): - #Create Cloud - cloud_create_string = 'oclip --request-id {} cloud-create --debug -e {} -b {} -I {{\\\\\\"openstack-region-id\\\\\\":\\\\\\"{}\\\\\\"}} \ - -x {} -y {} -j {} -w {} -l {} -url {} -n {} -q {} -r {} -Q {} -i {} -g {} -z {} -k {} -c {} -m {} -u {} -p {}'.format(request_id, - values.get("esr-system-info-id"), values.get("user-name"), cloud_region, parameters["cloud-owner"], \ - cloud_region, values.get("password"), values.get("cloud-region-version"), values.get("default-tenant"), \ - values.get("service-url"), parameters["complex_name"], values.get("cloud-type"), parameters["owner-defined-type"], \ - values.get("system-type"), values.get("identity-url"), parameters["cloud-zone"], values.get("ssl-insecure"), \ - values.get("system-status"), values.get("cloud-domain"), parameters["aai_url"], parameters["aai_username"], \ - parameters["aai_password"]) - - - os.system(cloud_create_string) - - #Associate Cloud with complex - complex_associate_string = "oclip --request-id {} complex-associate --debug -x {} -y {} -z {} -m {} -u {} -p {}".format(request_id, parameters["complex_name"], \ - cloud_region, parameters["cloud-owner"], parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) - os.system(complex_associate_string) - - #Register Cloud with Multicloud - multicloud_register_string = "oclip --request-id {} multicloud-register-cloud --debug -y {} -x {} -m {}".format(request_id, parameters["cloud-owner"], \ - cloud_region, parameters["multicloud_url"]) - os.system(multicloud_register_string) - -def register_all_clouds(parameters): - cloud_dictionary = parameters["cloud_region_data"] - for cloud_region, cloud_region_values in cloud_dictionary.iteritems(): - register_cloud_helper(cloud_region, cloud_region_values, parameters) - -def create_service_type(parameters): - create_string = "oclip --request-id {} service-type-create --debug -x {} -m {} -u {} -p {}".format(request_id, parameters["service_name"], \ - parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) - os.system(create_string) - -def create_customer(parameters): - create_string = "oclip --request-id {} customer-create --debug -x {} -y {} -m {} -u {} -p {}".format(request_id, parameters["customer_name"], \ - parameters["subscriber_name"], parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) - os.system(create_string) - -def add_customer_subscription(parameters): - subscription_check = 0 - for cloud_region, cloud_region_values in (parameters["cloud_region_data"]).iteritems(): - if subscription_check == 0 : - subscription_string = "oclip --request-id {} subscription-create --debug -x {} -c {} -z {} -e {} -y {} -r {} -m {} -u {} -p {}".format(request_id, \ - parameters["customer_name"], cloud_region_values.get("tenant-id"), parameters["cloud-owner"], parameters["service_name"],\ - cloud_region_values.get("default-tenant"), cloud_region, parameters["aai_url"], parameters["aai_username"], parameters["aai_password"] ) - else: - subscription_string = "oclip --request-id {} subscription-cloud-add --debug -x {} -c {} -z {} -e {} -y {} -r {} -m {} -u {} -p {}".format(request_id, \ - parameters["customer_name"], cloud_region_values.get("tenant-id"), parameters["cloud-owner"], parameters["service_name"],\ - cloud_region_values.get("default-tenant"), cloud_region, parameters["aai_url"], parameters["aai_username"], parameters["aai_password"] ) - os.system(subscription_string) - subscription_check+=1 - -def register_vnfm_helper(vnfm_key, values, parameters): - #Create vnfm - vnfm_create_string = 'oclip --request-id {} vnfm-create --debug -b {} -c {} -e {} -v {} -g {} -x {} -i {} -j {} -q {} \ - -m {} -u {} -p {}'.format(request_id, vnfm_key, values.get("type"), values.get("vendor"), \ - values.get("version"), values.get("url"), values.get("vim-id"), \ - values.get("user-name"), values.get("user-password"), values.get("vnfm-version"), \ - parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) - - os.system(vnfm_create_string) - -def register_vnfm(parameters): - vnfm_params = parameters["vnfm_params"] - for vnfm_key, vnfm_values in vnfm_params.iteritems(): - register_vnfm_helper(vnfm_key, vnfm_values, parameters) - - -def onboard_vnf(parameters): - vnfs = parameters["vnfs"] - vnf_onboard_outputs = {} - - for key, value in vnfs.items(): - vnf_onboard_string = 'oclip --request-id {} vfc-catalog-onboard-vnf --debug -c {}'.format(request_id, value.get("csar-id")) - vnf_onboard_outs[key] = (os.popen(ns_onboard_string)).read() - return vnf_onboard_outputs - -def onboard_ns(parameters): - ns_onboard_string = 'oclip --request-id {} vfc-catalog-onboard-ns --debug -c {}'.format(request_id, parameters["ns-csar-id"]) - ns_onboard_out = (os.popen(ns_onboard_string)).read() - return ns_onboard_out - -def create_ns(parameters, csar_id): - ns = parameters["ns"] - ns_create_string = 'oclip --request-id {} vfc-nslcm-create --debug -m {} -c {} -n {} -q {} -S {}'.format(request_id, parameters["vfc-url"], \ - csar_id, ns.get("name"), parameters["customer_name"], parameters["service_name"]) - print (ns_create_string) - - ns_create_out = (os.popen(ns_create_string)).read() - - print (ns_create_out) - - ns_instance_id = (get_out_helper_2(ns_create_out))[3] - - return ns_instance_id - -def instantiate_ns(parameters, ns_instance_id): - ns_instantiate_string = 'oclip --request-id {} vfc-nslcm-instantiate --debug -m {} -i {} -c {} -n {}'.format(request_id, parameters["vfc-url"], \ - ns_instance_id, parameters["location"], parameters["sdc-controller-id"]) - print (ns_instantiate_string) - - ns_instantiate_out = (os.popen(ns_instantiate_string)).read() - return ns_instantiate_out - -def create_ns_package(parameters): - ns = parameters["ns"] - create_ns_string = 'oclip --request-id {} vfc-catalog-create-ns --debug -m {} -c {} -e {}'.format(request_id, parameters["vfc-url"], \ - ns.get("key"), ns.get("value")) - cmd_out = (os.popen(create_ns_string)).read() - out_list = get_out_helper_2(cmd_out) - return out_list[4] - -def create_vnf_package(parameters): - vnfs = parameters["vnfs"] - outputs = {} - - for vnf_key, vnf_values in vnfs.iteritems(): - create_vnf_string = 'oclip --request-id {} vfc-catalog-create-vnf --debug -m {} -c {} -e {}'.format(request_id, parameters["vfc-url"], \ - vnf_values.get("key"), vnf_values.get("value")) - cmd_out = (os.popen(create_vnf_string)).read() - out_list = get_out_helper_2(cmd_out) - outputs[vnf_key] = out_list[4] - - return outputs - -def provision_vnf(): - - result_json = {} - result_json['vnf_id'] = '' - result_json['vnf_status'] = '' - result_json['ns_id'] = '' - result_json['ns_status'] = '' - - def _provision(): - # 1.Setup cloud and service - #setup cloud and region - create_complex(parameters) - register_all_clouds(parameters) - - # setup subscription and customer - create_service_type(parameters) - create_customer(parameters) - add_customer_subscription(parameters) - - # setup vnfm - register_vnfm(parameters) - - # Setup License - vlm_output = create_vlm(parameters) - print "vlm parameters={}".format(vlm_output) - - # 2. on-board VSP - vsp_id = create_vsp(parameters, vlm_output) - print "vsp id={}".format(vsp_id) - - # 3. model VF - vf_model_dict = create_vf_model(parameters, vsp_id) - print "vf model parameters={}".format(vf_model_dict) - vf_id = vf_model_dict["vf_id"] - vf_unique_id = vf_model_dict["vf_unique_id"] - - # 4. model NS and 5. Approve and distribute - service_model_list = create_service_model(parameters, vf_unique_id) - print "service model parameters={}".format(service_model_list) - - # 6. onboard VNF - vnf_onboard_output = onboard_vnf(parameters) - print vnf_onboard_output - - # 7. onboard NS - ns_onboard_out = onboard_ns(parameters) - print ns_onboard_out - - #TODO is create vnf and ns pacakge required ?? - # 8. create NS - ns_instance_id = create_ns(parameters, ns_package_output) - print ns_instance_id - - instantiate_ns_output = instantiate_ns(parameters, ns_instance_id) - print instantiate_ns_output - - _provision() - - return result_json - -def persist_result(result_path, result): - f = open(result_json_path, "w") - - result_json = {} - result_json['vnf_id'] = result['vnf_id'] - result_json['vnf_status'] = result['vnf_status'] - result_json['ns_id'] = result['ns_id'] - result_json['ns_status'] = result['ns_status'] - - f.write(json.dumps(result_json)) - - print result_json - - f.close() - -#Main -parser = argparse.ArgumentParser() -parser.add_argument('--config-json', action='store', dest='config_file_path', help='Config file path') -parser.add_argument('--vsp', action='store', dest='vsp', help='ONAP VSP') -parser.add_argument('--vnf-csar', action='store', dest='vnf_csar', help='VNF CSAR') -parser.add_argument('--ns-csar', action='store', dest='ns_csar', help='NS CSAR') -parser.add_argument('--vnfm-driver', action='store', dest='vnfm_driver', help='gVNFM or hwVNFM') -parser.add_argument('--result-json', action='store', dest='result_json_path', help='Output result json') -parser.add_argument('--request-id', action='store', dest='request_id', help='Request Id to track') - -#Retrive the params -args = parser.parse_args() -print args - -config_file = open(args.config_file_path) -vsp = args.vsp -vnf_csar = args.vnf_csar -ns_csar = args.ns_csar -vnfm_driver = args.vnfm_driver -result_json_path = args.result_json_path - -if args.request_id is None: - request_id = os.environ["OPEN_CLI_REQUEST_ID"] -else: - request_id = args.request_id - -# setup CLI -parameters = get_parameters(config_file) -set_open_cli_env(parameters) - -output = provision_vnf() - -persist_result(result_json_path, output) - -print "Provision is completed !"
\ No newline at end of file diff --git a/products/onap-dublin/features/integration/src/main/resources/script/vnf-tosca-provision.py b/products/onap-dublin/features/integration/src/main/resources/script/vnf-tosca-provision.py new file mode 100644 index 00000000..6dc7310e --- /dev/null +++ b/products/onap-dublin/features/integration/src/main/resources/script/vnf-tosca-provision.py @@ -0,0 +1,732 @@ +#!/usr/bin/python +# Copyright 2019 Huawei Technologies Co., Ltd. +# +# 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. + +import json +import os +import argparse +import sys +import uuid +import subprocess +import platform +import datetime +from argparse import RawTextHelpFormatter + +if platform.system() == 'Windows': + CMD_NAME = 'oclip.cmd' +else: + CMD_NAME = 'oclip.sh' + +class OcompException(Exception): + def __init__(self, code, message): + super(OcompException, self).__init__() + self.code = code; + self.message = message; + +class OCOMP: + def __init__(self, + request_id = os.environ.get('OPEN_CLI_REQUEST_ID'), + debug = False, + format = 'json', + product = os.environ.get('OPEN_CLI_PRODUCT_IN_USE'), + profile = os.environ.get('OPEN_CLI_PROFILE')): + if not request_id: + request_id = str(uuid.uuid4()) + self.request_id = request_id + self.debug = debug + self.format = format + self.product = product + self.profile = profile + + def __str__(self): + return str(vars(self)) + + def __repr__(self): + return str(self) + + @staticmethod + def version(): + return os.popen('{} --version'.format(CMD_NAME)).read() + + def run(self, command, params={}, product=None, profile=None, request_id=None): + CMD = [CMD_NAME] + + if not request_id: + request_id = self.request_id + + if request_id: + CMD.append('--request-id') + CMD.append(request_id) + + if not product: + product = self.product + + if product: + CMD.append('--product') + CMD.append(product) + + if not profile: + profile = self.profile + + if profile: + CMD.append('--profile') + CMD.append(profile) + + CMD.append(command) + + if self.debug: + CMD.append('--debug') + + CMD.append('--format') + CMD.append(self.format) + + for name, value in params.items(): + CMD.append('--{}'.format(name)) + CMD.append(value) + + cmd_string = ' '.join(CMD) + print (cmd_string) + + try: + res = subprocess.Popen(CMD, stdout=subprocess.PIPE) + res.wait() + result = res.stdout.read().strip() + print (res.returncode, result) + + if res.returncode != 0:# and res.returncode != 1: + raise OcompException(9999, result) + if result: + return json.loads(result) + else: + return {} + except OSError as e: + sys.stderr.write(str(e)) + msg = 'failed to executed the command {}'.format(cmd_string) + print (msg) + raise OcompException(9999, msg) + +class ONAP: + def __init__(self, + product, + profile, + conf, + request_id, + debug = False): + self.conf = conf + self.ocomp = OCOMP(request_id, debug, product=product, profile=profile) + self.preload() + self.tag = 'Created by Open Command Platform - OCOMP' + + def preload(self): + if self.conf['ONAP']: + for attr in self.conf['ONAP']: + setattr(self, attr, self.conf['ONAP'][attr]) + + def create_vlm(self): + submit = False + + if not self.vlm_id and not self.vlm_version: + output = self.ocomp.run(command='vlm-create', + params={'vendor-name': self.conf['vnf']['vendor-name'], + 'description': self.tag}) + + self.vlm_id = output['id'] + self.vlm_version = output['version'] + submit = True + + if not self.entitlement_id: + output = self.ocomp.run(command='vlm-entitlement-pool-create', + params={'name': '{} Entitlement Pool'.format(self.conf['vnf']['vendor-name']), + 'vlm-id': self.vlm_id, + 'vlm-version': self.vlm_version, + 'manufacture-reference-number': 'OCOMP', + 'start-date': datetime.datetime.strftime(datetime.datetime.today(),'%m/%d/%Y'), + 'expiry-date': datetime.datetime.strftime(datetime.datetime.today() + datetime.timedelta(1),'%m/%d/%Y')}) + self.entitlement_id = output['id'] + submit = True + + if not self.key_group_id: + output = self.ocomp.run(command='vlm-key-group-create', + params={'name': '{} Key goroup'.format(self.conf['vnf']['vendor-name']), + 'vlm-id': self.vlm_id, + 'vlm-version': self.vlm_version, + 'type': 'Universal'}) + + self.key_group_id = output['id'] + submit = True + + if not self.feature_group_id: + output = self.ocomp.run(command='vlm-feature-group-create', + params={'name': '{} Feature group'.format(self.conf['vnf']['vendor-name']), + 'vlm-id': self.vlm_id, + 'vlm-version': self.vlm_version, + 'vlm-key-group-id': self.key_group_id, + 'vlm-entitle-pool-id': self.entitlement_id, + 'part-number': 'OCOMP'}) + + self.feature_group_id = output['id'] + submit = True + + if not self.agreement_id: + output = self.ocomp.run(command='vlm-aggreement-create', + params={'name': '{} Agreement'.format(self.conf['vnf']['vendor-name']), + 'vlm-id': self.vlm_id, + 'vlm-version': self.vlm_version, + 'vlm-feature-group-id': self.feature_group_id}) + + self.agreement_id = output['id'] + submit = True + + if submit: + self.ocomp.run(command='vlm-submit', + params={'vlm-id': self.vlm_id, + 'vlm-version': self.vlm_version}) + + def create_vsp(self): + if not self.vsp_id and not self.vsp_version and not self.vsp_version_id: + output = self.ocomp.run(command='vsp-create', + params={'vlm-id': self.vlm_id, + 'vlm-version': self.vlm_version, + 'vlm-vendor': self.conf['vnf']['vendor-name'], + 'vsp-name': self.conf['vnf']['name'], + 'vsp-description': self.tag, + 'vlm-agreement-id': self.agreement_id, + 'vlm-feature-group-id': self.feature_group_id}) + self.vsp_id = output['id'] + self.vsp_version_id = output['version-id'] + self.vsp_version = output['version'] + + self.ocomp.run(command='vsp-add-artifact', + params={'vsp-id': self.vsp_id, + 'vsp-version': self.vsp_version_id, + 'vsp-file': self.conf['vnf']['vsp-csar']}) + output = self.ocomp.run(command='vsp-validate', + params={'vsp-id': self.vsp_id, + 'vsp-version': self.vsp_version_id}) + if not output['status'] == "Success": + raise Exception("Invalid VSP package, please check it compliance using VTP") + + self.ocomp.run(command='vsp-submit', + params={'vsp-id': self.vsp_id, + 'vsp-version': self.vsp_version_id}) + self.ocomp.run(command='vsp-package', + params={'vsp-id': self.vsp_id, + 'vsp-version': self.vsp_version_id}) + + def create_vf_model(self): + if not self.vf_id and not self.vf_version: + output = self.ocomp.run(command='vf-model-create', + params={'name': '{} Vnf'.format(self.conf['vnf']['name']), + 'vendor-name': self.conf['vnf']['vendor-name'], +# 'vsp-id': self.vsp_id, +# 'vsp-version': self.vsp_version, # TODO: SDC fails to add VSP, check it + 'description': self.tag}) + + vf_id = output['id'] + inputs = output['inputs'].replace('[', '').replace(']', '').split(',') + # add artifact + self.ocomp.run(command='vf-model-add-artifact', + params={'vf-id': vf_id, + 'remarks': self.tag, + 'artifact': self.conf['vnf']['vnf-csar'], + 'artifact-name': 'tosca csar'}) + + output = self.ocomp.run(command='vf-model-certify', + params={'vf-id': vf_id, + 'remarks': self.tag}) + self.vf_id = output['id'] + self.vf_version = output['version'] + self.vf_uuid = output['uuid'] + self.vf_inputs = inputs + + def create_service_model(self): + if not self.ns_id and not self.ns_version: + output = self.ocomp.run(command='service-model-create', + params={'service-name': '{} Service'.format(self.conf['vnf']['name']), + 'description': self.tag, + 'project-code': 'OCOMP', + 'category': 'network l1-3', + 'category-display-name': 'Network L1-3', + 'icon-id': 'network_l_1-3'}) + ns_id = output['id'] + + if not self.ns_vf_resource_id: + output = self.ocomp.run(command='service-model-add-vf', + params={'service-id': ns_id, + 'vf-id': self.vf_id, + 'vf-version': self.vf_version, + 'vf-name': self.conf['vnf']['name']}) + self.ns_vf_resource_id = output['id'] + + # add artifact + self.ocomp.run(command='service-model-add-artifact', + params={'service-id': ns_id, + 'remarks': self.tag, + 'artifact': self.conf['vnf']['ns-csar'], + 'artifact-name': 'tosca csar'}) + #set property vnfmdriver + for input in self.vf_inputs: + if input.endswith('.nf_type'): + tkns = input.strip().split('.') + input_uuid = tkns[0] + self.ocomp.run(command='service-model-set-property', + params={'service-id': ns_id, + 'vf-id': self.vf_id, + 'vf-resource-id': self.ns_vf_resource_id, + 'property-name': 'nf_type', + 'property-value': self.conf['vnf']['vnfm-driver'], + 'input-uuid': input_uuid}) + break + + self.ocomp.run(command='service-model-test-request', + params={'service-id': ns_id, + 'remarks': self.tag}) + + self.ocomp.run(command='service-model-test-start', + params={'service-id': ns_id}) + + output = self.ocomp.run(command='service-model-test-accept', + params={'service-id': ns_id, + 'remarks': self.tag}) + self.ns_id = output['id'] + self.ns_version = output['version'] + self.ns_uuid = output['uuid'] + + self.ocomp.run(command='service-model-approve', + params={'service-id': self.ns_id, + 'remarks': self.tag}) + + self.ocomp.run(command='service-model-distribute', + params={'service-id': self.ns_id}) + + def setup_cloud_and_subscription(self): + associate = False + if not self.location_id and not self.location_version: + location_id = 'ocomp-region' + self.ocomp.run(command='complex-create', + params={'physical-location-id': location_id, + 'data-center-code': 'ocomp', + 'complex-name': location_id, + 'identity-url': self.conf['cloud']['identity-url'], + 'physical-location-type': 'phy_type', + 'street1': 'ocomp-street1', + 'street2': 'ocomp-street2', + 'city': 'ocomp-city', + 'state': 'ocomp-state', + 'postal-code': '001481', + 'country': 'abc', + 'longitude': '1.0', + 'latitude': '1.0', + 'region': 'onap', + 'elevation': 'ocomp-elelation', + 'lata': 'ocomp-lata'}) + self.location_id = location_id + associate = True + + output = self.ocomp.run(command='complex-list') + + for location in output: + if location['complex-name'] == self.location_id: + self.location_version = location['resource-version'] + break + + if not self.cloud_id and not self.cloud_version: + cloud_id = 'OCOMP' + self.ocomp.run(command='cloud-create', + params={'region-name': self.conf['cloud']['region'], + 'complex-name': self.location_id, + 'identity-url': self.conf['cloud']['identity-url'], + 'cloud-owner': cloud_id, + 'cloud-type': 'OpenStack', + 'owner-type': 'ocomp', + 'cloud-region-version': self.conf['cloud']['version'], + 'cloud-zone': 'az1', + 'esr-id': cloud_id, + 'service-url': self.conf['cloud']['identity-url'], + 'username': self.conf['cloud']['username'], + 'password': self.conf['cloud']['password'], + 'system-type': 'VIM', + 'ssl-insecure': 'true', + 'cloud-domain': 'Default', + 'default-tenant': self.conf['cloud']['tenant'], + 'system-status': "active"}) + self.cloud_id = cloud_id + associate = True + + output = self.ocomp.run(command='cloud-list') + + for cloud in output: + if cloud['cloud'] == self.cloud_id: + self.cloud_version = cloud['resource-version'] + break + + if associate: + self.ocomp.run(command='complex-associate', + params={'complex-name': self.location_id, + 'cloud-region': self.conf['cloud']['region'], + 'cloud-owner': self.cloud_id}) + + subscribe = False + if not self.service_type_id and not self.service_type_version: + self.ocomp.run(command='service-type-create', + params={'service-type': self.conf['subscription']['service-type'], + 'service-type-id': self.conf['subscription']['service-type']}) + self.service_type_id = self.conf['subscription']['service-type'] + subscribe = True + + output = self.ocomp.run(command='service-type-list') + + for st in output: + if st['service-type'] == self.service_type_id: + self.service_type_version = st['resource-version'] + break + + if not self.customer_id and not self.customer_version: + self.ocomp.run(command='customer-create', + params={'customer-name': self.conf['subscription']['customer-name'], + 'subscriber-name': self.conf['subscription']['customer-name']}) + self.customer_id = self.conf['subscription']['customer-name'] + subscribe = True + + output = self.ocomp.run(command='customer-list') + + for customer in output: + if customer['name'] == self.customer_id: + self.customer_version = customer['resource-version'] + break + + if not self.tenant_id and not self.tenant_version: + tenant_id = str(uuid.uuid4()) + self.ocomp.run(command='tenant-create', + params={'tenant-name': self.conf['cloud']['tenant'], + 'tenant-id': tenant_id, + 'cloud':self.cloud_id, + 'region': self.conf['cloud']['region']}) + self.tenant_id = tenant_id + subscribe = True + + output = self.ocomp.run(command='tenant-list', params={ + 'cloud': self.cloud_id, + 'region': self.conf['cloud']['region'] + }) + + for tenant in output: + if tenant['tenant-id'] == self.tenant_id: + self.tenant_version = tenant['resource-version'] + break + + if subscribe: + self.ocomp.run(command='subscription-create', + params={'customer-name': self.customer_id, + 'cloud-owner': self.cloud_id, + 'cloud-region': self.conf['cloud']['region'], + 'cloud-tenant-id': self.tenant_id, + 'service-type': self.service_type_id, + 'tenant-name': self.conf['cloud']['tenant']}) + + if not self.subscription_version: + output = self.ocomp.run(command='subscription-list', params={ + 'customer-name': self.customer_id + }) + + for subscription in output: + if subscription['service-type'] == self.service_type_id: + self.subscription_version = subscription['resource-version'] + break + + if not self.esr_vnfm_id and not self.esr_vnfm_version: + vnfmdriver = self.conf['vnf']['vnfm-driver'] + + esr_vnfm_id = str(uuid.uuid4()) + self.ocomp.run(command='vnfm-create', + params={'vim-id': self.cloud_id, + 'vnfm-id': esr_vnfm_id, + 'name': 'OCOMP {}'.format(vnfmdriver), + 'type': vnfmdriver, + 'vendor': self.conf['vnf']['vendor-name'], + 'vnfm-version': self.conf['vnfm'][vnfmdriver]['version'], + 'url': self.conf['vnfm'][vnfmdriver]['url'], + 'username': self.conf['vnfm'][vnfmdriver]['username'] , + 'password': self.conf['vnfm'][vnfmdriver]['password']}) + self.esr_vnfm_id = esr_vnfm_id + + output = self.ocomp.run(command='vnfm-list') + + for vnfm in output: + if vnfm['vnfm-id'] == self.esr_vnfm_id: + self.esr_vnfm_version = vnfm['resource-version'] + break + +# self.ocomp.run(command='multicloud-register-cloud', +# params={'cloud-region': self.conf['cloud']['region'], +# 'cloud-owner': self.cloud_id}) + + def create_vnf(self): + self.ocomp.run(command='vfc-catalog-onboard-vnf', + params={'vnf-csar-uuid': self.vf_uuid}) + + self.ocomp.run(command='vfc-catalog-onboard-ns', + params={'ns-csar-uuid': self.ns_uuid}) + + output = self.ocomp.run(command='vfc-nslcm-create', + params={'ns-csar-uuid': self.ns_uuid, + 'ns-csar-name': '{} Service'.format(self.conf['vnf']['name']), + 'customer-name': self.customer_id, + 'service-type': self.service_type_id}) + + self.ns_instance_id = output['ns-instance-id'] + + vnfmdriver = self.conf['vnf']['vnfm-driver'] + self.ocomp.run(command='vfc-nslcm-instantiate', + params={'ns-instance-id': self.ns_instance_id, + 'location': self.cloud_id, + 'sdn-controller-id': self.esr_vnfm_id}) + + def vnf_status_check(self): + self.vnf_status = 'active' + self.ns_instance_status = 'active' + + def cleanup(self): + if self.ns_instance_id: + self.ocomp.run(command='vfc-nslcm-delete', + params={'ns-instance-id': self.ns_instance_id}) + self.ns_instance_id = None + + if self.ns_id: + self.ocomp.run(command='service-model-archive', + params={'service-id': self.ns_id}) + self.ns_id = self.ns_uuid = self.ns_version = self.ns_vf_resource_id = None + + if self.vf_id: + self.ocomp.run(command='vf-model-archive', + params={'vf-id': self.vf_id}) + self.vf_id = self.vf_uuid = self.vf_inputs = self.vf_version = None + + if self.vsp_id: + self.ocomp.run(command='vsp-archive', + params={'vsp-id': self.vsp_id}) + self.vsp_id = self.vsp_version_id = self.vsp_version = None + + if self.vlm_id: + self.ocomp.run(command='vlm-archive', + params={'vlm-id': self.vlm_id}) + self.vlm_id = self.vlm_version = self.entitlement_id = self.key_group_id = self.feature_group_id = self.agreement_id = None + + if self.subscription_version and self.customer_id and self.service_type_id: + self.ocomp.run(command='subscription-delete', + params={'customer-name': self.customer_id, + 'service-type': self.service_type_id, + 'resource-version': self.subscription_version}) + self.subscription_version = None + + if self.customer_id and self.customer_version: + self.ocomp.run(command='customer-delete', + params={'customer-id': self.customer_id, + 'resource-version': self.customer_version}) + self.customer_id = self.customer_version = None + + if self.service_type_id and self.service_type_version: + output = self.ocomp.run(command='service-type-list') + + for st in output: + if st['service-type-id'] == self.service_type_id: + self.service_type_version = st['resource-version'] + break + + self.ocomp.run(command='service-type-delete', + params={'service-type-id': self.service_type_id, + 'resource-version': self.service_type_version}) + self.service_type_id = self.service_type_version = None + + if self.tenant_id and self.tenant_version: + self.ocomp.run(command='tenant-delete', + params={'cloud': self.cloud_id, + 'region': self.conf['cloud']['region'], + 'tenant-id': self.tenant_id, + 'resource-version': self.tenant_version}) + self.tenant_id = self.tenant_version = None + + if self.cloud_id and self.location_id: + self.ocomp.run(command='complex-disassociate', + params={'cloud-owner': self.cloud_id, + 'cloud-region': self.conf['cloud']['region'], + 'complex-name': self.location_id}) + + if self.cloud_id and self.cloud_version: + output = self.ocomp.run(command='cloud-list') + + for c in output: + if c['cloud'] == self.cloud_id and c['region'] == self.conf['cloud']['region']: + self.cloud_version = c['resource-version'] + break + + self.ocomp.run(command='cloud-delete', + params={'cloud-name': self.cloud_id, + 'region-name': self.conf['cloud']['region'], + 'resource-version': self.cloud_version}) + self.cloud_id = self.cloud_version = None + + if self.location_id and self.location_version: + self.ocomp.run(command='complex-delete', + params={'complex-name': self.location_id, + 'resource-version': self.location_version}) + self.location_id = self.location_version = None + + if self.esr_vnfm_id and self.esr_vnfm_version: + self.ocomp.run(command='vnfm-delete', + params={'vnfm-id': self.esr_vnfm_id, + 'resource-version': self.esr_vnfm_version}) + self.esr_vnfm_id = self.esr_vnfm_version = None + + def __str__(self): + return str(vars(self)) + +#Main +if __name__ == '__main__': + parser = argparse.ArgumentParser(description="ONAP TOSCA VNF validation using ONAP CLI and Open Command Platform (OCOMP)", formatter_class=RawTextHelpFormatter) + parser.add_argument('--product', action='store', dest='product', help='OCOMP product to use, default to onap-dublin', + default=os.environ.get('OPEN_CLI_PRODUCT_IN_USE')) + parser.add_argument('--profile', action='store', dest='profile', help='OCOMP profile to use, default to onap-dublin', + default=os.environ.get('OPEN_CLI_PROFILE')) + parser.add_argument('--request-id', action='store', dest='request_id', + help='Request Id to track the progress of running this script', + default=os.environ.get('OPEN_CLI_REQUEST_ID')) + parser.add_argument('--conf', action='store', dest='config_file_path', help='Configuration file path') + parser.add_argument('--vsp', action='store', dest='vsp', help='ONAP VSP file path') + parser.add_argument('--vnf-csar', action='store', dest='vnf_csar', help='TOSCA VNF CSAR file path') + parser.add_argument('--ns-csar', action='store', dest='ns_csar', help='TOSCA VNF CSAR file path') + parser.add_argument('--vnfm-driver', action='store', dest='vnfm_driver', help='VNFM dirver type one of gvnfmdriver or hwvnfmdriver', + choices=('gvnfmdriver', 'hwvnfmdriver')) + parser.add_argument('--vnf-name', action='store', dest='vnf_name', help='VNF Name') + parser.add_argument('--vendor-name', action='store', dest='vendor_name', help='VNF Vendor name') + parser.add_argument('--result-json', action='store', dest='result', help='Result json file. ' \ + '\nInstead of creating new ONAP objects while running this script \nand to use the existing ONAP object Ids, '\ + 'use this \nresult json parameter. Object Id names are provided in configuration \nfile under ONAP section') + parser.add_argument('--mode', action='store', dest='mode', help='Supports 5 mode.'\ + '\nsetup - Create the required VLM, service type, cloud, customer and \nsubscription as given in conf file' \ + '\nstandup - Create the VSP, VF Model, Service Model and provision\n the service using VFC'\ + '\ncleanup - Remove the ONAP objects which are either created during \nsetup and standup phase or provided by the user in result-json file ' \ + '\nCAUTION: If required, do not provide the existing ONAP object ids \nin result-json while doing the cleanup, to avoid them getting deleted.'\ + '\ncheckup - Check the deployment weather OCOMP is working properly or not' \ + '\nvalidate - run thru setup -> standup -> cleanup modes for end to end vnf validation', + choices=('setup', 'standup', 'cleanup', 'checkup', 'validate')) + + args = parser.parse_args() + print (args) + + if not args.product: + product = 'onap-dublin' + else: + product = args.product + + if not args.profile: + profile = 'onap-dublin' + else: + profile = args.profile + + request_id = args.request_id + vsp_csar = args.vsp + vnf_csar = args.vnf_csar + ns_csar = args.ns_csar + if args.mode: + mode = args.mode + else: + mode = 'checkup' + + if args.vnfm_driver: + vnfm_driver = args.vnfm_driver + else: + vnfm_driver = 'gvnfmdriver' + + if args.vnf_name: + vnf_name = args.vnf_name + else: + vnf_name = None + + if args.vendor_name: + vendor_name = args.vendor_name + else: + vendor_name = None + + conf = {} + config_file = args.config_file_path + with open(config_file) as json_file: + conf = json.load(json_file) + if vsp_csar: + conf['vnf']['vsp-csar'] = vsp_csar + if vnf_csar: + conf['vnf']['vnf-csar'] = vnf_csar + if ns_csar: + conf['vnf']['ns-csar'] = vnf_csar + if vnf_name: + conf['vnf']['name'] = vnf_name + if vnf_name: + conf['vnf']['vendor-name'] = vendor_name + + + if args.result: + result_file = args.result + with open(result_file) as r_file: + result_json = json.load(r_file) + for r in result_json: + if r in conf['ONAP']: + conf['ONAP'][r] = result_json[r] + else: + result_file = None + + print (OCOMP.version()) + + onap = ONAP(product, profile, conf, request_id) + + def _setup(): + onap.create_vlm() + onap.setup_cloud_and_subscription() + + def _standup(): + onap.create_vsp() + onap.create_vf_model() + onap.create_service_model() +# onap.create_vnf() + onap.vnf_status_check() + + def _cleanup(): + onap.cleanup() + + try: + if mode == 'setup': + _setup() + elif mode == 'standup': + _standup() + elif mode == 'cleanup': + _cleanup() + elif mode == 'checkup': + onap.ocomp.product = 'open-cli' + onap.ocomp.run(command='schema-list', params={'product': 'open-cli'}) + elif mode == 'validate': + _setup() + _standup() + _cleanup() + + print ('Done') + finally: + onap_result = json.dumps(onap, default=lambda x: x.__dict__) + print(onap_result) + + if result_file: + #Remove conf and ocomp from the onap object + for attr in ['ocomp', 'tag', 'conf']: + delattr(onap, attr) + + with open(result_file, "w") as f: + f.write(json.dumps(onap, default=lambda x: x.__dict__))
\ No newline at end of file |