コード例 #1
0
    def create(self, request, body):
        context = request.environ['tacker.context']
        context.can(vnf_lcm_policies.VNFLCM % 'create')

        req_body = utils.convert_camelcase_to_snakecase(body)
        vnfd_id = req_body.get('vnfd_id')
        try:
            vnfd = objects.VnfPackageVnfd.get_by_id(request.context, vnfd_id)
        except exceptions.VnfPackageVnfdNotFound as exc:
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(exc))

        vnf_instance = objects.VnfInstance(
            context=request.context,
            vnf_instance_name=req_body.get('vnf_instance_name'),
            vnf_instance_description=req_body.get('vnf_instance_description'),
            vnfd_id=vnfd_id,
            instantiation_state=fields.VnfInstanceState.NOT_INSTANTIATED,
            vnf_provider=vnfd.vnf_provider,
            vnf_product_name=vnfd.vnf_product_name,
            vnf_software_version=vnfd.vnf_software_version,
            vnfd_version=vnfd.vnfd_version,
            vnf_pkg_id=vnfd.package_uuid,
            tenant_id=request.context.project_id,
            vnf_metadata=req_body.get('metadata'))

        vnf_instance.create()
        result = self._view_builder.create(vnf_instance)
        headers = {"location": self._get_vnf_instance_href(vnf_instance)}
        return wsgi.ResponseObject(result, headers=headers)
コード例 #2
0
    def test_instantiate_vnf_with_ext_virtual_links(self,
                                                    mock_vnf_instance_save,
                                                    mock_vnf_package_vnfd,
                                                    mock_create):
        vnf_package_vnfd = fakes.return_vnf_package_vnfd()
        vnf_package_id = vnf_package_vnfd.package_uuid
        mock_vnf_package_vnfd.return_value = vnf_package_vnfd
        req_body = fakes.get_instantiate_vnf_request_with_ext_virtual_links()
        instantiate_vnf_req_dict = utils.convert_camelcase_to_snakecase(
            req_body)
        instantiate_vnf_req_obj = \
            objects.InstantiateVnfRequest.obj_from_primitive(
                instantiate_vnf_req_dict, self.context)
        vnf_instance_obj = fakes.return_vnf_instance()

        fake_csar = os.path.join(self.temp_dir, vnf_package_id)
        cfg.CONF.set_override('vnf_package_csar_path',
                              self.temp_dir,
                              group='vnf_package')
        base_path = os.path.dirname(os.path.abspath(__file__))
        sample_vnf_package_zip = os.path.join(
            base_path, "../../etc/samples/sample_vnf_package_csar.zip")
        extracted_zip_path = fake_csar
        zipfile.ZipFile(sample_vnf_package_zip,
                        'r').extractall(extracted_zip_path)

        self._mock_vnf_manager()
        driver = vnflcm_driver.VnfLcmDriver()
        driver.instantiate_vnf(self.context, vnf_instance_obj,
                               instantiate_vnf_req_obj)

        self.assertEqual("INSTANTIATED", vnf_instance_obj.instantiation_state)
        self.assertEqual(2, mock_vnf_instance_save.call_count)
        self.assertEqual(4, self._vnf_manager.invoke.call_count)
        shutil.rmtree(fake_csar)
コード例 #3
0
    def test_instantiate_vnf_with_ext_virtual_links(self,
                                                    mock_vnf_instance_save,
                                                    mock_vnf_package_vnfd,
                                                    mock_create):
        vnf_package_vnfd = fakes.return_vnf_package_vnfd()
        vnf_package_id = vnf_package_vnfd.package_uuid
        mock_vnf_package_vnfd.return_value = vnf_package_vnfd
        req_body = fakes.get_instantiate_vnf_request_with_ext_virtual_links()
        instantiate_vnf_req_dict = utils.convert_camelcase_to_snakecase(
            req_body)
        instantiate_vnf_req_obj = \
            objects.InstantiateVnfRequest.obj_from_primitive(
                instantiate_vnf_req_dict, self.context)
        vnf_instance_obj = fakes.return_vnf_instance()

        fake_csar = os.path.join(self.temp_dir, vnf_package_id)
        cfg.CONF.set_override('vnf_package_csar_path',
                              self.temp_dir,
                              group='vnf_package')
        self._copy_csar_files(fake_csar, "vnflcm4")
        self._mock_vnf_manager()
        driver = vnflcm_driver.VnfLcmDriver()
        driver.instantiate_vnf(self.context, vnf_instance_obj,
                               instantiate_vnf_req_obj)

        self.assertEqual("INSTANTIATED", vnf_instance_obj.instantiation_state)
        self.assertEqual(2, mock_vnf_instance_save.call_count)
        self.assertEqual(4, self._vnf_manager.invoke.call_count)
        shutil.rmtree(fake_csar)
