~cbjchen/charms/trusty/cinder-ceph/remove_stale_key

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/hahelpers/cluster.py

  • Committer: james.page at ubuntu
  • Date: 2014-12-15 09:18:58 UTC
  • mfrom: (20.1.9 cinder-ceph)
  • Revision ID: james.page@ubuntu.com-20141215091858-qryinzazthotmi3p
[corey.bryant,r=james-page] Sort out charmhelpers issues.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
import subprocess
15
15
import os
16
 
 
17
16
from socket import gethostname as get_unit_hostname
18
17
 
 
18
import six
 
19
 
19
20
from charmhelpers.core.hookenv import (
20
21
    log,
21
22
    relation_ids,
77
78
        "show", resource
78
79
    ]
79
80
    try:
80
 
        status = subprocess.check_output(cmd)
 
81
        status = subprocess.check_output(cmd).decode('UTF-8')
81
82
    except subprocess.CalledProcessError:
82
83
        return False
83
84
    else:
139
140
        return True
140
141
    for r_id in relation_ids('identity-service'):
141
142
        for unit in relation_list(r_id):
 
143
            # TODO - needs fixing for new helper as ssl_cert/key suffixes with CN
142
144
            rel_state = [
143
145
                relation_get('https_keystone', rid=r_id, unit=unit),
144
 
                relation_get('ssl_cert', rid=r_id, unit=unit),
145
 
                relation_get('ssl_key', rid=r_id, unit=unit),
146
146
                relation_get('ca_cert', rid=r_id, unit=unit),
147
147
            ]
148
148
            # NOTE: works around (LP: #1203241)
151
151
    return False
152
152
 
153
153
 
154
 
def determine_api_port(public_port):
 
154
def determine_api_port(public_port, singlenode_mode=False):
155
155
    '''
156
156
    Determine correct API server listening port based on
157
157
    existence of HTTPS reverse proxy and/or haproxy.
158
158
 
159
159
    public_port: int: standard public port for given service
160
160
 
 
161
    singlenode_mode: boolean: Shuffle ports when only a single unit is present
 
162
 
161
163
    returns: int: the correct listening port for the API service
162
164
    '''
163
165
    i = 0
164
 
    if len(peer_units()) > 0 or is_clustered():
 
166
    if singlenode_mode:
 
167
        i += 1
 
168
    elif len(peer_units()) > 0 or is_clustered():
165
169
        i += 1
166
170
    if https():
167
171
        i += 1
168
172
    return public_port - (i * 10)
169
173
 
170
174
 
171
 
def determine_apache_port(public_port):
 
175
def determine_apache_port(public_port, singlenode_mode=False):
172
176
    '''
173
177
    Description: Determine correct apache listening port based on public IP +
174
178
    state of the cluster.
175
179
 
176
180
    public_port: int: standard public port for given service
177
181
 
 
182
    singlenode_mode: boolean: Shuffle ports when only a single unit is present
 
183
 
178
184
    returns: int: the correct listening port for the HAProxy service
179
185
    '''
180
186
    i = 0
181
 
    if len(peer_units()) > 0 or is_clustered():
 
187
    if singlenode_mode:
 
188
        i += 1
 
189
    elif len(peer_units()) > 0 or is_clustered():
182
190
        i += 1
183
191
    return public_port - (i * 10)
184
192
 
198
206
    for setting in settings:
199
207
        conf[setting] = config_get(setting)
200
208
    missing = []
201
 
    [missing.append(s) for s, v in conf.iteritems() if v is None]
 
209
    [missing.append(s) for s, v in six.iteritems(conf) if v is None]
202
210
    if missing:
203
211
        log('Insufficient config data to configure hacluster.', level=ERROR)
204
212
        raise HAIncompleteConfig