Esempio n. 1
0
    def _create(self, req, body, set_defaults=False):
        """Creates a new share type."""
        context = req.environ['manila.context']

        if (not self.is_valid_body(body, 'share_type') and
                not self.is_valid_body(body, 'volume_type')):
            raise webob.exc.HTTPBadRequest()

        elif self.is_valid_body(body, 'share_type'):
            share_type = body['share_type']
        else:
            share_type = body['volume_type']
        name = share_type.get('name')
        specs = share_type.get('extra_specs', {})
        is_public = share_type.get(
            'os-share-type-access:is_public',
            share_type.get('share_type_access:is_public', True),
        )

        if name is None or name == "" or len(name) > 255:
            msg = _("Type name is not valid.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        # Note(cknight): Set the default extra spec value for snapshot_support
        # for API versions before it was required.
        if set_defaults:
            if constants.ExtraSpecs.SNAPSHOT_SUPPORT not in specs:
                specs[constants.ExtraSpecs.SNAPSHOT_SUPPORT] = True

        try:
            required_extra_specs = (
                share_types.get_valid_required_extra_specs(specs)
            )
            share_types.create(context, name, specs, is_public)
            share_type = share_types.get_share_type_by_name(context, name)
            share_type['required_extra_specs'] = required_extra_specs
            req.cache_db_share_type(share_type)
            notifier_info = dict(share_types=share_type)
            rpc.get_notifier('shareType').info(
                context, 'share_type.create', notifier_info)

        except exception.InvalidExtraSpec as e:
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(e))
        except exception.ShareTypeExists as err:
            notifier_err = dict(share_types=share_type,
                                error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.create',
                                          notifier_err)

            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.NotFound as err:
            notifier_err = dict(share_types=share_type,
                                error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.create',
                                          notifier_err)
            raise webob.exc.HTTPNotFound()

        return self._view_builder.show(req, share_type)
Esempio n. 2
0
    def _create(self, req, body, set_defaults=False):
        """Creates a new share type."""
        context = req.environ['manila.context']

        if not self.is_valid_body(body, 'share_type') and \
                not self.is_valid_body(body, 'volume_type'):
            raise webob.exc.HTTPBadRequest()

        elif self.is_valid_body(body, 'share_type'):
            share_type = body['share_type']
        else:
            share_type = body['volume_type']
        name = share_type.get('name')
        specs = share_type.get('extra_specs', {})
        is_public = share_type.get(
            'os-share-type-access:is_public',
            share_type.get('share_type_access:is_public', True),
        )

        if name is None or name == "" or len(name) > 255:
            msg = _("Type name is not valid.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        # Note(cknight): Set the default extra spec value for snapshot_support
        # for API versions before it was required.
        if set_defaults:
            if constants.ExtraSpecs.SNAPSHOT_SUPPORT not in specs:
                specs[constants.ExtraSpecs.SNAPSHOT_SUPPORT] = True

        try:
            required_extra_specs = (
                share_types.get_valid_required_extra_specs(specs)
            )
            share_types.create(context, name, specs, is_public)
            share_type = share_types.get_share_type_by_name(context, name)
            share_type['required_extra_specs'] = required_extra_specs
            req.cache_db_share_type(share_type)
            notifier_info = dict(share_types=share_type)
            rpc.get_notifier('shareType').info(
                context, 'share_type.create', notifier_info)

        except exception.InvalidExtraSpec as e:
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(e))
        except exception.ShareTypeExists as err:
            notifier_err = dict(share_types=share_type,
                                error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.create',
                                          notifier_err)

            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.NotFound as err:
            notifier_err = dict(share_types=share_type,
                                error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.create',
                                          notifier_err)
            raise webob.exc.HTTPNotFound()

        return self._view_builder.show(req, share_type)
