~ubuntu-branches/ubuntu/trusty/quantum/trusty

« back to all changes in this revision

Viewing changes to quantum/context.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 09:43:14 UTC
  • mfrom: (2.1.16)
  • Revision ID: package-import@ubuntu.com-20121123094314-e1tqsulrwe21b9aq
Tags: 2013.1~g1-0ubuntu1
[ Adam Gandelman ]
* debian/patches/*: Refreshed for opening of Grizzly.

[ Chuck Short ]
* New upstream release.
* debian/rules: FTFBS if there is missing binaries.
* debian/quantum-server.install: Add quantum-debug.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""Context: context for security/db session."""
19
19
 
20
20
import copy
21
 
import logging
22
21
 
23
22
from datetime import datetime
24
23
 
25
24
from quantum.db import api as db_api
26
25
from quantum.openstack.common import context as common_context
 
26
from quantum.openstack.common import log as logging
 
27
 
 
28
 
27
29
LOG = logging.getLogger(__name__)
28
30
 
29
31
 
30
 
class Context(common_context.RequestContext):
 
32
class ContextBase(common_context.RequestContext):
31
33
    """Security context and request information.
32
34
 
33
35
    Represents the user taking a given action within the system.
44
46
        if kwargs:
45
47
            LOG.warn(_('Arguments dropped when creating '
46
48
                       'context: %s') % str(kwargs))
47
 
        super(Context, self).__init__(user=user_id, tenant=tenant_id,
48
 
                                      is_admin=is_admin)
49
 
        self.user_id = user_id
50
 
        self.tenant_id = tenant_id
 
49
        super(ContextBase, self).__init__(user=user_id, tenant=tenant_id,
 
50
                                          is_admin=is_admin)
51
51
        self.roles = roles or []
52
52
        if self.is_admin is None:
53
53
            self.is_admin = 'admin' in [x.lower() for x in self.roles]
59
59
        self.timestamp = timestamp
60
60
        self._session = None
61
61
 
 
62
    @property
 
63
    def project_id(self):
 
64
        return self.tenant
 
65
 
 
66
    @property
 
67
    def tenant_id(self):
 
68
        return self.tenant
 
69
 
 
70
    @tenant_id.setter
 
71
    def tenant_id(self, tenant_id):
 
72
        self.tenant = tenant_id
 
73
 
 
74
    @property
 
75
    def user_id(self):
 
76
        return self.user
 
77
 
 
78
    @user_id.setter
 
79
    def user_id(self, user_id):
 
80
        self.user = user_id
 
81
 
62
82
    def _get_read_deleted(self):
63
83
        return self._read_deleted
64
84
 
74
94
    read_deleted = property(_get_read_deleted, _set_read_deleted,
75
95
                            _del_read_deleted)
76
96
 
77
 
    @property
78
 
    def session(self):
79
 
        if self._session is None:
80
 
            self._session = db_api.get_session()
81
 
        return self._session
82
 
 
83
97
    def to_dict(self):
84
98
        return {'user_id': self.user_id,
85
99
                'tenant_id': self.tenant_id,
 
100
                'project_id': self.project_id,
86
101
                'is_admin': self.is_admin,
87
102
                'read_deleted': self.read_deleted,
88
103
                'roles': self.roles,
106
121
        return context
107
122
 
108
123
 
 
124
class Context(ContextBase):
 
125
    @property
 
126
    def session(self):
 
127
        if self._session is None:
 
128
            self._session = db_api.get_session()
 
129
        return self._session
 
130
 
 
131
 
109
132
def get_admin_context(read_deleted="no"):
110
133
    return Context(user_id=None,
111
134
                   tenant_id=None,
112
135
                   is_admin=True,
113
136
                   read_deleted=read_deleted)
 
137
 
 
138
 
 
139
def get_admin_context_without_session(read_deleted="no"):
 
140
    return ContextBase(user_id=None,
 
141
                       tenant_id=None,
 
142
                       is_admin=True,
 
143
                       read_deleted=read_deleted)