39
39
cinderclient = None
40
40
logger.info('cinderclient not available')
43
from ceilometerclient.v2 import client as ceilometerclient
45
ceilometerclient = None
46
logger.info('ceilometerclient not available')
44
50
cfg.StrOpt('cloud_backend',
69
82
return self._keystone
71
84
def url_for(self, **kwargs):
72
return self.keystone().client.service_catalog.url_for(**kwargs)
85
return self.keystone().url_for(**kwargs)
74
87
def nova(self, service_type='compute'):
75
88
if service_type in self._nova:
76
89
return self._nova[service_type]
92
if self.auth_token is None:
93
logger.error("Nova connection failed, no auth_token!")
80
97
'project_id': con.tenant,
81
98
'auth_url': con.auth_url,
82
99
'service_type': service_type,
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
92
logger.error("Nova connection failed, no password or auth_token!")
95
104
client = novaclient.Client(1.1, **args)
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
102
110
self._nova[service_type] = client
109
117
return self._swift
111
119
con = self.context
120
if self.auth_token is None:
121
logger.error("Swift connection failed, no auth_token!")
113
125
'auth_version': '2.0',
114
126
'tenant_name': con.tenant,
127
'user': con.username,
130
'preauthtoken': self.auth_token,
131
'preauthurl': self.url_for(service_type='object-store')
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:
123
args['authurl'] = None
124
args['preauthtoken'] = con.auth_token
125
args['preauthurl'] = self.url_for(service_type='object-store')
127
logger.error("Swift connection failed, no password or " +
130
133
self._swift = swiftclient.Connection(**args)
131
134
return self._swift
134
137
if neutronclient is None:
136
139
if self._neutron:
137
logger.debug('using existing _neutron')
138
140
return self._neutron
140
142
con = self.context
143
if self.auth_token is None:
144
logger.error("Neutron connection failed, no auth_token!")
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')
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')
154
logger.error("Quantum connection failed, "
155
"no password or auth_token!")
157
logger.debug('neutron args %s', args)
159
154
self._neutron = neutronclient.Client(**args)
161
156
return self._neutron
167
162
return self._cinder
169
164
con = self.context
165
if self.auth_token is None:
166
logger.error("Cinder connection failed, no auth_token!")
171
170
'service_type': 'volume',
172
171
'auth_url': con.auth_url,
173
'project_id': con.tenant
172
'project_id': con.tenant,
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
183
logger.error("Cinder connection failed, "
184
"no password or auth_token!")
186
logger.debug('cinder args %s', args)
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
194
182
return self._cinder
184
def ceilometer(self):
185
if ceilometerclient is None:
188
return self._ceilometer
190
if self.auth_token is None:
191
logger.error("Ceilometer connection failed, no auth_token!")
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'),
202
client = ceilometerclient.Client(**args)
204
self._ceilometer = client
205
return self._ceilometer
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