def test_from_vnf_instance_with_flavour(self):
        """Map flavour id"""

        inst_vnf_request = objects.InstantiateVnfRequest(flavour_id="simple")

        instantiated_vnf_info = objects.InstantiatedVnfInfo(
            flavour_id="simple")

        vnf_instance = self._create_vnf_instance()
        vnf_instance.instantiated_vnf_info = instantiated_vnf_info

        inst_vnf_request_actual = objects.InstantiateVnfRequest.\
            from_vnf_instance(vnf_instance)

        self.compare_obj(inst_vnf_request, inst_vnf_request_actual)
Beispiel #2
0
def get_vnf_instantiated_info(flavour_id='simple',
                              instantiation_level_id=None,
                              vnfc_resource_info=None,
                              virtual_storage_resource_info=None,
                              vnf_virtual_link_resource_info=None,
                              ext_managed_virtual_link_info=None):

    vnfc_resource_info = vnfc_resource_info or []
    vnf_virtual_link_resource_info = vnf_virtual_link_resource_info or []
    virtual_storage_resource_info = virtual_storage_resource_info or []
    ext_managed_virtual_link_info = ext_managed_virtual_link_info or []

    inst_vnf_info = objects.InstantiatedVnfInfo(
        flavour_id=flavour_id,
        instantiation_level_id=instantiation_level_id,
        instance_id=uuidsentinel.instance_id,
        vnfc_resource_info=vnfc_resource_info,
        vnf_virtual_link_resource_info=vnf_virtual_link_resource_info,
        virtual_storage_resource_info=virtual_storage_resource_info,
        ext_managed_virtual_link_info=ext_managed_virtual_link_info)

    return inst_vnf_info
Beispiel #3
0
    def _instantiate_vnf(self, context, vnf_instance, vim_connection_info,
                         instantiate_vnf_req):
        vnfd_dict = vnflcm_utils._get_vnfd_dict(context, vnf_instance.vnfd_id,
                                                instantiate_vnf_req.flavour_id)
        base_hot_dict = vnflcm_utils._get_base_hot_dict(
            context, vnf_instance.vnfd_id)
        vnf_package_path = None
        if base_hot_dict is not None:
            vnf_package_path = vnflcm_utils._get_vnf_package_path(
                context, vnf_instance.vnfd_id)

        param_for_subs_map = vnflcm_utils._get_param_data(
            vnfd_dict, instantiate_vnf_req)

        package_uuid = vnflcm_utils._get_vnf_package_id(
            context, vnf_instance.vnfd_id)
        vnf_software_images = vnflcm_utils._create_grant_request(
            vnfd_dict, package_uuid)
        vnf_resources = self._vnf_manager.invoke(
            vim_connection_info.vim_type,
            'pre_instantiation_vnf',
            context=context,
            vnf_instance=vnf_instance,
            vim_connection_info=vim_connection_info,
            vnf_software_images=vnf_software_images)

        # save the vnf resources in the db
        for _, resources in vnf_resources.items():
            for vnf_resource in resources:
                vnf_resource.create()

        vnfd_dict_to_create_final_dict = copy.deepcopy(vnfd_dict)
        final_vnf_dict = vnflcm_utils._make_final_vnf_dict(
            vnfd_dict_to_create_final_dict, vnf_instance.id,
            vnf_instance.vnf_instance_name, param_for_subs_map)

        try:
            instance_id = self._vnf_manager.invoke(
                vim_connection_info.vim_type,
                'instantiate_vnf',
                context=context,
                vnf_instance=vnf_instance,
                vnfd_dict=final_vnf_dict,
                grant_response=vnf_resources,
                vim_connection_info=vim_connection_info,
                base_hot_dict=base_hot_dict,
                vnf_package_path=vnf_package_path,
                instantiate_vnf_req=instantiate_vnf_req)
        except Exception as exp:
            with excutils.save_and_reraise_exception():
                exp.reraise = False
                LOG.error(
                    "Unable to instantiate vnf instance "
                    "%(id)s due to error : %(error)s", {
                        "id": vnf_instance.id,
                        "error": encodeutils.exception_to_unicode(exp)
                    })
                raise exceptions.VnfInstantiationFailed(
                    id=vnf_instance.id,
                    error=encodeutils.exception_to_unicode(exp))

        vnf_instance.instantiated_vnf_info = objects.InstantiatedVnfInfo(
            flavour_id=instantiate_vnf_req.flavour_id,
            instantiation_level_id=instantiate_vnf_req.instantiation_level_id,
            vnf_instance_id=vnf_instance.id,
            instance_id=instance_id,
            ext_cp_info=[])

        try:
            self._vnf_manager.invoke(vim_connection_info.vim_type,
                                     'create_wait',
                                     plugin=self,
                                     context=context,
                                     vnf_dict=final_vnf_dict,
                                     vnf_id=final_vnf_dict['instance_id'],
                                     auth_attr=vim_connection_info.access_info)

        except Exception as exp:
            with excutils.save_and_reraise_exception():
                exp.reraise = False
                LOG.error(
                    "Vnf creation wait failed for vnf instance "
                    "%(id)s due to error : %(error)s", {
                        "id": vnf_instance.id,
                        "error": encodeutils.exception_to_unicode(exp)
                    })
                raise exceptions.VnfInstantiationWaitFailed(
                    id=vnf_instance.id,
                    error=encodeutils.exception_to_unicode(exp))

        vnflcm_utils._build_instantiated_vnf_info(vnfd_dict,
                                                  instantiate_vnf_req,
                                                  vnf_instance,
                                                  vim_connection_info.vim_id)

        self._vnf_manager.invoke(vim_connection_info.vim_type,
                                 'post_vnf_instantiation',
                                 context=context,
                                 vnf_instance=vnf_instance,
                                 vim_connection_info=vim_connection_info)
