Ejemplo n.º 1
0
    def create_from_src(self, req, body):
        """Create a new group from a source.

        The source can be a group snapshot or a group. Note that
        this does not require group_type and volume_types as the
        "create" API above.
        """
        LOG.debug('Creating new group %s.', body)

        context = req.environ['cinder.context']
        group = body['create-from-src']
        name = group.get('name')
        description = group.get('description')
        if name:
            name = name.strip()
        if description:
            description = description.strip()
        group_snapshot_id = group.get('group_snapshot_id', None)
        source_group_id = group.get('source_group_id', None)

        group_type_id = None
        if group_snapshot_id:
            LOG.info(
                "Creating group %(name)s from group_snapshot "
                "%(snap)s.", {
                    'name': name,
                    'snap': group_snapshot_id
                },
                context=context)
            grp_snap = self.group_api.get_group_snapshot(
                context, group_snapshot_id)
            group_type_id = grp_snap.group_type_id
        elif source_group_id:
            LOG.info(
                "Creating group %(name)s from "
                "source group %(source_group_id)s.", {
                    'name': name,
                    'source_group_id': source_group_id
                },
                context=context)
            source_group = self.group_api.get(context, source_group_id)
            group_type_id = source_group.group_type_id

        self._check_default_cgsnapshot_type(group_type_id)

        try:
            new_group = self.group_api.create_from_src(context, name,
                                                       description,
                                                       group_snapshot_id,
                                                       source_group_id)
        except exception.InvalidGroup as error:
            raise exc.HTTPBadRequest(explanation=error.msg)
        except (exception.GroupNotFound, exception.GroupSnapshotNotFound):
            # 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
Ejemplo n.º 2
0
    def update(self, req, id, body):
        """Update the group.

        Expected format of the input parameter 'body':

        .. code-block:: json

            {
                "group":
                {
                    "name": "my_group",
                    "description": "My group",
                    "add_volumes": "volume-uuid-1,volume-uuid-2,...",
                    "remove_volumes": "volume-uuid-8,volume-uuid-9,..."
                }
            }

        """
        LOG.debug('Update called for group %s.', id)

        context = req.environ['cinder.context']

        group = body['group']
        name = group.get('name')
        description = group.get('description')
        if name:
            name = name.strip()
        if description:
            description = description.strip()
        add_volumes = group.get('add_volumes')
        remove_volumes = group.get('remove_volumes')

        LOG.info(
            "Updating group %(id)s with name %(name)s "
            "description: %(description)s add_volumes: "
            "%(add_volumes)s remove_volumes: %(remove_volumes)s.", {
                'id': id,
                'name': name,
                'description': description,
                'add_volumes': add_volumes,
                'remove_volumes': remove_volumes
            },
            context=context)

        try:
            group = self.group_api.get(context, id)
            self._check_default_cgsnapshot_type(group.group_type_id)
            self.group_api.update(context, group, name, description,
                                  add_volumes, remove_volumes)
        except exception.GroupNotFound:
            # Not found exception will be handled at the wsgi level
            raise
        except exception.InvalidGroup as error:
            raise exc.HTTPBadRequest(explanation=error.msg)

        return webob.Response(status_int=http_client.ACCEPTED)
Ejemplo n.º 3
0
    def update(self, req, id, body):
        """Update the group.

        Expected format of the input parameter 'body':

        .. code-block:: json

            {
                "group":
                {
                    "name": "my_group",
                    "description": "My group",
                    "add_volumes": "volume-uuid-1,volume-uuid-2,...",
                    "remove_volumes": "volume-uuid-8,volume-uuid-9,..."
                }
            }

        """
        LOG.debug('Update called for group %s.', id)

        context = req.environ['cinder.context']

        group = body['group']
        name = group.get('name')
        description = group.get('description')
        if name:
            name = name.strip()
        if description:
            description = description.strip()
        add_volumes = group.get('add_volumes')
        remove_volumes = group.get('remove_volumes')

        LOG.info("Updating group %(id)s with name %(name)s "
                 "description: %(description)s add_volumes: "
                 "%(add_volumes)s remove_volumes: %(remove_volumes)s.",
                 {'id': id, 'name': name,
                  'description': description,
                  'add_volumes': add_volumes,
                  'remove_volumes': remove_volumes},
                 context=context)

        try:
            group = self.group_api.get(context, id)
            self._check_default_cgsnapshot_type(group.group_type_id)
            self.group_api.update(
                context, group, name, description,
                add_volumes, remove_volumes)
        except exception.GroupNotFound:
            # Not found exception will be handled at the wsgi level
            raise
        except exception.InvalidGroup as error:
            raise exc.HTTPBadRequest(explanation=error.msg)

        return webob.Response(status_int=http_client.ACCEPTED)
