aboutsummaryrefslogtreecommitdiffstats
path: root/onap-client/onap_client/sdc
diff options
context:
space:
mode:
Diffstat (limited to 'onap-client/onap_client/sdc')
-rw-r--r--onap-client/onap_client/sdc/license_model.py30
-rw-r--r--onap-client/onap_client/sdc/service.py62
-rw-r--r--onap-client/onap_client/sdc/tests/test_license_model.py16
-rw-r--r--onap-client/onap_client/sdc/tests/test_service.py23
-rw-r--r--onap-client/onap_client/sdc/tests/test_vnf.py8
-rw-r--r--onap-client/onap_client/sdc/tests/test_vsp.py17
-rw-r--r--onap-client/onap_client/sdc/vnf.py99
-rw-r--r--onap-client/onap_client/sdc/vsp.py93
8 files changed, 111 insertions, 237 deletions
diff --git a/onap-client/onap_client/sdc/license_model.py b/onap-client/onap_client/sdc/license_model.py
index 591509e..52846c1 100644
--- a/onap-client/onap_client/sdc/license_model.py
+++ b/onap-client/onap_client/sdc/license_model.py
@@ -48,7 +48,7 @@ class LicenseModel(Resource):
"required": False,
"default": generate_dummy_string("test_vendor_"),
},
- "mfr_ref_number": {
+ "manufacturer_reference_number": {
"type": str,
"required": False,
"default": generate_dummy_string("mfref"),
@@ -85,38 +85,10 @@ class LicenseModel(Resource):
},
}
- def __init__(
- self,
- vendor_name,
- mfr_ref_number,
- entitlement_pool_name,
- key_group_name,
- feature_group_name,
- license_agreement_name,
- license_start_date,
- license_end_date,
- ):
- self.oc = Client()
-
- license_input = {}
- license_input["vendor_name"] = vendor_name
- license_input["manufacturer_reference_number"] = mfr_ref_number
- license_input["entitlement_pool_name"] = entitlement_pool_name
- license_input["key_group_name"] = key_group_name
- license_input["feature_group_name"] = feature_group_name
- license_input["license_agreement_name"] = license_agreement_name
- license_input["license_start_date"] = license_start_date
- license_input["license_end_date"] = license_end_date
-
- super().__init__(license_input)
-
def _create(self, license_input):
"""Creates a license model object in SDC"""
return create_license_model(license_input)
- def _post_create(self):
- pass
-
def _submit(self):
"""Submits the license model in SDC"""
diff --git a/onap-client/onap_client/sdc/service.py b/onap-client/onap_client/sdc/service.py
index 8b9c68b..8eec31a 100644
--- a/onap-client/onap_client/sdc/service.py
+++ b/onap-client/onap_client/sdc/service.py
@@ -117,53 +117,6 @@ class Service(Resource):
"wait_for_distribution": {"type": bool, "required": False, "default": False},
}
- def __init__(
- self,
- instantiation_type,
- service_name,
- contact_id,
- category_name,
- tag,
- project_code,
- environment_context,
- ecomp_generated_naming,
- description,
- service_type,
- service_role,
- naming_policy,
- resources=[],
- wait_for_distribution=False,
- allow_update=False,
- ):
- self.oc = Client()
-
- service_input = {}
-
- category_name_lower = category_name.lower()
- category_name_icon = normalize_category_icon(category_name)
- category_id = "serviceNewCategory.{}".format(category_name_lower)
-
- service_input["service_name"] = service_name
- service_input["instantiation_type"] = instantiation_type
- service_input["contact_id"] = contact_id
- service_input["category_name"] = category_name
- service_input["category_id"] = category_id
- service_input["category_name_lower"] = category_name_lower
- service_input["category_name_icon"] = category_name_icon
- service_input["tag"] = tag
- service_input["project_code"] = project_code
- service_input["environment_context"] = environment_context
- service_input["ecomp_generated_naming"] = ecomp_generated_naming
- service_input["description"] = description
- service_input["service_type"] = service_type
- service_input["service_role"] = service_role
- service_input["naming_policy"] = naming_policy
- service_input["resources"] = resources
- service_input["wait_for_distribution"] = wait_for_distribution
- service_input["allow_update"] = allow_update
-
- super().__init__(service_input)
-
def _create(self, service_input):
"""Creates a service object in SDC"""
service = None
@@ -372,14 +325,19 @@ def create_service(service_input):
"""
oc = Client()
- kwargs = service_input
+ category_name_lower = service_input.get("category_name").lower()
+ category_name_icon = normalize_category_icon(service_input.get("category_name"))
+ category_id = "serviceNewCategory.{}".format(category_name_lower)
+ service_input["category_id"] = category_id
+ service_input["category_name_lower"] = category_name_lower
+ service_input["category_name_icon"] = category_name_icon
- service = oc.sdc.service.add_catalog_service(**kwargs)
+ service = oc.sdc.service.add_catalog_service(**service_input)
- kwargs["catalog_service_id"] = service.catalog_service_id
- kwargs["tosca"] = service.response_data
+ service_input["catalog_service_id"] = service.catalog_service_id
+ service_input["tosca"] = service.response_data
- return kwargs
+ return service_input
@utility
diff --git a/onap-client/onap_client/sdc/tests/test_license_model.py b/onap-client/onap_client/sdc/tests/test_license_model.py
index 8da7d07..e9ca735 100644
--- a/onap-client/onap_client/sdc/tests/test_license_model.py
+++ b/onap-client/onap_client/sdc/tests/test_license_model.py
@@ -110,14 +110,14 @@ def test_license_model_create():
)
lm = LicenseModel(
- VENDOR_NAME,
- "abc123",
- "entitlement_pool_name",
- "key_group_name",
- "feature_group_name",
- "license_agreement_name",
- "license_start_date",
- "license_end_date",
+ vendor_name=VENDOR_NAME,
+ entitlement_pool_name="entitlement_pool_name",
+ key_group_name="key_group_name",
+ feature_group_name="feature_group_name",
+ license_agreement_name="license_agreement_name",
+ license_start_date="license_start_date",
+ license_end_date="license_end_date",
)
+ lm.create()
assert lm.tosca == return_data
diff --git a/onap-client/onap_client/sdc/tests/test_service.py b/onap-client/onap_client/sdc/tests/test_service.py
index e4789a5..77eadbd 100644
--- a/onap-client/onap_client/sdc/tests/test_service.py
+++ b/onap-client/onap_client/sdc/tests/test_service.py
@@ -104,18 +104,15 @@ def test_vnf_create():
)
service = Service(
- "A-la-carte",
- SERVICE_NAME,
- "cs0008",
- "Network L1-3",
- "robot",
- "123456",
- "General_Revenue-Bearing",
- "true",
- "This is a test",
- "",
- "",
- "",
+ instantiation_type="A-la-carte",
+ service_name=SERVICE_NAME,
+ contact_id="cs0008",
+ category_name="Network L1-3",
+ tag="robot",
+ project_code="123456",
+ environment_context="General_Revenue-Bearing",
+ ecomp_generated_naming="true",
+ description="This is a test",
resources=[{
"resource_name": VNF_NAME,
"resource_id": VNF_RESOURCE_ID,
@@ -126,7 +123,7 @@ def test_vnf_create():
allow_update=False,
wait_for_distribution=False
)
-
+ service.create()
service._submit()
assert service.service_name == SERVICE_NAME
diff --git a/onap-client/onap_client/sdc/tests/test_vnf.py b/onap-client/onap_client/sdc/tests/test_vnf.py
index dfa5af1..da3dd86 100644
--- a/onap-client/onap_client/sdc/tests/test_vnf.py
+++ b/onap-client/onap_client/sdc/tests/test_vnf.py
@@ -145,12 +145,12 @@ def test_vnf_create():
)
vnf = VNF(
- SOFTWARE_PRODUCT_NAME,
- VNF_NAME,
- RESOURCE_TYPE,
+ software_product_name=SOFTWARE_PRODUCT_NAME,
+ vnf_name=VNF_NAME,
+ resource_type=RESOURCE_TYPE,
vm_types=[{"vm_type": "red", "properties": {"nf_role": "blue"}}],
)
-
+ vnf.create()
vnf._submit()
assert "componentInstancesInputs" in vnf.tosca
diff --git a/onap-client/onap_client/sdc/tests/test_vsp.py b/onap-client/onap_client/sdc/tests/test_vsp.py
index f14e16e..cd35a90 100644
--- a/onap-client/onap_client/sdc/tests/test_vsp.py
+++ b/onap-client/onap_client/sdc/tests/test_vsp.py
@@ -102,15 +102,16 @@ def test_vsp_create():
mockup_client(oc.sdc.vsp)
vsp = sdc.vsp.VSP(
- "vendor_name",
- LICENSE_MODEL_NAME,
- "{}/test.zip".format(THIS_DIR),
- "application/zip",
- VSP_NAME,
- "description",
- "category",
- "sub_category",
+ vendor_name="vendor_name",
+ license_model_name=LICENSE_MODEL_NAME,
+ file_path="{}/test.zip".format(THIS_DIR),
+ file_type="application/zip",
+ software_product_name=VSP_NAME,
+ description="description",
+ category="category",
+ sub_category="sub_category",
contributers=["test123"],
)
+ vsp.create()
assert vsp.tosca == {"name": VSP_NAME}
diff --git a/onap-client/onap_client/sdc/vnf.py b/onap-client/onap_client/sdc/vnf.py
index f1ccb51..03b5c54 100644
--- a/onap-client/onap_client/sdc/vnf.py
+++ b/onap-client/onap_client/sdc/vnf.py
@@ -122,45 +122,6 @@ class VNF(Resource):
"allow_update": {"type": bool, "required": False, "default": False},
}
- def __init__(
- self,
- software_product_name,
- vnf_name,
- resource_type,
- inputs={},
- vm_types=[],
- network_roles=[],
- policies=[],
- allow_update=False,
- description="VNF",
- ):
- self.oc = Client()
-
- vnf_input = {}
-
- software_product_id = vsp.get_vsp_id(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)
-
- vsp_vendor = vsp_model.get("vendorName")
- vsp_category = vsp_model.get("category")
- vsp_sub_category = vsp_model.get("subCategory")
-
- vnf_input["software_product_id"] = software_product_id
- vnf_input["vsp_category"] = vsp_category
- vnf_input["vsp_sub_category"] = vsp_sub_category
- vnf_input["vendor_name"] = vsp_vendor
- vnf_input["vnf_name"] = vnf_name
- vnf_input["resource_type"] = resource_type
- vnf_input["inputs"] = inputs
- vnf_input["vm_types"] = vm_types
- vnf_input["network_roles"] = network_roles
- vnf_input["policies"] = policies
- vnf_input["allow_update"] = allow_update
- vnf_input["vnf_description"] = description
-
- super().__init__(vnf_input)
-
def _create(self, vnf_input):
"""Creates a vnf object in SDC"""
vnf = None
@@ -208,6 +169,18 @@ class VNF(Resource):
for k, v in inputs.items():
self.add_input_value(k, v)
+ def _submit(self):
+ """Submits the vnf in SDC"""
+ certification = self.oc.sdc.vnf.certify_catalog_resource(
+ **self.attributes, user_remarks="Ready!"
+ )
+ self.attributes["catalog_resource_id"] = certification.catalog_resource_id
+
+ vnf = self.oc.sdc.vnf.get_catalog_resource(**self.attributes)
+
+ self.attributes["catalog_resource_name"] = vnf.catalog_resource_name
+ self.attributes["tosca"] = vnf.response_data
+
def _add_instance_properties(self, instance_id, properties_dict):
for k, v in properties_dict.items():
# updating vm_type properties
@@ -322,18 +295,6 @@ class VNF(Resource):
return False
- def _submit(self):
- """Submits the vnf in SDC"""
- certification = self.oc.sdc.vnf.certify_catalog_resource(
- **self.attributes, user_remarks="Ready!"
- )
- self.attributes["catalog_resource_id"] = certification.catalog_resource_id
-
- vnf = self.oc.sdc.vnf.get_catalog_resource(**self.attributes)
-
- self.attributes["catalog_resource_name"] = vnf.catalog_resource_name
- self.attributes["tosca"] = vnf.response_data
-
def add_input_value(self, input_name, input_default_value):
"""Updates an input value on a VNF
@@ -548,24 +509,36 @@ def create_vnf(vnf_input):
"""
oc = Client()
- kwargs = vnf_input
+ 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)
- category = get_resource_category(kwargs.get("vsp_category"))
- vsp_sub_category = []
+ vsp_vendor = vsp_model.get("vendorName")
+ vsp_category = vsp_model.get("category")
+ vsp_sub_category = vsp_model.get("subCategory")
+
+ vnf_input["software_product_id"] = software_product_id
+ vnf_input["vsp_category"] = vsp_category
+ vnf_input["vsp_sub_category"] = vsp_sub_category
+ vnf_input["vendor_name"] = vsp_vendor
+ vnf_input["vnf_description"] = vnf_input.get("description")
+
+ category = get_resource_category(vsp_category)
+ vsp_sub_categories = []
for subcategory in category.get("subcategories", []):
- if subcategory.get("uniqueId") == kwargs.get("vsp_sub_category"):
- vsp_sub_category.append(subcategory)
+ if subcategory.get("uniqueId").lower() == vsp_sub_category.lower():
+ vsp_sub_categories.append(subcategory)
break
- category["subcategories"] = vsp_sub_category
- kwargs["contact_id"] = vsp.get_vsp_owner(kwargs.get("software_product_id"))
+ category["subcategories"] = vsp_sub_categories
+ vnf_input["contact_id"] = vsp.get_vsp_owner(software_product_id)
- vnf = oc.sdc.vnf.add_catalog_resource(**kwargs, categories=[category])
+ vnf = oc.sdc.vnf.add_catalog_resource(**vnf_input, categories=[category])
- kwargs["catalog_resource_id"] = vnf.catalog_resource_id
- kwargs["tosca"] = vnf.response_data
+ vnf_input["catalog_resource_id"] = vnf.catalog_resource_id
+ vnf_input["tosca"] = vnf.response_data
- return kwargs
+ return vnf_input
def instance_ids_for_property(vnf_model, property_name, property_value):
@@ -657,7 +630,7 @@ def get_resource_category(category_name):
oc = Client()
resource_categories = oc.sdc.get_resource_categories().response_data
for category in resource_categories:
- if category.get("uniqueId") == category_name:
+ if category.get("uniqueId").lower() == category_name.lower():
return category
return None
diff --git a/onap-client/onap_client/sdc/vsp.py b/onap-client/onap_client/sdc/vsp.py
index cd478e1..de47277 100644
--- a/onap-client/onap_client/sdc/vsp.py
+++ b/onap-client/onap_client/sdc/vsp.py
@@ -72,64 +72,19 @@ class VSP(Resource):
"allow_update": {"type": bool, "required": False, "default": False},
}
- def __init__(
- self,
- vendor_name,
- license_model_name,
- file_path,
- file_type,
- software_product_name,
- description,
- category,
- sub_category,
- contributers=[],
- allow_update=False,
- owner="",
- ):
- self.oc = Client()
- vsp_input = {}
-
- license_model_id = sdc.license_model.get_license_model_id(license_model_name)
- license_model_version_id = sdc.license_model.get_license_model_version_id(
- license_model_id
- )
- feature_group = sdc.license_model.get_license_model_attribute(
- license_model_id, license_model_version_id, "feature-groups"
- )
- license_agreement = sdc.license_model.get_license_model_attribute(
- license_model_id, license_model_version_id, "license-agreements"
- )
-
- vsp_input["software_product_name"] = software_product_name
- vsp_input["feature_group_id"] = feature_group["id"]
- vsp_input["license_agreement_id"] = license_agreement["id"]
- vsp_input["vendor_name"] = vendor_name
- vsp_input["license_model_id"] = license_model_id
- vsp_input["license_model_version_id"] = license_model_version_id
- vsp_input["file_path"] = file_path
- vsp_input["file_type"] = file_type
- vsp_input["description"] = description
- vsp_input["category"] = category.lower()
- vsp_input["sub_category"] = sub_category.lower()
- vsp_input["contributers"] = contributers
- vsp_input["allow_update"] = allow_update
- vsp_input["owner"] = owner
-
- super().__init__(vsp_input)
-
- def _create(self, kwargs):
+ def _create(self, vsp_input):
"""Creates a vsp object in SDC"""
vsp = None
- existing = get_vsp(kwargs.get("software_product_name"))
+ existing = get_vsp(vsp_input.get("software_product_name"))
if not existing:
- vsp = create_vsp(kwargs)
- elif kwargs.get("allow_update"):
- vsp = update_vsp(existing, kwargs)
+ vsp = create_vsp(vsp_input)
+ elif vsp_input.get("allow_update"):
+ vsp = update_vsp(existing, vsp_input)
else:
raise ResourceAlreadyExistsException(
"VSP resource {} already exists".format(
- kwargs.get("software_product_name")
+ vsp_input.get("software_product_name")
)
)
@@ -199,19 +154,37 @@ def create_vsp(vsp_input):
"""
oc = Client()
- kwargs = vsp_input
- vsp = oc.sdc.vsp.add_software_product(**kwargs)
+ license_model_id = sdc.license_model.get_license_model_id(vsp_input.get("license_model_name"))
+
+ license_model_version_id = sdc.license_model.get_license_model_version_id(
+ license_model_id
+ )
+
+ feature_group = sdc.license_model.get_license_model_attribute(
+ license_model_id, license_model_version_id, "feature-groups"
+ )
+
+ license_agreement = sdc.license_model.get_license_model_attribute(
+ license_model_id, license_model_version_id, "license-agreements"
+ )
- kwargs["software_product_id"] = vsp.software_product_id
- kwargs["software_product_version_id"] = vsp.software_product_version_id
+ vsp_input["license_model_id"] = license_model_id
+ vsp_input["license_model_version_id"] = license_model_version_id
+ vsp_input["feature_group_id"] = feature_group["id"]
+ vsp_input["license_agreement_id"] = license_agreement["id"]
- oc.sdc.vsp.upload_heat_package(**kwargs)
- oc.sdc.vsp.validate_software_product(**kwargs)
+ vsp = oc.sdc.vsp.add_software_product(**vsp_input)
- vsp = oc.sdc.vsp.get_software_product(**kwargs)
- kwargs["tosca"] = vsp.response_data
+ vsp_input["software_product_id"] = vsp.software_product_id
+ vsp_input["software_product_version_id"] = vsp.software_product_version_id
- return kwargs
+ oc.sdc.vsp.upload_heat_package(**vsp_input)
+ oc.sdc.vsp.validate_software_product(**vsp_input)
+
+ vsp = oc.sdc.vsp.get_software_product(**vsp_input)
+ vsp_input["tosca"] = vsp.response_data
+
+ return vsp_input
def get_vsp_id(vsp_name):