~ubuntu-branches/ubuntu/saucy/heat/saucy-updates

« back to all changes in this revision

Viewing changes to heat/engine/clients.py

  • Committer: Package Import Robot
  • Author(s): James Page, Chuck Short, James Page
  • Date: 2013-08-08 15:23:59 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130808152359-9jgqjp23kssvc3x9
Tags: 2013.2~b2.a186.g2b4b248-0ubuntu1
[ Chuck Short ]
* debian/patches/rename-quantumclient.patch: Dropped no longer needed. 
* debian/control: Add python-oslo.sphinx

[ James Page ]
* New upstream snapshot.
* d/watch: Updated to track releases on launchpad.
* d/control: Drop BD in pep8, no longer required.
* d/control,rules: Drop use of openstack-pkg-tools, revert use of xz
  compression for debs.
* d/control,*.config,*.templates,po: Drop use of debconf/dbconfig-common
  to configure heat.
* d/*.upstart: Add upstart configurations for Ubuntu.
* d/p/default-kombu.patch: Switch default messaging from qpid to
  kombu.
* d/p/default-sqlite.patch: Use sqlite as default database option.
* d/control: Add python-ceilometerclient to BD's.
* d/rules: Fail package build for unit test failures.
* d/*.install: Directly install configuration files to /etc/heat.
* d/control: Update VCS locations to ubuntu-server-dev branches.
* d/heat-common.{install,manpages}: Include new binaries and associated
  manpages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
    cinderclient = None
40
40
    logger.info('cinderclient not available')
41
41
 
 
42
try:
 
43
    from ceilometerclient.v2 import client as ceilometerclient
 
44
except ImportError:
 
45
    ceilometerclient = None
 
46
    logger.info('ceilometerclient not available')
 
47
 
42
48
 
43
49
cloud_opts = [
44
50
    cfg.StrOpt('cloud_backend',
60
66
        self._swift = None
61
67
        self._neutron = None
62
68
        self._cinder = None
 
69
        self._ceilometer = None
 
70
 
 
71
    @property
 
72
    def auth_token(self):
 
73
        # if there is no auth token in the context
 
74
        # attempt to get one using the context username and password
 
75
        return self.context.auth_token or self.keystone().auth_token
63
76
 
64
77
    def keystone(self):
65
78
        if self._keystone:
69
82
        return self._keystone
70
83
 
71
84
    def url_for(self, **kwargs):
72
 
        return self.keystone().client.service_catalog.url_for(**kwargs)
 
85
        return self.keystone().url_for(**kwargs)
73
86
 
74
87
    def nova(self, service_type='compute'):
75
88
        if service_type in self._nova:
76
89
            return self._nova[service_type]
77
90
 
78
91
        con = self.context
 
92
        if self.auth_token is None:
 
93
            logger.error("Nova connection failed, no auth_token!")
 
94
            return None
 
95
 
79
96
        args = {
80
97
            'project_id': con.tenant,
81
98
            'auth_url': con.auth_url,
82
99
            'service_type': service_type,
 
100
            'username': None,
 
101
            'api_key': None
83
102
        }
84
103
 
85
 
        if con.password is not None:
86
 
            args['username'] = con.username
87
 
            args['api_key'] = con.password
88
 
        elif con.auth_token is not None:
89
 
            args['username'] = None
90
 
            args['api_key'] = None
91
 
        else:
92
 
            logger.error("Nova connection failed, no password or auth_token!")
93
 
            return None
94
 
 
95
104
        client = novaclient.Client(1.1, **args)
96
105
 
97
 
        if con.password is None and con.auth_token is not None:
98
 
            management_url = self.url_for(service_type=service_type)
99
 
            client.client.auth_token = con.auth_token
100
 
            client.client.management_url = management_url
 
106
        management_url = self.url_for(service_type=service_type)
 
107
        client.client.auth_token = self.auth_token
 
108
        client.client.management_url = management_url
101
109
 
102
110
        self._nova[service_type] = client
103
111
        return client
109
117
            return self._swift
110
118
 
111
119
        con = self.context
 
120
        if self.auth_token is None:
 
121
            logger.error("Swift connection failed, no auth_token!")
 
122
            return None
 
123
 
112
124
        args = {
113
125
            'auth_version': '2.0',
114
126
            'tenant_name': con.tenant,
115
 
            'user': con.username
 
127
            'user': con.username,
 
128
            'key': None,
 
129
            'authurl': None,
 
130
            'preauthtoken': self.auth_token,
 
131
            'preauthurl': self.url_for(service_type='object-store')
116
132
        }
117
 
 
118
 
        if con.password is not None:
119
 
            args['key'] = con.password
120
 
            args['authurl'] = con.auth_url
121
 
        elif con.auth_token is not None:
122
 
            args['key'] = None
123
 
            args['authurl'] = None
124
 
            args['preauthtoken'] = con.auth_token
125
 
            args['preauthurl'] = self.url_for(service_type='object-store')
126
 
        else:
127
 
            logger.error("Swift connection failed, no password or " +
128
 
                         "auth_token!")
129
 
            return None
130
133
        self._swift = swiftclient.Connection(**args)
131
134
        return self._swift
132
135
 
134
137
        if neutronclient is None:
135
138
            return None
136
139
        if self._neutron:
137
 
            logger.debug('using existing _neutron')
138
140
            return self._neutron
139
141
 
140
142
        con = self.context
 
143
        if self.auth_token is None:
 
144
            logger.error("Neutron connection failed, no auth_token!")
 
145
            return None
 
146
 
141
147
        args = {
142
148
            'auth_url': con.auth_url,
143
149
            'service_type': 'network',
 
150
            'token': self.auth_token,
 
151
            'endpoint_url': self.url_for(service_type='network')
144
152
        }
145
153
 
146
 
        if con.password is not None:
147
 
            args['username'] = con.username
148
 
            args['password'] = con.password
149
 
            args['tenant_name'] = con.tenant
150
 
        elif con.auth_token is not None:
151
 
            args['token'] = con.auth_token
152
 
            args['endpoint_url'] = self.url_for(service_type='network')
153
 
        else:
154
 
            logger.error("Quantum connection failed, "
155
 
                         "no password or auth_token!")
156
 
            return None
157
 
        logger.debug('neutron args %s', args)
158
 
 
159
154
        self._neutron = neutronclient.Client(**args)
160
155
 
161
156
        return self._neutron
167
162
            return self._cinder
168
163
 
169
164
        con = self.context
 
165
        if self.auth_token is None:
 
166
            logger.error("Cinder connection failed, no auth_token!")
 
167
            return None
 
168
 
170
169
        args = {
171
170
            'service_type': 'volume',
172
171
            'auth_url': con.auth_url,
173
 
            'project_id': con.tenant
 
172
            'project_id': con.tenant,
 
173
            'username': None,
 
174
            'api_key': None
174
175
        }
175
176
 
176
 
        if con.password is not None:
177
 
            args['username'] = con.username
178
 
            args['api_key'] = con.password
179
 
        elif con.auth_token is not None:
180
 
            args['username'] = None
181
 
            args['api_key'] = None
182
 
        else:
183
 
            logger.error("Cinder connection failed, "
184
 
                         "no password or auth_token!")
185
 
            return None
186
 
        logger.debug('cinder args %s', args)
187
 
 
188
177
        self._cinder = cinderclient.Client('1', **args)
189
 
        if con.password is None and con.auth_token is not None:
190
 
            management_url = self.url_for(service_type='volume')
191
 
            self._cinder.client.auth_token = con.auth_token
192
 
            self._cinder.client.management_url = management_url
 
178
        management_url = self.url_for(service_type='volume')
 
179
        self._cinder.client.auth_token = self.auth_token
 
180
        self._cinder.client.management_url = management_url
193
181
 
194
182
        return self._cinder
195
183
 
 
184
    def ceilometer(self):
 
185
        if ceilometerclient is None:
 
186
            return None
 
187
        if self._ceilometer:
 
188
            return self._ceilometer
 
189
 
 
190
        if self.auth_token is None:
 
191
            logger.error("Ceilometer connection failed, no auth_token!")
 
192
            return None
 
193
        con = self.context
 
194
        args = {
 
195
            'auth_url': con.auth_url,
 
196
            'service_type': 'metering',
 
197
            'project_id': con.tenant,
 
198
            'token': self.auth_token,
 
199
            'endpoint': self.url_for(service_type='metering'),
 
200
        }
 
201
 
 
202
        client = ceilometerclient.Client(**args)
 
203
 
 
204
        self._ceilometer = client
 
205
        return self._ceilometer
 
206
 
 
207
 
196
208
if cfg.CONF.cloud_backend:
197
209
    cloud_backend_module = importutils.import_module(cfg.CONF.cloud_backend)
198
210
    Clients = cloud_backend_module.Clients