Пример #1
0
 def setUp(self):
     super(GroupTypesApiTest, self).setUp()
     self.controller = v3_group_types.GroupTypesController()
     self.specs_controller = v3_group_specs.GroupTypeSpecsController()
     self.ctxt = context.RequestContext(user_id=fake.USER_ID, project_id=fake.PROJECT_ID, is_admin=True)
     self.user_ctxt = context.RequestContext(user_id=fake.USER2_ID, project_id=fake.PROJECT2_ID, is_admin=False)
     self.type_id1 = self._create_group_type("group_type1", {"key1": "value1"})
     self.type_id2 = self._create_group_type("group_type2", {"key2": "value2"})
     self.type_id3 = self._create_group_type("group_type3", {"key3": "value3"}, False, [fake.PROJECT_ID])
     self.type_id0 = group_types.get_default_cgsnapshot_type()["id"]
Пример #2
0
    def detail(self, request, volume):
        """Detailed view of a single volume."""
        volume_ref = {
            'volume': {
                'id': volume.get('id'),
                'status': self._get_volume_status(volume),
                'size': volume.get('size'),
                'availability_zone': volume.get('availability_zone'),
                'created_at': volume.get('created_at'),
                'updated_at': volume.get('updated_at'),
                'attachments': self._get_attachments(volume),
                'name': volume.get('display_name'),
                'description': volume.get('display_description'),
                'volume_type': self._get_volume_type(volume),
                'snapshot_id': volume.get('snapshot_id'),
                'source_volid': volume.get('source_volid'),
                'metadata': self._get_volume_metadata(volume),
                'links': self._get_links(request, volume['id']),
                'user_id': volume.get('user_id'),
                'bootable': six.text_type(volume.get('bootable')).lower(),
                'encrypted': self._is_volume_encrypted(volume),
                'replication_status': volume.get('replication_status'),
                'consistencygroup_id': volume.get('consistencygroup_id'),
                'multiattach': volume.get('multiattach'),
            }
        }
        if request.environ['cinder.context'].is_admin:
            volume_ref['volume']['migration_status'] = (
                volume.get('migration_status'))

        # NOTE(xyang): Display group_id as consistencygroup_id in detailed
        # view of the volume if group is converted from cg.
        group_id = volume.get('group_id')
        if group_id is not None:
            # Not found exception will be handled at the wsgi level
            ctxt = request.environ['cinder.context']
            grp = group_api.API().get(ctxt, group_id)
            cgsnap_type = group_types.get_default_cgsnapshot_type()
            if grp.group_type_id == cgsnap_type['id']:
                volume_ref['volume']['consistencygroup_id'] = group_id

        volume_status = self._get_volume_status(volume)
        volume_type = self._get_volume_type(volume)
        if volume_status == 'in-use' and volume_type == 'lvm':
            authinfo = volume.get('provider_auth')
            portalinfo = volume.get('provider_location')
            username = authinfo.split()[1]
            password = authinfo.split()[2]
            volume_ref['volume']['auth_info'] = \
                'username:{} password:{}'.format(username, password)
            volume_ref['volume']['portal_info'] = portalinfo.split(',')[0]

        return volume_ref
Пример #3
0
    def create(self, req, body):
        """Create a new consistency group."""
        versionutils.report_deprecated_feature(LOG, DEPRECATE_CG_API_MSG)
        LOG.debug('Creating new consistency group %s', body)
        self.assert_valid_body(body, 'consistencygroup')

        context = req.environ['cinder.context']
        context.authorize(group_policy.CREATE_POLICY)
        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:
            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
Пример #4
0
    def detail(self, request, volume):
        """Detailed view of a single volume."""
        volume_ref = {
            'volume': {
                'id': volume.get('id'),
                'status': self._get_volume_status(volume),
                'size': volume.get('size'),
                'availability_zone': volume.get('availability_zone'),
                'created_at': volume.get('created_at'),
                'updated_at': volume.get('updated_at'),
                'name': volume.get('display_name'),
                'description': volume.get('display_description'),
                'volume_type': self._get_volume_type(volume),
                'snapshot_id': volume.get('snapshot_id'),
                'source_volid': volume.get('source_volid'),
                'metadata': self._get_volume_metadata(volume),
                'links': self._get_links(request, volume['id']),
                'user_id': volume.get('user_id'),
                'bootable': str(volume.get('bootable')).lower(),
                'encrypted': self._is_volume_encrypted(volume),
                'replication_status': volume.get('replication_status'),
                'consistencygroup_id': volume.get('consistencygroup_id'),
                'multiattach': volume.get('multiattach'),
            }
        }
        ctxt = request.environ['cinder.context']

        attachments = self._get_attachments(volume, ctxt.is_admin)
        volume_ref['volume']['attachments'] = attachments

        if ctxt.is_admin:
            volume_ref['volume']['migration_status'] = (
                volume.get('migration_status'))

        # NOTE(xyang): Display group_id as consistencygroup_id in detailed
        # view of the volume if group is converted from cg.
        group_id = volume.get('group_id')
        if group_id is not None:
            # Not found exception will be handled at the wsgi level
            grp = group_api.API().get(ctxt, group_id)
            cgsnap_type = group_types.get_default_cgsnapshot_type()
            if grp.group_type_id == cgsnap_type['id']:
                volume_ref['volume']['consistencygroup_id'] = group_id

        return volume_ref
