~openstack-charmers-archive/charms/trusty/neutron-api/next

« 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:14:03 UTC
  • mfrom: (63.1.8 neutron-api)
  • Revision ID: james.page@ubuntu.com-20141215091403-af7ic1lxnnjsh4zu
[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:
150
151
    return False
151
152
 
152
153
 
153
 
def determine_api_port(public_port):
 
154
def determine_api_port(public_port, singlenode_mode=False):
154
155
    '''
155
156
    Determine correct API server listening port based on
156
157
    existence of HTTPS reverse proxy and/or haproxy.
157
158
 
158
159
    public_port: int: standard public port for given service
159
160
 
 
161
    singlenode_mode: boolean: Shuffle ports when only a single unit is present
 
162
 
160
163
    returns: int: the correct listening port for the API service
161
164
    '''
162
165
    i = 0
163
 
    if len(peer_units()) > 0 or is_clustered():
 
166
    if singlenode_mode:
 
167
        i += 1
 
168
    elif len(peer_units()) > 0 or is_clustered():
164
169
        i += 1
165
170
    if https():
166
171
        i += 1
167
172
    return public_port - (i * 10)
168
173
 
169
174
 
170
 
def determine_apache_port(public_port):
 
175
def determine_apache_port(public_port, singlenode_mode=False):
171
176
    '''
172
177
    Description: Determine correct apache listening port based on public IP +
173
178
    state of the cluster.
174
179
 
175
180
    public_port: int: standard public port for given service
176
181
 
 
182
    singlenode_mode: boolean: Shuffle ports when only a single unit is present
 
183
 
177
184
    returns: int: the correct listening port for the HAProxy service
178
185
    '''
179
186
    i = 0
180
 
    if len(peer_units()) > 0 or is_clustered():
 
187
    if singlenode_mode:
 
188
        i += 1
 
189
    elif len(peer_units()) > 0 or is_clustered():
181
190
        i += 1
182
191
    return public_port - (i * 10)
183
192
 
197
206
    for setting in settings:
198
207
        conf[setting] = config_get(setting)
199
208
    missing = []
200
 
    [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]
201
210
    if missing:
202
211
        log('Insufficient config data to configure hacluster.', level=ERROR)
203
212
        raise HAIncompleteConfig