2
# Copyright 2012 Canonical Ltd.
4
# This file is sourced from lp:openstack-charm-helpers
7
# James Page <james.page@ubuntu.com>
8
# Adam Gandelman <adamg@ubuntu.com>
24
for r_id in (relation_ids('ha') or []):
25
for unit in (relation_list(r_id) or []):
26
clustered = relation_get('clustered',
34
def is_leader(resource):
40
status = subprocess.check_output(cmd)
41
except subprocess.CalledProcessError:
44
if get_unit_hostname() in status:
52
for r_id in (relation_ids('cluster') or []):
53
for unit in (relation_list(r_id) or []):
58
def oldest_peer(peers):
59
local_unit_no = int(os.getenv('JUJU_UNIT_NAME').split('/')[1])
61
remote_unit_no = int(peer.split('/')[1])
62
if remote_unit_no < local_unit_no:
67
def eligible_leader(resource):
69
if not is_leader(resource):
70
juju_log('INFO', 'Deferring action to CRM leader.')
74
if peers and not oldest_peer(peers):
75
juju_log('INFO', 'Deferring action to oldest service unit.')
82
Determines whether enough data has been provided in configuration
83
or relation data to configure HTTPS
87
if config_get('use-https') == "yes":
89
if config_get('ssl_cert') and config_get('ssl_key'):
91
for r_id in relation_ids('identity-service'):
92
for unit in relation_list(r_id):
93
if (relation_get('https_keystone', rid=r_id, unit=unit) and
94
relation_get('ssl_cert', rid=r_id, unit=unit) and
95
relation_get('ssl_key', rid=r_id, unit=unit) and
96
relation_get('ca_cert', rid=r_id, unit=unit)):
101
def determine_api_port(public_port):
103
Determine correct API server listening port based on
104
existence of HTTPS reverse proxy and/or haproxy.
106
public_port: int: standard public port for given service
108
returns: int: the correct listening port for the API service
111
if len(peer_units()) > 0 or is_clustered():
115
return public_port - (i * 10)
118
def determine_haproxy_port(public_port):
120
Description: Determine correct proxy listening port based on public IP +
121
existence of HTTPS reverse proxy.
123
public_port: int: standard public port for given service
125
returns: int: the correct listening port for the HAProxy service
130
return public_port - (i * 10)