~vds/charms/trusty/contrail-configuration/TLS_support_for_RabbitMQ_connection

« back to all changes in this revision

Viewing changes to hooks/contrail_configuration_utils.py

  • Committer: Robert Ayres
  • Date: 2016-07-29 05:22:31 UTC
  • Revision ID: robert.ayres@canonical.com-20160729052231-93zwlaocd1457uoe
Add control-network option, fixes lp #1597791

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
import json
17
17
import urllib2
18
18
 
 
19
from charmhelpers.contrib.network.ip import get_address_in_network
 
20
 
19
21
from charmhelpers.core.hookenv import (
20
22
    config,
21
23
    leader_get,
149
151
        pass
150
152
 
151
153
def contrail_ctx():
152
 
    addr = gethostbyname(unit_get("private-address"))
 
154
    addr = control_network_ip()
153
155
    return { "api_port": api_port(),
154
156
             "ifmap_server": addr,
155
157
             "disc_server": addr,
227
229
                creds.append(c)
228
230
    return { "ifmap_creds": creds }
229
231
 
 
232
def control_network_ip():
 
233
    fallback = gethostbyname(unit_get("private-address"))
 
234
    network = config.get("control-network")
 
235
    if network:
 
236
        return get_address_in_network(network, fallback)
 
237
    else:
 
238
        return fallback
 
239
 
230
240
def discovery_port():
231
241
    return 5998
232
242
 
308
318
 
309
319
def provision_configuration():
310
320
    hostname = gethostname()
311
 
    ip = gethostbyname(unit_get("private-address"))
 
321
    ip = control_network_ip()
312
322
    user, password, tenant = [ (relation_get("service_username", unit, rid),
313
323
                                relation_get("service_password", unit, rid),
314
324
                                relation_get("service_tenant_name", unit, rid))
325
335
                "--admin_user", user,
326
336
                "--admin_password", password,
327
337
                "--admin_tenant_name", tenant])
 
338
    config["provisioned-host-ip"] = ip
328
339
 
329
340
def provision_metadata():
330
341
    ip = [ gethostbyname(relation_get("private-address", unit, rid))
354
365
                  for unit in related_units(rid) ]
355
366
 
356
367
def unprovision_configuration():
357
 
    if not remote_unit():
 
368
    relation = relation_type()
 
369
    if relation and not remote_unit():
358
370
        return
359
371
    hostname = gethostname()
360
 
    ip = gethostbyname(unit_get("private-address"))
361
 
    relation = relation_type()
 
372
    ip = config["provisioned-host-ip"]
362
373
    user = None
363
374
    password = None
364
375
    tenant = None
382
393
                "--admin_user", user,
383
394
                "--admin_password", password,
384
395
                "--admin_tenant_name", tenant])
 
396
    del config["provisioned-host-ip"]
385
397
 
386
398
def unprovision_metadata():
387
399
    if not remote_unit():
417
429
                "--admin_user", user,
418
430
                "--admin_password", password])
419
431
 
 
432
def wait_for_contrail_api():
 
433
    port = str(api_port())
 
434
    try:
 
435
        check_url("http://localhost:" + port)
 
436
    except urllib2.URLError:
 
437
        log("contrail-api service has failed to start correctly on port {}".format(port),
 
438
            "CRITICAL")
 
439
        log("This is typically due to a runtime error in related services",
 
440
            "CRITICAL")
 
441
        raise
 
442
 
420
443
def write_barbican_auth_config():
421
444
    ctx = identity_admin_ctx()
422
445
    render("contrail-lbaas-auth.conf",