~thomnico/charms/precise/clearwater-ralf/trunk

« back to all changes in this revision

Viewing changes to lib/config_script

  • Committer: Mike Evans
  • Date: 2014-06-06 00:33:40 UTC
  • Revision ID: mike.evans@metaswitch.com-20140606003340-xviyguy7zcfffrnt
DNSaaS integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
import subprocess
3
 
import string
4
 
import socket
5
 
import os
6
 
import urllib2
7
 
 
8
 
# Create the /etc/clearwater/config file.
9
 
#
10
 
# Node specific information is got from the charms config, the IP
11
 
# infomation is got from the unit config, and the domain information
12
 
# is got from the relation with the clearwater-route53 charm
13
 
#
14
 
# The config file is templated in lib/config_template.
15
 
 
16
 
# Populate the dictionary
17
 
d = {}
18
 
 
19
 
# IP configuration
20
 
d['PUBLIC_HOSTNAME'] = subprocess.check_output(["unit-get", "public-address"])
21
 
d['LOCAL_IP'] = socket.gethostbyname(subprocess.check_output(["unit-get", "private-address"]).rstrip())
22
 
d['PUBLIC_IP'] = urllib2.urlopen('http://169.254.169.254/latest/meta-data/public-ipv4').read()
23
 
 
24
 
# Domain configuration
25
 
try:
26
 
        d['HOME_DOMAIN'] = subprocess.check_output(["relation-get", "home_domain"]).rstrip()
27
 
        d['SPROUT_HOSTNAME'] = subprocess.check_output(["relation-get", "sprout_domain"]).rstrip()
28
 
        d['HS_HOSTNAME'] = subprocess.check_output(["relation-get", "homestead_domain"]).rstrip()
29
 
        d['HS_PROVISIONING_HOSTNAME'] = subprocess.check_output(["relation-get", "provisioning_domain"]).rstrip()
30
 
        d['XDMS_HOSTNAME'] = subprocess.check_output(["relation-get", "homer_domain"]).rstrip()
31
 
        d['RALF_HOSTNAME'] = subprocess.check_output(["relation-get", "ralf_domain"]).rstrip()
32
 
        d['SAS_SERVER'] = subprocess.check_output(["relation-get", "sas_domain"]).rstrip()
33
 
        d['ENUM_SERVER'] = "enum_server=" + subprocess.check_output(["relation-get", "enum_domain"]).rstrip()
34
 
except subprocess.CalledProcessError:
35
 
        d['HOME_DOMAIN'] = "localhost"
36
 
        d['SPROUT_HOSTNAME'] = "localhost"
37
 
        d['HS_HOSTNAME'] = "localhost:8888"
38
 
        d['HS_PROVISIONING_HOSTNAME'] = "localhost:8889"
39
 
        d['XDMS_HOSTNAME'] = "localhost:7888"
40
 
        d['RALF_HOSTNAME'] = "localhost:9888"
41
 
        d['SAS_SERVER'] = "0.0.0.0"
42
 
        d['ENUM_SERVER'] = ""
43
 
 
44
 
# Open the template file
45
 
charm_dir = os.environ['CHARM_DIR']
46
 
with open( '%s/lib/config_template' % charm_dir ) as f:
47
 
        src = string.Template( f.read() )
48
 
 
49
 
# Make the substitutions
50
 
result = src.substitute(d)
51
 
 
52
 
# Write to /etc/clearwater/config, creating the clearwater directory
53
 
# if necessary, and set appropriate permissions
54
 
if not os.path.isdir("/etc/clearwater"):
55
 
        os.makedirs("/etc/clearwater")
56
 
with open("/etc/clearwater/config", 'w') as f:
57
 
        f.write(result)
58
 
os.chmod("/etc/clearwater/config", 0755)
 
1
#!/bin/bash
 
2
 
 
3
$relation_name=$1
 
4
 
 
5
set -e
 
6
 
 
7
# Defaults
 
8
sprout_hostname=sprout.$(config-get zone)
 
9
hs_hostname=homestead.$(config-get zone):8888
 
10
hs_provisioning_hostname=homestead.$(config-get zone):8889
 
11
xdms_hostname=homer.$(config-get zone):7888
 
12
ralf_hostname=
 
13
sas_server=0.0.0.0
 
14
enum_server=
 
15
 
 
16
# Import existing configuration
 
17
[ ! -f /etc/clearwater/config ] || . /etc/clearwater/config
 
18
 
 
19
# Apply new configuration
 
20
home_domain=$(config-get zone)
 
21
sas_server=$(config-get sas)
 
22
local_ip=$(dig +short $(unit-get private-address) | head -1)
 
23
public_ip=$(curl http://169.254.169.254/latest/meta-data/public-ipv4)
 
24
public_hostname=$(unit-get public-address)
 
25
 
 
26
# Write configuration back
 
27
mkdir -p /etc/clearwater
 
28
cat >/etc/clearwater/config <<EOF
 
29
# Deployment definitions
 
30
home_domain=$home_domain
 
31
sprout_hostname=$sprout_hostname
 
32
hs_hostname=$hs_hostname
 
33
hs_provisioning_hostname=$hs_provisioning_hostname
 
34
xdms_hostname=$xdms_hostname
 
35
ralf_hostname=$ralf_hostname
 
36
sas_server=$sas_server
 
37
enum_server=$enum_server
 
38
 
 
39
# Local IP configuration
 
40
local_ip=$local_ip
 
41
public_ip=$public_ip
 
42
public_hostname=$public_hostname
 
43
EOF