blob: e91a4683c6f69e3b3ae89919b4584a252d449f61 [file] [log] [blame]
Scott Bakerb30aa082014-01-03 08:36:00 -08001import os
2import base64
3import sys
4
5if __name__ == '__main__':
6 sys.path.append("/opt/planetstack")
7 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "planetstack.settings")
8
9from planetstack.config import Config
10from core.models import Service
11from hpc.models import HpcService
12from requestrouter.models import RequestRouterService
13from util.logger import Logger, logging
14
15logger = Logger(level=logging.INFO)
16
17class HpcLibrary:
18 def extract_slice_info(self, service):
19 """ Produce a dict that describes the slices for the CMI
20
21 slice_coblitz = <name of coblitz slice>
22 service_coblitz = <name of coblitz service>
23 hostname_coblitz = <name of first coblitz slice>
24 hostnames_coblitz = <name_of_first_cob_slice>,<name_of_second_cob_slice>,...
25
26 slice_cmi = <name of cmi slice>
27 ...
28 """
29
30 slicenames = {}
31 slicehosts = {}
32 for slice in service.service.all():
33 name = slice.name
34 if not ("_" in name):
35 continue
36
37 if "coblitz" in name:
38 slicenames["coblitz"] = name
39 slicehosts["coblitz"] = [sliver.node.name for sliver in slice.slivers.all()]
40 elif "cmi" in name:
41 slicenames["cmi"] = name
42 slicehosts["cmi"] = [sliver.node.name for sliver in slice.slivers.all()]
43 elif "dnsredir" in name:
44 slicenames["dnsredir"] = name
45 slicehosts["dnsredir"] = [sliver.node.name for sliver in slice.slivers.all()]
46 elif "dnsdemux" in name:
47 slicenames["dnsdemux"] = name
48 slicehosts["dnsdemux"] = [sliver.node.name for sliver in slice.slivers.all()]
49
50 base_hrn = None
51 if "coblitz" in slicenames:
52 base_hrn = slicenames["coblitz"].split("_")[0]
53
54 mapping = {}
55 mapping["base_hrn"] = base_hrn
56 for (k,v) in slicenames.items():
57 mapping["slice_" + k] = v
58 mapping["service_" + k] = v.split("_",1)[1]
59 for (k,v) in slicehosts.items():
60 mapping["hostname_" + k] = v[0]
61 mapping["hostnames_" + k] = ",".join(v)
62
63 return mapping
64
65 def write_slices_file(self, hpc_service, rr_service):
66 mapping = self.extract_slice_info(hpc_service)
67 rr_mapping = self.extract_slice_info(rr_service)
68
69 mapping.update(rr_mapping)
70
71 print mapping
72
73 fn = "/tmp/slices"
74
75 f = open(fn, "w")
76 f.write("""
77ENABLE_PLC=True
78ENABLE_PS=False
79BASE_HRN="%(base_hrn)s"
80RELEVANT_SERVICE_NAMES=['%(service_coblitz)s', '%(service_dnsredir)s', '%(service_dnsdemux)s']
81COBLITZ_SLICE_NAME="%(slice_coblitz)s"
82COBLITZ_SLICE_ID=1
83COBLITZ_PS_SLICE_NAME="%(slice_coblitz)s"
84DNSREDIR_SLICE_NAME="%(slice_dnsredir)s"
85DNSREDIR_SLICE_ID=2
86DNSREDIR_PS_SLICE_NAME="%(slice_dnsredir)s"
87DNSDEMUX_SLICE_NAME="%(slice_dnsdemux)s"
88DNSDEMUX_SLICE_ID=3
89DNSDEMUX_PS_SLICE_NAME="%(slice_dnsdemux)s"
90CMI_URL="http://%(hostname_cmi)s"
91CMI_HTTP_PORT="8004"
92CMI_HTTPS_PORT="8003"
93PUPPET_MASTER_HOSTNAME="%(hostname_cmi)s"
94PUPPET_MASTER_PORT="8140"
95""" % mapping)
96
97if __name__ == '__main__':
98 hpc_service = HpcService.objects.get()
99 rr_service = RequestRouterService.objects.get()
100 lib = HpcLibrary()
101 lib.write_slices_file(hpc_service, rr_service)
102
103