Example #1
0
def create_group(ctxt,
                 host='test_host@fakedrv#fakepool',
                 name='test_group',
                 description='this is a test group',
                 status=fields.GroupStatus.AVAILABLE,
                 availability_zone='fake_az',
                 group_type_id=None,
                 volume_type_ids=None,
                 **kwargs):
    """Create a group object in the DB."""

    grp = objects.Group(ctxt)
    grp.host = host
    grp.user_id = ctxt.user_id or fake.USER_ID
    grp.project_id = ctxt.project_id or fake.PROJECT_ID
    grp.status = status
    grp.name = name
    grp.description = description
    grp.availability_zone = availability_zone
    if group_type_id:
        grp.group_type_id = group_type_id
    if volume_type_ids:
        grp.volume_type_ids = volume_type_ids
    new_id = kwargs.pop('id', None)
    grp.update(kwargs)
    grp.create()
    if new_id and new_id != grp.id:
        db.group_update(ctxt, grp.id, {'id': new_id})
        grp = objects.Group.get_by_id(ctxt, new_id)
    return grp
Example #2
0
def create_group(ctxt,
                 host='test_host@fakedrv#fakepool',
                 name='test_group',
                 description='this is a test group',
                 status=fields.GroupStatus.AVAILABLE,
                 availability_zone='fake_az',
                 group_type_id=None,
                 volume_type_ids=None,
                 **kwargs):
    """Create a group object in the DB."""

    grp = objects.Group(ctxt)
    grp.host = host
    grp.user_id = ctxt.user_id or fake.USER_ID
    grp.project_id = ctxt.project_id or fake.PROJECT_ID
    grp.status = status
    grp.name = name
    grp.description = description
    grp.availability_zone = availability_zone
    if group_type_id:
        grp.group_type_id = group_type_id
    if volume_type_ids:
        grp.volume_type_ids = volume_type_ids
    new_id = kwargs.pop('id', None)
    grp.update(kwargs)
    grp.create()
    if new_id and new_id != grp.id:
        db.group_update(ctxt, grp.id, {'id': new_id})
        grp = objects.Group.get_by_id(ctxt, new_id)
    return grp
Example #3
0
    def save(self):
        updates = self.cinder_obj_get_changes()
        if updates:
            if 'volume_types' in updates:
                msg = _('Cannot save volume_types changes in group object '
                        'update.')
                raise exception.ObjectActionError(action='save', reason=msg)
            if 'volumes' in updates:
                msg = _('Cannot save volumes changes in group object update.')
                raise exception.ObjectActionError(action='save', reason=msg)
            if 'group_snapshots' in updates:
                msg = _('Cannot save group_snapshots changes in group object '
                        'update.')
                raise exception.ObjectActionError(action='save', reason=msg)

            db.group_update(self._context, self.id, updates)
            self.obj_reset_changes()
Example #4
0
    def save(self):
        updates = self.cinder_obj_get_changes()
        if updates:
            if 'volume_types' in updates:
                msg = _('Cannot save volume_types changes in group object '
                        'update.')
                raise exception.ObjectActionError(
                    action='save', reason=msg)
            if 'volumes' in updates:
                msg = _('Cannot save volumes changes in group object update.')
                raise exception.ObjectActionError(
                    action='save', reason=msg)
            if 'group_snapshots' in updates:
                msg = _('Cannot save group_snapshots changes in group object '
                        'update.')
                raise exception.ObjectActionError(
                    action='save', reason=msg)

            db.group_update(self._context, self.id, updates)
            self.obj_reset_changes()