Esempio n. 3
0
    def _create(self, req, body):
        """Creates a new share type."""
        context = req.environ['manila.context']

        if not self.is_valid_body(body, 'share_type') and \
                not self.is_valid_body(body, 'volume_type'):
            raise webob.exc.HTTPBadRequest()

        elif self.is_valid_body(body, 'share_type'):
            share_type = body['share_type']
        else:
            share_type = body['volume_type']
        name = share_type.get('name', None)
        specs = share_type.get('extra_specs', {})
        is_public = share_type.get(
            'os-share-type-access:is_public',
            share_type.get('share_type_access:is_public', True),
        )

        if name is None or name == "" or len(name) > 255:
            msg = _("Type name is not valid.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        try:
            required_extra_specs = (
                share_types.get_valid_required_extra_specs(specs)
            )
        except exception.InvalidExtraSpec as e:
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(e))

        try:
            share_types.create(context, name, specs, is_public)
            share_type = share_types.get_share_type_by_name(context, name)
            share_type['required_extra_specs'] = required_extra_specs
            req.cache_db_share_type(share_type)
            notifier_info = dict(share_types=share_type)
            rpc.get_notifier('shareType').info(
                context, 'share_type.create', notifier_info)

        except exception.ShareTypeExists as err:
            notifier_err = dict(share_types=share_type,
                                error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.create',
                                          notifier_err)

            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.NotFound as err:
            notifier_err = dict(share_types=share_type,
                                error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.create',
                                          notifier_err)
            raise webob.exc.HTTPNotFound()

        return self._view_builder.show(req, share_type)
Esempio n. 4
0
    def test_remove_access(self):
        project_id = "456"
        extra_specs = {constants.ExtraSpecs.DRIVER_HANDLES_SHARE_SERVERS: "true"}
        share_type = share_types.create(self.context, "type1", projects=["456"], extra_specs=extra_specs)
        share_type_id = share_type.get("id")

        share_types.remove_share_type_access(self.context, share_type_id, project_id)
        stype_access = db.share_type_access_get_all(self.context, share_type_id)
        self.assertNotIn(project_id, stype_access)
Esempio n. 5
0
    def test_add_access(self):
        project_id = "456"
        extra_specs = {constants.ExtraSpecs.DRIVER_HANDLES_SHARE_SERVERS: "true"}
        share_type = share_types.create(self.context, "type1", extra_specs)
        share_type_id = share_type.get("id")

        share_types.add_share_type_access(self.context, share_type_id, project_id)
        stype_access = db.share_type_access_get_all(self.context, share_type_id)
        self.assertIn(project_id, [a.project_id for a in stype_access])
Esempio n. 6
0
    def test_provision_filter_on_size(self):
        share_types.create(self.context, "type1",
                           extra_specs={
                               "key1": "val1",
                               "key2": "val2",
                               "driver_handles_share_servers": False})
        share_types.create(self.context, "type2",
                           extra_specs={
                               share_types.MIN_SIZE_KEY: "12",
                               "key3": "val3",
                               "driver_handles_share_servers": False})
        share_types.create(self.context, "type3",
                           extra_specs={
                               share_types.MAX_SIZE_KEY: "99",
                               "key4": "val4",
                               "driver_handles_share_servers": False})
        share_types.create(self.context, "type4",
                           extra_specs={
                               share_types.MIN_SIZE_KEY: "24",
                               share_types.MAX_SIZE_KEY: "99",
                               "key4": "val4",
                               "driver_handles_share_servers": False})

        # Make sure we don't raise if there are no min/max set
        type1 = share_types.get_share_type_by_name(self.context, 'type1')
        share_types.provision_filter_on_size(self.context, type1, "11")

        # verify minimum size requirements
        type2 = share_types.get_share_type_by_name(self.context, 'type2')
        self.assertRaises(exception.InvalidInput,
                          share_types.provision_filter_on_size,
                          self.context, type2, "11")
        share_types.provision_filter_on_size(self.context, type2, "12")
        share_types.provision_filter_on_size(self.context, type2, "100")

        # verify max size requirements
        type3 = share_types.get_share_type_by_name(self.context, 'type3')
        self.assertRaises(exception.InvalidInput,
                          share_types.provision_filter_on_size,
                          self.context, type3, "100")
        share_types.provision_filter_on_size(self.context, type3, "99")
        share_types.provision_filter_on_size(self.context, type3, "1")

        # verify min and max
        type4 = share_types.get_share_type_by_name(self.context, 'type4')
        self.assertRaises(exception.InvalidInput,
                          share_types.provision_filter_on_size,
                          self.context, type4, "20")
        self.assertRaises(exception.InvalidInput,
                          share_types.provision_filter_on_size,
                          self.context, type4, "100")
        share_types.provision_filter_on_size(self.context, type4, "24")
        share_types.provision_filter_on_size(self.context, type4, "99")
        share_types.provision_filter_on_size(self.context, type4, "30")
