之前一直不知道context模块中存储的是什么东西,这回看一下代码;
其中最主要的类是:RequestContext;
class RequestContext(object):
 
"""Helper class to represent useful information about a request context.
 
Stores information about the security context under which the user
accesses the system, as well as additional request information.
"""
 
    user_idt_format = '{user} {tenant} {domain} {user_domain} {p_domain}'
 
    def __init__(self, auth_token=None, user=None, tenant=None, domain=None,
                       user_domain=None, project_domain=None, is_admin=False,
                       read_only=False, show_deleted=False, request_id=None,
                       instance_uuid=None):
        self.auth_token = auth_token
        self.user = user
        self.tenant = tenant
        self.domain = domain
        self.user_domain = user_domain
        self.project_domain = project_domain
        self.is_admin = is_admin
        self.read_only = read_only
        self.show_deleted = show_deleted
        self.instance_uuid = instance_uuid
        if not request_id:
            request_id = generate_request_id()
        self.request_id = request_id
        …...
"""Helper class to represent useful information about a request context.
 
Stores information about the security context under which the user
accesses the system, as well as additional request information.
"""
RequestContext类主要保存了一次web请求的useful context information,主要包括安全验证信息和其他一些信息;
如果用户想要对request的上下文新增一些信息,或加强功能,可以继承这个类;
 
其中两个函数分别获取admin上下文信息,和判断一个context是不是一个normal user:
def get_admin_context(show_deleted=False):
    context = RequestContext(None,
                    tenant=None,
                    is_admin=True,
                    show_deleted=show_deleted)
    return context
 
def is_user_context(context):
"""Indicates if the request context is a normal user."""
    if not context:
        return False
    if context.is_admin:
        return False
    if not context.user_id or not context.project_id:
        return False
    return True
 

openstack context的更多相关文章

  1. 在Openstack H版部署Nova Cell 时 ,终端输入nova service-list 和 nova host-list 命令将报错

    关于Cell的基本介绍,可以参考贤哥的一篇文章: [OpenStack]G版中关于Nova的Cell  http://blog.csdn.net/lynn_kong/article/details/8 ...

  2. Integrate NSX into Neutron

    NSX is VMware's strategy for Software-defined networking, it was implemented purely in software, and ...

  3. Openstack Periodic Task

    Openstack Periodic Task 周期性任务在各个模块的manager.py(computer,scheduler,cell,network)中添加. 添加方法:在模块manager类实 ...

  4. OpenStack 企业私有云的若干需求(3):多租户和租户间隔离(multi-tenancy and isolation)

    本系列会介绍OpenStack 企业私有云的几个需求: 自动扩展(Auto-scaling)支持 多租户和租户隔离 (multi-tenancy and tenancy isolation) 混合云( ...

  5. OpenStack 企业私有云的若干需求(1):Nova 虚机支持 GPU

    本系列会介绍OpenStack 企业私有云的几个需求: 自动扩展(Auto-scaling)支持 多租户和租户隔离 (multi-tenancy and tenancy isolation) 混合云( ...

  6. openstack vm_lifecycle

    nova instance状态:power_state, vm_state, task_state 2015-09-22 Openstack 185 nova instance有3种状态:power_ ...

  7. 理解 OpenStack 高可用(HA) (6): MySQL HA

    本系列会分析OpenStack 的高可用性(HA)概念和解决方案: (1)OpenStack 高可用方案概述 (2)Neutron L3 Agent HA - VRRP (虚拟路由冗余协议) (3)N ...

  8. 理解 OpenStack + Ceph (5):OpenStack 与 Ceph 之间的集成 [OpenStack Integration with Ceph]

    理解 OpenStack + Ceph 系列文章: (1)安装和部署 (2)Ceph RBD 接口和工具 (3)Ceph 物理和逻辑结构 (4)Ceph 的基础数据结构 (5)Ceph 与 OpenS ...

  9. 理解 OpenStack + Ceph (3):Ceph RBD 接口和工具 [Ceph RBD API and Tools]

    本系列文章会深入研究 Ceph 以及 Ceph 和 OpenStack 的集成: (1)安装和部署 (2)Ceph RBD 接口和工具 (3)Ceph 物理和逻辑结构 (4)Ceph 的基础数据结构 ...

随机推荐

  1. 【BZOJ 3295】动态逆序对 - 分块+树状数组

    题目描述 给定一个1~n的序列,然后m次删除元素,每次删除之前询问逆序对的个数. 分析:分块+树状数组 (PS:本题的CDQ分治解法见下一篇) 首先将序列分成T块,每一块开一个树状数组,并且先把最初的 ...

  2. 【Problem solved】 error C2665: “loadimage”: 2 个重载中没有一个可以转换所有参数类型

    选择“项目”菜单->项目属性->配置属性->常规->字符集,改为“未设置”即可.

  3. (02)odoo自定义模块

    * 官方建议模块骨架    --------------------------    addons/<my_module_name>/                 │─ __init ...

  4. struts2在pom.xml中的配置

    <dependencies> <dependency> <groupId>org.apache.struts</groupId> <artifac ...

  5. uva 242

    242 - Stamps and Envelope Size Time limit: 3.000 seconds  Stamps and Envelope Size  Philatelists hav ...

  6. 用Google Analytics跟踪JavaScript Errors (译)

    通过custom events来实施 // Track basic JavaScript errors window.addEventListener('error', function(e) { _ ...

  7. Greenplum——升级的分布式PostgresSQL

    Greenplum数据库基于PostgreSQL开源技术.本质上讲,它是多个PostgreSQL实例一起充当一个数据库管理系统.Greenplum以PostgreSQL 8.2.15为基础构建,在SQ ...

  8. java.lang.ThreadGroup.enumerate

    java.lang.ThreadGroup.enumerate(Thread[] list) 方法复制该线程组及其子组中的所有活动线程到指定的数组. 声明 以下是java.lang.ThreadGro ...

  9. Android 浮动搜索框 searchable 使用(转)。

    Android为程序的搜索功能提供了统一的搜索接口,search dialog和search widget,这里介绍search dialog使用.search dialog 只能为于activity ...

  10. HDU 3567 Eight II 打表,康托展开,bfs,g++提交可过c++不可过 难度:3

    http://acm.hdu.edu.cn/showproblem.php?pid=3567 相比Eight,似乎只是把目标状态由确定的改成不确定的,但是康托展开+曼哈顿为h值的A*和IDA*都不过, ...