Beispiel #4
0
def return_vnf_instance(
        instantiated_state=fields.VnfInstanceState.NOT_INSTANTIATED,
        scale_status=None,
        **updates):

    if instantiated_state == fields.VnfInstanceState.NOT_INSTANTIATED:
        data = _model_non_instantiated_vnf_instance(**updates)
        data['instantiation_state'] = instantiated_state
        vnf_instance_obj = objects.VnfInstance(**data)

    elif scale_status:
        data = _model_non_instantiated_vnf_instance(**updates)
        data['instantiation_state'] = instantiated_state
        vnf_instance_obj = objects.VnfInstance(**data)

        get_instantiated_vnf_info = {
            'flavour_id': uuidsentinel.flavour_id,
            'vnf_state': 'STARTED',
            'instance_id': uuidsentinel.instance_id
        }
        instantiated_vnf_info = get_instantiated_vnf_info

        s_status = {"aspect_id": "SP1", "scale_level": 1}
        scale_status = objects.ScaleInfo(**s_status)

        instantiated_vnf_info.update({
            "ext_cp_info": [],
            'ext_virtual_link_info': [],
            'ext_managed_virtual_link_info': [],
            'vnfc_resource_info': [],
            'vnf_virtual_link_resource_info': [],
            'virtual_storage_resource_info': [],
            "flavour_id": "simple",
            "scale_status": [scale_status],
            "vnf_instance_id": "171f3af2-a753-468a-b5a7-e3e048160a79",
            "additional_params": {
                "key": "value"
            },
            'vnf_state': "STARTED"
        })
        info_data = objects.InstantiatedVnfInfo(**instantiated_vnf_info)

        vnf_instance_obj.instantiated_vnf_info = info_data
    else:
        data = _model_non_instantiated_vnf_instance(**updates)
        data['instantiation_state'] = instantiated_state
        vnf_instance_obj = objects.VnfInstance(**data)
        inst_vnf_info = objects.InstantiatedVnfInfo.obj_from_primitive(
            {
                "ext_cp_info": [],
                'ext_virtual_link_info': [],
                'ext_managed_virtual_link_info': [],
                'vnfc_resource_info': [],
                'vnf_virtual_link_resource_info': [],
                'virtual_storage_resource_info': [],
                "flavour_id": "simple",
                "additional_params": {
                    "key": "value"
                },
                'vnf_state': "STARTED"
            }, None)

        vnf_instance_obj.instantiated_vnf_info = inst_vnf_info

    return vnf_instance_obj