104
105
def config_flags_parser(config_flags):
105
106
"""Parses config flags string into dict.
108
This parsing method supports a few different formats for the config
109
flag values to be parsed:
111
1. A string in the simple format of key=value pairs, with the possibility
112
of specifying multiple key value pairs within the same string. For
113
example, a string in the format of 'key1=value1, key2=value2' will
118
2. A string in the above format, but supporting a comma-delimited list
119
of values for the same key. For example, a string in the format of
120
'key1=value1, key2=value3,value4,value5' will return a dict of:
122
'key2', 'value2,value3,value4'}
124
3. A string containing a colon character (:) prior to an equal
125
character (=) will be treated as yaml and parsed as such. This can be
126
used to specify more complex key value pairs. For example,
127
a string in the format of 'key1: subkey1=value1, subkey2=value2' will
129
{'key1', 'subkey1=value1, subkey2=value2'}
107
131
The provided config_flags string may be a list of comma-separated values
108
132
which themselves may be comma-separated list of values.
134
# If we find a colon before an equals sign then treat it as yaml.
135
# Note: limit it to finding the colon first since this indicates assignment
137
colon = config_flags.find(':')
138
equals = config_flags.find('=')
140
if colon < equals or equals < 0:
141
return yaml.safe_load(config_flags)
110
143
if config_flags.find('==') >= 0:
111
144
log("config_flags is not in expected format (key=value)", level=ERROR)
112
145
raise OSContextError
191
224
unit=local_unit())
192
225
if set_hostname != access_hostname:
193
226
relation_set(relation_settings={hostname_key: access_hostname})
194
return ctxt # Defer any further hook execution for now....
227
return None # Defer any further hook execution for now....
196
229
password_setting = 'password'
197
230
if self.relation_prefix:
279
312
class IdentityServiceContext(OSContextGenerator):
280
313
interfaces = ['identity-service']
315
def __init__(self, service=None, service_user=None):
316
self.service = service
317
self.service_user = service_user
282
319
def __call__(self):
283
320
log('Generating template context for identity-service', level=DEBUG)
323
if self.service and self.service_user:
324
# This is required for pki token signing if we don't want /tmp to
326
cachedir = '/var/cache/%s' % (self.service)
327
if not os.path.isdir(cachedir):
328
log("Creating service cache dir %s" % (cachedir), level=DEBUG)
329
mkdir(path=cachedir, owner=self.service_user,
330
group=self.service_user, perms=0o700)
332
ctxt['signing_dir'] = cachedir
285
334
for rid in relation_ids('identity-service'):
286
335
for unit in related_units(rid):
287
336
rdata = relation_get(rid=rid, unit=unit)
291
340
auth_host = format_ipv6_addr(auth_host) or auth_host
292
341
svc_protocol = rdata.get('service_protocol') or 'http'
293
342
auth_protocol = rdata.get('auth_protocol') or 'http'
294
ctxt = {'service_port': rdata.get('service_port'),
295
'service_host': serv_host,
296
'auth_host': auth_host,
297
'auth_port': rdata.get('auth_port'),
298
'admin_tenant_name': rdata.get('service_tenant'),
299
'admin_user': rdata.get('service_username'),
300
'admin_password': rdata.get('service_password'),
301
'service_protocol': svc_protocol,
302
'auth_protocol': auth_protocol}
343
ctxt.update({'service_port': rdata.get('service_port'),
344
'service_host': serv_host,
345
'auth_host': auth_host,
346
'auth_port': rdata.get('auth_port'),
347
'admin_tenant_name': rdata.get('service_tenant'),
348
'admin_user': rdata.get('service_username'),
349
'admin_password': rdata.get('service_password'),
350
'service_protocol': svc_protocol,
351
'auth_protocol': auth_protocol})
303
353
if context_complete(ctxt):
304
354
# NOTE(jamespage) this is required for >= icehouse
305
355
# so a missing value just indicates keystone needs
1021
1071
for unit in related_units(rid):
1022
1072
ctxt['zmq_nonce'] = relation_get('nonce', unit, rid)
1023
1073
ctxt['zmq_host'] = relation_get('host', unit, rid)
1074
ctxt['zmq_redis_address'] = relation_get(
1075
'zmq_redis_address', unit, rid)