From 08f6cbf5307459ac3e91fc2c98f9b76010b23d4a Mon Sep 17 00:00:00 2001 From: Kanagaraj M Date: Mon, 30 Sep 2019 06:19:30 +0200 Subject: Fix ovp lcm validation Issue-ID: CLI-166 Change-Id: I0c8def49c6d3eb79d4686b40899ff165ae2461ce Signed-off-by: Kanagaraj Manickam k00365106 --- .../src/main/resources/conf/vnf-tosca-lcm.json | 74 ++ .../main/resources/conf/vnf-tosca-provision.json | 74 -- .../vnf-tosca-lcm-dublin-schema-sample.yaml | 43 ++ .../vnf-tosca-provision-dublin-schema-sample.yaml | 43 -- .../vnf-tosca-lcm-dublin-schema.yaml | 210 ++++++ .../vnf-tosca-provision-dublin-schema.yaml | 210 ------ .../src/main/resources/script/vnf-tosca-lcm.py | 764 +++++++++++++++++++++ .../main/resources/script/vnf-tosca-provision.py | 749 -------------------- .../vfc-catalog-onboard-ns-schema-moco.json | 9 +- .../vfc-catalog-onboard-vnf-schema-moco.json | 11 +- .../resources/open-cli-sample/moco-global.json | 20 + .../nslcm/vfc-nslcm-create-schema-moco.json | 10 +- .../nslcm/vfc-nslcm-delete-schema-moco.json | 10 + .../nslcm/vfc-nslcm-delete-schema-sample.yaml | 9 + .../nslcm/vfc-nslcm-instantiate-schema-moco.json | 12 + .../nslcm/vfc-nslcm-instantiate-schema-sample.yaml | 14 + .../nslcm/vfc-nslcm-terminate-schema-moco.json | 12 + .../nslcm/vfc-nslcm-terminate-schema-sample.yaml | 14 + .../nslcm/vfc-nslcm-create-schema.yaml | 2 +- .../nslcm/vfc-nslcm-delete-schema.yaml | 11 +- .../nslcm/vfc-nslcm-get-schema.yaml | 2 +- .../nslcm/vfc-nslcm-instantiate-schema.yaml | 2 +- .../nslcm/vfc-nslcm-terminate-schema.yaml | 2 +- 23 files changed, 1191 insertions(+), 1116 deletions(-) create mode 100644 products/onap-dublin/features/integration/src/main/resources/conf/vnf-tosca-lcm.json delete mode 100644 products/onap-dublin/features/integration/src/main/resources/conf/vnf-tosca-provision.json create mode 100644 products/onap-dublin/features/integration/src/main/resources/open-cli-sample/vnf-tosca-lcm-dublin-schema-sample.yaml delete mode 100644 products/onap-dublin/features/integration/src/main/resources/open-cli-sample/vnf-tosca-provision-dublin-schema-sample.yaml create mode 100644 products/onap-dublin/features/integration/src/main/resources/open-cli-schema/vnf-tosca-lcm-dublin-schema.yaml delete mode 100644 products/onap-dublin/features/integration/src/main/resources/open-cli-schema/vnf-tosca-provision-dublin-schema.yaml create mode 100644 products/onap-dublin/features/integration/src/main/resources/script/vnf-tosca-lcm.py delete mode 100644 products/onap-dublin/features/integration/src/main/resources/script/vnf-tosca-provision.py create mode 100644 products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/moco-global.json create mode 100644 products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-delete-schema-moco.json create mode 100644 products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-delete-schema-sample.yaml create mode 100644 products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-instantiate-schema-moco.json create mode 100644 products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-instantiate-schema-sample.yaml create mode 100644 products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-terminate-schema-moco.json create mode 100644 products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-terminate-schema-sample.yaml (limited to 'products') diff --git a/products/onap-dublin/features/integration/src/main/resources/conf/vnf-tosca-lcm.json b/products/onap-dublin/features/integration/src/main/resources/conf/vnf-tosca-lcm.json new file mode 100644 index 00000000..a944e373 --- /dev/null +++ b/products/onap-dublin/features/integration/src/main/resources/conf/vnf-tosca-lcm.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" : "vgw-vendor", + "name": "vgw", + "vsp-csar": "D:\\workspace\\onap\\1.1\\SOL001\\vCPE\\csar_files\\default\\vgw.csar", + "vnf-csar": "D:\\workspace\\onap\\1.1\\SOL001\\vCPE_VFC\\csar_files\\default\\vgw.csar", + "ns-csar": "D:\\workspace\\onap\\1.1\\SOL001\\vCPE_VFC\\csar_files\\default\\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/conf/vnf-tosca-provision.json b/products/onap-dublin/features/integration/src/main/resources/conf/vnf-tosca-provision.json deleted file mode 100644 index a944e373..00000000 --- a/products/onap-dublin/features/integration/src/main/resources/conf/vnf-tosca-provision.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "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" : "vgw-vendor", - "name": "vgw", - "vsp-csar": "D:\\workspace\\onap\\1.1\\SOL001\\vCPE\\csar_files\\default\\vgw.csar", - "vnf-csar": "D:\\workspace\\onap\\1.1\\SOL001\\vCPE_VFC\\csar_files\\default\\vgw.csar", - "ns-csar": "D:\\workspace\\onap\\1.1\\SOL001\\vCPE_VFC\\csar_files\\default\\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-lcm-dublin-schema-sample.yaml b/products/onap-dublin/features/integration/src/main/resources/open-cli-sample/vnf-tosca-lcm-dublin-schema-sample.yaml new file mode 100644 index 00000000..360418df --- /dev/null +++ b/products/onap-dublin/features/integration/src/main/resources/open-cli-sample/vnf-tosca-lcm-dublin-schema-sample.yaml @@ -0,0 +1,43 @@ +open_cli_sample_version: 1.0 +name: vnf-tosca-lcm +version: onap-dublin +samples: + sample1: + name: vnf-tosca-lcm + 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-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 deleted file mode 100644 index 46c98327..00000000 --- a/products/onap-dublin/features/integration/src/main/resources/open-cli-sample/vnf-tosca-provision-dublin-schema-sample.yaml +++ /dev/null @@ -1,43 +0,0 @@ -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/vnf-tosca-lcm-dublin-schema.yaml b/products/onap-dublin/features/integration/src/main/resources/open-cli-schema/vnf-tosca-lcm-dublin-schema.yaml new file mode 100644 index 00000000..980a9493 --- /dev/null +++ b/products/onap-dublin/features/integration/src/main/resources/open-cli-schema/vnf-tosca-lcm-dublin-schema.yaml @@ -0,0 +1,210 @@ +# 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-lcm +description: | + ONAP TOSCA VNF validation using ONAP CLI and Open Command Platform (OCOMP) + + This command runs in 5 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. provision:Run setup -> standup + 5. 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 + + prerequisites + ------------- + 1. Setup the OCOMP profile to configure the ONAP service URL and creadentials as given below + + a. Run command 'oclip' to go to OCOMP interactive mode + + b. Type 'use onap-dublin' to choose the onap-dublin product + + c. Type 'profile onap-dublin' to create or to use existing onap-dublin profile + + d. Set following entries: + set sdc.onboarding:host-url=http://159.138.8.8:30280 + set sdc.onboarding:host-username=cs0008 + set sdc.onboarding:host-password=demo123456! + set sdc.catalog:host-url=http://159.138.8.8:30205 + set sdc.catalog:host-password=demo123456\! + set sdc.catalog:host-username=cs0008 + set sdc.catalog:service-model-approve:host-username=gv0001 + set sdc.catalog:service-model-distribute:host-username=op0001 + set sdc.catalog:service-model-test-start:host-username=jm0007 + set sdc.catalog:service-model-test-accept:host-username=jm0007 + set sdc.catalog:service-model-add-artifact:host-username=ocomp + set sdc.catalog:vf-model-add-artifact:host-username=ocomp + set aai:host-url=https://159.138.8.8:30233 + set aai:host-username=AAI + set aai:host-password=AAI + set vfc:host-url=http://159.138.8.8:30280 + set multicloud:host-url=http://159.138.8.8:30280 + + NOTE: + By default, SDC onboarding service does not provide node port, which is available to access from external ONAP network. + so to enable for external access, register the SDC onboarding service into MSB and use MSB url for sdc.onboarding:host-url. + + oclip --product onap-dublin microservice-create --host-url http://159.138.8.8:30280 --service-name sdcob --service-version v1.0 --service-url /onboarding-api/v1.0 --path /onboarding-api/v1.0 --node-ip 172.16.1.0 --node-port 8081 + + oclip --product onap-dublin microservice-create --host-url http://159.138.8.8:30280 --service-name sdcobs --service-version v1.0 --service-url /onboarding-api/v1.0 --path /onboarding-api/v1.0 --node-ip 172.16.1.0 --node-port 8445 --enable-ssl + + Find out SDC onboarding service IP and port details as given here: + [root@onap-dublin-vfw-93996-50c1z ~]# kubectl get pods -n onap -o wide | grep sdc-onboarding-be + dev-sdc-sdc-onboarding-be-5564b877c8-vpwr5 2/2 Running 0 29d 172.16.1.0 192.168.2.163 + dev-sdc-sdc-onboarding-be-cassandra-init-mtvz6 0/1 Completed 0 29d 172.16.0.220 192.168.2.163 + [root@onap-dublin-vfw-93996-50c1z ~]# + + Note down the IP address for sdc-onboarding-be 172.16.1.0 + + [root@onap-dublin-vfw-93996-50c1z ~]# kubectl get services -n onap -o wide | grep sdc-onboarding-be + sdc-onboarding-be ClusterIP 10.247.198.92 8445/TCP,8081/TCP 29d app=sdc-onboarding-be,release=dev-sdc + [root@onap-dublin-vfw-93996-50c1z ~]# + + Note down the port for sdc-onboarding-be 8445 8081 + + Similarly, other service IP and Port could be discovered like above, in case not know earlier :) + + This profile would be used while running the command with ONAP setup configured in it, as below + oclip --profile onap-dublin vnf-tosca-lcm ..... + + e. Verify these details once by typing 'set' + + f. Exit from the interactive console by typing 'exit' + + 2. Setup SDC consumer + oclip --product onap-dublin --profile onap-dublin sdc-consumer-create --consumer-name ocomp + + 3. Update the cloud and vnfm driver details in the configuration file $OPEN_CLI_HOME/conf/vnf-tosca-provision.json + +info: + product: onap-dublin + service: vnf-validation + author: ONAP VTP Team kanagaraj.manickam@huawei.com + +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-lcm.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 or provision or validate + type: string + short_option: Y + long_option: mode + is_optional: true + default_value: checkup + - 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-lcm.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/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 deleted file mode 100644 index ff67ee5e..00000000 --- a/products/onap-dublin/features/integration/src/main/resources/open-cli-schema/vnf-tosca-provision-dublin-schema.yaml +++ /dev/null @@ -1,210 +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: vnf-tosca-provision -description: | - ONAP TOSCA VNF validation using ONAP CLI and Open Command Platform (OCOMP) - - This command runs in 5 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. provision:Run setup -> standup - 5. 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 - - prerequisites - ------------- - 1. Setup the OCOMP profile to configure the ONAP service URL and creadentials as given below - - a. Run command 'oclip' to go to OCOMP interactive mode - - b. Type 'use onap-dublin' to choose the onap-dublin product - - c. Type 'profile onap-dublin' to create or to use existing onap-dublin profile - - d. Set following entries: - set sdc.onboarding:host-url=http://159.138.8.8:30280 - set sdc.onboarding:host-username=cs0008 - set sdc.onboarding:host-password=demo123456! - set sdc.catalog:host-url=http://159.138.8.8:30205 - set sdc.catalog:host-password=demo123456\! - set sdc.catalog:host-username=cs0008 - set sdc.catalog:service-model-approve:host-username=gv0001 - set sdc.catalog:service-model-distribute:host-username=op0001 - set sdc.catalog:service-model-test-start:host-username=jm0007 - set sdc.catalog:service-model-test-accept:host-username=jm0007 - set sdc.catalog:service-model-add-artifact:host-username=ocomp - set sdc.catalog:vf-model-add-artifact:host-username=ocomp - set aai:host-url=https://159.138.8.8:30233 - set aai:host-username=AAI - set aai:host-password=AAI - set vfc:host-url=http://159.138.8.8:30280 - set multicloud:host-url=http://159.138.8.8:30280 - - NOTE: - By default, SDC onboarding service does not provide node port, which is available to access from external ONAP network. - so to enable for external access, register the SDC onboarding service into MSB and use MSB url for sdc.onboarding:host-url. - - oclip --product onap-dublin microservice-create --host-url http://159.138.8.8:30280 --service-name sdcob --service-version v1.0 --service-url /onboarding-api/v1.0 --path /onboarding-api/v1.0 --node-ip 172.16.1.0 --node-port 8081 - - oclip --product onap-dublin microservice-create --host-url http://159.138.8.8:30280 --service-name sdcobs --service-version v1.0 --service-url /onboarding-api/v1.0 --path /onboarding-api/v1.0 --node-ip 172.16.1.0 --node-port 8445 --enable-ssl - - Find out SDC onboarding service IP and port details as given here: - [root@onap-dublin-vfw-93996-50c1z ~]# kubectl get pods -n onap -o wide | grep sdc-onboarding-be - dev-sdc-sdc-onboarding-be-5564b877c8-vpwr5 2/2 Running 0 29d 172.16.1.0 192.168.2.163 - dev-sdc-sdc-onboarding-be-cassandra-init-mtvz6 0/1 Completed 0 29d 172.16.0.220 192.168.2.163 - [root@onap-dublin-vfw-93996-50c1z ~]# - - Note down the IP address for sdc-onboarding-be 172.16.1.0 - - [root@onap-dublin-vfw-93996-50c1z ~]# kubectl get services -n onap -o wide | grep sdc-onboarding-be - sdc-onboarding-be ClusterIP 10.247.198.92 8445/TCP,8081/TCP 29d app=sdc-onboarding-be,release=dev-sdc - [root@onap-dublin-vfw-93996-50c1z ~]# - - Note down the port for sdc-onboarding-be 8445 8081 - - Similarly, other service IP and Port could be discovered like above, in case not know earlier :) - - This profile would be used while running the command with ONAP setup configured in it, as below - oclip --profile onap-dublin vnf-tosca-provision ..... - - e. Verify these details once by typing 'set' - - f. Exit from the interactive console by typing 'exit' - - 2. Setup SDC consumer - oclip --product onap-dublin --profile onap-dublin sdc-consumer-create --consumer-name ocomp - - 3. Update the cloud and vnfm driver details in the configuration file $OPEN_CLI_HOME/conf/vnf-tosca-provision.json - -info: - product: onap-dublin - service: vnf-validation - author: ONAP VTP Team kanagaraj.manickam@huawei.com - -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 or provision or validate - type: string - short_option: Y - long_option: mode - is_optional: true - default_value: checkup - - 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/vnf-tosca-lcm.py b/products/onap-dublin/features/integration/src/main/resources/script/vnf-tosca-lcm.py new file mode 100644 index 00000000..e6201714 --- /dev/null +++ b/products/onap-dublin/features/integration/src/main/resources/script/vnf-tosca-lcm.py @@ -0,0 +1,764 @@ +#!/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. + +# This script uses the ONAP CLI for providing the end-end service creation and termination. +# Used in devops, testing, certification and production +# NOTE: This feature is avaialble as ONAP CLI vnf-tosca-lcm +# +# Author: kanagaraj.manickam@huawei.com +# + +import json +import os +import argparse +import sys +import uuid +import subprocess +import platform +import datetime +import string +import random + +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 or {} + self.ocomp = OCOMP(request_id, debug, product=product, profile=profile) + self.preload() + self.tag = 'Powered 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]) + else: + self.conf['ONAP'] = {} + + 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': '100000'}) + + 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-commit', + params={'vsp-id': self.vsp_id, + 'vsp-version': self.vsp_version_id, + 'remarks': self.tag}) + + 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-{}'.format(self.conf['ONAP']['uid']) + 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-{}'.format(self.conf['ONAP']['uid']) + 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: + service_type_id = '{}-{}'.format(self.conf['subscription']['service-type'], self.conf['ONAP']['uid']) + self.ocomp.run(command='service-type-create', + params={'service-type': service_type_id, + 'service-type-id': service_type_id}) + self.service_type_id = service_type_id + 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: + customer_id = '{}-{}'.format(self.conf['subscription']['customer-name'], self.ocomp.conf['ONAP']['random']) + self.ocomp.run(command='customer-create', + params={'customer-name': customer_id, + 'subscriber-name': customer_id}) + self.customer_id = customer_id + 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-terminate', + params={'ns-instance-id': 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' \ + '\nprovision - Run thru setup -> standup' \ + '\nvalidate - run thru setup -> standup -> cleanup modes for end to end vnf validation', + choices=('setup', 'standup', 'cleanup', 'checkup', 'provision', '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 + if not request_id: + request_id = str(uuid.uuid4()) + 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 not conf['ONAP']['uid']: + conf['ONAP']['uid'] = ''.join(random.sample(string.ascii_lowercase,5)) + 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 + conf['vnf']['name'] = '{}{}'.format(conf['vnf']['name'], conf['ONAP']['uid']) + if vendor_name: + conf['vnf']['vendor-name'] = vendor_name + conf['vnf']['vendor-name'] = '{}-{}'.format(conf['vnf']['vendor-name'], conf['ONAP']['uid']) + + 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 == 'provision': + _setup() + _standup() + 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 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 deleted file mode 100644 index d412fa66..00000000 --- a/products/onap-dublin/features/integration/src/main/resources/script/vnf-tosca-provision.py +++ /dev/null @@ -1,749 +0,0 @@ -#!/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 = 'Powered 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': '100000'}) - - 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-commit', - params={'vsp-id': self.vsp_id, - 'vsp-version': self.vsp_version_id, - 'remarks': self.tag}) - - 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-{}'.format(self.ocomp.request_id) - 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-{}'.format(self.ocomp.request_id) - 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: - service_type_id = '{}-{}'.format(self.conf['subscription']['service-type'], self.ocomp.request_id) - self.ocomp.run(command='service-type-create', - params={'service-type': service_type_id, - 'service-type-id': service_type_id}) - self.service_type_id = service_type_id - 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: - customer_id = '{}-{}'.format(self.conf['subscription']['customer-name'], self.ocomp.request_id) - self.ocomp.run(command='customer-create', - params={'customer-name': customer_id, - 'subscriber-name': customer_id}) - self.customer_id = customer_id - 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' \ - '\nprovision - Run thru setup -> standup' \ - '\nvalidate - run thru setup -> standup -> cleanup modes for end to end vnf validation', - choices=('setup', 'standup', 'cleanup', 'checkup', 'provision', '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 - if not request_id: - request_id = str(uuid.uuid4()) - 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 - conf['vnf']['name'] = '{}{}'.format(conf['vnf']['name'], request_id).replace("-", "").replace("_", "") - if vnf_name: - conf['vnf']['vendor-name'] = vendor_name - conf['vnf']['vendor-name'] = '{}-{}'.format(conf['vnf']['vendor-name'], request_id) - - - 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 == 'provision': - _setup() - _standup() - 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 diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/catalog/vfc-catalog-onboard-ns-schema-moco.json b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/catalog/vfc-catalog-onboard-ns-schema-moco.json index 5218f7fd..41accfa7 100644 --- a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/catalog/vfc-catalog-onboard-ns-schema-moco.json +++ b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/catalog/vfc-catalog-onboard-ns-schema-moco.json @@ -1,14 +1,7 @@ [ { "request" : { "method" : "post", - "uri" : "/api/catalog/v1/nspackages", - "headers" : { - "Accept" : "application/json", - "Content-Type" : "application/json" - }, - "json" : { - "csarId" : "a3394090-c5b4-49b4-974c-00a6eac755ab" - } + "uri" : "/api/catalog/v1/nspackages" }, "response" : { "status" : 202, diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/catalog/vfc-catalog-onboard-vnf-schema-moco.json b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/catalog/vfc-catalog-onboard-vnf-schema-moco.json index 5e0591de..5327af7a 100644 --- a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/catalog/vfc-catalog-onboard-vnf-schema-moco.json +++ b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/catalog/vfc-catalog-onboard-vnf-schema-moco.json @@ -1,14 +1,7 @@ [ { "request" : { "method" : "post", - "uri" : "/api/catalog/v1/vnfpackages", - "headers" : { - "Accept" : "application/json", - "Content-Type" : "application/json" - }, - "json" : { - "csarId" : "c1cec675-1069-487d-b1a9-c256b17c3291" - } + "uri" : "/api/catalog/v1/vnfpackages" }, "response" : { "status" : 202, @@ -16,4 +9,4 @@ "jobId" : "1d871fc4-380c-4699-8f7f-77e508f9734d" } } -} ] \ No newline at end of file +} ] diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/moco-global.json b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/moco-global.json new file mode 100644 index 00000000..1ae10db0 --- /dev/null +++ b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/moco-global.json @@ -0,0 +1,20 @@ +[ + { + "include" : "catalog/vfc-catalog-onboard-vnf-schema-moco.json" + }, + { + "include" : "catalog/vfc-catalog-onboard-ns-schema-moco.json" + }, + { + "include" : "nslcm/vfc-nslcm-create-schema-moco.json" + }, + { + "include" : "nslcm/vfc-nslcm-instantiate-schema-moco.json" + }, + { + "include" : "nslcm/vfc-nslcm-delete-schema-moco.json" + }, + { + "include" : "nslcm/vfc-nslcm-terminate-schema-moco.json" + } +] \ No newline at end of file diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-create-schema-moco.json b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-create-schema-moco.json index 07392582..9a7fd103 100644 --- a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-create-schema-moco.json +++ b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-create-schema-moco.json @@ -1,15 +1,7 @@ [ { "request" : { "method" : "post", - "uri" : "/api/nslcm/v1/ns", - "headers" : { - "Accept" : "application/json", - "Content-Type" : "application/json" - }, - "json" : { - "csarId" : "a3394090-c5b4-49b4-974c-00a6eac755ab", - "nsName" : "vcpe1" - } + "uri" : "/api/nslcm/v1/ns" }, "response" : { "status" : 201, diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-delete-schema-moco.json b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-delete-schema-moco.json new file mode 100644 index 00000000..de6743cc --- /dev/null +++ b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-delete-schema-moco.json @@ -0,0 +1,10 @@ +[ { + "request" : { + "method" : "delete", + "uri" : "/api/nslcm/v1/ns/25f3159c-ff2d-4ad0-ac66-3270941bfa52" + }, + "response" : { + "status" : 204, + "json" : null + } +} ] diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-delete-schema-sample.yaml b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-delete-schema-sample.yaml new file mode 100644 index 00000000..4ce418b8 --- /dev/null +++ b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-delete-schema-sample.yaml @@ -0,0 +1,9 @@ +open_cli_sample_version: 1.0 +name: vfc-nslcm-delete +version: onap-dublin +samples: + sample1: + name: vfc-nslcm-delete + input: --host-url http://localhost:12306 --ns-instance-id 25f3159c-ff2d-4ad0-ac66-3270941bfa52 + moco: vfc-nslcm-delete-schema-moco.json + output: \ No newline at end of file diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-instantiate-schema-moco.json b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-instantiate-schema-moco.json new file mode 100644 index 00000000..94a357b3 --- /dev/null +++ b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-instantiate-schema-moco.json @@ -0,0 +1,12 @@ +[ { + "request" : { + "method" : "post", + "uri" : "/api/nslcm/v1/ns/25f3159c-ff2d-4ad0-ac66-3270941bfa52/instantiate" + }, + "response" : { + "status" : 200, + "json" : { + "jobId" : "7b06898d-e67a-4c9f-b1ce-90346ed6e520" + } + } +} ] diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-instantiate-schema-sample.yaml b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-instantiate-schema-sample.yaml new file mode 100644 index 00000000..bdda2352 --- /dev/null +++ b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-instantiate-schema-sample.yaml @@ -0,0 +1,14 @@ +open_cli_sample_version: 1.0 +name: vfc-nslcm-instantiate +version: onap-dublin +samples: + sample1: + name: vfc-nslcm-instantiate + input: --host-url http://localhost:12306 --ns-instance-id 25f3159c-ff2d-4ad0-ac66-3270941bfa52 --location OCOMP-lcm3_RegionOVP --sdn-controller-id 1 + moco: vfc-nslcm-instantiate-schema-moco.json + output: | + +--------------------------------------+ + |job-id | + +--------------------------------------+ + |7b06898d-e67a-4c9f-b1ce-90346ed6e520 | + +--------------------------------------+ diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-terminate-schema-moco.json b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-terminate-schema-moco.json new file mode 100644 index 00000000..f7d43635 --- /dev/null +++ b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-terminate-schema-moco.json @@ -0,0 +1,12 @@ +[ { + "request" : { + "method" : "post", + "uri" : "/api/nslcm/v1/ns/25f3159c-ff2d-4ad0-ac66-3270941bfa52/terminate" + }, + "response" : { + "status" : 202, + "json" : { + "jobId" : "f479d5eb-82a1-4a1f-9174-e071ee46c841" + } + } +} ] diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-terminate-schema-sample.yaml b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-terminate-schema-sample.yaml new file mode 100644 index 00000000..e6bdfbce --- /dev/null +++ b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-terminate-schema-sample.yaml @@ -0,0 +1,14 @@ +open_cli_sample_version: 1.0 +name: vfc-nslcm-terminate +version: onap-dublin +samples: + sample1: + name: vfc-nslcm-terminate + input: --host-url http://localhost:12306 --ns-instance-id 25f3159c-ff2d-4ad0-ac66-3270941bfa52 + moco: vfc-nslcm-terminate-schema-moco.json + output: | + +--------------------------------------+ + |job-id | + +--------------------------------------+ + |f479d5eb-82a1-4a1f-9174-e071ee46c841 | + +--------------------------------------+ diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-create-schema.yaml b/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-create-schema.yaml index 29fceccd..777e33bb 100644 --- a/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-create-schema.yaml +++ b/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-create-schema.yaml @@ -48,7 +48,7 @@ parameters: is_optional: false results: - direction: landscape + direction: portrait attributes: - name: ns-instance-id description: ns-instance-id diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-delete-schema.yaml b/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-delete-schema.yaml index 4850e070..cda2e7f8 100644 --- a/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-delete-schema.yaml +++ b/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-delete-schema.yaml @@ -29,14 +29,6 @@ parameters: long_option: ns-instance-id is_optional: false -results: - direction: landscape - attributes: - - name: status - description: status - scope: short - type: string - http: service: auth: none @@ -52,5 +44,4 @@ http: Accept: application/json success_codes: - 204 - result_map: - status: ${success_codes} + diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-get-schema.yaml b/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-get-schema.yaml index d6fa4398..984a1dc7 100644 --- a/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-get-schema.yaml +++ b/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-get-schema.yaml @@ -22,7 +22,7 @@ info: author: ONAP HPA Integration Team (haibin.huang@intel.com) results: - direction: landscape + direction: portrait attributes: - name: ns-instance-id description: ns-instance-id diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-instantiate-schema.yaml b/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-instantiate-schema.yaml index b31d4e4f..91387f03 100644 --- a/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-instantiate-schema.yaml +++ b/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-instantiate-schema.yaml @@ -42,7 +42,7 @@ parameters: is_optional: false results: - direction: landscape + direction: portrait attributes: - name: job-id description: job id diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-terminate-schema.yaml b/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-terminate-schema.yaml index 19f68666..387ab16c 100644 --- a/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-terminate-schema.yaml +++ b/products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-terminate-schema.yaml @@ -30,7 +30,7 @@ parameters: is_optional: false results: - direction: landscape + direction: portrait attributes: - name: job-id description: job id -- cgit 1.2.3-korg