Example #1
0
    def _get_vnf_instance_info(self, vnf_instance):
        vnf_instance_dict = vnf_instance.to_dict()
        vnf_instance_dict = utils.convert_snakecase_to_camelcase(
            vnf_instance_dict)

        links = self._get_links(vnf_instance)

        vnf_instance_dict.update(links)
        return vnf_instance_dict
Example #2
0
    def _get_vnf_lcm_op_occs(self, vnf_lcm_op_occs):
        vnf_lcm_op_occs_dict = vnf_lcm_op_occs.to_dict()
        vnf_lcm_op_occs_dict.pop('error_point')
        vnf_lcm_op_occs_dict = utils.convert_snakecase_to_camelcase(
            vnf_lcm_op_occs_dict)

        links = self._get_lcm_op_occs_links(vnf_lcm_op_occs)

        vnf_lcm_op_occs_dict.update(links)
        return vnf_lcm_op_occs_dict
Example #3
0
    def test_convert_snakecase_to_camelcase_list_with_string_items(self):
        """Conversion of snakecase to camelcase should be ignored.

        For simple list with string items, the elements which are actual
        values should be ignored during conversion
        """
        data = ["snake_case_value1", "snake_case_value2"]
        actual_val = utils.convert_snakecase_to_camelcase(data)
        expected_val = ["snake_case_value1", "snake_case_value2"]
        self.assertEqual(expected_val, actual_val)
Example #4
0
def _build_affected_resources(vnf_instance,
                              change_type=fields.ResourceChangeType.ADDED):
    '''build affected resources from vnf_instance instantiated info '''

    affected_resources = {}
    instantiated_vnf_info = vnf_instance.instantiated_vnf_info
    if hasattr(instantiated_vnf_info, 'instance_id'):
        if instantiated_vnf_info.instance_id:

            affected_resources['affectedVnfcs'] = []
            affected_resources['affectedVirtualLinks'] = []
            affected_resources['affectedVirtualStorages'] = []

            # build AffectedVnfc
            vnfc_resource_info = \
                instantiated_vnf_info.vnfc_resource_info
            for vnfc_resource in vnfc_resource_info:
                data = {}
                data['id'] = vnfc_resource.id
                data['vduId'] = vnfc_resource.vdu_id
                data['changeType'] = change_type
                data['computeResource'] = \
                    vnfc_resource.compute_resource.to_dict()
                data['metadata'] = vnfc_resource.metadata
                affected_resources['affectedVnfcs'].append(data)

            # build AffectedVirtualLink
            vnf_virtual_link = \
                instantiated_vnf_info.vnf_virtual_link_resource_info
            for vnf_vl_info in vnf_virtual_link:
                data = {}
                data['id'] = vnf_vl_info.id
                data['vnfVirtualLinkDescId'] = \
                    vnf_vl_info.vnf_virtual_link_desc_id
                data['changeType'] = change_type
                data['networkResource'] = \
                    vnf_vl_info.network_resource.to_dict()
                data['metadata'] = {}
                affected_resources['affectedVirtualLinks'].append(data)

            # build affectedVirtualStorages
            virtual_storage = \
                instantiated_vnf_info.virtual_storage_resource_info
            for vnf_storage_info in virtual_storage:
                data = {}
                data['id'] = vnf_storage_info.id
                data['virtualStorageDescId'] = \
                    vnf_storage_info.virtual_storage_desc_id
                data['changeType'] = change_type
                data['storageResource'] = \
                    vnf_storage_info.storage_resource.to_dict()
                data['metadata'] = {}
                affected_resources['affectedVirtualStorages'].append(data)

    return utils.convert_snakecase_to_camelcase(affected_resources)
Example #5
0
    def _get_vnf_instance_info(self, vnf_instance):
        vnf_instance_dict = vnf_instance.to_dict()
        vnf_metadata = vnf_instance_dict.pop("vnf_metadata")
        if vnf_metadata:
            vnf_instance_dict.update({"metadata": vnf_metadata})
        vnf_instance_dict = utils.convert_snakecase_to_camelcase(
            vnf_instance_dict)

        links = self._get_links(vnf_instance)

        vnf_instance_dict.update(links)
        return vnf_instance_dict
Example #6
0
    def _get_vnf_instance_info(self, vnf_instance, api_version=None):
        vnf_instance_dict = vnf_instance.to_dict()
        if 'vnf_metadata' in vnf_instance_dict:
            metadata_val = vnf_instance_dict.pop('vnf_metadata')
            vnf_instance_dict['metadata'] = metadata_val

        vnf_instance_dict = utils.convert_snakecase_to_camelcase(
            vnf_instance_dict)

        if api_version == "2.6.1":
            del vnf_instance_dict["vnfPkgId"]

        links = self._get_links(vnf_instance)

        vnf_instance_dict.update(links)
        return vnf_instance_dict
Example #7
0
 def test_convert_snakecase_to_camelcase_list_with_dict_items(self):
     """Only the dict keys from list should be converted to camelcase"""
     data = [{"snake_case_key": "snake_case_value"}]
     actual_val = utils.convert_snakecase_to_camelcase(data)
     expected_val = [{"snakeCaseKey": "snake_case_value"}]
     self.assertEqual(expected_val, actual_val)
Example #8
0
 def test_convert_snakecase_to_camelcase_dict(self):
     """Only the dict keys from list should be converted to camelcase"""
     actual_val = utils.convert_snakecase_to_camelcase(
         {"snake_case_key": "snake_case_value"})
     expected_val = {"snakeCaseKey": "snake_case_value"}
     self.assertEqual(expected_val, actual_val)
Example #9
0
 def to_request_body(self):
     req_dict = self.to_dict()
     req_dict = utils.convert_snakecase_to_camelcase(req_dict)
     return jsonutils.dumps(req_dict).replace('Links', '_links')