Example #1
0
    def delete(self, req, id, body):
        """Delete a consistency group."""
        LOG.debug('delete called for member %s', id)
        context = req.environ['cinder.context']
        force = False
        if body:
            self.assert_valid_body(body, 'consistencygroup')

            cg_body = body['consistencygroup']
            try:
                force = strutils.bool_from_string(cg_body.get('force', False),
                                                  strict=True)
            except ValueError:
                msg = _("Invalid value '%s' for force.") % force
                raise exc.HTTPBadRequest(explanation=msg)

        LOG.info('Delete consistency group with id: %s', id)

        try:
            group = self._get(context, id)
            consistencygroup_api.check_policy(context, 'delete')
            self.group_api.delete(context, group, force)
        # Not found exception will be handled at the wsgi level
        except exception.InvalidConsistencyGroup as error:
            raise exc.HTTPBadRequest(explanation=error.msg)

        return webob.Response(status_int=http_client.ACCEPTED)
    def delete(self, req, id, body):
        """Delete a consistency group."""
        LOG.debug('delete called for member %s', id)
        context = req.environ['cinder.context']
        force = False
        if body:
            if not self.is_valid_body(body, 'consistencygroup'):
                msg = _("Missing required element 'consistencygroup' in "
                        "request body.")
                raise exc.HTTPBadRequest(explanation=msg)

            cg_body = body['consistencygroup']
            try:
                force = strutils.bool_from_string(cg_body.get('force', False),
                                                  strict=True)
            except ValueError:
                msg = _("Invalid value '%s' for force.") % force
                raise exc.HTTPBadRequest(explanation=msg)

        LOG.info('Delete consistency group with id: %s', id)

        try:
            group = self._get(context, id)
            consistencygroup_api.check_policy(context, 'delete')
            self.group_api.delete(context, group, force)
        # Not found exception will be handled at the wsgi level
        except exception.InvalidConsistencyGroup as error:
            raise exc.HTTPBadRequest(explanation=error.msg)

        return webob.Response(status_int=http_client.ACCEPTED)
Example #3
0
    def create_from_src(self, req, body):
        """Create a new consistency group from a source.

        The source can be a CG snapshot or a CG. Note that
        this does not require volume_types as the "create"
        API above.
        """
        LOG.debug('Creating new consistency group %s.', body)
        self.assert_valid_body(body, 'consistencygroup-from-src')

        context = req.environ['cinder.context']
        consistencygroup = body['consistencygroup-from-src']
        self.validate_name_and_description(consistencygroup)
        name = consistencygroup.get('name', None)
        description = consistencygroup.get('description', None)
        cgsnapshot_id = consistencygroup.get('cgsnapshot_id', None)
        source_cgid = consistencygroup.get('source_cgid', None)
        if not cgsnapshot_id and not source_cgid:
            msg = _("Either 'cgsnapshot_id' or 'source_cgid' must be "
                    "provided to create consistency group %(name)s "
                    "from source.") % {'name': name}
            raise exc.HTTPBadRequest(explanation=msg)

        if cgsnapshot_id and source_cgid:
            msg = _("Cannot provide both 'cgsnapshot_id' and 'source_cgid' "
                    "to create consistency group %(name)s from "
                    "source.") % {'name': name}
            raise exc.HTTPBadRequest(explanation=msg)

        if cgsnapshot_id:
            LOG.info("Creating consistency group %(name)s from "
                     "cgsnapshot %(snap)s.",
                     {'name': name, 'snap': cgsnapshot_id})
        elif source_cgid:
            LOG.info("Creating consistency group %(name)s from "
                     "source consistency group %(source_cgid)s.",
                     {'name': name, 'source_cgid': source_cgid})

        try:
            if source_cgid:
                self._get(context, source_cgid)
            if cgsnapshot_id:
                self._get_cgsnapshot(context, cgsnapshot_id)
            consistencygroup_api.check_policy(context, 'create')
            new_group = self.group_api.create_from_src(
                context, name, description, cgsnapshot_id, source_cgid)
        except exception.NotFound:
            # Not found exception will be handled at the wsgi level
            raise
        except exception.CinderException as error:
            raise exc.HTTPBadRequest(explanation=error.msg)

        retval = self._view_builder.summary(req, new_group)
        return retval
    def create_from_src(self, req, body):
        """Create a new consistency group from a source.

        The source can be a CG snapshot or a CG. Note that
        this does not require volume_types as the "create"
        API above.
        """
        LOG.debug('Creating new consistency group %s.', body)
        self.assert_valid_body(body, 'consistencygroup-from-src')

        context = req.environ['cinder.context']
        consistencygroup = body['consistencygroup-from-src']
        self.validate_name_and_description(consistencygroup)
        name = consistencygroup.get('name', None)
        description = consistencygroup.get('description', None)
        cgsnapshot_id = consistencygroup.get('cgsnapshot_id', None)
        source_cgid = consistencygroup.get('source_cgid', None)
        if not cgsnapshot_id and not source_cgid:
            msg = _("Either 'cgsnapshot_id' or 'source_cgid' must be "
                    "provided to create consistency group %(name)s "
                    "from source.") % {'name': name}
            raise exc.HTTPBadRequest(explanation=msg)

        if cgsnapshot_id and source_cgid:
            msg = _("Cannot provide both 'cgsnapshot_id' and 'source_cgid' "
                    "to create consistency group %(name)s from "
                    "source.") % {'name': name}
            raise exc.HTTPBadRequest(explanation=msg)

        if cgsnapshot_id:
            LOG.info("Creating consistency group %(name)s from "
                     "cgsnapshot %(snap)s.",
                     {'name': name, 'snap': cgsnapshot_id})
        elif source_cgid:
            LOG.info("Creating consistency group %(name)s from "
                     "source consistency group %(source_cgid)s.",
                     {'name': name, 'source_cgid': source_cgid})

        try:
            if source_cgid:
                self._get(context, source_cgid)
            if cgsnapshot_id:
                self._get_cgsnapshot(context, cgsnapshot_id)
            consistencygroup_api.check_policy(context, 'create')
            new_group = self.group_api.create_from_src(
                context, name, description, cgsnapshot_id, source_cgid)
        except exception.NotFound:
            # Not found exception will be handled at the wsgi level
            raise
        except exception.CinderException as error:
            raise exc.HTTPBadRequest(explanation=error.msg)

        retval = self._view_builder.summary(req, new_group)
        return retval
