274
279
Obtains all relevant configuration from charm configuration required
275
280
for initiating a relation to hacluster:
277
ha-bindiface, ha-mcastport, vip
282
ha-bindiface, ha-mcastport, vip, os-internal-hostname,
283
os-admin-hostname, os-public-hostname
279
285
param: exclude_keys: list of setting key(s) to be excluded.
280
286
returns: dict: A dict containing settings keyed by setting name.
281
raises: HAIncompleteConfig if settings are missing.
287
raises: HAIncompleteConfig if settings are missing or incorrect.
283
settings = ['ha-bindiface', 'ha-mcastport', 'vip']
289
settings = ['ha-bindiface', 'ha-mcastport', 'vip', 'os-internal-hostname',
290
'os-admin-hostname', 'os-public-hostname']
285
292
for setting in settings:
286
293
if exclude_keys and setting in exclude_keys:
289
296
conf[setting] = config_get(setting)
291
[missing.append(s) for s, v in six.iteritems(conf) if v is None]
293
log('Insufficient config data to configure hacluster.', level=ERROR)
294
raise HAIncompleteConfig
298
if not valid_hacluster_config():
299
raise HAIncorrectConfig('Insufficient or incorrect config data to '
300
'configure hacluster.')
304
def valid_hacluster_config():
306
Check that either vip or dns-ha is set. If dns-ha then one of os-*-hostname
309
Note: ha-bindiface and ha-macastport both have defaults and will always
310
be set. We only care that either vip or dns-ha is set.
312
:returns: boolean: valid config returns true.
313
raises: HAIncompatibileConfig if settings conflict.
314
raises: HAIncompleteConfig if settings are missing.
316
vip = config_get('vip')
317
dns = config_get('dns-ha')
318
if not(bool(vip) ^ bool(dns)):
319
msg = ('HA: Either vip or dns-ha must be set but not both in order to '
320
'use high availability')
321
status_set('blocked', msg)
322
raise HAIncorrectConfig(msg)
324
# If dns-ha then one of os-*-hostname must be set
326
dns_settings = ['os-internal-hostname', 'os-admin-hostname',
327
'os-public-hostname']
328
# At this point it is unknown if one or all of the possible
329
# network spaces are in HA. Validate at least one is set which is
330
# the minimum required.
331
for setting in dns_settings:
332
if config_get(setting):
333
log('DNS HA: At least one hostname is set {}: {}'
334
''.format(setting, config_get(setting)),
338
msg = ('DNS HA: At least one os-*-hostname(s) must be set to use '
340
status_set('blocked', msg)
341
raise HAIncompleteConfig(msg)
343
log('VIP HA: VIP is set {}'.format(vip), level=DEBUG)
298
347
def canonical_url(configs, vip_setting='vip'):
300
349
Returns the correct HTTP URL to this host given the state of HTTPS