コード例 #4
0
    def create_package(cls, context, vnf_package_info):
        """vnf_package, create a vnf_package_vnfd table."""

        vnf_package_info = utils.convert_camelcase_to_snakecase(
            vnf_package_info)

        try:
            vnf_package = cls.__create_vnf_package(context, vnf_package_info)
        except Exception as exc:
            raise webob.exc.HTTPInternalServerError(explanation=exc)

        try:
            artifact_paths = cls._get_artifact_paths(vnf_package_info)
            vnf_package_binary = \
                nfvo_client.VnfPackageRequest.download_vnf_packages(
                    vnf_package.id, artifact_paths)
        except nfvo_client.UndefinedExternalSettingException as exc:
            raise webob.exc.HTTPNotFound(explanation=exc)
        except (nfvo_client.FaliedDownloadContentException, Exception) as exc:
            raise webob.exc.HTTPInternalServerError(explanation=exc)

        try:
            (location, size, _, multihash,
             _) = glance_store.store_csar(context, vnf_package.id,
                                          vnf_package_binary)

            cls.__update_vnf_package(vnf_package, location, size, multihash)
            cls.vnf_package_rpc_api.upload_vnf_package_content(
                context, vnf_package)
            vnf_package_vnfd = cls._get_vnf_package_vnfd(
                context, vnf_package_info.get('vnfd_id'))
        except Exception as exc:
            raise webob.exc.HTTPInternalServerError(explanation=exc)

        return vnf_package_vnfd
コード例 #5
0
    def _terminate(self, context, vnf_instance, request_body):
        req_body = utils.convert_camelcase_to_snakecase(request_body)
        terminate_vnf_req = \
            objects.TerminateVnfRequest.obj_from_primitive(
                req_body, context=context)

        vnf_instance.task_state = fields.VnfInstanceTaskState.TERMINATING
        vnf_instance.save()
        self.rpc_api.terminate(context, vnf_instance, terminate_vnf_req)
コード例 #6
0
    def _instantiate(self, context, vnf_instance, request_body):
        req_body = utils.convert_camelcase_to_snakecase(request_body)

        try:
            self._validate_flavour_and_inst_level(context, req_body,
                                                  vnf_instance)
        except exceptions.NotFound as ex:
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(ex))

        instantiate_vnf_request = \
            objects.InstantiateVnfRequest.obj_from_primitive(
                req_body, context=context)

        # validate the vim connection id passed through request is exist or not
        self._validate_vim_connection(context, instantiate_vnf_request)

        vnf_instance.task_state = fields.VnfInstanceTaskState.INSTANTIATING
        vnf_instance.save()

        self.rpc_api.instantiate(context, vnf_instance,
                                 instantiate_vnf_request)
コード例 #7
0
    def _heal(self, context, vnf_instance, request_body):
        req_body = utils.convert_camelcase_to_snakecase(request_body)
        heal_vnf_request = objects.HealVnfRequest(context=context, **req_body)
        inst_vnf_info = vnf_instance.instantiated_vnf_info
        vnfc_resource_info_ids = [
            vnfc_resource_info.id
            for vnfc_resource_info in inst_vnf_info.vnfc_resource_info
        ]

        for vnfc_id in heal_vnf_request.vnfc_instance_id:
            # check if vnfc_id exists in vnfc_resource_info
            if vnfc_id not in vnfc_resource_info_ids:
                msg = _("Vnfc id %(vnfc_id)s not present in vnf instance "
                        "%(id)s")
                raise webob.exc.HTTPBadRequest(explanation=msg % {
                    "vnfc_id": vnfc_id,
                    "id": vnf_instance.id
                })

        vnf_instance.task_state = fields.VnfInstanceTaskState.HEALING
        vnf_instance.save()

        self.rpc_api.heal(context, vnf_instance, heal_vnf_request)
コード例 #8
0
    def set_auth_client(self, id='local', auth_type=None, auth_params=None):
        """Set up an Auth client.

        Args:
            id (str, optional): Management ID
            auth_type (str, optional): Authentication type.
            auth_params (dict, optional): Authentication information.
        """
        snakecase_auth_params = utils.convert_camelcase_to_snakecase(
            auth_params)
        if self.__empty(auth_type) or self.__empty(snakecase_auth_params):
            return

        if id in self.__manages:
            LOG.debug("Use cache, Auth Managed Id=<{}>".format(id))
            return

        client = self.__DEFAULT_CLIENT
        if auth_type == 'BASIC':
            client = _BasicAuthSession(
                user_name=snakecase_auth_params.get('user_name'),
                password=snakecase_auth_params.get('password'))
        elif (auth_type == 'OAUTH2_CLIENT_CREDENTIALS' and
                not self.__empty(snakecase_auth_params.get('token_endpoint'))):
            grant = _ClientCredentialsGrant(
                client_id=snakecase_auth_params.get('client_id'),
                client_password=snakecase_auth_params.get('client_password'),
                token_endpoint=snakecase_auth_params.get('token_endpoint'))
            client = _OAuth2Session(grant)
            client.apply_access_token_info()

        LOG.info(
            "Add to Auth management, id=<{}>, type=<{}>, class=<{}>".format(
                id, auth_type, client.__class__.__name__))

        self.__add_manages(id, client)
コード例 #9
0
ファイル: test_utils.py プロジェクト: vutuong/tacker
 def test_convert_camelcase_to_snakecase_list_with_dict_items(self):
     """Only the dict keys from list should be converted to snakecase"""
     data = [{"camelCaseKey": "camelCaseValue"}]
     actual_val = utils.convert_camelcase_to_snakecase(data)
     expected_val = [{"camel_case_key": "camelCaseValue"}]
     self.assertEqual(expected_val, actual_val)
コード例 #10
0
ファイル: test_utils.py プロジェクト: vutuong/tacker
 def test_convert_camelcase_to_snakecase_dict(self):
     """Only the dict keys should be converted to snakecase"""
     actual_val = utils.convert_camelcase_to_snakecase(
         {"camelCaseKey": "camelCaseValue"})
     expected_val = {"camel_case_key": "camelCaseValue"}
     self.assertEqual(expected_val, actual_val)