Example #1
0
    def _add_resources(self, instance_id, resources_dict, resource_name_index=""):
        for resource in resources_dict:
            resource_name = resource.get("resource_name")
            if resource_name_index:
                resource_name = "{}-{}".format(resource_name, resource_name_index)

            if self.resource_exists(resource_name):
                continue

            catalog_resource_name = resource.get("catalog_resource_name")
            resource_id = resource.get("resource_id")
            resource_origin = resource.get("origin_type")
            resource_relationship = resource.get("relationship", {})

            if not resource_id:
                resource_id = get_vnf_id(catalog_resource_name)
                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)
            self._refresh()
            new_resource_id = new_resource["id"]
            if resource_relationship:
                relationship_type = resource_relationship.get("relationship_type")
                relationship_requirement = resource_relationship.get("requirement")
                relationship_requirement_id = resource_relationship.get("requirement_id")
                self.add_resource_relationship(new_resource_id, instance_id, relationship_type, relationship_requirement, relationship_requirement_id)
                for k, v in resource_relationship.get("properties", {}).items():
                    self.add_instance_property_non_vf(new_resource_id, k, v, origin_section="componentInstancesProperties")
Example #2
0
    def _post_create(self):
        resources = self.resources

        for resource in resources:
            resource_name = resource.get("resource_name")
            catalog_resource_name = resource.get("catalog_resource_name")
            resource_id = resource.get("resource_id")
            resource_properties = resource.get("properties")
            if not resource_id:
                resource_id = get_vnf_id(catalog_resource_name)
                if not resource_id:
                    raise exceptions.ResourceIDNotFoundException(
                        "resource ID was not passed, and resource lookup by name was not found {}"
                        .format(resource_name))
            resource_origin = resource.get("origin_type")
            self.add_resource(resource_id,
                              resource_name,
                              origin_type=resource_origin)
            for k, v in resource_properties.items():
                if isinstance(v, dict):
                    v = json.dumps(v).replace('"', '\\"')
                self.add_property_value(resource_name, k, v)

            if resource.get("deployment_properties"):
                self.update_resource_deployment_properties(
                    resource_name, resource.get("deployment_properties"))