Esempio n. 1
0
    def _create(self, req, body):
        context = req.environ['nova.context']
        # TODO(rb560u): remove this check in future release
        using_old_action = \
            policy.verify_deprecated_policy(fm_policies.BASE_POLICY_NAME,
                fm_policies.POLICY_ROOT % 'create',
                base.RULE_ADMIN_API,
                context)

        if not using_old_action:
            context.can(fm_policies.POLICY_ROOT % 'create')

        vals = body['flavor']

        name = vals['name']
        flavorid = vals.get('id')
        memory = vals['ram']
        vcpus = vals['vcpus']
        root_gb = vals['disk']
        ephemeral_gb = vals.get('OS-FLV-EXT-DATA:ephemeral', 0)
        swap = vals.get('swap', 0)
        rxtx_factor = vals.get('rxtx_factor', 1.0)
        is_public = vals.get('os-flavor-access:is_public', True)

        # The user can specify a description starting with microversion 2.55.
        include_description = api_version_request.is_supported(
            req, flavors_view.FLAVOR_DESCRIPTION_MICROVERSION)
        description = vals.get('description') if include_description else None

        try:
            flavor = flavors.create(name,
                                    memory,
                                    vcpus,
                                    root_gb,
                                    ephemeral_gb=ephemeral_gb,
                                    flavorid=flavorid,
                                    swap=swap,
                                    rxtx_factor=rxtx_factor,
                                    is_public=is_public,
                                    description=description)
            # NOTE(gmann): For backward compatibility, non public flavor
            # access is not being added for created tenant. Ref -bug/1209101
            req.cache_db_flavor(flavor)
        except (exception.FlavorExists, exception.FlavorIdExists) as err:
            raise webob.exc.HTTPConflict(explanation=err.format_message())

        include_extra_specs = False
        if api_version_request.is_supported(
                req, flavors_view.FLAVOR_EXTRA_SPECS_MICROVERSION):
            include_extra_specs = context.can(fes_policies.POLICY_ROOT %
                                              'index',
                                              fatal=False)
            # NOTE(yikun): This empty extra_spec only for keeping consistent
            # with other related flavor api.
            flavor.extra_specs = {}

        return self._view_builder.show(req,
                                       flavor,
                                       include_description,
                                       include_extra_specs=include_extra_specs)
Esempio n. 2
0
    def test_verify_deprecated_policy_using_new_action(self):
        old_policy = "old_action_default"
        new_policy = "new_action"
        default_rule = "rule:admin_api"

        using_old_action = policy.verify_deprecated_policy(
            old_policy, new_policy, default_rule, self.context)

        self.assertFalse(using_old_action)
Esempio n. 3
0
    def test_verify_deprecated_policy_using_new_action(self):
        old_policy = "old_action_default"
        new_policy = "new_action"
        default_rule = "rule:admin_api"

        using_old_action = policy.verify_deprecated_policy(
            old_policy, new_policy, default_rule, self.context)

        self.assertFalse(using_old_action)
Esempio n. 4
0
    def _create(self, req, body):
        context = req.environ['nova.context']
        # TODO(rb560u): remove this check in future release
        using_old_action = \
            policy.verify_deprecated_policy(fm_policies.BASE_POLICY_NAME,
                fm_policies.POLICY_ROOT % 'create',
                base.RULE_ADMIN_API,
                context)

        if not using_old_action:
            context.can(fm_policies.POLICY_ROOT % 'create')

        vals = body['flavor']

        name = vals['name']
        flavorid = vals.get('id')
        memory = vals['ram']
        vcpus = vals['vcpus']
        root_gb = vals['disk']
        ephemeral_gb = vals.get('OS-FLV-EXT-DATA:ephemeral', 0)
        swap = vals.get('swap', 0)
        rxtx_factor = vals.get('rxtx_factor', 1.0)
        is_public = vals.get('os-flavor-access:is_public', True)

        # The user can specify a description starting with microversion 2.55.
        include_description = api_version_request.is_supported(
            req, flavors_view.FLAVOR_DESCRIPTION_MICROVERSION)
        description = vals.get('description') if include_description else None

        try:
            flavor = flavors.create(name, memory, vcpus, root_gb,
                                    ephemeral_gb=ephemeral_gb,
                                    flavorid=flavorid, swap=swap,
                                    rxtx_factor=rxtx_factor,
                                    is_public=is_public,
                                    description=description)
            # NOTE(gmann): For backward compatibility, non public flavor
            # access is not being added for created tenant. Ref -bug/1209101
            req.cache_db_flavor(flavor)
        except (exception.FlavorExists,
                exception.FlavorIdExists) as err:
            raise webob.exc.HTTPConflict(explanation=err.format_message())

        include_extra_specs = False
        if api_version_request.is_supported(
                req, flavors_view.FLAVOR_EXTRA_SPECS_MICROVERSION):
            include_extra_specs = context.can(
                fes_policies.POLICY_ROOT % 'index', fatal=False)
            # NOTE(yikun): This empty extra_spec only for keeping consistent
            # with other related flavor api.
            flavor.extra_specs = {}

        return self._view_builder.show(req, flavor, include_description,
                                       include_extra_specs=include_extra_specs)