Esempio n. 7
0
    def test_add_access(self):
        project_id = '456'
        extra_specs = {
            constants.ExtraSpecs.DRIVER_HANDLES_SHARE_SERVERS: 'true'
        }
        share_type = share_types.create(self.context, 'type1', extra_specs)
        share_type_id = share_type.get('id')

        share_types.add_share_type_access(self.context, share_type_id,
                                          project_id)
        stype_access = db.share_type_access_get_all(self.context,
                                                    share_type_id)
        self.assertIn(project_id, [a.project_id for a in stype_access])
Esempio n. 8
0
    def test_remove_access(self):
        project_id = '456'
        extra_specs = {
            constants.ExtraSpecs.DRIVER_HANDLES_SHARE_SERVERS: 'true'
        }
        share_type = share_types.create(
            self.context, 'type1', projects=['456'], extra_specs=extra_specs)
        share_type_id = share_type.get('id')

        share_types.remove_share_type_access(self.context, share_type_id,
                                             project_id)
        stype_access = db.share_type_access_get_all(self.context,
                                                    share_type_id)
        self.assertNotIn(project_id, stype_access)
Esempio n. 9
0
    def _create(self, req, body, set_defaults=False):
        """Creates a new share type."""
        context = req.environ['manila.context']

        if (not self.is_valid_body(body, 'share_type')
                and not self.is_valid_body(body, 'volume_type')):
            raise webob.exc.HTTPBadRequest()

        elif self.is_valid_body(body, 'share_type'):
            share_type = body['share_type']
        else:
            share_type = body['volume_type']
        name = share_type.get('name')
        specs = share_type.get('extra_specs', {})
        description = share_type.get('description')
        if (description and req.api_version_request <
                api_version.APIVersionRequest("2.41")):
            msg = _("'description' key is not supported by this "
                    "microversion. Use 2.41 or greater microversion "
                    "to be able to use 'description' in share type.")
            raise webob.exc.HTTPBadRequest(explanation=msg)
        is_public = share_type.get(
            'os-share-type-access:is_public',
            share_type.get('share_type_access:is_public', True),
        )

        if (name is None or name == "" or len(name) > 255
                or (description and len(description) > 255)):
            msg = _("Type name or description is not valid.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        # Note(cknight): Set the default extra spec value for snapshot_support
        # for API versions before it was required.
        if set_defaults:
            if constants.ExtraSpecs.SNAPSHOT_SUPPORT not in specs:
                specs[constants.ExtraSpecs.SNAPSHOT_SUPPORT] = True

        try:
            required_extra_specs = (
                share_types.get_valid_required_extra_specs(specs))
            share_types.create(context,
                               name,
                               specs,
                               is_public,
                               description=description)
            share_type = share_types.get_share_type_by_name(context, name)
            share_type['required_extra_specs'] = required_extra_specs
            req.cache_db_share_type(share_type)
            self._notify_share_type_info(context, 'share_type.create',
                                         share_type)

        except exception.InvalidExtraSpec as e:
            raise webob.exc.HTTPBadRequest(explanation=e.message)
        except exception.ShareTypeExists as err:
            notifier_err = dict(share_types=share_type,
                                error_message=err.message)
            self._notify_share_type_error(context, 'share_type.create',
                                          notifier_err)

            raise webob.exc.HTTPConflict(explanation=err.message)
        except exception.NotFound as err:
            notifier_err = dict(share_types=share_type,
                                error_message=err.message)
            self._notify_share_type_error(context, 'share_type.create',
                                          notifier_err)
            raise webob.exc.HTTPNotFound()

        return self._view_builder.show(req, share_type)