blob: fbd8f31f9b103fe7c0ca6439cf03115c0da78c1f [file] [log] [blame]
A R Karthick41adfce2016-06-10 09:51:25 -07001#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07002# Copyright 2016-present Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
A R Karthick41adfce2016-06-10 09:51:25 -07007#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07008# http://www.apache.org/licenses/LICENSE-2.0
A R Karthick41adfce2016-06-10 09:51:25 -07009#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070010# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
Chetan Gaonker3533faa2016-04-25 17:50:14 -070016import os,time
17import io
18import json
A R Karthickd44cea12016-07-20 12:16:41 -070019import yaml
Chetan Gaonker3533faa2016-04-25 17:50:14 -070020from pyroute2 import IPRoute
21from itertools import chain
22from nsenter import Namespace
23from docker import Client
24from shutil import copy
A.R Karthick95d044e2016-06-10 18:44:36 -070025from OnosCtrl import OnosCtrl
Chetan Gaonker3533faa2016-04-25 17:50:14 -070026
27class docker_netns(object):
28
29 dckr = Client()
30 def __init__(self, name):
31 pid = int(self.dckr.inspect_container(name)['State']['Pid'])
32 if pid == 0:
33 raise Exception('no container named {0}'.format(name))
34 self.pid = pid
35
36 def __enter__(self):
37 pid = self.pid
38 if not os.path.exists('/var/run/netns'):
39 os.mkdir('/var/run/netns')
40 os.symlink('/proc/{0}/ns/net'.format(pid), '/var/run/netns/{0}'.format(pid))
41 return str(pid)
42
43 def __exit__(self, type, value, traceback):
44 pid = self.pid
45 os.unlink('/var/run/netns/{0}'.format(pid))
46
47flatten = lambda l: chain.from_iterable(l)
48
49class Container(object):
50 dckr = Client()
A R Karthick07608ef2016-08-23 16:51:19 -070051 IMAGE_PREFIX = '' ##for saving global prefix for all test classes
52
53 def __init__(self, name, image, prefix='', tag = 'candidate', command = 'bash', quagga_config = None):
Chetan Gaonker3533faa2016-04-25 17:50:14 -070054 self.name = name
A R Karthick07608ef2016-08-23 16:51:19 -070055 self.prefix = prefix
56 if prefix:
57 self.prefix += '/'
58 image = '{}{}'.format(self.prefix, image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -070059 self.image = image
60 self.tag = tag
A R Karthickd44cea12016-07-20 12:16:41 -070061 if tag:
62 self.image_name = image + ':' + tag
63 else:
64 self.image_name = image
Chetan Gaonker3533faa2016-04-25 17:50:14 -070065 self.id = None
66 self.command = command
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -070067 self.quagga_config = quagga_config
Chetan Gaonker3533faa2016-04-25 17:50:14 -070068
69 @classmethod
70 def build_image(cls, dockerfile, tag, force=True, nocache=False):
71 f = io.BytesIO(dockerfile.encode('utf-8'))
72 if force or not cls.image_exists(tag):
73 print('Build {0}...'.format(tag))
74 for line in cls.dckr.build(fileobj=f, rm=True, tag=tag, decode=True, nocache=nocache):
75 if 'stream' in line:
76 print(line['stream'].strip())
77
78 @classmethod
79 def image_exists(cls, name):
80 return name in [ctn['RepoTags'][0] for ctn in cls.dckr.images()]
81
82 @classmethod
83 def create_host_config(cls, port_list = None, host_guest_map = None, privileged = False):
84 port_bindings = None
85 binds = None
86 if port_list:
87 port_bindings = {}
88 for p in port_list:
89 port_bindings[str(p)] = str(p)
90
91 if host_guest_map:
92 binds = []
93 for h, g in host_guest_map:
94 binds.append('{0}:{1}'.format(h, g))
95
96 return cls.dckr.create_host_config(binds = binds, port_bindings = port_bindings, privileged = privileged)
97
98 @classmethod
99 def cleanup(cls, image):
A R Karthick09b1f4e2016-05-12 14:31:50 -0700100 cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True))
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700101 for cnt in cnt_list:
102 print('Cleaning container %s' %cnt['Id'])
A.R Karthick95d044e2016-06-10 18:44:36 -0700103 if cnt.has_key('State') and cnt['State'] == 'running':
A R Karthick09b1f4e2016-05-12 14:31:50 -0700104 cls.dckr.kill(cnt['Id'])
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700105 cls.dckr.remove_container(cnt['Id'], force=True)
106
107 @classmethod
108 def remove_container(cls, name, force=True):
109 try:
110 cls.dckr.remove_container(name, force = force)
111 except: pass
112
113 def exists(self):
114 return '/{0}'.format(self.name) in list(flatten(n['Names'] for n in self.dckr.containers()))
115
116 def img_exists(self):
A R Karthick6d98a592016-08-24 15:16:46 -0700117 return self.image_name in [ctn['RepoTags'][0] if ctn['RepoTags'] else '' for ctn in self.dckr.images()]
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700118
119 def ip(self):
A R Karthick2b93d6a2016-09-06 15:19:09 -0700120 cnt_list = filter(lambda c: c['Names'][0] == '/{}'.format(self.name), self.dckr.containers())
121 #if not cnt_list:
122 # cnt_list = filter(lambda c: c['Image'] == self.image_name, self.dckr.containers())
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700123 cnt_settings = cnt_list.pop()
124 return cnt_settings['NetworkSettings']['Networks']['bridge']['IPAddress']
125
A R Karthick2b93d6a2016-09-06 15:19:09 -0700126 @classmethod
127 def ips(cls, image_name):
128 cnt_list = filter(lambda c: c['Image'] == image_name, cls.dckr.containers())
129 ips = [ cnt['NetworkSettings']['Networks']['bridge']['IPAddress'] for cnt in cnt_list ]
130 return ips
131
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700132 def kill(self, remove = True):
133 self.dckr.kill(self.name)
134 self.dckr.remove_container(self.name, force=True)
135
A R Karthick41adfce2016-06-10 09:51:25 -0700136 def start(self, rm = True, ports = None, volumes = None, host_config = None,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700137 environment = None, tty = False, stdin_open = True):
138
139 if rm and self.exists():
140 print('Removing container:', self.name)
141 self.dckr.remove_container(self.name, force=True)
142
A R Karthick41adfce2016-06-10 09:51:25 -0700143 ctn = self.dckr.create_container(image=self.image_name, ports = ports, command=self.command,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700144 detach=True, name=self.name,
A R Karthick41adfce2016-06-10 09:51:25 -0700145 environment = environment,
146 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700147 host_config = host_config, stdin_open=stdin_open, tty = tty)
148 self.dckr.start(container=self.name)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700149 if self.quagga_config:
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700150 self.connect_to_br()
151 self.id = ctn['Id']
152 return ctn
153
154 def connect_to_br(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700155 index = 0
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700156 with docker_netns(self.name) as pid:
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700157 for quagga_config in self.quagga_config:
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700158 ip = IPRoute()
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700159 br = ip.link_lookup(ifname=quagga_config['bridge'])
160 if len(br) == 0:
Chetan Gaonker5a0fda32016-05-10 14:09:07 -0700161 ip.link_create(ifname=quagga_config['bridge'], kind='bridge')
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700162 br = ip.link_lookup(ifname=quagga_config['bridge'])
163 br = br[0]
164 ip.link('set', index=br, state='up')
165 ifname = '{0}-{1}'.format(self.name, index)
166 ifs = ip.link_lookup(ifname=ifname)
167 if len(ifs) > 0:
168 ip.link_remove(ifs[0])
169 peer_ifname = '{0}-{1}'.format(pid, index)
Chetan Gaonker5a0fda32016-05-10 14:09:07 -0700170 ip.link_create(ifname=ifname, kind='veth', peer=peer_ifname)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700171 host = ip.link_lookup(ifname=ifname)[0]
172 ip.link('set', index=host, master=br)
173 ip.link('set', index=host, state='up')
174 guest = ip.link_lookup(ifname=peer_ifname)[0]
175 ip.link('set', index=guest, net_ns_fd=pid)
176 with Namespace(pid, 'net'):
177 ip = IPRoute()
178 ip.link('set', index=guest, ifname='eth{}'.format(index+1))
179 ip.addr('add', index=guest, address=quagga_config['ip'], mask=quagga_config['mask'])
180 ip.link('set', index=guest, state='up')
181 index += 1
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700182
183 def execute(self, cmd, tty = True, stream = False, shell = False):
184 res = 0
185 if type(cmd) == str:
186 cmds = (cmd,)
187 else:
188 cmds = cmd
189 if shell:
190 for c in cmds:
191 res += os.system('docker exec {0} {1}'.format(self.name, c))
192 return res
193 for c in cmds:
194 i = self.dckr.exec_create(container=self.name, cmd=c, tty = tty, privileged = True)
195 self.dckr.exec_start(i['Id'], stream = stream, detach=True)
196 result = self.dckr.exec_inspect(i['Id'])
197 res += 0 if result['ExitCode'] == None else result['ExitCode']
198 return res
199
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700200 def restart(self, timeout =10):
201 return self.dckr.restart(self.name, timeout)
202
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700203def get_mem():
204 with open('/proc/meminfo', 'r') as fd:
205 meminfo = fd.readlines()
206 mem = 0
207 for m in meminfo:
208 if m.startswith('MemTotal:') or m.startswith('SwapTotal:'):
209 mem += int(m.split(':')[1].strip().split()[0])
210
Chetan Gaonkerc0421e82016-05-04 17:23:08 -0700211 mem = max(mem/1024/1024/2, 1)
Chetan Gaonker6d0a7b02016-05-03 16:57:28 -0700212 mem = min(mem, 16)
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700213 return str(mem) + 'G'
214
A R Karthickd44cea12016-07-20 12:16:41 -0700215class OnosCord(Container):
216 """Use this when running the cord tester agent on the onos compute node"""
217 onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord')
218 onos_config_dir_guest = '/root/onos/config'
219 onos_config_dir = os.path.join(onos_cord_dir, 'config')
220 docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml')
221
A R Karthickbd9b8a32016-07-21 09:56:45 -0700222 def __init__(self, onos_ip, conf, boot_delay = 60):
223 self.onos_ip = onos_ip
A R Karthickd44cea12016-07-20 12:16:41 -0700224 self.cord_conf_dir = conf
A R Karthickbd9b8a32016-07-21 09:56:45 -0700225 self.boot_delay = boot_delay
A R Karthickd44cea12016-07-20 12:16:41 -0700226 if os.access(self.cord_conf_dir, os.F_OK) and not os.access(self.onos_cord_dir, os.F_OK):
227 os.mkdir(self.onos_cord_dir)
228 os.mkdir(self.onos_config_dir)
229 ##copy the config file from cord-tester-config
230 cmd = 'cp {}/* {}'.format(self.cord_conf_dir, self.onos_cord_dir)
231 os.system(cmd)
232
233 ##update the docker yaml with the config volume
234 with open(self.docker_yaml, 'r') as f:
235 yaml_config = yaml.load(f)
236 image = yaml_config['services'].keys()[0]
237 name = 'cordtestercord_{}_1'.format(image)
238 volumes = yaml_config['services'][image]['volumes']
239 config_volumes = filter(lambda e: e.find(self.onos_config_dir_guest) >= 0, volumes)
240 if not config_volumes:
241 config_volume = '{}:{}'.format(self.onos_config_dir, self.onos_config_dir_guest)
242 volumes.append(config_volume)
243 docker_yaml_changed = '{}-changed'.format(self.docker_yaml)
244 with open(docker_yaml_changed, 'w') as wf:
245 yaml.dump(yaml_config, wf)
246
247 os.rename(docker_yaml_changed, self.docker_yaml)
248 self.volumes = volumes
249
250 super(OnosCord, self).__init__(name, image, tag = '')
251 cord_conf_dir_basename = os.path.basename(self.cord_conf_dir.replace('-', ''))
252 self.xos_onos_name = '{}_{}_1'.format(cord_conf_dir_basename, image)
253 ##Create an container instance of xos onos
254 self.xos_onos = Container(self.xos_onos_name, image, tag = '')
255
256 def start(self, restart = False, network_cfg = None):
257 if restart is True:
258 if self.exists():
259 ##Kill the existing instance
260 print('Killing container %s' %self.name)
261 self.kill()
262 if self.xos_onos.exists():
263 print('Killing container %s' %self.xos_onos.name)
264 self.xos_onos.kill()
265
266 if network_cfg is not None:
267 json_data = json.dumps(network_cfg, indent=4)
268 with open('{}/network-cfg.json'.format(self.onos_config_dir), 'w') as f:
269 f.write(json_data)
270
271 #start the container using docker-compose
272 cmd = 'cd {} && docker-compose up -d'.format(self.onos_cord_dir)
273 os.system(cmd)
A R Karthickbd9b8a32016-07-21 09:56:45 -0700274 #Delay to make sure ONOS fully boots
275 time.sleep(self.boot_delay)
276 Onos.install_cord_apps(onos_ip = self.onos_ip)
A R Karthickd44cea12016-07-20 12:16:41 -0700277
278 def build_image(self):
279 build_cmd = 'cd {} && docker-compose build'.format(self.onos_cord_dir)
280 os.system(build_cmd)
281
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700282class Onos(Container):
283
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700284 quagga_config = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.4', 'mask' : 16 }, )
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700285 SYSTEM_MEMORY = (get_mem(),) * 2
286 JAVA_OPTS = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode'.format(*SYSTEM_MEMORY)#-XX:+PrintGCDetails -XX:+PrintGCTimeStamps'
A.R Karthick95d044e2016-06-10 18:44:36 -0700287 env = { 'ONOS_APPS' : 'drivers,openflow,proxyarp,vrouter', 'JAVA_OPTS' : JAVA_OPTS }
288 onos_cord_apps = ( ('cord-config', '1.0-SNAPSHOT'),
289 ('aaa', '1.0-SNAPSHOT'),
290 ('igmp', '1.0-SNAPSHOT'),
A R Karthickedab01c2016-09-08 14:05:44 -0700291 #('vtn', '1.0-SNAPSHOT'),
A.R Karthick95d044e2016-06-10 18:44:36 -0700292 )
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700293 ports = [ 8181, 8101, 9876, 6653, 6633, 2000, 2620 ]
A R Karthickf2f4ca62016-08-17 10:34:08 -0700294 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
295 host_config_dir = os.path.join(setup_dir, 'onos-config')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700296 guest_config_dir = '/root/onos/config'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700297 onos_gen_partitions = os.path.join(setup_dir, 'onos-gen-partitions')
A R Karthick2b93d6a2016-09-06 15:19:09 -0700298 onos_form_cluster = os.path.join(setup_dir, 'onos-form-cluster')
A.R Karthick95d044e2016-06-10 18:44:36 -0700299 cord_apps_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'apps')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700300 host_guest_map = ( (host_config_dir, guest_config_dir), )
A R Karthick2b93d6a2016-09-06 15:19:09 -0700301 cluster_cfg = os.path.join(host_config_dir, 'cluster.json')
302 cluster_mode = False
303 cluster_instances = []
Chetan Gaonker503032a2016-05-12 12:06:29 -0700304 NAME = 'cord-onos'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700305 ##the ip of ONOS in default cluster.json in setup/onos-config
306 CLUSTER_CFG_IP = '172.17.0.2'
A R Karthick07608ef2016-08-23 16:51:19 -0700307 IMAGE = 'onosproject/onos'
308 TAG = 'latest'
309 PREFIX = ''
A R Karthickf2f4ca62016-08-17 10:34:08 -0700310
311 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700312 def generate_cluster_cfg(cls, ip):
313 if type(ip) in [ list, tuple ]:
314 ips = ' '.join(ip)
315 else:
316 ips = ip
A R Karthickf2f4ca62016-08-17 10:34:08 -0700317 try:
A R Karthick2b93d6a2016-09-06 15:19:09 -0700318 cmd = '{} {} {}'.format(cls.onos_gen_partitions, cls.cluster_cfg, ips)
319 os.system(cmd)
320 except: pass
321
322 @classmethod
323 def form_cluster(cls, ips):
324 nodes = ' '.join(ips)
325 try:
326 cmd = '{} {}'.format(cls.onos_form_cluster, nodes)
A R Karthickf2f4ca62016-08-17 10:34:08 -0700327 os.system(cmd)
328 except: pass
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700329
A R Karthick9d48c652016-09-15 09:16:36 -0700330 @classmethod
331 def cleanup_runtime(cls):
332 '''Cleanup ONOS runtime generated files'''
333 files = ( Onos.cluster_cfg, os.path.join(Onos.host_config_dir, 'network-cfg.json') )
334 for f in files:
335 if os.access(f, os.F_OK):
336 try:
337 os.unlink(f)
338 except: pass
339
A R Karthick07608ef2016-08-23 16:51:19 -0700340 def __init__(self, name = NAME, image = 'onosproject/onos', prefix = '', tag = 'latest',
A R Karthick2b93d6a2016-09-06 15:19:09 -0700341 boot_delay = 60, restart = False, network_cfg = None, cluster = False):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700342 if restart is True:
343 ##Find the right image to restart
344 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
345 if running_image:
346 image_name = running_image[0]['Image']
347 try:
348 image = image_name.split(':')[0]
349 tag = image_name.split(':')[1]
350 except: pass
351
A R Karthick07608ef2016-08-23 16:51:19 -0700352 super(Onos, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.quagga_config)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700353 self.boot_delay = boot_delay
354 if cluster is True:
355 self.ports = []
356 if os.access(self.cluster_cfg, os.F_OK):
357 try:
358 os.unlink(self.cluster_cfg)
359 except: pass
360
361 self.host_config = self.create_host_config(port_list = self.ports,
362 host_guest_map = self.host_guest_map)
363 self.volumes = []
364 for _,g in self.host_guest_map:
365 self.volumes.append(g)
366
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700367 if restart is True and self.exists():
368 self.kill()
A R Karthick2b93d6a2016-09-06 15:19:09 -0700369
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700370 if not self.exists():
371 self.remove_container(name, force=True)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700372 host_config = self.create_host_config(port_list = self.ports,
373 host_guest_map = self.host_guest_map)
374 volumes = []
375 for _,g in self.host_guest_map:
376 volumes.append(g)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700377 if network_cfg is not None:
A R Karthick81acbff2016-06-17 14:45:16 -0700378 json_data = json.dumps(network_cfg, indent=4)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700379 with open('{}/network-cfg.json'.format(self.host_config_dir), 'w') as f:
380 f.write(json_data)
381 print('Starting ONOS container %s' %self.name)
A R Karthick41adfce2016-06-10 09:51:25 -0700382 self.start(ports = self.ports, environment = self.env,
A R Karthick2b93d6a2016-09-06 15:19:09 -0700383 host_config = self.host_config, volumes = self.volumes, tty = True)
A R Karthickf2f4ca62016-08-17 10:34:08 -0700384 if not restart:
385 ##wait a bit before fetching IP to regenerate cluster cfg
386 time.sleep(5)
387 ip = self.ip()
388 ##Just a quick hack/check to ensure we don't regenerate in the common case.
389 ##As ONOS is usually the first test container that is started
A R Karthick2b93d6a2016-09-06 15:19:09 -0700390 if cluster is False:
391 if ip != self.CLUSTER_CFG_IP or not os.access(self.cluster_cfg, os.F_OK):
392 print('Regenerating ONOS cluster cfg for ip %s' %ip)
393 self.generate_cluster_cfg(ip)
394 self.kill()
395 self.remove_container(self.name, force=True)
396 print('Restarting ONOS container %s' %self.name)
397 self.start(ports = self.ports, environment = self.env,
398 host_config = self.host_config, volumes = self.volumes, tty = True)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700399 print('Waiting %d seconds for ONOS to boot' %(boot_delay))
400 time.sleep(boot_delay)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700401 self.ipaddr = self.ip()
402 if cluster is False:
403 self.install_cord_apps(self.ipaddr)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700404
A R Karthick2b93d6a2016-09-06 15:19:09 -0700405 @classmethod
406 def setup_cluster_deprecated(cls, onos_instances, image_name = None):
407 if not onos_instances or len(onos_instances) < 2:
408 return
409 ips = []
410 if image_name is not None:
411 ips = Container.ips(image_name)
412 else:
413 for onos in onos_instances:
414 ips.append(onos.ipaddr)
415 Onos.cluster_instances = onos_instances
416 Onos.cluster_mode = True
417 ##regenerate the cluster json with the 3 instance ips before restarting them back
418 print('Generating cluster cfg for ONOS instances with ips %s' %ips)
419 Onos.generate_cluster_cfg(ips)
420 for onos in onos_instances:
421 onos.kill()
422 onos.remove_container(onos.name, force=True)
423 print('Restarting ONOS container %s for forming cluster' %onos.name)
424 onos.start(ports = onos.ports, environment = onos.env,
425 host_config = onos.host_config, volumes = onos.volumes, tty = True)
426 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
427 time.sleep(onos.boot_delay)
428 onos.ipaddr = onos.ip()
429 onos.install_cord_apps(onos.ipaddr)
430
431 @classmethod
432 def setup_cluster(cls, onos_instances, image_name = None):
433 if not onos_instances or len(onos_instances) < 2:
434 return
435 ips = []
436 if image_name is not None:
437 ips = Container.ips(image_name)
438 else:
439 for onos in onos_instances:
440 ips.append(onos.ipaddr)
441 Onos.cluster_instances = onos_instances
442 Onos.cluster_mode = True
443 ##regenerate the cluster json with the 3 instance ips before restarting them back
444 print('Forming cluster for ONOS instances with ips %s' %ips)
445 Onos.form_cluster(ips)
446 ##wait for the cluster to be formed
447 print('Waiting for the cluster to be formed')
448 time.sleep(60)
449 for onos in onos_instances:
450 onos.install_cord_apps(onos.ipaddr)
451
452 @classmethod
453 def restart_cluster(cls, network_cfg = None):
454 if cls.cluster_mode is False:
455 return
456 if not cls.cluster_instances:
457 return
458
459 if network_cfg is not None:
460 json_data = json.dumps(network_cfg, indent=4)
461 with open('{}/network-cfg.json'.format(cls.host_config_dir), 'w') as f:
462 f.write(json_data)
463
464 for onos in cls.cluster_instances:
465 if onos.exists():
466 onos.kill()
467 onos.remove_container(onos.name, force=True)
468 print('Restarting ONOS container %s' %onos.name)
469 onos.start(ports = onos.ports, environment = onos.env,
470 host_config = onos.host_config, volumes = onos.volumes, tty = True)
471 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
472 time.sleep(onos.boot_delay)
473 onos.ipaddr = onos.ip()
474
475 ##form the cluster
476 cls.setup_cluster(cls.cluster_instances)
477
478 @classmethod
479 def cluster_ips(cls):
480 if cls.cluster_mode is False:
481 return []
482 if not cls.cluster_instances:
483 return []
484 ips = [ onos.ipaddr for onos in cls.cluster_instances ]
485 return ips
486
487 @classmethod
488 def cleanup_cluster(cls):
489 if cls.cluster_mode is False:
490 return
491 if not cls.cluster_instances:
492 return
493 for onos in cls.cluster_instances:
494 if onos.exists():
495 onos.kill()
496 onos.remove_container(onos.name, force=True)
A R Karthickd44cea12016-07-20 12:16:41 -0700497
A.R Karthick95d044e2016-06-10 18:44:36 -0700498 @classmethod
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700499 def install_cord_apps(cls, onos_ip = None):
A.R Karthick95d044e2016-06-10 18:44:36 -0700500 for app, version in cls.onos_cord_apps:
501 app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version)
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700502 ok, code = OnosCtrl.install_app(app_file, onos_ip = onos_ip)
A.R Karthick95d044e2016-06-10 18:44:36 -0700503 ##app already installed (conflicts)
504 if code in [ 409 ]:
505 ok = True
506 print('ONOS app %s, version %s %s' %(app, version, 'installed' if ok else 'failed to install'))
507 time.sleep(2)
508
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700509class Radius(Container):
510 ports = [ 1812, 1813 ]
A R Karthick41adfce2016-06-10 09:51:25 -0700511 env = {'TIMEZONE':'America/Los_Angeles',
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700512 'DEBUG': 'true', 'cert_password':'whatever', 'primary_shared_secret':'radius_password'
513 }
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700514 host_db_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/db')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700515 guest_db_dir = os.path.join(os.path.sep, 'opt', 'db')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700516 host_config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/freeradius')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700517 guest_config_dir = os.path.join(os.path.sep, 'etc', 'freeradius')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700518 start_command = os.path.join(guest_config_dir, 'start-radius.py')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700519 host_guest_map = ( (host_db_dir, guest_db_dir),
520 (host_config_dir, guest_config_dir)
521 )
Chetan Gaonker503032a2016-05-12 12:06:29 -0700522 IMAGE = 'cord-test/radius'
523 NAME = 'cord-radius'
524
A R Karthick07608ef2016-08-23 16:51:19 -0700525 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
Chetan Gaonker503032a2016-05-12 12:06:29 -0700526 boot_delay = 10, restart = False, update = False):
A R Karthick07608ef2016-08-23 16:51:19 -0700527 super(Radius, self).__init__(name, image, prefix = prefix, tag = tag, command = self.start_command)
Chetan Gaonker503032a2016-05-12 12:06:29 -0700528 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -0700529 self.build_image(self.image_name)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700530 if restart is True and self.exists():
531 self.kill()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700532 if not self.exists():
533 self.remove_container(name, force=True)
534 host_config = self.create_host_config(port_list = self.ports,
535 host_guest_map = self.host_guest_map)
536 volumes = []
537 for _,g in self.host_guest_map:
538 volumes.append(g)
A R Karthick41adfce2016-06-10 09:51:25 -0700539 self.start(ports = self.ports, environment = self.env,
540 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700541 host_config = host_config, tty = True)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700542 time.sleep(boot_delay)
543
544 @classmethod
545 def build_image(cls, image):
546 print('Building Radius image %s' %image)
547 dockerfile = '''
548FROM hbouvier/docker-radius
549MAINTAINER chetan@ciena.com
550LABEL RUN docker pull hbouvier/docker-radius
551LABEL RUN docker run -it --name cord-radius hbouvier/docker-radius
A R Karthickc762df42016-05-25 10:09:21 -0700552RUN apt-get update && \
553 apt-get -y install python python-pexpect strace
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700554WORKDIR /root
555CMD ["/etc/freeradius/start-radius.py"]
556'''
557 super(Radius, cls).build_image(dockerfile, image)
558 print('Done building image %s' %image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700559
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700560class Quagga(Container):
A R Karthick41adfce2016-06-10 09:51:25 -0700561 quagga_config = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 },
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700562 { 'bridge' : 'quagga-br', 'ip': '192.168.10.3', 'mask': 16 },
563 )
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700564 ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ]
565 host_quagga_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/quagga-config')
566 guest_quagga_config = '/root/config'
567 quagga_config_file = os.path.join(guest_quagga_config, 'testrib.conf')
568 host_guest_map = ( (host_quagga_config, guest_quagga_config), )
Chetan Gaonker503032a2016-05-12 12:06:29 -0700569 IMAGE = 'cord-test/quagga'
570 NAME = 'cord-quagga'
571
A R Karthick07608ef2016-08-23 16:51:19 -0700572 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
Chetan Gaonker503032a2016-05-12 12:06:29 -0700573 boot_delay = 15, restart = False, config_file = quagga_config_file, update = False):
A R Karthick07608ef2016-08-23 16:51:19 -0700574 super(Quagga, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.quagga_config)
Chetan Gaonker503032a2016-05-12 12:06:29 -0700575 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -0700576 self.build_image(self.image_name)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700577 if restart is True and self.exists():
578 self.kill()
579 if not self.exists():
580 self.remove_container(name, force=True)
A R Karthick41adfce2016-06-10 09:51:25 -0700581 host_config = self.create_host_config(port_list = self.ports,
582 host_guest_map = self.host_guest_map,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700583 privileged = True)
584 volumes = []
585 for _,g in self.host_guest_map:
586 volumes.append(g)
587 self.start(ports = self.ports,
A R Karthick41adfce2016-06-10 09:51:25 -0700588 host_config = host_config,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700589 volumes = volumes, tty = True)
590 print('Starting Quagga on container %s' %self.name)
591 self.execute('{0}/start.sh {1}'.format(self.guest_quagga_config, config_file))
592 time.sleep(boot_delay)
593
594 @classmethod
595 def build_image(cls, image):
Chetan Gaonker2a6601b2016-05-02 17:28:26 -0700596 onos_quagga_ip = Onos.quagga_config[0]['ip']
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700597 print('Building Quagga image %s' %image)
598 dockerfile = '''
A R Karthick41adfce2016-06-10 09:51:25 -0700599FROM ubuntu:14.04
600MAINTAINER chetan@ciena.com
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700601WORKDIR /root
602RUN useradd -M quagga
603RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga
604RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga
605RUN apt-get update && apt-get install -qy git autoconf libtool gawk make telnet libreadline6-dev
ChetanGaonkerb5b46c62016-08-16 12:02:53 -0700606RUN git clone git://git.savannah.nongnu.org/quagga.git quagga && \
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700607(cd quagga && git checkout HEAD && ./bootstrap.sh && \
608sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \
609./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install)
610RUN ldconfig
611'''.format(onos_quagga_ip)
612 super(Quagga, cls).build_image(dockerfile, image)
613 print('Done building image %s' %image)
A R Karthick81acbff2016-06-17 14:45:16 -0700614
615def reinitContainerClients():
616 docker_netns.dckr = Client()
617 Container.dckr = Client()
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700618
619class Xos(Container):
620 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
621 TAG = 'latest'
622 PREFIX = ''
623
624 def __init__(self, name, image, dockerfile = None, prefix = PREFIX, tag = TAG,
625 boot_delay = 30, restart = False, network_cfg = None, update = False):
626 GITHUB_ERROR = False
627 if restart is True:
628 ##Find the right image to restart
629 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
630 if running_image:
631 image_name = running_image[0]['Image']
632 try:
633 image = image_name.split(':')[0]
634 tag = image_name.split(':')[1]
635 except: pass
636
637 super(Xos, self).__init__(name, image, prefix = prefix, tag = tag)
638 if update is True or not self.img_exists():
639 self.build_image(self.image_name)
640 if not self.img_exists():
641 print ('Xos base container image is not built on host, check github repo')
642 GITHUB_ERROR = True
643 if GITHUB_ERROR is not True:
644 if restart is True and self.exists():
645 self.kill()
646 if not self.exists():
647 self.remove_container(name, force=True)
648 host_config = self.create_host_config(port_list = self.ports)
649 print('Starting XOS container %s' %self.name)
650 self.start(ports = self.ports, environment = self.env, host_config = host_config,
651 tty = True)
652 print('Waiting %d seconds for XOS Base Container to boot' %(boot_delay))
653 time.sleep(boot_delay)
654
655 @classmethod
656 def build_image(cls, image):
657 print('Building XOS base image %s' %image)
658 super(Xos, cls).build_image(self.dockerfile, image)
659 print('Done building image %s' %image)
660
661class Xos_base(Container):
662 SYSTEM_MEMORY = (get_mem(),) * 2
663 ports = [ 8000,9998,9999 ]
664 env = { 'XOS_GIT_REPO' : 'https://github.com/opencord/xos.git', 'XOS_GIT_BRANCH' : 'master', 'NG_XOS_LIB_URL' : ' https://github.com/opencord/ng-xos-lib.git', 'NG_XOS_LIB_VERSION' : '1.0.0',}
665 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
666 NAME = 'xos-base'
667 IMAGE = 'xosproject/xos-base'
668 TAG = 'latest'
669 PREFIX = ''
670
671 def __init__(self, name = NAME, image = 'xosproject/xos-base', prefix = '', tag = 'latest',
672 boot_delay = 60, restart = False, network_cfg = None, update = False):
673 GITHUB_ERROR = False
674 if restart is True:
675 ##Find the right image to restart
676 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
677 if running_image:
678 image_name = running_image[0]['Image']
679 try:
680 image = image_name.split(':')[0]
681 tag = image_name.split(':')[1]
682 except: pass
683
684 super(Xos_base, self).__init__(name, image, prefix = prefix, tag = tag)
685 if update is True or not self.img_exists():
686 self.build_image(self.image_name)
687 if not self.img_exists():
688 print ('Xos base container image is not built on host, have to check github repository ')
689 GITHUB_ERROR = True
690 if GITHUB_ERROR is not True:
691 if restart is True and self.exists():
692 self.kill()
693 if not self.exists():
694 self.remove_container(name, force=True)
695 host_config = self.create_host_config(port_list = self.ports)
696 print('Starting XOS base container %s' %self.name)
697 self.start(ports = self.ports, environment = self.env, host_config = host_config,
698 tty = True)
699 if not restart:
700 ##wait a bit before fetching IP to regenerate cluster cfg
701 time.sleep(5)
702 ip = self.ip()
703 print('Waiting %d seconds for XOS Base Container to boot' %(boot_delay))
704 time.sleep(boot_delay)
705
706 @classmethod
707 def build_image(cls, image):
708 print('Building XOS base image %s' %image)
709 dockerfile = '''
710FROM xosproject/xos-base
711MAINTAINER chetan@ciena.com
712ADD local_certs.crt /usr/local/share/ca-certificates/local_certs.crt
713RUN update-ca-certificates
714RUN git clone $XOS_GIT_REPO -b $XOS_GIT_BRANCH /tmp/xos && \
715 mv /tmp/xos/xos /opt/ && \
716 chmod +x /opt/xos/tools/xos-manage && \
717 /opt/xos/tools/xos-manage genkeys
718
719RUN git clone $NG_XOS_LIB_URL /tmp/ng-xos-lib
720RUN cd /tmp/ng-xos-lib && git checkout tags/$NG_XOS_LIB_VERSION
721RUN cp /tmp/ng-xos-lib/dist/ngXosHelpers.min.js /opt/xos/core/xoslib/static/vendor/
722RUN cp /tmp/ng-xos-lib/dist/ngXosVendor.min.js /opt/xos/core/xoslib/static/vendor/
723WORKDIR /opt/xos
724CMD python /opt/xos/manage.py runserver 0.0.0.0:8000 --insecure --makemigrations
725'''
726 super(Xos_base, cls).build_image(dockerfile, image)
727 print('Done building image %s' %image)
728
729class Xos_sync_openstack(Container):
730 SYSTEM_MEMORY = (get_mem(),) * 2
731 ports = [ 2375 ]
732 env = {'DOCKER_URL' : 'https://get.docker.com/builds/Linux/x86_64/docker-1.10.3', 'DOCKER_SHA256' : 'd0df512afa109006a450f41873634951e19ddabf8c7bd419caeb5a526032d86d', 'DOCKER_COMPOSE_URL' : ' https://github.com/docker/compose/releases/download/1.5.2/docker-compose-Linux-x86_64', 'DOCKER_COMPOSE_SHA256' : ' b6b975badc5389647ef1c16fe8a33bdc5935c61f6afd5a15a28ff765427d01e3' }
733 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
734 NAME = 'xos-openstack'
735 IMAGE = 'xosproject/xos-synchronizer-openstack'
736 TAG = 'latest'
737 PREFIX = ''
738
739 def __init__(self, name = NAME, image = 'xosproject/xos-synchronizer-openstack', prefix = '', tag = 'latest',
740 boot_delay = 60, restart = False, network_cfg = None, update = False):
741 GITHUB_ERROR = False
742 if restart is True:
743 ##Find the right image to restart
744 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
745 if running_image:
746 image_name = running_image[0]['Image']
747 try:
748 image = image_name.split(':')[0]
749 tag = image_name.split(':')[1]
750 except: pass
751
752 super(Xos_sync_openstack, self).__init__(name, image, prefix = prefix, tag = tag)
753 if update is True or not self.img_exists():
754 self.build_image(self.image_name)
755 if not self.img_exists():
756 print ('Xos base container image is not built on host, have to check github repository ')
757 GITHUB_ERROR = True
758 if GITHUB_ERROR is not True:
759 if restart is True and self.exists():
760 self.kill()
761 if not self.exists():
762 self.remove_container(name, force=True)
763 host_config = self.create_host_config(port_list = self.ports)
764 print('Starting XOS Synchronizer Openstack container %s' %self.name)
765 self.start(environment = self.env,
766 tty = True)
767 if not restart:
768 time.sleep(5)
769 ip = self.ip()
770 print('Waiting %d seconds for XOS Synchronizer Openstack Container to boot' %(boot_delay))
771 time.sleep(boot_delay)
772
773 @classmethod
774 def build_image(cls, image):
775 print('Building XOS Synchronizer Openstack image %s' %image)
776 dockerfile = '''
777FROM xosproject/xos-synchronizer-openstack
778RUN curl -fLsS $DOCKER_URL -o docker && \
779 echo "${DOCKER_SHA256} docker" | sha256sum -c - && \
780 mv docker /usr/local/bin/docker && \
781 chmod +x /usr/local/bin/docker
782RUN curl -fLsS $DOCKER_COMPOSE_URL -o docker-compose && \
783 echo "${DOCKER_COMPOSE_SHA256} docker-compose" | sha256sum -c - && \
784 mv docker-compose /usr/local/bin/docker-compose && \
785 chmod +x /usr/local/bin/docker-compose
786CMD /usr/bin/supervisord -c /etc/supervisor/conf.d/synchronizer.conf
787'''
788 super(Xos_sync_openstack, cls).build_image(dockerfile, image)
789 print('Done building image %s' %image)
790
791class Xos_openvpn(Container):
792 SYSTEM_MEMORY = (get_mem(),) * 2
793 ports = [8000]
794 env = {'DOCKER_URL' : 'https://get.docker.com/builds/Linux/x86_64/docker-1.10.3', 'DOCKER_SHA256' : 'd0df512afa109006a450f41873634951e19ddabf8c7bd419caeb5a526032d86d', 'DOCKER_COMPOSE_URL' : ' https://github.com/docker/compose/releases/download/1.5.2/docker-compose-Linux-x86_64', 'DOCKER_COMPOSE_SHA256' : ' b6b975badc5389647ef1c16fe8a33bdc5935c61f6afd5a15a28ff765427d01e3' }
795 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
796 NAME = 'openvpn'
797 IMAGE = 'xosproject/xos-synchronizer-openstack'
798 TAG = 'latest'
799 PREFIX = ''
800
801 def __init__(self, name = NAME, image = 'xosproject/xos-synchronizer-openstack', prefix = '', tag = 'latest',
802 boot_delay = 60, restart = False, network_cfg = None, update = False):
803 GITHUB_ERROR = False
804 if restart is True:
805 ##Find the right image to restart
806 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
807 if running_image:
808 image_name = running_image[0]['Image']
809 try:
810 image = image_name.split(':')[0]
811 tag = image_name.split(':')[1]
812 except: pass
813
814 super(Xos_openvpn, self).__init__(name, image, prefix = prefix, tag = tag)
815 if update is True or not self.img_exists():
816 self.build_image(self.image_name)
817 if not self.img_exists():
818 print ('Xos base container image is not built on host, have to check github repository ')
819 GITHUB_ERROR = True
820 if GITHUB_ERROR is not True:
821 if restart is True and self.exists():
822 self.kill()
823 if not self.exists():
824 self.remove_container(name, force=True)
825 host_config = self.create_host_config(port_list = self.ports)
826 print('Starting XOS Openvpn container %s' %self.name)
827 self.start(ports = self.ports, host_config = host_config,
828 tty = True)
829 if not restart:
830 ##wait a bit before fetching IP to regenerate cluster cfg
831 time.sleep(5)
832 ip = self.ip()
833 print('Waiting %d seconds for XOS Openvpn Container to boot' %(boot_delay))
834 time.sleep(boot_delay)
835
836 @classmethod
837 def build_image(cls, image):
838 print('Building XOS Synchronizer Openstack image %s' %image)
839 dockerfile = '''
840FROM xosproject/xos-synchronizer-openstack
841RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \
842 openvpn
843RUN mkdir -p /opt/openvpn
844RUN chmod 777 /opt/openvpn
845RUN git clone https://github.com/OpenVPN/easy-rsa.git /opt/openvpn
846RUN git -C /opt/openvpn pull origin master
847RUN echo 'set_var EASYRSA "/opt/openvpn/easyrsa3"' | tee /opt/openvpn/vars
848RUN echo 'set_var EASYRSA_BATCH "true"' | tee -a /opt/openvpn/vars
849'''
850 super(Xos_openvpn, cls).build_image(dockerfile, image)
851 print('Done building image %s' %image)
852
853class Xos_postgresql(Container):
854 SYSTEM_MEMORY = (get_mem(),) * 2
855 ports = [ 5432 ]
856 NAME = 'xos-postgresql'
857 IMAGE = 'xosproject/xos-postgres'
858 TAG = 'latest'
859 PREFIX = ''
860
861 def __init__(self, name = NAME, image = 'ubuntu', prefix = '', tag = '14.04',
862 boot_delay = 60, restart = False, network_cfg = None, update = False):
863 if restart is True:
864 ##Find the right image to restart
865 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
866 if running_image:
867 image_name = running_image[0]['Image']
868 try:
869 image = image_name.split(':')[0]
870 tag = image_name.split(':')[1]
871 except: pass
872
873 super(Xos_postgresql, self).__init__(name, image, prefix = prefix, tag = tag)
874 if restart is True and self.exists():
875 self.kill()
876 if not self.exists():
877 self.remove_container(name, force=True)
878 host_config = self.create_host_config(port_list = self.ports)
879 volumes = ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
880 print('Starting Xos postgresql container %s' %self.name)
881 self.start(ports = self.ports, host_config = host_config, volumes = volumes, tty = True)
882 if not restart:
883 ##wait a bit before fetching IP to regenerate cluster cfg
884 time.sleep(5)
885 ip = self.ip()
886 print('Waiting %d seconds for Xos postgresql to boot' %(boot_delay))
887 time.sleep(boot_delay)
888
889 @classmethod
890 def build_image(cls, image):
891 print('Building XOS postgresql image %s' %image)
892 dockerfile = '''
893FROM ubuntu:14.04
894RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
895RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
896RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --force-yes\
897 python-software-properties \
898 software-properties-common \
899 postgresql-9.3 \
900 postgresql-client-9.3 \
901 postgresql-contrib-9.3
902
903RUN mkdir /etc/ssl/private-copy; mv /etc/ssl/private/* /etc/ssl/private-copy/; rm -r /etc/ssl/private; mv /etc/ssl/private-copy /etc/ssl/private; chmod -R 0700 /etc/ssl/private; chown -R postgres /etc/ssl/private
904USER postgres
905RUN /etc/init.d/postgresql start && \
906 psql --command "ALTER USER postgres WITH SUPERUSER PASSWORD 'password' " && \
907 psql --command "CREATE DATABASE xos"
908RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf
909RUN echo "host all all 0.0.0.0/0 password" >> /etc/postgresql/9.3/main/pg_hba.conf
910RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf
911VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
912CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]
913'''
914 super(Xos_postgresql, cls).build_image(dockerfile, image)
915 print('Done building image %s' %image)
916
917class Xos_synchronizer(Container):
918 SYSTEM_MEMORY = (get_mem(),) * 2
919 ports = [ 8000 ]
920 env = { 'XOS_GIT_REPO' : 'https://github.com/opencord/xos.git', 'XOS_GIT_BRANCH' : 'master', 'NG_XOS_LIB_URL' : ' https://github.com/opencord/ng-xos-lib.git', 'NG_XOS_LIB_VERSION' : '1.0.0',}
921 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
922 NAME = 'xos'
923 IMAGE = 'xosproject/xos'
924 TAG = 'latest'
925 PREFIX = ''
926
927 def __init__(self, name = NAME, image = 'xosproject/xos', prefix = '', tag = 'latest',
928 boot_delay = 60, restart = False, network_cfg = None, update = False):
929 GITHUB_ERROR = False
930 if restart is True:
931 ##Find the right image to restart
932 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
933 if running_image:
934 image_name = running_image[0]['Image']
935 try:
936 image = image_name.split(':')[0]
937 tag = image_name.split(':')[1]
938 except: pass
939
940 super(Xos_synchronizer, self).__init__(name, image, prefix = prefix, tag = tag)
941 if update is True or not self.img_exists():
942 self.build_image(self.image_name)
943 if not self.img_exists():
944 print ('Xos base container image is not built on host, have to check github repository ')
945 GITHUB_ERROR = True
946 if GITHUB_ERROR is not True:
947 if restart is True and self.exists():
948 self.kill()
949 if not self.exists():
950 self.remove_container(name, force=True)
951 host_config = self.create_host_config(port_list = self.ports)
952 print('Starting XOS synchronizer container %s' %self.name)
953 self.start(ports = self.ports, environment = self.env, host_config = host_config,
954 tty = True)
955 if not restart:
956 ##wait a bit before fetching IP to regenerate cluster cfg
957 time.sleep(5)
958 ip = self.ip()
959 print('Waiting %d seconds for XOS Synchronizer Container to boot' %(boot_delay))
960 time.sleep(boot_delay)
961
962
963 @classmethod
964 def build_image(cls, image):
965 print('Building XOS Synchronizer image %s' %image)
966 dockerfile = '''
967FROM xosproject/xos
968MAINTAINER chetan@ciena.com
969COPY conf/synchronizer.conf /etc/supervisor/conf.d/
970CMD /usr/bin/supervisord -c /etc/supervisor/conf.d/synchronizer.conf
971'''
972 super(Xos_synchronizer, cls).build_image(dockerfile, image)
973 print('Done building image %s' %image)
974
975class Xos_syndicate_ms(Container):
976 SYSTEM_MEMORY = (get_mem(),) * 2
977 ports = [ 8080 ]
978 env = { 'APT_KEY' : 'butler_opencloud_cs_arizona_edu_pub.gpg', 'MS_PORT': '8080', 'GAE_SDK' : 'google_appengine_1.9.35.zip', 'HOME' : '/home/syndicate' }
979 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
980 NAME = 'syndicate-ms'
981 IMAGE = 'xosproject/syndicate-ms'
982 TAG = 'latest'
983 PREFIX = ''
984
985 def __init__(self, name = NAME, image = 'ubuntu', prefix = '', tag = '14.04.4',
986 boot_delay = 60, restart = False, network_cfg = None, update = False):
987 GITHUB_ERROR = False
988 if restart is True:
989 ##Find the right image to restart
990 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
991 if running_image:
992 image_name = running_image[0]['Image']
993 try:
994 image = image_name.split(':')[0]
995 tag = image_name.split(':')[1]
996 except: pass
997
998 super(Xos_syndicate_ms, self).__init__(name, image, prefix = prefix, tag = tag)
999 if update is True or not self.img_exists():
1000 self.build_image(self.image_name)
1001 if not self.img_exists():
1002 print ('Xos base container image is not built on host, have to check github repository ')
1003 GITHUB_ERROR = True
1004 if GITHUB_ERROR is not True:
1005 if restart is True and self.exists():
1006 self.kill()
1007 if not self.exists():
1008 self.remove_container(name, force=True)
1009 host_config = self.create_host_config(port_list = self.ports)
1010 print('Starting XOS syndicate-ms container %s' %self.name)
1011 self.start(ports = self.ports, environment = self.env, host_config = host_config,
1012 tty = True)
1013 if not restart:
1014 ##wait a bit before fetching IP to regenerate cluster cfg
1015 time.sleep(5)
1016 ip = self.ip()
1017 print('Waiting %d seconds for XOS syndicate-ms Container to boot' %(boot_delay))
1018 time.sleep(boot_delay)
1019
1020 @classmethod
1021 def build_image(cls, image):
1022 print('Building XOS Syndicate-ms image %s' %image)
1023 dockerfile = '''
1024FROM ubuntu:14.04.4
1025MAINTAINER chetan@ciena.com
1026RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --force-yes\
1027 apt-transport-https
1028COPY butler.crt /usr/local/share/ca-certificates
1029RUN update-ca-certificates
1030COPY $APT_KEY /tmp/
1031RUN apt-key add /tmp/$APT_KEY
1032RUN echo "deb https://butler.opencloud.cs.arizona.edu/repos/release/syndicate syndicate main" > /etc/apt/sources.list.d/butler.list
1033RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --force-yes\
1034 syndicate-core \
1035 syndicate-ms \
1036 wget \
1037 unzip
1038
1039RUN groupadd -r syndicate && useradd -m -r -g syndicate syndicate
1040USER syndicate
1041ENV HOME /home/syndicate
1042WORKDIR $HOME
1043RUN wget -nv https://storage.googleapis.com/appengine-sdks/featured/$GAE_SDK
1044RUN unzip -q $GAE_SDK
1045RUN mkdir $HOME/datastore
1046CMD $HOME/google_appengine/dev_appserver.py --admin_host=0.0.0.0 --host=0.0.0.0 --storage_path=$HOME/datastore --skip_sdk_update_check=true /usr/src/syndicate/ms
1047'''
1048 super(Xos_syndicate_ms, cls).build_image(dockerfile, image)
1049 print('Done building image %s' %image)
1050
1051class Xos_sync_vtr(Container):
1052 SYSTEM_MEMORY = (get_mem(),) * 2
1053 ports = [ 8080 ]
1054 env = { 'APT_KEY' : 'butler_opencloud_cs_arizona_edu_pub.gpg', 'MS_PORT': '8080', 'GAE_SDK' : 'google_appengine_1.9.35.zip', 'HOME' : '/home/syndicate' }
1055 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
1056 NAME = 'xos-synchronizer-vtr'
1057 IMAGE = 'xosproject/xos-synchronizer-vtr'
1058 TAG = 'latest'
1059 PREFIX = ''
1060
1061 def __init__(self, name = NAME, image = 'xosproject/xos-synchronizer-vtr', prefix = '', tag = 'latest',
1062 boot_delay = 60, restart = False, network_cfg = None, update = False):
1063 GITHUB_ERROR = False
1064 if restart is True:
1065 ##Find the right image to restart
1066 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
1067 if running_image:
1068 image_name = running_image[0]['Image']
1069 try:
1070 image = image_name.split(':')[0]
1071 tag = image_name.split(':')[1]
1072 except: pass
1073
1074 super(Xos_sync_vtr, self).__init__(name, image, prefix = prefix, tag = tag)
1075 if update is True or not self.img_exists():
1076 self.build_image(self.image_name)
1077 if not self.img_exists():
1078 print ('Xos base container image is not built on host, have to check github repository ')
1079 GITHUB_ERROR = True
1080 if GITHUB_ERROR is not True:
1081 if restart is True and self.exists():
1082 self.kill()
1083 if not self.exists():
1084 self.remove_container(name, force=True)
1085 host_config = self.create_host_config(port_list = self.ports)
1086 print('Starting XOS xos-synchronizer-vtr container %s' %self.name)
1087 self.start(ports = self.ports, environment = self.env, host_config = host_config,
1088 tty = True)
1089 if not restart:
1090 ##wait a bit before fetching IP to regenerate cluster cfg
1091 time.sleep(5)
1092 ip = self.ip()
1093 print('Waiting %d seconds for XOS synchronizer-vtr Container to boot' %(boot_delay))
1094 time.sleep(boot_delay)
1095
1096 @classmethod
1097 def build_image(cls, image):
1098 print('Building XOS Synchronizer-vtr image %s' %image)
1099 dockerfile = '''
1100FROM xosproject/xos-synchronizer-vtr
1101MAINTAINER chetan@ciena.com
1102RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --force-yes\
1103 apt-transport-https
1104COPY butler.crt /usr/local/share/ca-certificates
1105RUN update-ca-certificates
1106COPY $APT_KEY /tmp/
1107RUN apt-key add /tmp/$APT_KEY
1108RUN echo "deb https://butler.opencloud.cs.arizona.edu/repos/release/syndicate syndicate main" > /etc/apt/sources.list.d/butler.list
1109RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --force-yes\
1110 syndicate-core \
1111 syndicate-ms \
1112 wget \
1113 unzip
1114
1115RUN groupadd -r syndicate && useradd -m -r -g syndicate syndicate
1116USER syndicate
1117ENV HOME /home/syndicate
1118WORKDIR $HOME
1119RUN wget -nv https://storage.googleapis.com/appengine-sdks/featured/$GAE_SDK
1120RUN unzip -q $GAE_SDK
1121RUN mkdir $HOME/datastore
1122CMD $HOME/google_appengine/dev_appserver.py --admin_host=0.0.0.0 --host=0.0.0.0 --storage_path=$HOME/datastore --skip_sdk_update_check=true /usr/src/syndicate/ms
1123'''
1124 super(Xos_sync_vtr, cls).build_image(dockerfile, image)
1125 print('Done building image %s' %image)
1126
1127class Xos_sync_vsg(Container):
1128 SYSTEM_MEMORY = (get_mem(),) * 2
1129 ports = [ 8080 ]
1130 env = { 'APT_KEY' : 'butler_opencloud_cs_arizona_edu_pub.gpg', 'MS_PORT': '8080', 'GAE_SDK' : 'google_appengine_1.9.35.zip', 'HOME' : '/home/syndicate' }
1131 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
1132 NAME = 'xos-synchronizer-vsg'
1133 IMAGE = 'xosproject/xos-synchronizer-vsg'
1134 TAG = 'latest'
1135 PREFIX = ''
1136
1137 def __init__(self, name = NAME, image = 'xosproject/xos-synchronizer-vsg', prefix = '', tag = 'latest',
1138 boot_delay = 60, restart = False, network_cfg = None, update = False):
1139 GITHUB_ERROR = False
1140 if restart is True:
1141 ##Find the right image to restart
1142 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
1143 if running_image:
1144 image_name = running_image[0]['Image']
1145 try:
1146 image = image_name.split(':')[0]
1147 tag = image_name.split(':')[1]
1148 except: pass
1149
1150 super(Xos_sync_vsg, self).__init__(name, image, prefix = prefix, tag = tag)
1151 if update is True or not self.img_exists():
1152 self.build_image(self.image_name)
1153 if not self.img_exists():
1154 print ('Xos base container image is not built on host, have to check github repository ')
1155 GITHUB_ERROR = True
1156 if GITHUB_ERROR is not True:
1157 if restart is True and self.exists():
1158 self.kill()
1159 if not self.exists():
1160 self.remove_container(name, force=True)
1161 host_config = self.create_host_config(port_list = self.ports)
1162 print('Starting XOS xos-synchronizer-vsg container %s' %self.name)
1163 self.start(ports = self.ports, environment = self.env, host_config = host_config,
1164 tty = True)
1165 if not restart:
1166 ##wait a bit before fetching IP to regenerate cluster cfg
1167 time.sleep(5)
1168 ip = self.ip()
1169 print('Waiting %d seconds for XOS synchronizer-vsg Container to boot' %(boot_delay))
1170 time.sleep(boot_delay)
1171
1172
1173 @classmethod
1174 def build_image(cls, image):
1175 print('Building XOS Synchronizer-vsg image %s' %image)
1176 dockerfile = '''
1177FROM xosproject/xos-synchronizer-vsg
1178MAINTAINER chetan@ciena.com
1179RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --force-yes\
1180 apt-transport-https
1181COPY butler.crt /usr/local/share/ca-certificates
1182RUN update-ca-certificates
1183COPY $APT_KEY /tmp/
1184RUN apt-key add /tmp/$APT_KEY
1185RUN echo "deb https://butler.opencloud.cs.arizona.edu/repos/release/syndicate syndicate main" > /etc/apt/sources.list.d/butler.list
1186RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --force-yes\
1187 syndicate-core \
1188 syndicate-ms \
1189 wget \
1190 unzip
1191
1192RUN groupadd -r syndicate && useradd -m -r -g syndicate syndicate
1193USER syndicate
1194ENV HOME /home/syndicate
1195WORKDIR $HOME
1196RUN wget -nv https://storage.googleapis.com/appengine-sdks/featured/$GAE_SDK
1197RUN unzip -q $GAE_SDK
1198RUN mkdir $HOME/datastore
1199CMD $HOME/google_appengine/dev_appserver.py --admin_host=0.0.0.0 --host=0.0.0.0 --storage_path=$HOME/datastore --skip_sdk_update_check=true /usr/src/syndicate/ms
1200'''
1201 super(Xos_sync_vsg, cls).build_image(dockerfile, image)
1202 print('Done building image %s' %image)
1203
1204class Xos_sync_onos(Container):
1205 SYSTEM_MEMORY = (get_mem(),) * 2
1206 ports = [ 8080 ]
1207 env = { 'APT_KEY' : 'butler_opencloud_cs_arizona_edu_pub.gpg', 'MS_PORT': '8080', 'GAE_SDK' : 'google_appengine_1.9.35.zip', 'HOME' : '/home/syndicate' }
1208 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
1209 NAME = 'xos-synchronizer-onos'
1210 IMAGE = 'xosproject/xos-synchronizer-onos'
1211 TAG = 'latest'
1212 PREFIX = ''
1213
1214 def __init__(self, name = NAME, image = 'xosproject/xos-synchronizer-onos', prefix = '', tag = 'latest',
1215 boot_delay = 60, restart = False, network_cfg = None, update = False):
1216 GITHUB_ERROR = False
1217 if restart is True:
1218 ##Find the right image to restart
1219 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
1220 if running_image:
1221 image_name = running_image[0]['Image']
1222 try:
1223 image = image_name.split(':')[0]
1224 tag = image_name.split(':')[1]
1225 except: pass
1226
1227 super(Xos_sync_onos, self).__init__(name, image, prefix = prefix, tag = tag)
1228 if update is True or not self.img_exists():
1229 self.build_image(self.image_name)
1230 if not self.img_exists():
1231 print ('Xos base container image is not built on host, have to check github repository ')
1232 GITHUB_ERROR = True
1233 if GITHUB_ERROR is not True:
1234 if restart is True and self.exists():
1235 self.kill()
1236 if not self.exists():
1237 self.remove_container(name, force=True)
1238 host_config = self.create_host_config(port_list = self.ports)
1239 print('Starting XOS xos-synchronizer-onos container %s' %self.name)
1240 self.start(ports = self.ports, environment = self.env, host_config = host_config,
1241 tty = True)
1242 if not restart:
1243 ##wait a bit before fetching IP to regenerate cluster cfg
1244 time.sleep(5)
1245 ip = self.ip()
1246 print('Waiting %d seconds for XOS synchronizer-onos Container to boot' %(boot_delay))
1247 time.sleep(boot_delay)
1248
1249 @classmethod
1250 def build_image(cls, image):
1251 print('Building XOS Synchronizer-onos image %s' %image)
1252 dockerfile = '''
1253FROM xosproject/xos-synchronizer-onos
1254MAINTAINER chetan@ciena.com
1255RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --force-yes\
1256 apt-transport-https
1257COPY butler.crt /usr/local/share/ca-certificates
1258RUN update-ca-certificates
1259COPY $APT_KEY /tmp/
1260RUN apt-key add /tmp/$APT_KEY
1261RUN echo "deb https://butler.opencloud.cs.arizona.edu/repos/release/syndicate syndicate main" > /etc/apt/sources.list.d/butler.list
1262RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --force-yes\
1263 syndicate-core \
1264 syndicate-ms \
1265 wget \
1266 unzip
1267
1268RUN groupadd -r syndicate && useradd -m -r -g syndicate syndicate
1269USER syndicate
1270ENV HOME /home/syndicate
1271WORKDIR $HOME
1272RUN wget -nv https://storage.googleapis.com/appengine-sdks/featured/$GAE_SDK
1273RUN unzip -q $GAE_SDK
1274RUN mkdir $HOME/datastore
1275CMD $HOME/google_appengine/dev_appserver.py --admin_host=0.0.0.0 --host=0.0.0.0 --storage_path=$HOME/datastore --skip_sdk_update_check=true /usr/src/syndicate/ms
1276'''
1277 super(Xos_sync_onos, cls).build_image(dockerfile, image)
1278 print('Done building image %s' %image)
1279
1280class Xos_sync_fabric(Container):
1281 SYSTEM_MEMORY = (get_mem(),) * 2
1282 ports = [ 8080 ]
1283 env = { 'APT_KEY' : 'butler_opencloud_cs_arizona_edu_pub.gpg', 'MS_PORT': '8080', 'GAE_SDK' : 'google_appengine_1.9.35.zip', 'HOME' : '/home/syndicate' }
1284 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
1285 NAME = 'xos-synchronizer-fabric'
1286 IMAGE = 'xosproject/xos-synchronizer-fabric'
1287 TAG = 'latest'
1288 PREFIX = ''
1289
1290 def __init__(self, name = NAME, image = 'xosproject/xos-synchronizer-fabric', prefix = '', tag = 'latest',
1291 boot_delay = 60, restart = False, network_cfg = None, update = False):
1292 GITHUB_ERROR = False
1293 if restart is True:
1294 ##Find the right image to restart
1295 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
1296 if running_image:
1297 image_name = running_image[0]['Image']
1298 try:
1299 image = image_name.split(':')[0]
1300 tag = image_name.split(':')[1]
1301 except: pass
1302
1303 super(Xos_sync_fabric, self).__init__(name, image, prefix = prefix, tag = tag)
1304 if update is True or not self.img_exists():
1305 self.build_image(self.image_name)
1306 if not self.img_exists():
1307 print ('Xos base container image is not built on host, have to check github repository ')
1308 GITHUB_ERROR = True
1309 if GITHUB_ERROR is not True:
1310 if restart is True and self.exists():
1311 self.kill()
1312 if not self.exists():
1313 self.remove_container(name, force=True)
1314 host_config = self.create_host_config(port_list = self.ports)
1315 print('Starting XOS xos-synchronizer-fabric container %s' %self.name)
1316 self.start(ports = self.ports, environment = self.env, host_config = host_config,
1317 tty = True)
1318 if not restart:
1319 ##wait a bit before fetching IP to regenerate cluster cfg
1320 time.sleep(5)
1321 ip = self.ip()
1322 print('Waiting %d seconds for XOS synchronizer-fabric Container to boot' %(boot_delay))
1323 time.sleep(boot_delay)
1324
1325 @classmethod
1326 def build_image(cls, image):
1327 print('Building XOS Synchronizer-fabric image %s' %image)
1328 dockerfile = '''
1329FROM xosproject/xos-synchronizer-fabric
1330MAINTAINER chetan@ciena.com
1331RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --force-yes\
1332 apt-transport-https
1333COPY butler.crt /usr/local/share/ca-certificates
1334RUN update-ca-certificates
1335COPY $APT_KEY /tmp/
1336RUN apt-key add /tmp/$APT_KEY
1337RUN echo "deb https://butler.opencloud.cs.arizona.edu/repos/release/syndicate syndicate main" > /etc/apt/sources.list.d/butler.list
1338RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --force-yes\
1339 syndicate-core \
1340 syndicate-ms \
1341 wget \
1342 unzip
1343
1344RUN groupadd -r syndicate && useradd -m -r -g syndicate syndicate
1345USER syndicate
1346ENV HOME /home/syndicate
1347WORKDIR $HOME
1348RUN wget -nv https://storage.googleapis.com/appengine-sdks/featured/$GAE_SDK
1349RUN unzip -q $GAE_SDK
1350RUN mkdir $HOME/datastore
1351CMD $HOME/google_appengine/dev_appserver.py --admin_host=0.0.0.0 --host=0.0.0.0 --storage_path=$HOME/datastore --skip_sdk_update_check=true /usr/src/syndicate/ms
1352'''
1353 super(Xos_sync_fabric, cls).build_image(dockerfile, image)
1354 print('Done building image %s' %image)
1355
1356class Xos_sync_vtn(Container):
1357 SYSTEM_MEMORY = (get_mem(),) * 2
1358 ports = [ 8080 ]
1359 env = { 'APT_KEY' : 'butler_opencloud_cs_arizona_edu_pub.gpg', 'MS_PORT': '8080', 'GAE_SDK' : 'google_appengine_1.9.35.zip', 'HOME' : '/home/syndicate' }
1360 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
1361 NAME = 'xos-synchronizer-vtn'
1362 IMAGE = 'xosproject/xos-synchronizer-vtn'
1363 TAG = 'latest'
1364 PREFIX = ''
1365
1366 def __init__(self, name = NAME, image = 'xosproject/xos-synchronizer-vtn', prefix = '', tag = 'latest',
1367 boot_delay = 60, restart = False, network_cfg = None, update = False):
1368 GITHUB_ERROR = False
1369 if restart is True:
1370 ##Find the right image to restart
1371 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
1372 if running_image:
1373 image_name = running_image[0]['Image']
1374 try:
1375 image = image_name.split(':')[0]
1376 tag = image_name.split(':')[1]
1377 except: pass
1378
1379 super(Xos_sync_vtn, self).__init__(name, image, prefix = prefix, tag = tag)
1380 if update is True or not self.img_exists():
1381 self.build_image(self.image_name)
1382 if not self.img_exists():
1383 print ('Xos base container image is not built on host, have to check github repository ')
1384 GITHUB_ERROR = True
1385 if GITHUB_ERROR is not True:
1386 if restart is True and self.exists():
1387 self.kill()
1388 if not self.exists():
1389 self.remove_container(name, force=True)
1390 host_config = self.create_host_config(port_list = self.ports)
1391 print('Starting XOS xos-synchronizer-vtn container %s' %self.name)
1392 self.start(ports = self.ports, environment = self.env, host_config = host_config,
1393 tty = True)
1394 if not restart:
1395 ##wait a bit before fetching IP to regenerate cluster cfg
1396 time.sleep(5)
1397 ip = self.ip()
1398 print('Waiting %d seconds for XOS synchronizer-vtn Container to boot' %(boot_delay))
1399 time.sleep(boot_delay)
1400
1401 @classmethod
1402 def build_image(cls, image):
1403 print('Building XOS Synchronizer-vtn image %s' %image)
1404 dockerfile = '''
1405FROM xosproject/xos-synchronizer-vtn
1406MAINTAINER chetan@ciena.com
1407RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --force-yes\
1408 apt-transport-https
1409COPY butler.crt /usr/local/share/ca-certificates
1410RUN update-ca-certificates
1411COPY $APT_KEY /tmp/
1412RUN apt-key add /tmp/$APT_KEY
1413RUN echo "deb https://butler.opencloud.cs.arizona.edu/repos/release/syndicate syndicate main" > /etc/apt/sources.list.d/butler.list
1414RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --force-yes\
1415 syndicate-core \
1416 syndicate-ms \
1417 wget \
1418 unzip
1419
1420RUN groupadd -r syndicate && useradd -m -r -g syndicate syndicate
1421USER syndicate
1422ENV HOME /home/syndicate
1423WORKDIR $HOME
1424RUN wget -nv https://storage.googleapis.com/appengine-sdks/featured/$GAE_SDK
1425RUN unzip -q $GAE_SDK
1426RUN mkdir $HOME/datastore
1427CMD $HOME/google_appengine/dev_appserver.py --admin_host=0.0.0.0 --host=0.0.0.0 --storage_path=$HOME/datastore --skip_sdk_update_check=true /usr/src/syndicate/ms
1428'''
1429 super(Xos_sync_vtn, cls).build_image(dockerfile, image)
1430 print('Done building image %s' %image)
1431
1432class Xos_sync_onboarding(Container):
1433 SYSTEM_MEMORY = (get_mem(),) * 2
1434 ports = [ 8080 ]
1435 env = { 'APT_KEY' : 'butler_opencloud_cs_arizona_edu_pub.gpg', 'MS_PORT': '8080', 'GAE_SDK' : 'google_appengine_1.9.35.zip', 'HOME' : '/home/syndicate' }
1436 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
1437 NAME = 'xos-synchronizer-onboarding'
1438 IMAGE = 'xosproject/xos-synchronizer-onboarding'
1439 TAG = 'latest'
1440 PREFIX = ''
1441
1442 def __init__(self, name = NAME, image = 'xosproject/xos-synchronizer-onboarding', prefix = '', tag = 'latest',
1443 boot_delay = 60, restart = False, network_cfg = None, update = False):
1444 GITHUB_ERROR = False
1445 if restart is True:
1446 ##Find the right image to restart
1447 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
1448 if running_image:
1449 image_name = running_image[0]['Image']
1450 try:
1451 image = image_name.split(':')[0]
1452 tag = image_name.split(':')[1]
1453 except: pass
1454
1455 super(Xos_sync_onboarding, self).__init__(name, image, prefix = prefix, tag = tag)
1456 if update is True or not self.img_exists():
1457 self.build_image(self.image_name)
1458 if not self.img_exists():
1459 print ('Xos base container image is not built on host, have to check github repository ')
1460 GITHUB_ERROR = True
1461 if GITHUB_ERROR is not True:
1462 if restart is True and self.exists():
1463 self.kill()
1464 if not self.exists():
1465 self.remove_container(name, force=True)
1466 host_config = self.create_host_config(port_list = self.ports)
1467 print('Starting XOS xos-synchronizer-onboarding container %s' %self.name)
1468 self.start(ports = self.ports, environment = self.env, host_config = host_config,
1469 tty = True)
1470 if not restart:
1471 ##wait a bit before fetching IP to regenerate cluster cfg
1472 time.sleep(5)
1473 ip = self.ip()
1474 print('Waiting %d seconds for XOS synchronizer-onboarding Container to boot' %(boot_delay))
1475 time.sleep(boot_delay)
1476
1477 @classmethod
1478 def build_image(cls, image):
1479 print('Building XOS Synchronizer-onboarding image %s' %image)
1480 dockerfile = '''
1481FROM xosproject/xos-synchronizer-onboarding
1482MAINTAINER chetan@ciena.com
1483RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --force-yes\
1484 apt-transport-https
1485COPY butler.crt /usr/local/share/ca-certificates
1486RUN update-ca-certificates
1487COPY $APT_KEY /tmp/
1488RUN apt-key add /tmp/$APT_KEY
1489RUN echo "deb https://butler.opencloud.cs.arizona.edu/repos/release/syndicate syndicate main" > /etc/apt/sources.list.d/butler.list
1490RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --force-yes\
1491 syndicate-core \
1492 syndicate-ms \
1493 wget \
1494 unzip
1495
1496RUN groupadd -r syndicate && useradd -m -r -g syndicate syndicate
1497USER syndicate
1498ENV HOME /home/syndicate
1499WORKDIR $HOME
1500RUN wget -nv https://storage.googleapis.com/appengine-sdks/featured/$GAE_SDK
1501RUN unzip -q $GAE_SDK
1502RUN mkdir $HOME/datastore
1503CMD $HOME/google_appengine/dev_appserver.py --admin_host=0.0.0.0 --host=0.0.0.0 --storage_path=$HOME/datastore --skip_sdk_update_check=true /usr/src/syndicate/ms
1504'''
1505 super(Xos_sync_onboarding, cls).build_image(dockerfile, image)
1506 print('Done building image %s' %image)
1507
1508