Esempio n. 5
0
    def _create(self, req, body):
        context = req.environ['nova.context']
        # TODO(rb560u): remove this check in future release
        using_old_action = \
            policy.verify_deprecated_policy(fm_policies.BASE_POLICY_NAME,
                fm_policies.POLICY_ROOT % 'create',
                base.RULE_ADMIN_API,
                context)

        if not using_old_action:
            context.can(fm_policies.POLICY_ROOT % 'create')

        vals = body['flavor']

        name = vals['name']
        flavorid = vals.get('id')
        memory = vals['ram']
        vcpus = vals['vcpus']
        root_gb = vals['disk']
        ephemeral_gb = vals.get('OS-FLV-EXT-DATA:ephemeral', 0)
        swap = vals.get('swap', 0)
        rxtx_factor = vals.get('rxtx_factor', 1.0)
        is_public = vals.get('os-flavor-access:is_public', True)

        try:
            flavor = flavors.create(name,
                                    memory,
                                    vcpus,
                                    root_gb,
                                    ephemeral_gb=ephemeral_gb,
                                    flavorid=flavorid,
                                    swap=swap,
                                    rxtx_factor=rxtx_factor,
                                    is_public=is_public)

            # WRS: set local storage backend default to local_image
            flavor.extra_specs = {
                'aggregate_instance_extra_specs:storage': 'local_image'
            }
            flavor.save()

            # NOTE(gmann): For backward compatibility, non public flavor
            # access is not being added for created tenant. Ref -bug/1209101
            req.cache_db_flavor(flavor)
        except (exception.FlavorExists, exception.FlavorIdExists) as err:
            raise webob.exc.HTTPConflict(explanation=err.format_message())
        except exception.ObjectActionError:
            raise webob.exc.HTTPConflict(explanation=_(
                'Not all flavors have been migrated to the API database'))

        return self._view_builder.show(req, flavor)
Esempio n. 6
0
    def test_verify_deprecated_policy_using_old_action(self, mock_warning):

        old_policy = "old_action_not_default"
        new_policy = "new_action"
        default_rule = "rule:admin_api"

        using_old_action = policy.verify_deprecated_policy(
            old_policy, new_policy, default_rule, self.context)

        mock_warning.assert_called_once_with("Start using the new "
            "action '{0}'. The existing action '{1}' is being deprecated and "
            "will be removed in future release.".format(new_policy,
                                                        old_policy))
        self.assertTrue(using_old_action)
Esempio n. 7
0
    def test_verify_deprecated_policy_using_old_action(self, mock_warning):

        old_policy = "old_action_not_default"
        new_policy = "new_action"
        default_rule = "rule:admin_api"

        using_old_action = policy.verify_deprecated_policy(
            old_policy, new_policy, default_rule, self.context)

        mock_warning.assert_called_once_with("Start using the new "
            "action '{0}'. The existing action '{1}' is being deprecated and "
            "will be removed in future release.".format(new_policy,
                                                        old_policy))
        self.assertTrue(using_old_action)
Esempio n. 8
0
    def _delete(self, req, id):
        context = req.environ['nova.context']
        # TODO(rb560u): remove this check in future release
        using_old_action = \
            policy.verify_deprecated_policy(fm_policies.BASE_POLICY_NAME,
                fm_policies.POLICY_ROOT % 'delete',
                base.RULE_ADMIN_API,
                context)

        if not using_old_action:
            context.can(fm_policies.POLICY_ROOT % 'delete')

        flavor = objects.Flavor(context=context, flavorid=id)
        try:
            flavor.destroy()
        except exception.FlavorNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())
Esempio n. 9
0
    def _delete(self, req, id):
        context = req.environ['nova.context']
        # TODO(rb560u): remove this check in future release
        using_old_action = \
            policy.verify_deprecated_policy(fm_policies.BASE_POLICY_NAME,
                fm_policies.POLICY_ROOT % 'delete',
                base.RULE_ADMIN_API,
                context)

        if not using_old_action:
            context.can(fm_policies.POLICY_ROOT % 'delete')

        flavor = objects.Flavor(context=context, flavorid=id)
        try:
            flavor.destroy()
        except exception.FlavorNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())
Esempio n. 10
0
    def _create(self, req, body):
        context = req.environ['nova.context']
        # TODO(rb560u): remove this check in future release
        using_old_action = \
            policy.verify_deprecated_policy(fm_policies.BASE_POLICY_NAME,
                fm_policies.POLICY_ROOT % 'create',
                base.RULE_ADMIN_API,
                context)

        if not using_old_action:
            context.can(fm_policies.POLICY_ROOT % 'create')

        vals = body['flavor']

        name = vals['name']
        flavorid = vals.get('id')
        memory = vals['ram']
        vcpus = vals['vcpus']
        root_gb = vals['disk']
        ephemeral_gb = vals.get('OS-FLV-EXT-DATA:ephemeral', 0)
        swap = vals.get('swap', 0)
        rxtx_factor = vals.get('rxtx_factor', 1.0)
        is_public = vals.get('os-flavor-access:is_public', True)

        try:
            flavor = flavors.create(name, memory, vcpus, root_gb,
                                    ephemeral_gb=ephemeral_gb,
                                    flavorid=flavorid, swap=swap,
                                    rxtx_factor=rxtx_factor,
                                    is_public=is_public)
            # NOTE(gmann): For backward compatibility, non public flavor
            # access is not being added for created tenant. Ref -bug/1209101
            req.cache_db_flavor(flavor)
        except (exception.FlavorExists,
                exception.FlavorIdExists) as err:
            raise webob.exc.HTTPConflict(explanation=err.format_message())
        except exception.ObjectActionError:
            raise webob.exc.HTTPConflict(explanation=_(
                'Not all flavors have been migrated to the API database'))

        return self._view_builder.show(req, flavor)