diff options
author | 2020-09-17 13:04:35 -0700 | |
---|---|---|
committer | 2020-09-17 13:04:35 -0700 | |
commit | 35375724d9657de99adb8e530e1be21305555a40 (patch) | |
tree | 28806a1a1317426546ffdb9755d6f632ce088605 /onap-client/onap_client/sdc | |
parent | 591c548e569423dad8d106d4d2cd26bc5ce24b19 (diff) |
[VVP] Updating onap-client
Removing dependency on distutils
moving etc/ to package resource
Adding support for volume creation and delete
Removing module level imports
Adding delete capability to spec-engine
Adding kwarg to pass Client instance to functions
Issue-ID: VVP-469
Signed-off-by: stark, steven <steven.stark@att.com>
Change-Id: Ie00065f54411c8ff40ea20c35fe919ce15f65e6a
Diffstat (limited to 'onap-client/onap_client/sdc')
-rw-r--r-- | onap-client/onap_client/sdc/catalog/license_model_catalog.py | 37 | ||||
-rw-r--r-- | onap-client/onap_client/sdc/catalog/service_catalog.py | 65 | ||||
-rw-r--r-- | onap-client/onap_client/sdc/catalog/vnf_catalog.py | 65 | ||||
-rw-r--r-- | onap-client/onap_client/sdc/catalog/vsp_catalog.py | 43 | ||||
-rw-r--r-- | onap-client/onap_client/sdc/client.py | 6 | ||||
-rw-r--r-- | onap-client/onap_client/sdc/license_model.py | 22 | ||||
-rw-r--r-- | onap-client/onap_client/sdc/service.py | 67 | ||||
-rw-r--r-- | onap-client/onap_client/sdc/vnf.py | 59 | ||||
-rw-r--r-- | onap-client/onap_client/sdc/vsp.py | 70 |
9 files changed, 225 insertions, 209 deletions
diff --git a/onap-client/onap_client/sdc/catalog/license_model_catalog.py b/onap-client/onap_client/sdc/catalog/license_model_catalog.py index a01b967..0a90ebf 100644 --- a/onap-client/onap_client/sdc/catalog/license_model_catalog.py +++ b/onap-client/onap_client/sdc/catalog/license_model_catalog.py @@ -34,16 +34,11 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from functools import partial -from onap_client import config from onap_client.sdc.client import SDCClient -PAYLOADS_DIR = config.PAYLOADS_DIR -application_id = config.APPLICATION_ID - class LicenseModelClient(SDCClient): @property @@ -61,7 +56,7 @@ class LicenseModelClient(SDCClient): endpoint=self.config.sdc.SDC_BE_ONBOARD_ENDPOINT, service_path=self.config.sdc.SDC_VENDOR_LICENSE_MODEL_PATH, ), - "payload": "{}/license_model.jinja".format(PAYLOADS_DIR), + "payload": "{}/license_model.jinja".format(self.config.payload_directory), "payload-parameters": ["vendor_name"], "success_code": 200, "headers": { @@ -69,7 +64,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": { "license_model_id": ("itemId",), @@ -89,7 +84,7 @@ class LicenseModelClient(SDCClient): service_path=self.config.sdc.SDC_VENDOR_LICENSE_MODEL_PATH, ), "uri-parameters": ["license_model_id", "license_model_version_id"], - "payload": "{}/key_group.jinja".format(PAYLOADS_DIR), + "payload": "{}/key_group.jinja".format(self.config.payload_directory), "payload-parameters": [ "license_start_date", "license_end_date", @@ -101,7 +96,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"key_group_id": ("value",)}, "auth": ( @@ -118,7 +113,7 @@ class LicenseModelClient(SDCClient): service_path=self.config.sdc.SDC_VENDOR_LICENSE_MODEL_PATH, ), "uri-parameters": ["license_model_id", "license_model_version_id"], - "payload": "{}/entitlement_pool.jinja".format(PAYLOADS_DIR), + "payload": "{}/entitlement_pool.jinja".format(self.config.payload_directory), "payload-parameters": [ "license_start_date", "license_end_date", @@ -130,7 +125,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"entitlement_pool_id": ("value",)}, "auth": ( @@ -147,7 +142,7 @@ class LicenseModelClient(SDCClient): service_path=self.config.sdc.SDC_VENDOR_LICENSE_MODEL_PATH, ), "uri-parameters": ["license_model_id", "license_model_version_id"], - "payload": "{}/feature_group.jinja".format(PAYLOADS_DIR), + "payload": "{}/feature_group.jinja".format(self.config.payload_directory), "payload-parameters": [ "feature_group_name", "key_group_id", @@ -160,7 +155,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"feature_group_id": ("value",)}, "auth": ( @@ -177,7 +172,7 @@ class LicenseModelClient(SDCClient): service_path=self.config.sdc.SDC_VENDOR_LICENSE_MODEL_PATH, ), "uri-parameters": ["license_model_id", "license_model_version_id"], - "payload": "{}/license_agreement.jinja".format(PAYLOADS_DIR), + "payload": "{}/license_agreement.jinja".format(self.config.payload_directory), "payload-parameters": ["feature_group_id", "license_agreement_name"], "success_code": 200, "headers": { @@ -185,7 +180,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"license_agreement_id": ("value",)}, "auth": ( @@ -202,7 +197,7 @@ class LicenseModelClient(SDCClient): service_path=self.config.sdc.SDC_VENDOR_LICENSE_MODEL_PATH, ), "uri-parameters": ["license_model_id", "license_model_version_id"], - "payload": "{}/action.jinja".format(PAYLOADS_DIR), + "payload": "{}/action.jinja".format(self.config.payload_directory), "payload-parameters": ["action"], "success_code": 200, "headers": { @@ -210,7 +205,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -232,7 +227,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": { "vendor_name": ("vendorName",), @@ -259,7 +254,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -281,7 +276,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -302,7 +297,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"results": ("results",)}, "auth": ( diff --git a/onap-client/onap_client/sdc/catalog/service_catalog.py b/onap-client/onap_client/sdc/catalog/service_catalog.py index aad645f..dad8456 100644 --- a/onap-client/onap_client/sdc/catalog/service_catalog.py +++ b/onap-client/onap_client/sdc/catalog/service_catalog.py @@ -34,16 +34,11 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from functools import partial -from onap_client import config from onap_client.sdc.client import SDCClient -PAYLOADS_DIR = config.PAYLOADS_DIR -application_id = config.APPLICATION_ID - class ServiceCatalog(SDCClient): @property @@ -61,7 +56,7 @@ class ServiceCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ENDPOINT, service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, ), - "payload": "{}/catalog_service.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_service.jinja".format(self.config.payload_directory), "payload-parameters": [ "service_name", "instantiation_type", @@ -85,7 +80,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_service_id": ("uniqueId",)}, "auth": ( @@ -108,7 +103,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_service_id": ("uniqueId",)}, "auth": ( @@ -125,7 +120,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, ), "uri-parameters": ["catalog_service_id"], - "payload": "{}/resource_instance.jinja".format(PAYLOADS_DIR), + "payload": "{}/resource_instance.jinja".format(self.config.payload_directory), "payload-parameters": [ "milli_timestamp", "catalog_resource_id", @@ -140,7 +135,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_resource_instance_id": ("uniqueId",)}, "auth": ( @@ -163,7 +158,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -179,7 +174,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, ), "uri-parameters": ["catalog_service_id", "component_name"], - "payload": "{}/update_resource_instance.jinja".format(PAYLOADS_DIR), + "payload": "{}/update_resource_instance.jinja".format(self.config.payload_directory), "payload-parameters": [ "component_id", ], @@ -189,7 +184,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -205,7 +200,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, ), "uri-parameters": ["catalog_service_id"], - "payload": "{}/user_remarks.jinja".format(PAYLOADS_DIR), + "payload": "{}/user_remarks.jinja".format(self.config.payload_directory), "payload-parameters": ["user_remarks"], "success_code": 200, "headers": { @@ -213,7 +208,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -229,7 +224,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, ), "uri-parameters": ["catalog_service_id"], - "payload": "{}/user_remarks.jinja".format(PAYLOADS_DIR), + "payload": "{}/user_remarks.jinja".format(self.config.payload_directory), "payload-parameters": ["user_remarks"], "success_code": 200, "headers": { @@ -237,7 +232,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -253,7 +248,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, ), "uri-parameters": ["catalog_service_id"], - "payload": "{}/user_remarks.jinja".format(PAYLOADS_DIR), + "payload": "{}/user_remarks.jinja".format(self.config.payload_directory), "payload-parameters": ["user_remarks"], "success_code": 200, "headers": { @@ -261,7 +256,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_tester_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -277,7 +272,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, ), "uri-parameters": ["catalog_service_id"], - "payload": "{}/user_remarks.jinja".format(PAYLOADS_DIR), + "payload": "{}/user_remarks.jinja".format(self.config.payload_directory), "payload-parameters": ["user_remarks"], "success_code": 200, "headers": { @@ -285,7 +280,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_tester_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_service_id": ("uniqueId",)}, "auth": ( @@ -302,7 +297,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, ), "uri-parameters": ["catalog_service_id"], - "payload": "{}/user_remarks.jinja".format(PAYLOADS_DIR), + "payload": "{}/user_remarks.jinja".format(self.config.payload_directory), "payload-parameters": ["user_remarks"], "success_code": 200, "headers": { @@ -310,7 +305,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_governor_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -333,7 +328,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_ops_user_id, # "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -349,7 +344,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), "uri-parameters": ["catalog_service_id", "catalog_resource_instance_id"], - "payload": "{}/catalog_service_property.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_service_property.jinja".format(self.config.payload_directory), "payload-parameters": [ "unique_id", "parent_unique_id", @@ -365,7 +360,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -381,7 +376,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), "uri-parameters": ["catalog_service_id", "catalog_resource_instance_id"], - "payload": "{}/catalog_service_property.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_service_property.jinja".format(self.config.payload_directory), "payload-parameters": [ "unique_id", "parent_unique_id", @@ -395,7 +390,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -411,7 +406,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), "uri-parameters": ["catalog_service_id", "catalog_resource_instance_id", "module_id"], - "payload": "{}/generic_payload.jinja".format(PAYLOADS_DIR), + "payload": "{}/generic_payload.jinja".format(self.config.payload_directory), "payload-parameters": [ "payload_data", ], @@ -421,7 +416,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -443,7 +438,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -464,7 +459,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"services": ("services",)}, "auth": ( @@ -487,7 +482,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -509,7 +504,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -531,7 +526,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, diff --git a/onap-client/onap_client/sdc/catalog/vnf_catalog.py b/onap-client/onap_client/sdc/catalog/vnf_catalog.py index 692052f..71b20ca 100644 --- a/onap-client/onap_client/sdc/catalog/vnf_catalog.py +++ b/onap-client/onap_client/sdc/catalog/vnf_catalog.py @@ -34,16 +34,11 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from functools import partial -from onap_client import config from onap_client.sdc.client import SDCClient -PAYLOADS_DIR = config.PAYLOADS_DIR -application_id = config.APPLICATION_ID - class VNFCatalog(SDCClient): @property @@ -61,7 +56,7 @@ class VNFCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ENDPOINT, service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), - "payload": "{}/catalog_resource.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_resource.jinja".format(self.config.payload_directory), "payload-parameters": [ "software_product_id", "vnf_name", @@ -77,7 +72,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_resource_id": ("uniqueId",)}, "auth": ( @@ -94,7 +89,7 @@ class VNFCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), "uri-parameters": ["catalog_resource_id"], - "payload": "{}/user_remarks.jinja".format(PAYLOADS_DIR), + "payload": "{}/user_remarks.jinja".format(self.config.payload_directory), "payload-parameters": ["user_remarks"], "success_code": 200, "headers": { @@ -102,7 +97,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_resource_id": ("uniqueId",)}, "auth": ( @@ -118,7 +113,7 @@ class VNFCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ENDPOINT, service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), - "payload": "{}/catalog_vnf_input.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_vnf_input.jinja".format(self.config.payload_directory), "payload-parameters": [ "input_default_value", "input_name", @@ -133,7 +128,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -150,14 +145,14 @@ class VNFCatalog(SDCClient): ), "uri-parameters": ["catalog_resource_id"], "success_code": 200, - "payload": "{}/generic_payload.jinja".format(PAYLOADS_DIR), + "payload": "{}/generic_payload.jinja".format(self.config.payload_directory), "payload-parameters": ["payload_data"], "headers": { "Accept": "application/json", "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -179,7 +174,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -194,7 +189,7 @@ class VNFCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ENDPOINT, service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), - "payload": "{}/catalog_vnf_property.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_vnf_property.jinja".format(self.config.payload_directory), "payload-parameters": [ "unique_id", "parent_unique_id", @@ -211,7 +206,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -226,7 +221,7 @@ class VNFCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ENDPOINT, service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), - "payload": "{}/catalog_vnf_property.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_vnf_property.jinja".format(self.config.payload_directory), "payload-parameters": [ "unique_id", "parent_unique_id", @@ -243,7 +238,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -265,7 +260,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_resource_id": ("uniqueId",)}, "auth": ( @@ -282,7 +277,7 @@ class VNFCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), "uri-parameters": ["catalog_resource_id", "catalog_policy_id"], - "payload": "{}/catalog_vnf_policy_property.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_vnf_policy_property.jinja".format(self.config.payload_directory), "payload-parameters": [ "unique_id", "property_name", @@ -296,7 +291,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -318,7 +313,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_resource_id": ("uniqueId",)}, "auth": ( @@ -335,7 +330,7 @@ class VNFCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), "uri-parameters": ["catalog_resource_id", "catalog_group_id"], - "payload": "{}/catalog_vnf_group_property.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_vnf_group_property.jinja".format(self.config.payload_directory), "payload-parameters": [ "unique_id", "property_name", @@ -351,7 +346,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -366,7 +361,7 @@ class VNFCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ENDPOINT, service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), - "payload": "{}/catalog_vnf_group.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_vnf_group.jinja".format(self.config.payload_directory), "payload-parameters": ["instance_id"], "uri-parameters": ["catalog_resource_id", "catalog_group_id"], "success_code": 200, @@ -375,7 +370,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -390,7 +385,7 @@ class VNFCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ENDPOINT, service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), - "payload": "{}/catalog_vnf_policy.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_vnf_policy.jinja".format(self.config.payload_directory), "payload-parameters": ["instance_ids"], "uri-parameters": ["catalog_resource_id", "catalog_policy_id"], "success_code": 200, @@ -399,7 +394,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -415,7 +410,7 @@ class VNFCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), "uri-parameters": ["catalog_resource_id"], - "payload": "{}/resource_instance_vnf.jinja".format(PAYLOADS_DIR), + "payload": "{}/resource_instance_vnf.jinja".format(self.config.payload_directory), "payload-parameters": [ "milli_timestamp", "new_catalog_resource_id", @@ -431,7 +426,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -447,7 +442,7 @@ class VNFCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), "uri-parameters": ["catalog_resource_id"], - "payload": "{}/add_resource_relationship.jinja".format(PAYLOADS_DIR), + "payload": "{}/add_resource_relationship.jinja".format(self.config.payload_directory), "payload-parameters": [ "from_node_resource_id", "to_node_resource_id", @@ -464,7 +459,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -486,7 +481,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_resource_name": ("name",)}, "auth": ( @@ -509,7 +504,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -530,7 +525,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"resources": ("resources",)}, "auth": ( diff --git a/onap-client/onap_client/sdc/catalog/vsp_catalog.py b/onap-client/onap_client/sdc/catalog/vsp_catalog.py index c16fa16..f8ddb9b 100644 --- a/onap-client/onap_client/sdc/catalog/vsp_catalog.py +++ b/onap-client/onap_client/sdc/catalog/vsp_catalog.py @@ -34,16 +34,11 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from functools import partial -from onap_client import config from onap_client.sdc.client import SDCClient -PAYLOADS_DIR = config.PAYLOADS_DIR -application_id = config.APPLICATION_ID - class VSPCatalog(SDCClient): @property @@ -61,7 +56,7 @@ class VSPCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ONBOARD_ENDPOINT, service_path=self.config.sdc.SDC_VENDOR_SOFTWARE_PRODUCT_PATH, ), - "payload": "{}/software_product.jinja".format(PAYLOADS_DIR), + "payload": "{}/software_product.jinja".format(self.config.payload_directory), "payload-parameters": [ "software_product_name", "feature_group_id", @@ -79,7 +74,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": { "software_product_id": ("itemId",), @@ -98,7 +93,7 @@ class VSPCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ONBOARD_ENDPOINT, service_path=self.config.sdc.SDC_VENDOR_ITEMS_PATH, ), - "payload": "{}/software_product_update.jinja".format(PAYLOADS_DIR), + "payload": "{}/software_product_update.jinja".format(self.config.payload_directory), "payload-parameters": [ "description", ], @@ -109,7 +104,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -132,7 +127,7 @@ class VSPCatalog(SDCClient): "Content-Type": "multipart/form-data", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -154,7 +149,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -170,7 +165,7 @@ class VSPCatalog(SDCClient): service_path=self.config.sdc.SDC_VENDOR_SOFTWARE_PRODUCT_PATH, ), "uri-parameters": ["software_product_id", "software_product_version_id"], - "payload": "{}/action.jinja".format(PAYLOADS_DIR), + "payload": "{}/action.jinja".format(self.config.payload_directory), "payload-parameters": ["action"], "success_code": 200, "headers": { @@ -178,7 +173,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -194,7 +189,7 @@ class VSPCatalog(SDCClient): service_path=self.config.sdc.SDC_VENDOR_SOFTWARE_PRODUCT_PATH, ), "uri-parameters": ["software_product_id", "software_product_version_id"], - "payload": "{}/action.jinja".format(PAYLOADS_DIR), + "payload": "{}/action.jinja".format(self.config.payload_directory), "payload-parameters": ["action"], "success_code": 200, "headers": { @@ -202,7 +197,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -224,7 +219,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"name": ("name",)}, "auth": ( @@ -247,7 +242,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"name": ("name",)}, "auth": ( @@ -270,7 +265,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": { "software_product_version_id": ("id",), @@ -295,7 +290,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"results": ("results",)}, "auth": ( @@ -318,7 +313,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -334,7 +329,7 @@ class VSPCatalog(SDCClient): service_path=self.config.sdc.SDC_VENDOR_ITEMS_PATH, ), "uri-parameters": ["software_product_id"], - "payload": "{}/add_vsp_contributer.jinja".format(PAYLOADS_DIR), + "payload": "{}/add_vsp_contributer.jinja".format(self.config.payload_directory), "payload-parameters": ["user_id"], "success_code": 200, "headers": { @@ -342,7 +337,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -358,7 +353,7 @@ class VSPCatalog(SDCClient): service_path=self.config.sdc.SDC_VENDOR_ITEMS_PATH, ), "uri-parameters": ["software_product_id"], - "payload": "{}/add_vsp_contributer.jinja".format(PAYLOADS_DIR), + "payload": "{}/add_vsp_contributer.jinja".format(self.config.payload_directory), "payload-parameters": ["user_id"], "success_code": 200, "headers": { @@ -366,7 +361,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, diff --git a/onap-client/onap_client/sdc/client.py b/onap-client/onap_client/sdc/client.py index cfdd4ad..725cbeb 100644 --- a/onap-client/onap_client/sdc/client.py +++ b/onap-client/onap_client/sdc/client.py @@ -34,14 +34,10 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from functools import partial from onap_client.client.clients import Client -from onap_client import config - -application_id = config.APPLICATION_ID class SDCClient(Client): @@ -66,7 +62,7 @@ class SDCClient(Client): "Content-Type": "application/json", "USER_ID": self.config.sdc.SDC_DESIGNER_USER_ID, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, # "auth": ( # self.sdc_designer_user_id, diff --git a/onap-client/onap_client/sdc/license_model.py b/onap-client/onap_client/sdc/license_model.py index 1fbcea2..ed5ba80 100644 --- a/onap-client/onap_client/sdc/license_model.py +++ b/onap-client/onap_client/sdc/license_model.py @@ -87,7 +87,7 @@ class LicenseModel(Resource): def _create(self, license_input): """Creates a license model object in SDC""" - return create_license_model(license_input) + return create_license_model(license_input, oc=self.oc) def _submit(self): """Submits the license model in SDC""" @@ -103,14 +103,15 @@ class LicenseModel(Resource): # TODO # Break this up into class funcs? -def create_license_model(license_input): +def create_license_model(license_input, oc=None): """Creates a license model object in SDC :license_input: dictionary with values to input for lm creation :return: dictionary of updated values for created lm """ - oc = Client() + if not oc: + oc = Client() kwargs = license_input license_model = oc.sdc.license_model.add_license_model(**kwargs) @@ -141,14 +142,15 @@ def create_license_model(license_input): return kwargs -def get_license_model_id(license_model_name): +def get_license_model_id(license_model_name, oc=None): """GETs license model UUID from SDC :license_model_name: name of license model in SDC :return: uuid of lm or None """ - oc = Client() + if not oc: + oc = Client() response = oc.sdc.license_model.get_license_models() results = response.response_data.get("results") @@ -158,14 +160,15 @@ def get_license_model_id(license_model_name): return None -def get_license_model_version_id(license_model_id): +def get_license_model_version_id(license_model_id, oc=None): """GETs license model version UUID from SDC :license_model_id: uuid of license model in SDC :return: uuid of lm version id or None """ - oc = Client() + if not oc: + oc = Client() license_model_version_id = None creation_time = -1 @@ -181,7 +184,7 @@ def get_license_model_version_id(license_model_id): return license_model_version_id -def get_license_model_attribute(license_model_id, license_model_version_id, attribute): +def get_license_model_attribute(license_model_id, license_model_version_id, attribute, oc=None): """GETs license model attribute from SDC :license_model_id: uuid of license model in SDC @@ -190,7 +193,8 @@ def get_license_model_attribute(license_model_id, license_model_version_id, attr :return: uuid of attribute of license-model """ - oc = Client() + if not oc: + oc = Client() response = oc.sdc.license_model.get_license_model_version_attribute( license_model_id=license_model_id, diff --git a/onap-client/onap_client/sdc/service.py b/onap-client/onap_client/sdc/service.py index 6aace73..c405e42 100644 --- a/onap-client/onap_client/sdc/service.py +++ b/onap-client/onap_client/sdc/service.py @@ -121,11 +121,11 @@ class Service(Resource): """Creates a service object in SDC""" service = None - existing = get_service_id(service_input.get("service_name")) + existing = get_service_id(service_input.get("service_name"), oc=self.oc) if existing is None: - service = create_service(service_input) + service = create_service(service_input, oc=self.oc) elif service_input.get("allow_update"): - service = update_service(existing, service_input) + service = update_service(existing, service_input, oc=self.oc) else: raise exceptions.ResourceAlreadyExistsException( "Service resource {} already exists".format( @@ -144,7 +144,7 @@ class Service(Resource): resource_id = resource.get("resource_id") resource_properties = resource.get("properties") if not resource_id: - resource_id = get_vnf_id(catalog_resource_name) + resource_id = get_vnf_id(catalog_resource_name, oc=self.oc) if not resource_id: raise exceptions.ResourceIDNotFoundException( "resource ID was not passed, and resource lookup by name was not found {}".format( @@ -205,7 +205,7 @@ class Service(Resource): self.oc.sdc.service.distribute_sdc_service(**self.attributes, **headers) if self.wait_for_distribution: - poll_distribution(self.service_name) + poll_distribution(self.service_name, oc=self.oc) self._refresh() @@ -326,8 +326,9 @@ class Service(Resource): return self.tosca -def update_service(existing_service_id, service_input): - oc = Client() +def update_service(existing_service_id, service_input, oc=None): + if not oc: + oc = Client() kwargs = service_input @@ -348,14 +349,15 @@ def update_service(existing_service_id, service_input): return kwargs -def create_service(service_input): +def create_service(service_input, oc=None): """Creates a service object in SDC :service_input: dictionary with values to input for service creation :return: dictionary of updated values for created service """ - oc = Client() + if not oc: + oc = Client() category_name_lower = service_input.get("category_name").lower() category_name_icon = normalize_category_icon(service_input.get("category_name")) @@ -373,19 +375,21 @@ def create_service(service_input): @utility -def get_service(service_name): +def get_service(service_name, oc=None): """Queries SDC for the TOSCA model for a service""" - oc = Client() + if not oc: + oc = Client() return oc.sdc.service.get_sdc_service( - catalog_service_id=get_service_id(service_name) + catalog_service_id=get_service_id(service_name, oc=oc) ).response_data @utility -def get_service_id(service_name): +def get_service_id(service_name, oc=None): """Queries SDC for the uniqueId of a service model""" - oc = Client() + if not oc: + oc = Client() response = oc.sdc.service.get_services() results = response.response_data.get("services", []) @@ -399,14 +403,18 @@ def get_service_id(service_name): return catalog_service.get("uniqueId") -def get_service_uuid(service_name): - return get_service(service_name).get("uuid") +def get_service_uuid(service_name, oc=None): + if not oc: + oc = Client() + + return get_service(service_name, oc=oc).get("uuid") -def get_service_distribution(service_name): - oc = Client() +def get_service_distribution(service_name, oc=None): + if not oc: + oc = Client() - distribution_id = get_distribution_id(service_name) + distribution_id = get_distribution_id(service_name, oc=oc) if distribution_id: return oc.sdc.service.get_service_distribution_details( @@ -416,11 +424,12 @@ def get_service_distribution(service_name): return None -def get_distribution_id(service_name): - oc = Client() +def get_distribution_id(service_name, oc=None): + if not oc: + oc = Client() distribution = oc.sdc.service.get_service_distribution( - distribution_service_id=get_service_uuid(service_name) + distribution_service_id=get_service_uuid(service_name, oc=oc) ).response_data if distribution: details = distribution.get("distributionStatusOfServiceList", []) @@ -431,14 +440,15 @@ def get_distribution_id(service_name): @utility -def poll_distribution(service_name): +def poll_distribution(service_name, oc=None): """Polls a distributed service until distribution is complete""" - oc = Client() + if not oc: + oc = Client() poll_interval = oc.config.sdc.POLL_INTERVAL or 30 x = 0 while x < 30: - distribution = get_service_distribution(service_name) + distribution = get_service_distribution(service_name, oc=oc) if not distribution: raise exceptions.DistributionNotFound( "Could not determine distribution status for {}".format(service_name) @@ -470,10 +480,11 @@ def poll_distribution(service_name): @utility -def download_csar(service_name, output_file): - oc = Client() +def download_csar(service_name, output_file, oc=None): + if not oc: + oc = Client() - service = get_service(service_name) + service = get_service(service_name, oc=oc) artifact_id = service.get("toscaArtifacts", {}).get("assettoscacsar", {}).get("uniqueId") csar_data = oc.sdc.service.get_sdc_csar( diff --git a/onap-client/onap_client/sdc/vnf.py b/onap-client/onap_client/sdc/vnf.py index 39c66b8..4c42dbe 100644 --- a/onap-client/onap_client/sdc/vnf.py +++ b/onap-client/onap_client/sdc/vnf.py @@ -126,11 +126,11 @@ class VNF(Resource): """Creates a vnf object in SDC""" vnf = None - existing = get_vnf_id(vnf_input.get("vnf_name")) + existing = get_vnf_id(vnf_input.get("vnf_name"), oc=self.oc) if not existing: - vnf = create_vnf(vnf_input) + vnf = create_vnf(vnf_input, oc=self.oc) elif vnf_input.get("allow_update"): - vnf = update_vnf(existing, vnf_input) + vnf = update_vnf(existing, vnf_input, oc=self.oc) else: raise exceptions.ResourceAlreadyExistsException( "VNF resource {} already exists".format(vnf_input.get("vnf_name")) @@ -206,14 +206,14 @@ class VNF(Resource): resource_relationship = resource.get("relationship", {}) if not resource_id: - resource_id = get_vnf_id(catalog_resource_name) + resource_id = get_vnf_id(catalog_resource_name, oc=self.oc) if not resource_id: raise exceptions.ResourceIDNotFoundException( "resource ID was not passed, and resource lookup by name was not found {}".format( resource_name ) ) - new_resource = add_resource(self.catalog_resource_id, resource_id, resource_name, origin_type=resource_origin) + new_resource = add_resource(self.catalog_resource_id, resource_id, resource_name, origin_type=resource_origin, oc=self.oc) self._refresh() new_resource_id = new_resource["id"] if resource_relationship: @@ -460,9 +460,7 @@ class VNF(Resource): :policy_name: name of the policy, matching onap-client.conf """ - oc = Client() - - policy = oc.config.sdc.POLICIES.get(policy_name) + policy = self.oc.config.sdc.POLICIES.get(policy_name) if not policy: raise exceptions.UnknownPolicyException( "Policy {} was not found in configuration file".format(policy_name) @@ -497,8 +495,9 @@ class VNF(Resource): return self.tosca -def update_vnf(catalog_resource_id, vnf_input): - oc = Client() +def update_vnf(catalog_resource_id, vnf_input, oc=None): + if not oc: + oc = Client() existing_vnf = oc.sdc.vnf.get_catalog_resource( catalog_resource_id=catalog_resource_id @@ -511,7 +510,7 @@ def update_vnf(catalog_resource_id, vnf_input): new_vnf_metadata = oc.sdc.vnf.get_catalog_resource_metadata(catalog_resource_id=vnf.get("uniqueId")).response_data.get("metadata", {}) - csar_version = vsp.get_vsp_version_id(vnf.get("csarUUID"), search_key="name") + csar_version = vsp.get_vsp_version_id(vnf.get("csarUUID"), search_key="name", oc=oc) vnf["csarVersion"] = csar_version vnf["componentMetadata"] = new_vnf_metadata @@ -524,18 +523,19 @@ def update_vnf(catalog_resource_id, vnf_input): return vnf_input -def create_vnf(vnf_input): +def create_vnf(vnf_input, oc=None): """Creates a vnf object in SDC :vnf_input: dictionary with values to input for vnf creation :return: dictionary of updated values for created vnf """ - oc = Client() + if not oc: + oc = Client() - software_product_id = vsp.get_vsp_id(vnf_input.get("software_product_name")) - software_product_version_id = vsp.get_vsp_version_id(software_product_id) - vsp_model = vsp.get_vsp_model(software_product_id, software_product_version_id) + software_product_id = vsp.get_vsp_id(vnf_input.get("software_product_name"), oc=oc) + software_product_version_id = vsp.get_vsp_version_id(software_product_id, oc=oc) + vsp_model = vsp.get_vsp_model(software_product_id, software_product_version_id, oc=oc) vsp_vendor = vsp_model.get("vendorName") vsp_category = vsp_model.get("category") @@ -547,7 +547,7 @@ def create_vnf(vnf_input): vnf_input["vendor_name"] = vsp_vendor vnf_input["vnf_description"] = vnf_input.get("description") - category = get_resource_category(vsp_category) + category = get_resource_category(vsp_category, oc=oc) vsp_sub_categories = [] for subcategory in category.get("subcategories", []): if subcategory.get("uniqueId").lower() == vsp_sub_category.lower(): @@ -555,7 +555,7 @@ def create_vnf(vnf_input): break category["subcategories"] = vsp_sub_categories - vnf_input["contact_id"] = vsp.get_vsp_owner(software_product_id) + vnf_input["contact_id"] = vsp.get_vsp_owner(software_product_id, oc=oc) vnf = oc.sdc.vnf.add_catalog_resource(**vnf_input, categories=[category]) @@ -611,7 +611,7 @@ def network_role_property_for_instance(network_role_tag, vnf_model, instance_id) return properties -def add_resource(parent_resource_id, catalog_resource_id, catalog_resource_name, origin_type="VF"): +def add_resource(parent_resource_id, catalog_resource_id, catalog_resource_name, origin_type="VF", oc=None): """Attaches a resource to a VNF in SDC :catalog_resource_id: ID of a resource in the SDC catalog @@ -619,7 +619,8 @@ def add_resource(parent_resource_id, catalog_resource_id, catalog_resource_name, :origin_type: specifies the origin of the attached resource """ - oc = Client() + if not oc: + oc = Client() milli_timestamp = int(time.time() * 1000) @@ -642,17 +643,20 @@ def add_resource(parent_resource_id, catalog_resource_id, catalog_resource_name, @utility -def get_vnf(vnf_name): +def get_vnf(vnf_name, oc=None): """Queries SDC for the TOSCA model for a VNF""" - oc = Client() + if not oc: + oc = Client() return oc.sdc.vnf.get_catalog_resource( - catalog_resource_id=get_vnf_id(vnf_name) + catalog_resource_id=get_vnf_id(vnf_name, oc=oc) ).response_data -def get_resource_category(category_name): - oc = Client() +def get_resource_category(category_name, oc=None): + if not oc: + oc = Client() + resource_categories = oc.sdc.get_resource_categories().response_data for category in resource_categories: if category.get("uniqueId").lower() == category_name.lower(): @@ -660,8 +664,9 @@ def get_resource_category(category_name): return None -def get_vnf_id(vnf_name): - oc = Client() +def get_vnf_id(vnf_name, oc=None): + if not oc: + oc = Client() response = oc.sdc.vnf.get_resources() results = response.response_data.get("resources", []) diff --git a/onap-client/onap_client/sdc/vsp.py b/onap-client/onap_client/sdc/vsp.py index 365c628..3a8dcde 100644 --- a/onap-client/onap_client/sdc/vsp.py +++ b/onap-client/onap_client/sdc/vsp.py @@ -81,11 +81,11 @@ class VSP(Resource): """Creates a vsp object in SDC""" vsp = None - existing = get_vsp(vsp_input.get("software_product_name")) + existing = get_vsp(vsp_input.get("software_product_name"), oc=self.oc) if not existing: - vsp = create_vsp(vsp_input) + vsp = create_vsp(vsp_input, oc=self.oc) elif vsp_input.get("allow_update"): - vsp = update_vsp(existing, vsp_input) + vsp = update_vsp(existing, vsp_input, oc=self.oc) else: raise ResourceAlreadyExistsException( "VSP resource {} already exists".format( @@ -128,13 +128,14 @@ class VSP(Resource): return self.tosca -def update_vsp(existing_vsp, vsp_input): - oc = Client() +def update_vsp(existing_vsp, vsp_input, oc=None): + if not oc: + oc = Client() existing_vsp_id = existing_vsp.get("id") existing_vsp_version_id = existing_vsp.get("version") - if get_vsp_version_id(existing_vsp_id, search_key="status") == "Certified": + if get_vsp_version_id(existing_vsp_id, search_key="status", oc=oc) == "Certified": oc.sdc.vsp.update_software_product( software_product_id=existing_vsp_id, software_product_version_id=existing_vsp_version_id, @@ -142,7 +143,7 @@ def update_vsp(existing_vsp, vsp_input): ) vsp_input["software_product_id"] = existing_vsp_id - vsp_input["software_product_version_id"] = get_vsp_version_id(existing_vsp_id) + vsp_input["software_product_version_id"] = get_vsp_version_id(existing_vsp_id, oc=oc) oc.sdc.vsp.upload_heat_package(**vsp_input) oc.sdc.vsp.validate_software_product(**vsp_input) @@ -153,27 +154,38 @@ def update_vsp(existing_vsp, vsp_input): return vsp_input -def create_vsp(vsp_input): +def create_vsp(vsp_input, oc=None): """Creates a VSP object in SDC :vsp_input: dictionary with values to input for vsp creation :return: dictionary of updated values for created vsp """ - oc = Client() + if not oc: + oc = Client() - license_model_id = sdc.license_model.get_license_model_id(vsp_input.get("license_model_name")) + license_model_id = sdc.license_model.get_license_model_id( + vsp_input.get("license_model_name"), + oc=oc + ) license_model_version_id = sdc.license_model.get_license_model_version_id( - license_model_id + license_model_id, + oc=oc ) feature_group = sdc.license_model.get_license_model_attribute( - license_model_id, license_model_version_id, "feature-groups" + license_model_id, + license_model_version_id, + "feature-groups", + oc=oc ) license_agreement = sdc.license_model.get_license_model_attribute( - license_model_id, license_model_version_id, "license-agreements" + license_model_id, + license_model_version_id, + "license-agreements", + oc=oc ) vsp_input["license_model_id"] = license_model_id @@ -195,14 +207,15 @@ def create_vsp(vsp_input): return vsp_input -def get_vsp_id(vsp_name): +def get_vsp_id(vsp_name, oc=None): """GETs vsp model ID from SDC :vsp_name: name of vsp model in SDC :return: id of vsp or None """ - oc = Client() + if not oc: + oc = Client() response = oc.sdc.vsp.get_software_products() results = response.response_data.get("results", {}) @@ -212,14 +225,15 @@ def get_vsp_id(vsp_name): return None -def get_vsp_version_id(vsp_id, search_key="id"): +def get_vsp_version_id(vsp_id, search_key="id", oc=None): """GETs vsp model version UUID from SDC :vsp_id: uuid of vsp model in SDC :return: uuid of vsp version id or None """ - oc = Client() + if not oc: + oc = Client() vsp_version_id = None creation_time = -1 @@ -233,16 +247,19 @@ def get_vsp_version_id(vsp_id, search_key="id"): return vsp_version_id -def get_vsp_model(vsp_id, vsp_version_id): - oc = Client() +def get_vsp_model(vsp_id, vsp_version_id, oc=None): + if not oc: + oc = Client() return oc.sdc.vsp.get_software_product( software_product_id=vsp_id, software_product_version_id=vsp_version_id, ).response_data -def get_vsp_owner(vsp_id): - oc = Client() +def get_vsp_owner(vsp_id, oc=None): + if not oc: + oc = Client() + vsps = oc.sdc.vsp.get_software_products().response_data.get("results", []) for vsp in vsps: if vsp.get("id") == vsp_id: @@ -251,13 +268,16 @@ def get_vsp_owner(vsp_id): @utility -def get_vsp(vsp_name): +def get_vsp(vsp_name, oc=None): """Queries SDC for the tosca model for a VSP""" - vsp_id = get_vsp_id(vsp_name) + if not oc: + oc = Client() + + vsp_id = get_vsp_id(vsp_name, oc=oc) if vsp_id is None: return None - vsp_version_id = get_vsp_version_id(vsp_id) - return get_vsp_model(vsp_id, vsp_version_id) + vsp_version_id = get_vsp_version_id(vsp_id, oc=oc) + return get_vsp_model(vsp_id, vsp_version_id, oc=oc) def user_exists(contributer, vsp_permissions, permission="Contributor"): |