Example #1
0
    def create(self, req, body):
        """Creates a new snapshot."""
        kwargs = {}
        context = req.environ['cinder.context']
        snapshot = body['snapshot']
        kwargs['metadata'] = snapshot.get('metadata', None)
        volume_id = snapshot['volume_id']
        volume = self.volume_api.get(context, volume_id)
        force = snapshot.get('force', False)
        force = strutils.bool_from_string(force, strict=True)
        LOG.info("Create snapshot from volume %s", volume_id)

        self.validate_name_and_description(snapshot, check_length=False)
        # NOTE(thingee): v2 API allows name instead of display_name
        if 'name' in snapshot:
            snapshot['display_name'] = snapshot.pop('name')

        if force:
            new_snapshot = self.volume_api.create_snapshot_force(
                context, volume, snapshot.get('display_name'),
                snapshot.get('description'), **kwargs)
        else:
            new_snapshot = self.volume_api.create_snapshot(
                context, volume, snapshot.get('display_name'),
                snapshot.get('description'), **kwargs)
        req.cache_db_snapshot(new_snapshot)

        return self._view_builder.detail(req, new_snapshot)
Example #2
0
    def create(self, req, body):
        """Creates a new snapshot."""
        kwargs = {}
        context = req.environ['cinder.context']
        snapshot = body['snapshot']
        kwargs['metadata'] = snapshot.get('metadata', None)
        volume_id = snapshot['volume_id']
        volume = self.volume_api.get(context, volume_id)
        force = snapshot.get('force', False)
        force = strutils.bool_from_string(force, strict=True)
        LOG.info("Create snapshot from volume %s", volume_id)

        self.validate_name_and_description(snapshot, check_length=False)
        # NOTE(thingee): v2 API allows name instead of display_name
        if 'name' in snapshot:
            snapshot['display_name'] = snapshot.pop('name')

        if force:
            new_snapshot = self.volume_api.create_snapshot_force(
                context,
                volume,
                snapshot.get('display_name'),
                snapshot.get('description'),
                **kwargs)
        else:
            new_snapshot = self.volume_api.create_snapshot(
                context,
                volume,
                snapshot.get('display_name'),
                snapshot.get('description'),
                **kwargs)
        req.cache_db_snapshot(new_snapshot)

        return self._view_builder.detail(req, new_snapshot)
Example #3
0
    def create(self, req, body):
        """Creates a new snapshot."""
        kwargs = {}
        context = req.environ['cinder.context']
        snapshot = body['snapshot']
        kwargs['metadata'] = snapshot.get('metadata', None)
        volume_id = snapshot['volume_id']
        volume = self.volume_api.get(context, volume_id)
        req_version = req.api_version_request
        force_flag = snapshot.get('force')
        force = False
        if force_flag is not None:
            # note: this won't raise because it passed schema validation
            force = strutils.bool_from_string(force_flag, strict=True)

            if req_version.matches(mv.SNAPSHOT_IN_USE):
                # strictly speaking, the 'force' flag is invalid for
                # mv.SNAPSHOT_IN_USE, but we silently ignore a True
                # value for backward compatibility
                if force is False:
                    raise exc.HTTPBadRequest(
                        explanation=SNAPSHOT_IN_USE_FLAG_MSG)

        LOG.info("Create snapshot from volume %s", volume_id)

        self.validate_name_and_description(snapshot, check_length=False)
        if 'name' in snapshot:
            snapshot['display_name'] = snapshot.pop('name')

        if force:
            new_snapshot = self.volume_api.create_snapshot_force(
                context, volume, snapshot.get('display_name'),
                snapshot.get('description'), **kwargs)
        else:
            if req_version.matches(mv.SNAPSHOT_IN_USE):
                kwargs['allow_in_use'] = True

            new_snapshot = self.volume_api.create_snapshot(
                context, volume, snapshot.get('display_name'),
                snapshot.get('description'), **kwargs)
        req.cache_db_snapshot(new_snapshot)

        return self._view_builder.detail(req, new_snapshot)