Пример #5
0
 def setUp(self):
     super(GroupTypesApiTest, self).setUp()
     self.controller = v3_group_types.GroupTypesController()
     self.specs_controller = v3_group_specs.GroupTypeSpecsController()
     self.ctxt = context.RequestContext(user_id=fake.USER_ID,
                                        project_id=fake.PROJECT_ID,
                                        is_admin=True)
     self.user_ctxt = context.RequestContext(user_id=fake.USER2_ID,
                                             project_id=fake.PROJECT2_ID,
                                             is_admin=False)
     self.type_id1 = self._create_group_type('group_type1',
                                             {'key1': 'value1'})
     self.type_id2 = self._create_group_type('group_type2',
                                             {'key2': 'value2'})
     self.type_id3 = self._create_group_type('group_type3',
                                             {'key3': 'value3'}, False,
                                             [fake.PROJECT_ID])
     self.type_id0 = group_types.get_default_cgsnapshot_type()['id']
Пример #6
0
 def setUp(self):
     super(GroupTypesApiTest, self).setUp()
     self.controller = v3_group_types.GroupTypesController()
     self.specs_controller = v3_group_specs.GroupTypeSpecsController()
     self.ctxt = context.RequestContext(user_id=fake.USER_ID,
                                        project_id=fake.PROJECT_ID,
                                        is_admin=True)
     self.user_ctxt = context.RequestContext(user_id=fake.USER2_ID,
                                             project_id=fake.PROJECT2_ID,
                                             is_admin=False)
     self.type_id1 = self._create_group_type('group_type1',
                                             {'key1': 'value1'})
     self.type_id2 = self._create_group_type('group_type2',
                                             {'key2': 'value2'})
     self.type_id3 = self._create_group_type('group_type3',
                                             {'key3': 'value3'}, False,
                                             [fake.PROJECT_ID])
     self.type_id0 = group_types.get_default_cgsnapshot_type()['id']
Пример #7
0
    def create(self, req, body):
        """Create a new consistency group."""
        versionutils.report_deprecated_feature(LOG, DEPRECATE_CG_API_MSG)
        LOG.debug('Creating new consistency group %s', body)
        self.assert_valid_body(body, 'consistencygroup')

        context = req.environ['cinder.context']
        context.authorize(group_policy.CREATE_POLICY)
        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:
            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
Пример #8
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(_LI("Creating consistency group %(name)s."), {"name": name})

        try:
            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
Пример #9
0
    def detail(self, request, volume):
        """Detailed view of a single volume."""
        volume_ref = {
            'volume': {
                'id': volume.get('id'),
                'status': self._get_volume_status(volume),
                'size': volume.get('size'),
                'availability_zone': volume.get('availability_zone'),
                'created_at': volume.get('created_at'),
                'updated_at': volume.get('updated_at'),
                'attachments': self._get_attachments(volume),
                'name': volume.get('display_name'),
                'description': volume.get('display_description'),
                'volume_type': self._get_volume_type(volume),
                'snapshot_id': volume.get('snapshot_id'),
                'source_volid': volume.get('source_volid'),
                'metadata': self._get_volume_metadata(volume),
                'links': self._get_links(request, volume['id']),
                'user_id': volume.get('user_id'),
                'bootable': six.text_type(volume.get('bootable')).lower(),
                'encrypted': self._is_volume_encrypted(volume),
                'replication_status': volume.get('replication_status'),
                'consistencygroup_id': volume.get('consistencygroup_id'),
                'multiattach': volume.get('multiattach'),
            }
        }
        if request.environ['cinder.context'].is_admin:
            volume_ref['volume']['migration_status'] = (
                volume.get('migration_status'))

        # NOTE(xyang): Display group_id as consistencygroup_id in detailed
        # view of the volume if group is converted from cg.
        group_id = volume.get('group_id')
        if group_id is not None:
            # Not found exception will be handled at the wsgi level
            ctxt = request.environ['cinder.context']
            grp = group_api.API().get(ctxt, group_id)
            cgsnap_type = group_types.get_default_cgsnapshot_type()
            if grp.group_type_id == cgsnap_type['id']:
                volume_ref['volume']['consistencygroup_id'] = group_id

        return volume_ref
Пример #10
0
    def detail(self, request, volume):
        """Detailed view of a single volume."""
        volume_ref = {
            "volume": {
                "id": volume.get("id"),
                "status": self._get_volume_status(volume),
                "size": volume.get("size"),
                "availability_zone": volume.get("availability_zone"),
                "created_at": volume.get("created_at"),
                "updated_at": volume.get("updated_at"),
                "attachments": self._get_attachments(volume),
                "name": volume.get("display_name"),
                "description": volume.get("display_description"),
                "volume_type": self._get_volume_type(volume),
                "snapshot_id": volume.get("snapshot_id"),
                "source_volid": volume.get("source_volid"),
                "metadata": self._get_volume_metadata(volume),
                "links": self._get_links(request, volume["id"]),
                "user_id": volume.get("user_id"),
                "bootable": six.text_type(volume.get("bootable")).lower(),
                "encrypted": self._is_volume_encrypted(volume),
                "replication_status": volume.get("replication_status"),
                "consistencygroup_id": volume.get("consistencygroup_id"),
                "multiattach": volume.get("multiattach"),
            }
        }
        if request.environ["cinder.context"].is_admin:
            volume_ref["volume"]["migration_status"] = volume.get("migration_status")

        # NOTE(xyang): Display group_id as consistencygroup_id in detailed
        # view of the volume if group is converted from cg.
        group_id = volume.get("group_id")
        if group_id is not None:
            # Not found exception will be handled at the wsgi level
            ctxt = request.environ["cinder.context"]
            grp = group_api.API().get(ctxt, group_id)
            cgsnap_type = group_types.get_default_cgsnapshot_type()
            if grp.group_type_id == cgsnap_type["id"]:
                volume_ref["volume"]["consistencygroup_id"] = group_id

        return volume_ref