8
# Create the /etc/clearwater/config file.
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
14
# The config file is templated in lib/config_template.
16
# Populate the dictionary
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()
24
# Domain configuration
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"
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() )
49
# Make the substitutions
50
result = src.substitute(d)
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:
58
os.chmod("/etc/clearwater/config", 0755)
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
16
# Import existing configuration
17
[ ! -f /etc/clearwater/config ] || . /etc/clearwater/config
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)
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
39
# Local IP configuration
42
public_hostname=$public_hostname