1
1
# Copyright 2014-2015 Canonical Limited.
3
# This file is part of charm-helpers.
5
# charm-helpers is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU Lesser General Public License version 3 as
7
# published by the Free Software Foundation.
9
# charm-helpers is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public License
15
# along with charm-helpers. If not, see <http://www.gnu.org/licenses/>.
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
18
16
# Copyright 2012 Canonical Ltd.
274
277
Obtains all relevant configuration from charm configuration required
275
278
for initiating a relation to hacluster:
277
ha-bindiface, ha-mcastport, vip
280
ha-bindiface, ha-mcastport, vip, os-internal-hostname,
281
os-admin-hostname, os-public-hostname, os-access-hostname
279
283
param: exclude_keys: list of setting key(s) to be excluded.
280
284
returns: dict: A dict containing settings keyed by setting name.
281
raises: HAIncompleteConfig if settings are missing.
285
raises: HAIncompleteConfig if settings are missing or incorrect.
283
settings = ['ha-bindiface', 'ha-mcastport', 'vip']
287
settings = ['ha-bindiface', 'ha-mcastport', 'vip', 'os-internal-hostname',
288
'os-admin-hostname', 'os-public-hostname', 'os-access-hostname']
285
290
for setting in settings:
286
291
if exclude_keys and setting in exclude_keys:
289
294
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
296
if not valid_hacluster_config():
297
raise HAIncorrectConfig('Insufficient or incorrect config data to '
298
'configure hacluster.')
302
def valid_hacluster_config():
304
Check that either vip or dns-ha is set. If dns-ha then one of os-*-hostname
307
Note: ha-bindiface and ha-macastport both have defaults and will always
308
be set. We only care that either vip or dns-ha is set.
310
:returns: boolean: valid config returns true.
311
raises: HAIncompatibileConfig if settings conflict.
312
raises: HAIncompleteConfig if settings are missing.
314
vip = config_get('vip')
315
dns = config_get('dns-ha')
316
if not(bool(vip) ^ bool(dns)):
317
msg = ('HA: Either vip or dns-ha must be set but not both in order to '
318
'use high availability')
319
status_set('blocked', msg)
320
raise HAIncorrectConfig(msg)
322
# If dns-ha then one of os-*-hostname must be set
324
dns_settings = ['os-internal-hostname', 'os-admin-hostname',
325
'os-public-hostname', 'os-access-hostname']
326
# At this point it is unknown if one or all of the possible
327
# network spaces are in HA. Validate at least one is set which is
328
# the minimum required.
329
for setting in dns_settings:
330
if config_get(setting):
331
log('DNS HA: At least one hostname is set {}: {}'
332
''.format(setting, config_get(setting)),
336
msg = ('DNS HA: At least one os-*-hostname(s) must be set to use '
338
status_set('blocked', msg)
339
raise HAIncompleteConfig(msg)
341
log('VIP HA: VIP is set {}'.format(vip), level=DEBUG)
298
345
def canonical_url(configs, vip_setting='vip'):
300
347
Returns the correct HTTP URL to this host given the state of HTTPS