'Tenant id is given to handle the case when creating a security
group rule on behalf of another use.'

@db_api.retry_if_session_inactive()
def get_security_group(self, context, id, fields=None, tenant_id=None):

    if tenant_id:
        tmp_context_tenant_id = context.tenant_id
        context.tenant_id = tenant_id
    try:
        with db_api.context_manager.reader.using(context):
            ret = self._make_security_group_dict(self._get_security_group(context, id), fields)
            ret['security_group_rules'] = self.get_security_group_rules(context, {'security_group_id': [id]})
    finally:
        if tenant_id:
            context.tenant_id = tmp_context_tenant_id
    return ret