Example #5
0
    def create(self, req, body):
        """Create a new consistency group."""
        LOG.debug('Creating new consistency group %s', body)
        self.assert_valid_body(body, 'consistencygroup')

        context = req.environ['cinder.context']
        consistencygroup = body['consistencygroup']
        self.validate_name_and_description(consistencygroup)
        name = consistencygroup.get('name', None)
        description = consistencygroup.get('description', None)
        volume_types = consistencygroup.get('volume_types', None)
        if not volume_types:
            msg = _("volume_types must be provided to create "
                    "consistency group %(name)s.") % {'name': name}
            raise exc.HTTPBadRequest(explanation=msg)
        volume_types = volume_types.rstrip(',').split(',')
        availability_zone = consistencygroup.get('availability_zone', None)
        group_type = group_types.get_default_cgsnapshot_type()
        if not group_type:
            msg = (_('Group type %s not found. Rerun migration script to '
                     'create the default cgsnapshot type.') %
                   group_types.DEFAULT_CGSNAPSHOT_TYPE)
            raise exc.HTTPBadRequest(explanation=msg)

        LOG.info("Creating consistency group %(name)s.",
                 {'name': name})

        try:
            consistencygroup_api.check_policy(context, 'create')
            new_consistencygroup = self.group_api.create(
                context, name, description, group_type['id'], volume_types,
                availability_zone=availability_zone)
        except (exception.InvalidConsistencyGroup,
                exception.InvalidGroup,
                exception.InvalidVolumeType,
                exception.ObjectActionError) as error:
            raise exc.HTTPBadRequest(explanation=error.msg)
        except exception.NotFound:
            # Not found exception will be handled at the wsgi level
            raise

        retval = self._view_builder.summary(req, new_consistencygroup)
        return retval
    def create(self, req, body):
        """Create a new consistency group."""
        LOG.debug('Creating new consistency group %s', body)
        self.assert_valid_body(body, 'consistencygroup')

        context = req.environ['cinder.context']
        consistencygroup = body['consistencygroup']
        self.validate_name_and_description(consistencygroup)
        name = consistencygroup.get('name', None)
        description = consistencygroup.get('description', None)
        volume_types = consistencygroup.get('volume_types', None)
        if not volume_types:
            msg = _("volume_types must be provided to create "
                    "consistency group %(name)s.") % {'name': name}
            raise exc.HTTPBadRequest(explanation=msg)
        volume_types = volume_types.rstrip(',').split(',')
        availability_zone = consistencygroup.get('availability_zone', None)
        group_type = group_types.get_default_cgsnapshot_type()
        if not group_type:
            msg = (_('Group type %s not found. Rerun migration script to '
                     'create the default cgsnapshot type.') %
                   group_types.DEFAULT_CGSNAPSHOT_TYPE)
            raise exc.HTTPBadRequest(explanation=msg)

        LOG.info("Creating consistency group %(name)s.",
                 {'name': name})

        try:
            consistencygroup_api.check_policy(context, 'create')
            new_consistencygroup = self.group_api.create(
                context, name, description, group_type['id'], volume_types,
                availability_zone=availability_zone)
        except (exception.InvalidConsistencyGroup,
                exception.InvalidGroup,
                exception.InvalidVolumeType,
                exception.ObjectActionError) as error:
            raise exc.HTTPBadRequest(explanation=error.msg)
        except exception.NotFound:
            # Not found exception will be handled at the wsgi level
            raise

        retval = self._view_builder.summary(req, new_consistencygroup)
        return retval