~raharper/charms/trusty/swift-proxy/next-unique-get-zone

« back to all changes in this revision

Viewing changes to hooks/lib/openstack_common.py

  • Committer: James Page
  • Date: 2013-03-12 11:17:32 UTC
  • mto: (35.1.7 swift-proxy)
  • mto: This revision was merged to the branch mainline in revision 41.
  • Revision ID: james.page@canonical.com-20130312111732-h5movczdd3ymk5m2
Refactoring to split up utils, use common lib

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
    'oneiric': 'diablo',
13
13
    'precise': 'essex',
14
14
    'quantal': 'folsom',
15
 
    'raring' : 'grizzly'
 
15
    'raring': 'grizzly'
16
16
}
17
17
 
18
18
 
20
20
    '2011.2': 'diablo',
21
21
    '2012.1': 'essex',
22
22
    '2012.2': 'folsom',
23
 
    '2013.1': 'grizzly'
 
23
    '2013.1': 'grizzly',
 
24
    '2013.2': 'havana'
24
25
}
25
26
 
26
27
# The ugly duckling
32
33
    '1.7.7': 'grizzly'
33
34
}
34
35
 
 
36
 
35
37
def juju_log(msg):
36
38
    subprocess.check_call(['juju-log', msg])
37
39
 
76
78
            if v in src:
77
79
                return v
78
80
 
 
81
 
79
82
def get_os_codename_version(vers):
80
83
    '''Determine OpenStack codename from version number.'''
81
84
    try:
115
118
        return clean
116
119
 
117
120
    vers = None
118
 
    for l in output.split('\n'):
 
121
    for l in str(output).split('\n'):
119
122
        if l.startswith('ii'):
120
123
            l = _clean(l)
121
124
            if l[1] == pkg:
153
156
    e = "Could not determine OpenStack version for package: %s" % pkg
154
157
    error_out(e)
155
158
 
 
159
 
156
160
def configure_installation_source(rel):
157
161
    '''Configure apt installation source.'''
158
162
 
159
 
    def _import_key(id):
 
163
    def _import_key(keyid):
160
164
        cmd = "apt-key adv --keyserver keyserver.ubuntu.com " \
161
 
              "--recv-keys %s" % id
 
165
              "--recv-keys %s" % keyid
162
166
        try:
163
167
            subprocess.check_call(cmd.split(' '))
164
 
        except:
165
 
            error_out("Error importing repo key %s" % id)
 
168
        except subprocess.CalledProcessError:
 
169
            error_out("Error importing repo key %s" % keyid)
166
170
 
167
171
    if rel == 'distro':
168
172
        return
171
175
        subprocess.check_call(["add-apt-repository", "-y", src])
172
176
    elif rel[:3] == "deb":
173
177
        l = len(rel.split('|'))
174
 
        if l ==  2:
 
178
        if l == 2:
175
179
            src, key = rel.split('|')
176
180
            juju_log("Importing PPA key from keyserver for %s" % src)
177
181
            _import_key(key)
225
229
    else:
226
230
        error_out("Invalid openstack-release specified: %s" % rel)
227
231
 
228
 
HAPROXY_CONF = '/etc/haproxy/haproxy.cfg'
229
 
HAPROXY_DEFAULT = '/etc/default/haproxy'
230
 
 
231
 
def configure_haproxy(units, service_ports, template_dir=None):
232
 
    template_dir = template_dir or 'templates'
233
 
    import jinja2
234
 
    context = {
235
 
        'units': units,
236
 
        'service_ports': service_ports
237
 
        }
238
 
    templates = jinja2.Environment(
239
 
                    loader=jinja2.FileSystemLoader(template_dir)
240
 
                    )
241
 
    template = templates.get_template(
242
 
                    os.path.basename(HAPROXY_CONF)
243
 
                    )
244
 
    with open(HAPROXY_CONF, 'w') as f:
245
 
        f.write(template.render(context))
246
 
    with open(HAPROXY_DEFAULT, 'w') as f:
247
 
        f.write('ENABLED=1')
248
232
 
249
233
def save_script_rc(script_path="scripts/scriptrc", **env_vars):
250
234
    """
255
239
    service changes.
256
240
    """
257
241
    unit_name = os.getenv('JUJU_UNIT_NAME').replace('/', '-')
258
 
    juju_rc_path="/var/lib/juju/units/%s/charm/%s" % (unit_name, script_path)
 
242
    juju_rc_path = "/var/lib/juju/units/%s/charm/%s" % (unit_name, script_path)
259
243
    with open(juju_rc_path, 'wb') as rc_script:
260
244
        rc_script.write(
261
245
            "#!/bin/bash\n")