def server_group_update(self, context, group_uuid, values): """Update the attributes of a group. If values contains a metadata key, it updates the aggregate metadata too. Similarly for the policies and members. """ group_query = model_query( context, models.ServerGroup).filter_by(uuid=group_uuid) group = group_query.first() if not group: raise exception.ServerGroupNotFound(group_uuid=group_uuid) policies = values.get('policies') if policies is not None: self._server_group_policies_add(context, group.id, values.pop('policies'), True) members = values.get('members') if members is not None: self._server_group_members_add(context, group.id, values.pop('members'), True) with _session_for_write(): group_query.update(values) if policies: values['policies'] = policies if members: values['members'] = members
def server_group_get(self, context, group_uuid): """Get a specific group by uuid.""" columns_to_join = ['_policies', '_members'] query = model_query(context, models.ServerGroup) for c in columns_to_join: query = query.options(orm.joinedload(c)) query = query.filter(models.ServerGroup.uuid == group_uuid) group = query.first() if not group: raise exception.ServerGroupNotFound(group_uuid=group_uuid) return group
def server_group_delete(self, context, group_uuid): """Delete a group.""" query = model_query(context, models.ServerGroup).filter_by(uuid=group_uuid) group = query.first() if not group: raise exception.ServerGroupNotFound(group_uuid=group_uuid) # Delete policies and members instance_models = [models.ServerGroupPolicy, models.ServerGroupMember] for model in instance_models: model_query(context, model).filter_by(group_id=group.id).delete() with _session_for_write(): query.delete()
def server_group_members_add(self, context, group_uuid, members): group = model_query( context, models.ServerGroup).filter_by(uuid=group_uuid).first() if not group: raise exception.ServerGroupNotFound(group_uuid=group_uuid) self._server_group_members_add(context, group.id, members)