Ejemplo n.º 4
0
    def create_from_src(self, req, body):
        """Create a new group from a source.

        The source can be a group snapshot or a group. Note that
        this does not require group_type and volume_types as the
        "create" API above.
        """
        LOG.debug('Creating new group %s.', body)

        context = req.environ['cinder.context']
        group = body['create-from-src']
        name = group.get('name')
        description = group.get('description')
        if name:
            name = name.strip()
        if description:
            description = description.strip()
        group_snapshot_id = group.get('group_snapshot_id', None)
        source_group_id = group.get('source_group_id', None)

        group_type_id = None
        if group_snapshot_id:
            LOG.info("Creating group %(name)s from group_snapshot "
                     "%(snap)s.",
                     {'name': name, 'snap': group_snapshot_id},
                     context=context)
            grp_snap = self.group_api.get_group_snapshot(context,
                                                         group_snapshot_id)
            group_type_id = grp_snap.group_type_id
        elif source_group_id:
            LOG.info("Creating group %(name)s from "
                     "source group %(source_group_id)s.",
                     {'name': name, 'source_group_id': source_group_id},
                     context=context)
            source_group = self.group_api.get(context, source_group_id)
            group_type_id = source_group.group_type_id

        self._check_default_cgsnapshot_type(group_type_id)

        try:
            new_group = self.group_api.create_from_src(
                context, name, description, group_snapshot_id, source_group_id)
        except exception.InvalidGroup as error:
            raise exc.HTTPBadRequest(explanation=error.msg)
        except (exception.GroupNotFound, exception.GroupSnapshotNotFound):
            # 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
Ejemplo n.º 5
0
    def create(self, req, body):
        """Create a new group."""
        LOG.debug('Creating new group %s', body)
        context = req.environ['cinder.context']
        group = body['group']
        name = group.get('name')
        description = group.get('description')
        if name:
            name = name.strip()
        if description:
            description = description.strip()
        group_type = group['group_type']
        if not uuidutils.is_uuid_like(group_type):
            req_group_type = group_types.get_group_type_by_name(
                context, group_type)
            group_type = req_group_type['id']
        self._check_default_cgsnapshot_type(group_type)
        volume_types = group['volume_types']
        availability_zone = group.get('availability_zone')

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

        try:
            new_group = self.group_api.create(
                context,
                name,
                description,
                group_type,
                volume_types,
                availability_zone=availability_zone)
        except (exception.Invalid, 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_group)
        return retval
Ejemplo n.º 6
0
    def create(self, req, body):
        """Create a new group."""
        LOG.debug('Creating new group %s', body)
        context = req.environ['cinder.context']
        group = body['group']
        name = group.get('name')
        description = group.get('description')
        if name:
            name = name.strip()
        if description:
            description = description.strip()
        group_type = group['group_type']
        if not uuidutils.is_uuid_like(group_type):
            req_group_type = group_types.get_group_type_by_name(context,
                                                                group_type)
            group_type = req_group_type['id']
        self._check_default_cgsnapshot_type(group_type)
        volume_types = group['volume_types']
        availability_zone = group.get('availability_zone')

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

        try:
            new_group = self.group_api.create(
                context, name, description, group_type, volume_types,
                availability_zone=availability_zone)
        except (exception.Invalid, 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_group)
        return retval