blob: 8391273d85c0d5c293b1de5b923c47b0ce0ef730 [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
A R Karthickec2db322016-11-17 15:06:01 -080024from shutil import rmtree
A.R Karthick95d044e2016-06-10 18:44:36 -070025from OnosCtrl import OnosCtrl
A R Karthick19aaf5c2016-11-09 17:47:57 -080026from OnosLog import OnosLog
Chetan Gaonker3533faa2016-04-25 17:50:14 -070027
28class docker_netns(object):
29
30 dckr = Client()
31 def __init__(self, name):
32 pid = int(self.dckr.inspect_container(name)['State']['Pid'])
33 if pid == 0:
34 raise Exception('no container named {0}'.format(name))
35 self.pid = pid
36
37 def __enter__(self):
38 pid = self.pid
39 if not os.path.exists('/var/run/netns'):
40 os.mkdir('/var/run/netns')
41 os.symlink('/proc/{0}/ns/net'.format(pid), '/var/run/netns/{0}'.format(pid))
42 return str(pid)
43
44 def __exit__(self, type, value, traceback):
45 pid = self.pid
46 os.unlink('/var/run/netns/{0}'.format(pid))
47
48flatten = lambda l: chain.from_iterable(l)
49
50class Container(object):
51 dckr = Client()
A R Karthick07608ef2016-08-23 16:51:19 -070052 IMAGE_PREFIX = '' ##for saving global prefix for all test classes
53
54 def __init__(self, name, image, prefix='', tag = 'candidate', command = 'bash', quagga_config = None):
Chetan Gaonker3533faa2016-04-25 17:50:14 -070055 self.name = name
A R Karthick07608ef2016-08-23 16:51:19 -070056 self.prefix = prefix
57 if prefix:
58 self.prefix += '/'
59 image = '{}{}'.format(self.prefix, image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -070060 self.image = image
61 self.tag = tag
A R Karthickd44cea12016-07-20 12:16:41 -070062 if tag:
63 self.image_name = image + ':' + tag
64 else:
65 self.image_name = image
Chetan Gaonker3533faa2016-04-25 17:50:14 -070066 self.id = None
67 self.command = command
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -070068 self.quagga_config = quagga_config
Chetan Gaonker3533faa2016-04-25 17:50:14 -070069
70 @classmethod
71 def build_image(cls, dockerfile, tag, force=True, nocache=False):
72 f = io.BytesIO(dockerfile.encode('utf-8'))
73 if force or not cls.image_exists(tag):
74 print('Build {0}...'.format(tag))
75 for line in cls.dckr.build(fileobj=f, rm=True, tag=tag, decode=True, nocache=nocache):
76 if 'stream' in line:
77 print(line['stream'].strip())
78
79 @classmethod
80 def image_exists(cls, name):
81 return name in [ctn['RepoTags'][0] for ctn in cls.dckr.images()]
82
83 @classmethod
84 def create_host_config(cls, port_list = None, host_guest_map = None, privileged = False):
85 port_bindings = None
86 binds = None
87 if port_list:
88 port_bindings = {}
89 for p in port_list:
90 port_bindings[str(p)] = str(p)
91
92 if host_guest_map:
93 binds = []
94 for h, g in host_guest_map:
95 binds.append('{0}:{1}'.format(h, g))
96
97 return cls.dckr.create_host_config(binds = binds, port_bindings = port_bindings, privileged = privileged)
98
99 @classmethod
100 def cleanup(cls, image):
A R Karthick09b1f4e2016-05-12 14:31:50 -0700101 cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True))
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700102 for cnt in cnt_list:
103 print('Cleaning container %s' %cnt['Id'])
A.R Karthick95d044e2016-06-10 18:44:36 -0700104 if cnt.has_key('State') and cnt['State'] == 'running':
A R Karthick09b1f4e2016-05-12 14:31:50 -0700105 cls.dckr.kill(cnt['Id'])
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700106 cls.dckr.remove_container(cnt['Id'], force=True)
107
108 @classmethod
109 def remove_container(cls, name, force=True):
110 try:
111 cls.dckr.remove_container(name, force = force)
112 except: pass
113
114 def exists(self):
115 return '/{0}'.format(self.name) in list(flatten(n['Names'] for n in self.dckr.containers()))
116
117 def img_exists(self):
A R Karthick6d98a592016-08-24 15:16:46 -0700118 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 -0700119
120 def ip(self):
A R Karthick2b93d6a2016-09-06 15:19:09 -0700121 cnt_list = filter(lambda c: c['Names'][0] == '/{}'.format(self.name), self.dckr.containers())
122 #if not cnt_list:
123 # cnt_list = filter(lambda c: c['Image'] == self.image_name, self.dckr.containers())
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700124 cnt_settings = cnt_list.pop()
125 return cnt_settings['NetworkSettings']['Networks']['bridge']['IPAddress']
126
A R Karthick2b93d6a2016-09-06 15:19:09 -0700127 @classmethod
128 def ips(cls, image_name):
129 cnt_list = filter(lambda c: c['Image'] == image_name, cls.dckr.containers())
130 ips = [ cnt['NetworkSettings']['Networks']['bridge']['IPAddress'] for cnt in cnt_list ]
131 return ips
132
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700133 def kill(self, remove = True):
134 self.dckr.kill(self.name)
135 self.dckr.remove_container(self.name, force=True)
136
A R Karthick41adfce2016-06-10 09:51:25 -0700137 def start(self, rm = True, ports = None, volumes = None, host_config = None,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700138 environment = None, tty = False, stdin_open = True):
139
140 if rm and self.exists():
141 print('Removing container:', self.name)
142 self.dckr.remove_container(self.name, force=True)
143
A R Karthick41adfce2016-06-10 09:51:25 -0700144 ctn = self.dckr.create_container(image=self.image_name, ports = ports, command=self.command,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700145 detach=True, name=self.name,
A R Karthick41adfce2016-06-10 09:51:25 -0700146 environment = environment,
147 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700148 host_config = host_config, stdin_open=stdin_open, tty = tty)
149 self.dckr.start(container=self.name)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700150 if self.quagga_config:
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700151 self.connect_to_br()
152 self.id = ctn['Id']
153 return ctn
154
155 def connect_to_br(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700156 index = 0
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700157 with docker_netns(self.name) as pid:
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700158 for quagga_config in self.quagga_config:
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700159 ip = IPRoute()
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700160 br = ip.link_lookup(ifname=quagga_config['bridge'])
161 if len(br) == 0:
Chetan Gaonker5a0fda32016-05-10 14:09:07 -0700162 ip.link_create(ifname=quagga_config['bridge'], kind='bridge')
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700163 br = ip.link_lookup(ifname=quagga_config['bridge'])
164 br = br[0]
165 ip.link('set', index=br, state='up')
166 ifname = '{0}-{1}'.format(self.name, index)
167 ifs = ip.link_lookup(ifname=ifname)
168 if len(ifs) > 0:
169 ip.link_remove(ifs[0])
170 peer_ifname = '{0}-{1}'.format(pid, index)
Chetan Gaonker5a0fda32016-05-10 14:09:07 -0700171 ip.link_create(ifname=ifname, kind='veth', peer=peer_ifname)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700172 host = ip.link_lookup(ifname=ifname)[0]
173 ip.link('set', index=host, master=br)
174 ip.link('set', index=host, state='up')
175 guest = ip.link_lookup(ifname=peer_ifname)[0]
176 ip.link('set', index=guest, net_ns_fd=pid)
177 with Namespace(pid, 'net'):
178 ip = IPRoute()
179 ip.link('set', index=guest, ifname='eth{}'.format(index+1))
180 ip.addr('add', index=guest, address=quagga_config['ip'], mask=quagga_config['mask'])
181 ip.link('set', index=guest, state='up')
182 index += 1
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700183
A.R Karthicke4631062016-11-03 14:28:19 -0700184 def execute(self, cmd, tty = True, stream = False, shell = False):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700185 res = 0
186 if type(cmd) == str:
187 cmds = (cmd,)
188 else:
189 cmds = cmd
190 if shell:
191 for c in cmds:
192 res += os.system('docker exec {0} {1}'.format(self.name, c))
193 return res
194 for c in cmds:
195 i = self.dckr.exec_create(container=self.name, cmd=c, tty = tty, privileged = True)
196 self.dckr.exec_start(i['Id'], stream = stream, detach=True)
197 result = self.dckr.exec_inspect(i['Id'])
198 res += 0 if result['ExitCode'] == None else result['ExitCode']
199 return res
200
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700201 def restart(self, timeout =10):
202 return self.dckr.restart(self.name, timeout)
203
A R Karthick1f908202016-11-16 17:32:20 -0800204def get_mem(instances = 1):
205 if instances <= 0:
206 instances = 1
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700207 with open('/proc/meminfo', 'r') as fd:
208 meminfo = fd.readlines()
209 mem = 0
210 for m in meminfo:
211 if m.startswith('MemTotal:') or m.startswith('SwapTotal:'):
212 mem += int(m.split(':')[1].strip().split()[0])
213
A R Karthick1f908202016-11-16 17:32:20 -0800214 mem = max(mem/1024/1024/2/instances, 1)
Chetan Gaonker6d0a7b02016-05-03 16:57:28 -0700215 mem = min(mem, 16)
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700216 return str(mem) + 'G'
217
A R Karthickd44cea12016-07-20 12:16:41 -0700218class OnosCord(Container):
219 """Use this when running the cord tester agent on the onos compute node"""
220 onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord')
221 onos_config_dir_guest = '/root/onos/config'
222 onos_config_dir = os.path.join(onos_cord_dir, 'config')
223 docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml')
224
A R Karthickbd9b8a32016-07-21 09:56:45 -0700225 def __init__(self, onos_ip, conf, boot_delay = 60):
226 self.onos_ip = onos_ip
A R Karthickd44cea12016-07-20 12:16:41 -0700227 self.cord_conf_dir = conf
A R Karthickbd9b8a32016-07-21 09:56:45 -0700228 self.boot_delay = boot_delay
A R Karthickd44cea12016-07-20 12:16:41 -0700229 if os.access(self.cord_conf_dir, os.F_OK) and not os.access(self.onos_cord_dir, os.F_OK):
230 os.mkdir(self.onos_cord_dir)
231 os.mkdir(self.onos_config_dir)
232 ##copy the config file from cord-tester-config
233 cmd = 'cp {}/* {}'.format(self.cord_conf_dir, self.onos_cord_dir)
234 os.system(cmd)
235
236 ##update the docker yaml with the config volume
237 with open(self.docker_yaml, 'r') as f:
238 yaml_config = yaml.load(f)
239 image = yaml_config['services'].keys()[0]
240 name = 'cordtestercord_{}_1'.format(image)
241 volumes = yaml_config['services'][image]['volumes']
242 config_volumes = filter(lambda e: e.find(self.onos_config_dir_guest) >= 0, volumes)
243 if not config_volumes:
244 config_volume = '{}:{}'.format(self.onos_config_dir, self.onos_config_dir_guest)
245 volumes.append(config_volume)
246 docker_yaml_changed = '{}-changed'.format(self.docker_yaml)
247 with open(docker_yaml_changed, 'w') as wf:
248 yaml.dump(yaml_config, wf)
249
250 os.rename(docker_yaml_changed, self.docker_yaml)
251 self.volumes = volumes
252
253 super(OnosCord, self).__init__(name, image, tag = '')
254 cord_conf_dir_basename = os.path.basename(self.cord_conf_dir.replace('-', ''))
255 self.xos_onos_name = '{}_{}_1'.format(cord_conf_dir_basename, image)
256 ##Create an container instance of xos onos
257 self.xos_onos = Container(self.xos_onos_name, image, tag = '')
258
259 def start(self, restart = False, network_cfg = None):
260 if restart is True:
261 if self.exists():
262 ##Kill the existing instance
263 print('Killing container %s' %self.name)
264 self.kill()
265 if self.xos_onos.exists():
266 print('Killing container %s' %self.xos_onos.name)
267 self.xos_onos.kill()
268
269 if network_cfg is not None:
270 json_data = json.dumps(network_cfg, indent=4)
271 with open('{}/network-cfg.json'.format(self.onos_config_dir), 'w') as f:
272 f.write(json_data)
273
274 #start the container using docker-compose
275 cmd = 'cd {} && docker-compose up -d'.format(self.onos_cord_dir)
276 os.system(cmd)
A R Karthickbd9b8a32016-07-21 09:56:45 -0700277 #Delay to make sure ONOS fully boots
278 time.sleep(self.boot_delay)
279 Onos.install_cord_apps(onos_ip = self.onos_ip)
A R Karthickd44cea12016-07-20 12:16:41 -0700280
281 def build_image(self):
282 build_cmd = 'cd {} && docker-compose build'.format(self.onos_cord_dir)
283 os.system(build_cmd)
284
A.R Karthick1700e0e2016-10-06 18:16:57 -0700285class OnosCordStopWrapper(Container):
286 onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord')
287 docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml')
288
289 def __init__(self):
290 if os.access(self.docker_yaml, os.F_OK):
291 with open(self.docker_yaml, 'r') as f:
292 yaml_config = yaml.load(f)
293 image = yaml_config['services'].keys()[0]
294 name = 'cordtestercord_{}_1'.format(image)
295 super(OnosCordStopWrapper, self).__init__(name, image, tag = '')
296 if self.exists():
297 print('Killing container %s' %self.name)
298 self.kill()
299
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700300class Onos(Container):
301
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700302 quagga_config = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.4', 'mask' : 16 }, )
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700303 SYSTEM_MEMORY = (get_mem(),) * 2
A R Karthick1f908202016-11-16 17:32:20 -0800304 INSTANCE_MEMORY = (get_mem(instances=3),) * 2
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700305 JAVA_OPTS = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode'.format(*SYSTEM_MEMORY)#-XX:+PrintGCDetails -XX:+PrintGCTimeStamps'
A R Karthick1f908202016-11-16 17:32:20 -0800306 JAVA_OPTS_CLUSTER = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode'.format(*INSTANCE_MEMORY)
A.R Karthick95d044e2016-06-10 18:44:36 -0700307 env = { 'ONOS_APPS' : 'drivers,openflow,proxyarp,vrouter', 'JAVA_OPTS' : JAVA_OPTS }
A.R Karthickdfeadb02016-11-30 17:55:51 -0800308 onos_cord_apps = ( ('cord-config', '1.1-SNAPSHOT'),
309 ('aaa', '1.1-SNAPSHOT'),
310 ('igmp', '1.1-SNAPSHOT'),
311 #('vtn', '1.1-SNAPSHOT'),
A.R Karthick95d044e2016-06-10 18:44:36 -0700312 )
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700313 ports = [ 8181, 8101, 9876, 6653, 6633, 2000, 2620 ]
A R Karthickf2f4ca62016-08-17 10:34:08 -0700314 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
315 host_config_dir = os.path.join(setup_dir, 'onos-config')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700316 guest_config_dir = '/root/onos/config'
A R Karthickec2db322016-11-17 15:06:01 -0800317 guest_data_dir = '/root/onos/apache-karaf-3.0.5/data'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700318 onos_gen_partitions = os.path.join(setup_dir, 'onos-gen-partitions')
A R Karthick2b93d6a2016-09-06 15:19:09 -0700319 onos_form_cluster = os.path.join(setup_dir, 'onos-form-cluster')
A.R Karthick95d044e2016-06-10 18:44:36 -0700320 cord_apps_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'apps')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700321 host_guest_map = ( (host_config_dir, guest_config_dir), )
A R Karthick2b93d6a2016-09-06 15:19:09 -0700322 cluster_cfg = os.path.join(host_config_dir, 'cluster.json')
323 cluster_mode = False
324 cluster_instances = []
Chetan Gaonker503032a2016-05-12 12:06:29 -0700325 NAME = 'cord-onos'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700326 ##the ip of ONOS in default cluster.json in setup/onos-config
327 CLUSTER_CFG_IP = '172.17.0.2'
A R Karthick07608ef2016-08-23 16:51:19 -0700328 IMAGE = 'onosproject/onos'
329 TAG = 'latest'
330 PREFIX = ''
A R Karthickf2f4ca62016-08-17 10:34:08 -0700331
332 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700333 def generate_cluster_cfg(cls, ip):
334 if type(ip) in [ list, tuple ]:
335 ips = ' '.join(ip)
336 else:
337 ips = ip
A R Karthickf2f4ca62016-08-17 10:34:08 -0700338 try:
A R Karthick2b93d6a2016-09-06 15:19:09 -0700339 cmd = '{} {} {}'.format(cls.onos_gen_partitions, cls.cluster_cfg, ips)
340 os.system(cmd)
341 except: pass
342
343 @classmethod
344 def form_cluster(cls, ips):
345 nodes = ' '.join(ips)
346 try:
347 cmd = '{} {}'.format(cls.onos_form_cluster, nodes)
A R Karthickf2f4ca62016-08-17 10:34:08 -0700348 os.system(cmd)
349 except: pass
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700350
A R Karthick9d48c652016-09-15 09:16:36 -0700351 @classmethod
352 def cleanup_runtime(cls):
353 '''Cleanup ONOS runtime generated files'''
354 files = ( Onos.cluster_cfg, os.path.join(Onos.host_config_dir, 'network-cfg.json') )
355 for f in files:
356 if os.access(f, os.F_OK):
357 try:
358 os.unlink(f)
359 except: pass
360
A R Karthickec2db322016-11-17 15:06:01 -0800361 @classmethod
362 def get_data_map(cls, host_volume, guest_volume_dir):
363 host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume))
364 if not os.path.exists(host_volume_dir):
365 os.mkdir(host_volume_dir)
366 return ( (host_volume_dir, guest_volume_dir), )
367
368 @classmethod
369 def remove_data_map(cls, host_volume, guest_volume_dir):
370 host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume))
371 if os.path.exists(host_volume_dir):
372 rmtree(host_volume_dir)
373
374 def remove_data_volume(self):
375 if self.data_map is not None:
376 self.remove_data_map(*self.data_map)
377
A.R Karthick1700e0e2016-10-06 18:16:57 -0700378 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthickec2db322016-11-17 15:06:01 -0800379 boot_delay = 20, restart = False, network_cfg = None,
380 cluster = False, data_volume = None):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700381 if restart is True:
382 ##Find the right image to restart
383 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
384 if running_image:
385 image_name = running_image[0]['Image']
386 try:
387 image = image_name.split(':')[0]
388 tag = image_name.split(':')[1]
389 except: pass
390
A R Karthick07608ef2016-08-23 16:51:19 -0700391 super(Onos, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.quagga_config)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700392 self.boot_delay = boot_delay
A R Karthickec2db322016-11-17 15:06:01 -0800393 self.data_map = None
A R Karthick2b93d6a2016-09-06 15:19:09 -0700394 if cluster is True:
395 self.ports = []
A R Karthick1f908202016-11-16 17:32:20 -0800396 self.env['JAVA_OPTS'] = self.JAVA_OPTS_CLUSTER
A R Karthickec2db322016-11-17 15:06:01 -0800397 if data_volume is not None:
398 self.data_map = self.get_data_map(data_volume, self.guest_data_dir)
399 self.host_guest_map = self.host_guest_map + self.data_map
A R Karthick2b93d6a2016-09-06 15:19:09 -0700400 if os.access(self.cluster_cfg, os.F_OK):
401 try:
402 os.unlink(self.cluster_cfg)
403 except: pass
404
405 self.host_config = self.create_host_config(port_list = self.ports,
406 host_guest_map = self.host_guest_map)
407 self.volumes = []
408 for _,g in self.host_guest_map:
409 self.volumes.append(g)
410
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700411 if restart is True and self.exists():
412 self.kill()
A R Karthick2b93d6a2016-09-06 15:19:09 -0700413
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700414 if not self.exists():
415 self.remove_container(name, force=True)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700416 host_config = self.create_host_config(port_list = self.ports,
417 host_guest_map = self.host_guest_map)
418 volumes = []
419 for _,g in self.host_guest_map:
420 volumes.append(g)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700421 if network_cfg is not None:
A R Karthick81acbff2016-06-17 14:45:16 -0700422 json_data = json.dumps(network_cfg, indent=4)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700423 with open('{}/network-cfg.json'.format(self.host_config_dir), 'w') as f:
424 f.write(json_data)
425 print('Starting ONOS container %s' %self.name)
A R Karthick41adfce2016-06-10 09:51:25 -0700426 self.start(ports = self.ports, environment = self.env,
A R Karthick2b93d6a2016-09-06 15:19:09 -0700427 host_config = self.host_config, volumes = self.volumes, tty = True)
A R Karthickf2f4ca62016-08-17 10:34:08 -0700428 if not restart:
429 ##wait a bit before fetching IP to regenerate cluster cfg
430 time.sleep(5)
431 ip = self.ip()
432 ##Just a quick hack/check to ensure we don't regenerate in the common case.
433 ##As ONOS is usually the first test container that is started
A R Karthick2b93d6a2016-09-06 15:19:09 -0700434 if cluster is False:
435 if ip != self.CLUSTER_CFG_IP or not os.access(self.cluster_cfg, os.F_OK):
436 print('Regenerating ONOS cluster cfg for ip %s' %ip)
437 self.generate_cluster_cfg(ip)
438 self.kill()
439 self.remove_container(self.name, force=True)
440 print('Restarting ONOS container %s' %self.name)
441 self.start(ports = self.ports, environment = self.env,
442 host_config = self.host_config, volumes = self.volumes, tty = True)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800443 print('Waiting for ONOS to boot')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700444 time.sleep(boot_delay)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800445 self.wait_for_onos_start(self.ip())
446
A R Karthick2b93d6a2016-09-06 15:19:09 -0700447 self.ipaddr = self.ip()
448 if cluster is False:
449 self.install_cord_apps(self.ipaddr)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700450
A R Karthick2b93d6a2016-09-06 15:19:09 -0700451 @classmethod
A R Karthick19aaf5c2016-11-09 17:47:57 -0800452 def wait_for_onos_start(cls, ip, tries = 30):
453 onos_log = OnosLog(host = ip)
454 num_tries = 0
455 started = None
456 while not started and num_tries < tries:
457 time.sleep(3)
458 started = onos_log.search_log_pattern('ApplicationManager .* Started')
459 num_tries += 1
460
A R Karthick19aaf5c2016-11-09 17:47:57 -0800461 if not started:
462 print('ONOS did not start')
463 else:
464 print('ONOS started')
465 return started
466
467 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700468 def setup_cluster_deprecated(cls, onos_instances, image_name = None):
469 if not onos_instances or len(onos_instances) < 2:
470 return
471 ips = []
472 if image_name is not None:
473 ips = Container.ips(image_name)
474 else:
475 for onos in onos_instances:
476 ips.append(onos.ipaddr)
477 Onos.cluster_instances = onos_instances
478 Onos.cluster_mode = True
479 ##regenerate the cluster json with the 3 instance ips before restarting them back
480 print('Generating cluster cfg for ONOS instances with ips %s' %ips)
481 Onos.generate_cluster_cfg(ips)
482 for onos in onos_instances:
483 onos.kill()
484 onos.remove_container(onos.name, force=True)
485 print('Restarting ONOS container %s for forming cluster' %onos.name)
486 onos.start(ports = onos.ports, environment = onos.env,
487 host_config = onos.host_config, volumes = onos.volumes, tty = True)
488 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
489 time.sleep(onos.boot_delay)
490 onos.ipaddr = onos.ip()
491 onos.install_cord_apps(onos.ipaddr)
492
493 @classmethod
494 def setup_cluster(cls, onos_instances, image_name = None):
495 if not onos_instances or len(onos_instances) < 2:
496 return
497 ips = []
498 if image_name is not None:
499 ips = Container.ips(image_name)
500 else:
501 for onos in onos_instances:
502 ips.append(onos.ipaddr)
503 Onos.cluster_instances = onos_instances
504 Onos.cluster_mode = True
505 ##regenerate the cluster json with the 3 instance ips before restarting them back
506 print('Forming cluster for ONOS instances with ips %s' %ips)
507 Onos.form_cluster(ips)
508 ##wait for the cluster to be formed
509 print('Waiting for the cluster to be formed')
510 time.sleep(60)
511 for onos in onos_instances:
512 onos.install_cord_apps(onos.ipaddr)
513
514 @classmethod
A R Karthicke2c24bd2016-10-07 14:51:38 -0700515 def add_cluster(cls, count = 1, network_cfg = None):
516 if not cls.cluster_instances or Onos.cluster_mode is False:
517 return
518 for i in range(count):
519 name = '{}-{}'.format(Onos.NAME, len(cls.cluster_instances)+1)
520 onos = cls(name = name, image = Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX,
521 cluster = True, network_cfg = network_cfg)
522 cls.cluster_instances.append(onos)
523
524 cls.setup_cluster(cls.cluster_instances)
525
526 @classmethod
A.R Karthick2560f042016-11-30 14:38:52 -0800527 def restart_cluster(cls, network_cfg = None, timeout = 10, setup = False):
A R Karthick2b93d6a2016-09-06 15:19:09 -0700528 if cls.cluster_mode is False:
529 return
530 if not cls.cluster_instances:
531 return
532
533 if network_cfg is not None:
534 json_data = json.dumps(network_cfg, indent=4)
535 with open('{}/network-cfg.json'.format(cls.host_config_dir), 'w') as f:
536 f.write(json_data)
537
A.R Karthick2560f042016-11-30 14:38:52 -0800538 cls.cleanup_cluster()
539 if timeout > 0:
540 time.sleep(timeout)
541
A R Karthick2b93d6a2016-09-06 15:19:09 -0700542 for onos in cls.cluster_instances:
A R Karthick2b93d6a2016-09-06 15:19:09 -0700543 print('Restarting ONOS container %s' %onos.name)
544 onos.start(ports = onos.ports, environment = onos.env,
545 host_config = onos.host_config, volumes = onos.volumes, tty = True)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700546 onos.ipaddr = onos.ip()
A.R Karthick2560f042016-11-30 14:38:52 -0800547 onos.wait_for_onos_start(onos.ipaddr)
548 onos.install_cord_apps(onos.ipaddr)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700549
A.R Karthick2560f042016-11-30 14:38:52 -0800550 ##form the cluster as appropriate
551 if setup is True:
552 cls.setup_cluster(cls.cluster_instances)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700553
554 @classmethod
555 def cluster_ips(cls):
556 if cls.cluster_mode is False:
557 return []
558 if not cls.cluster_instances:
559 return []
560 ips = [ onos.ipaddr for onos in cls.cluster_instances ]
561 return ips
562
563 @classmethod
564 def cleanup_cluster(cls):
565 if cls.cluster_mode is False:
566 return
567 if not cls.cluster_instances:
568 return
569 for onos in cls.cluster_instances:
570 if onos.exists():
571 onos.kill()
572 onos.remove_container(onos.name, force=True)
A R Karthickd44cea12016-07-20 12:16:41 -0700573
A.R Karthick95d044e2016-06-10 18:44:36 -0700574 @classmethod
A R Karthickde6b9dc2016-11-29 17:46:16 -0800575 def restart_node(cls, node = None, network_cfg = None, timeout = 10):
A R Karthick889d9652016-10-03 14:13:45 -0700576 if node is None:
577 cls(restart = True, network_cfg = network_cfg, image = cls.IMAGE, tag = cls.TAG)
578 else:
579 #Restarts a node in the cluster
580 valid_node = filter(lambda onos: node in [ onos.ipaddr, onos.name ], cls.cluster_instances)
581 if valid_node:
582 onos = valid_node.pop()
583 if onos.exists():
584 onos.kill()
585 onos.remove_container(onos.name, force=True)
A R Karthickde6b9dc2016-11-29 17:46:16 -0800586 if timeout > 0:
587 time.sleep(timeout)
A R Karthick889d9652016-10-03 14:13:45 -0700588 print('Restarting ONOS container %s' %onos.name)
589 onos.start(ports = onos.ports, environment = onos.env,
590 host_config = onos.host_config, volumes = onos.volumes, tty = True)
A R Karthick889d9652016-10-03 14:13:45 -0700591 onos.ipaddr = onos.ip()
A.R Karthick2560f042016-11-30 14:38:52 -0800592 onos.wait_for_onos_start(onos.ipaddr)
593 onos.install_cord_apps(onos.ipaddr)
A R Karthick889d9652016-10-03 14:13:45 -0700594
595 @classmethod
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700596 def install_cord_apps(cls, onos_ip = None):
A.R Karthick95d044e2016-06-10 18:44:36 -0700597 for app, version in cls.onos_cord_apps:
598 app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version)
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700599 ok, code = OnosCtrl.install_app(app_file, onos_ip = onos_ip)
A.R Karthick95d044e2016-06-10 18:44:36 -0700600 ##app already installed (conflicts)
601 if code in [ 409 ]:
602 ok = True
603 print('ONOS app %s, version %s %s' %(app, version, 'installed' if ok else 'failed to install'))
604 time.sleep(2)
605
A.R Karthick1700e0e2016-10-06 18:16:57 -0700606class OnosStopWrapper(Container):
607 def __init__(self, name):
608 super(OnosStopWrapper, self).__init__(name, Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX)
609 if self.exists():
610 self.kill()
611 else:
612 if Onos.cluster_mode is True:
613 valid_node = filter(lambda onos: name in [ onos.ipaddr, onos.name ], Onos.cluster_instances)
614 if valid_node:
615 onos = valid_node.pop()
616 if onos.exists():
617 onos.kill()
618
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700619class Radius(Container):
620 ports = [ 1812, 1813 ]
A R Karthick41adfce2016-06-10 09:51:25 -0700621 env = {'TIMEZONE':'America/Los_Angeles',
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700622 'DEBUG': 'true', 'cert_password':'whatever', 'primary_shared_secret':'radius_password'
623 }
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700624 host_db_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/db')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700625 guest_db_dir = os.path.join(os.path.sep, 'opt', 'db')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700626 host_config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/freeradius')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700627 guest_config_dir = os.path.join(os.path.sep, 'etc', 'freeradius')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700628 start_command = os.path.join(guest_config_dir, 'start-radius.py')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700629 host_guest_map = ( (host_db_dir, guest_db_dir),
630 (host_config_dir, guest_config_dir)
631 )
Chetan Gaonker503032a2016-05-12 12:06:29 -0700632 IMAGE = 'cord-test/radius'
633 NAME = 'cord-radius'
634
A R Karthick07608ef2016-08-23 16:51:19 -0700635 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
Chetan Gaonker503032a2016-05-12 12:06:29 -0700636 boot_delay = 10, restart = False, update = False):
A R Karthick07608ef2016-08-23 16:51:19 -0700637 super(Radius, self).__init__(name, image, prefix = prefix, tag = tag, command = self.start_command)
Chetan Gaonker503032a2016-05-12 12:06:29 -0700638 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -0700639 self.build_image(self.image_name)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700640 if restart is True and self.exists():
641 self.kill()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700642 if not self.exists():
643 self.remove_container(name, force=True)
644 host_config = self.create_host_config(port_list = self.ports,
645 host_guest_map = self.host_guest_map)
646 volumes = []
647 for _,g in self.host_guest_map:
648 volumes.append(g)
A R Karthick41adfce2016-06-10 09:51:25 -0700649 self.start(ports = self.ports, environment = self.env,
650 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700651 host_config = host_config, tty = True)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700652 time.sleep(boot_delay)
653
654 @classmethod
655 def build_image(cls, image):
656 print('Building Radius image %s' %image)
657 dockerfile = '''
658FROM hbouvier/docker-radius
659MAINTAINER chetan@ciena.com
660LABEL RUN docker pull hbouvier/docker-radius
661LABEL RUN docker run -it --name cord-radius hbouvier/docker-radius
A R Karthickc762df42016-05-25 10:09:21 -0700662RUN apt-get update && \
663 apt-get -y install python python-pexpect strace
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700664WORKDIR /root
665CMD ["/etc/freeradius/start-radius.py"]
666'''
667 super(Radius, cls).build_image(dockerfile, image)
668 print('Done building image %s' %image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700669
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700670class Quagga(Container):
A R Karthick41adfce2016-06-10 09:51:25 -0700671 quagga_config = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 },
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700672 { 'bridge' : 'quagga-br', 'ip': '192.168.10.3', 'mask': 16 },
673 )
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700674 ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ]
675 host_quagga_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/quagga-config')
676 guest_quagga_config = '/root/config'
677 quagga_config_file = os.path.join(guest_quagga_config, 'testrib.conf')
678 host_guest_map = ( (host_quagga_config, guest_quagga_config), )
Chetan Gaonker503032a2016-05-12 12:06:29 -0700679 IMAGE = 'cord-test/quagga'
680 NAME = 'cord-quagga'
681
A R Karthick07608ef2016-08-23 16:51:19 -0700682 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
Chetan Gaonker503032a2016-05-12 12:06:29 -0700683 boot_delay = 15, restart = False, config_file = quagga_config_file, update = False):
A R Karthick07608ef2016-08-23 16:51:19 -0700684 super(Quagga, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.quagga_config)
Chetan Gaonker503032a2016-05-12 12:06:29 -0700685 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -0700686 self.build_image(self.image_name)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700687 if restart is True and self.exists():
688 self.kill()
689 if not self.exists():
690 self.remove_container(name, force=True)
A R Karthick41adfce2016-06-10 09:51:25 -0700691 host_config = self.create_host_config(port_list = self.ports,
692 host_guest_map = self.host_guest_map,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700693 privileged = True)
694 volumes = []
695 for _,g in self.host_guest_map:
696 volumes.append(g)
697 self.start(ports = self.ports,
A R Karthick41adfce2016-06-10 09:51:25 -0700698 host_config = host_config,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700699 volumes = volumes, tty = True)
700 print('Starting Quagga on container %s' %self.name)
701 self.execute('{0}/start.sh {1}'.format(self.guest_quagga_config, config_file))
702 time.sleep(boot_delay)
703
704 @classmethod
705 def build_image(cls, image):
Chetan Gaonker2a6601b2016-05-02 17:28:26 -0700706 onos_quagga_ip = Onos.quagga_config[0]['ip']
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700707 print('Building Quagga image %s' %image)
708 dockerfile = '''
A R Karthick41adfce2016-06-10 09:51:25 -0700709FROM ubuntu:14.04
710MAINTAINER chetan@ciena.com
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700711WORKDIR /root
712RUN useradd -M quagga
713RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga
714RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga
A R Karthick973ea692016-10-17 12:23:02 -0700715RUN apt-get update && apt-get install -qy git autoconf libtool gawk make telnet libreadline6-dev pkg-config protobuf-c-compiler
ChetanGaonkerb5b46c62016-08-16 12:02:53 -0700716RUN git clone git://git.savannah.nongnu.org/quagga.git quagga && \
A R Karthick8f69c2c2016-10-21 11:43:26 -0700717(cd quagga && git checkout quagga-1.0.20160315 && ./bootstrap.sh && \
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700718sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \
719./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install)
720RUN ldconfig
721'''.format(onos_quagga_ip)
722 super(Quagga, cls).build_image(dockerfile, image)
723 print('Done building image %s' %image)
A R Karthick81acbff2016-06-17 14:45:16 -0700724
A.R Karthick1700e0e2016-10-06 18:16:57 -0700725class QuaggaStopWrapper(Container):
726 def __init__(self, name = Quagga.NAME, image = Quagga.IMAGE, tag = 'candidate'):
727 super(QuaggaStopWrapper, self).__init__(name, image, prefix = Container.IMAGE_PREFIX, tag = tag)
728 if self.exists():
729 self.kill()
730
731
A R Karthick81acbff2016-06-17 14:45:16 -0700732def reinitContainerClients():
733 docker_netns.dckr = Client()
734 Container.dckr = Client()
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700735
736class Xos(Container):
737 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
738 TAG = 'latest'
739 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700740 host_guest_map = None
741 env = None
742 ports = None
743 volumes = None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700744
A R Karthick6e80afd2016-10-10 16:03:12 -0700745 @classmethod
746 def get_cmd(cls, img_name):
747 cmd = cls.dckr.inspect_image(img_name)['Config']['Cmd']
748 return ' '.join(cmd)
749
A R Karthicke3bde962016-09-27 15:06:35 -0700750 def __init__(self, name, image, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700751 boot_delay = 20, restart = False, network_cfg = None, update = False):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700752 if restart is True:
753 ##Find the right image to restart
754 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
755 if running_image:
756 image_name = running_image[0]['Image']
757 try:
758 image = image_name.split(':')[0]
759 tag = image_name.split(':')[1]
760 except: pass
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700761 super(Xos, self).__init__(name, image, prefix = prefix, tag = tag)
762 if update is True or not self.img_exists():
763 self.build_image(self.image_name)
A R Karthick6e80afd2016-10-10 16:03:12 -0700764 self.command = self.get_cmd(self.image_name).strip() or None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700765 if restart is True and self.exists():
766 self.kill()
767 if not self.exists():
768 self.remove_container(name, force=True)
A R Karthicke3bde962016-09-27 15:06:35 -0700769 host_config = self.create_host_config(port_list = self.ports,
770 host_guest_map = self.host_guest_map,
771 privileged = True)
772 print('Starting XOS container %s' %self.name)
773 self.start(ports = self.ports, environment = self.env, host_config = host_config,
774 volumes = self.volumes, tty = True)
775 print('Waiting %d seconds for XOS Base Container to boot' %(boot_delay))
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700776 time.sleep(boot_delay)
777
778 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700779 def build_image(cls, image, dockerfile_path, image_target = 'build'):
780 cmd = 'cd {} && make {}'.format(dockerfile_path, image_target)
781 print('Building XOS %s' %image)
782 res = os.system(cmd)
783 print('Done building image %s. Image build %s' %(image, 'successful' if res == 0 else 'failed'))
784 return res
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700785
A R Karthicke3bde962016-09-27 15:06:35 -0700786class XosServer(Xos):
787 ports = [8000,9998,9999]
788 NAME = 'xos-server'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700789 IMAGE = 'xosproject/xos'
A R Karthicke3bde962016-09-27 15:06:35 -0700790 BASE_IMAGE = 'xosproject/xos-base'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700791 TAG = 'latest'
792 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700793 dockerfile_path = os.path.join(Xos.setup_dir, 'xos')
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700794
A R Karthicke3bde962016-09-27 15:06:35 -0700795 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700796 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700797 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700798
799 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700800 def build_image(cls, image = IMAGE):
801 ##build the base image and then build the server image
802 Xos.build_image(cls.BASE_IMAGE, cls.dockerfile_path, image_target = 'base')
803 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700804
A R Karthicke3bde962016-09-27 15:06:35 -0700805class XosSynchronizerOpenstack(Xos):
806 ports = [2375,]
807 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer')
808 NAME = 'xos-synchronizer'
809 IMAGE = 'xosproject/xos-synchronizer-openstack'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700810 TAG = 'latest'
811 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700812 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700813
A R Karthicke3bde962016-09-27 15:06:35 -0700814 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700815 tag = TAG, boot_delay = 20, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700816 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700817
818 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700819 def build_image(cls, image = IMAGE):
820 XosServer.build_image()
821 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700822
A R Karthicke3bde962016-09-27 15:06:35 -0700823class XosSynchronizerOnboarding(Xos):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700824 NAME = 'xos-synchronizer-onboarding'
825 IMAGE = 'xosproject/xos-synchronizer-onboarding'
826 TAG = 'latest'
827 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700828 dockerfile_path = os.path.join(Xos.setup_dir, 'onboarding_synchronizer')
829 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700830
A R Karthicke3bde962016-09-27 15:06:35 -0700831 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700832 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700833 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700834
835 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700836 def build_image(cls, image = IMAGE):
837 XosSynchronizerOpenstack.build_image()
838 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700839
A R Karthicke3bde962016-09-27 15:06:35 -0700840class XosSynchronizerOpenvpn(Xos):
841 NAME = 'xos-synchronizer-openvpn'
842 IMAGE = 'xosproject/xos-openvpn'
843 TAG = 'latest'
844 PREFIX = ''
845 dockerfile_path = os.path.join(Xos.setup_dir, 'openvpn')
846 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700847
A R Karthicke3bde962016-09-27 15:06:35 -0700848 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700849 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700850 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
851
852 @classmethod
853 def build_image(cls, image = IMAGE):
854 XosSynchronizerOpenstack.build_image()
855 Xos.build_image(image, cls.dockerfile_path)
856
857class XosPostgresql(Xos):
858 ports = [5432,]
859 NAME = 'xos-db-postgres'
860 IMAGE = 'xosproject/xos-postgres'
861 TAG = 'latest'
862 PREFIX = ''
863 volumes = ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
864 dockerfile_path = os.path.join(Xos.setup_dir, 'postgresql')
865
866 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700867 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700868 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
869
870 @classmethod
871 def build_image(cls, image = IMAGE):
872 Xos.build_image(image, cls.dockerfile_path)
873
874class XosSyndicateMs(Xos):
875 ports = [8080,]
876 env = None
877 NAME = 'xos-syndicate-ms'
878 IMAGE = 'xosproject/syndicate-ms'
879 TAG = 'latest'
880 PREFIX = ''
881 dockerfile_path = os.path.join(Xos.setup_dir, 'syndicate-ms')
882
883 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700884 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700885 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
886
887 @classmethod
888 def build_image(cls, image = IMAGE):
889 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700890
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700891class XosSyncVtn(Xos):
892 ports = [8080,]
893 env = None
894 NAME = 'xos-synchronizer-vtn'
895 IMAGE = 'xosproject/xos-synchronizer-vtn'
896 TAG = 'latest'
897 PREFIX = ''
898 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtn')
899
900 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700901 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700902 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
903
904 @classmethod
905 def build_image(cls, image = IMAGE):
906 Xos.build_image(image, cls.dockerfile_path)
907
908class XosSyncVtr(Xos):
909 ports = [8080,]
910 env = None
911 NAME = 'xos-synchronizer-vtr'
912 IMAGE = 'xosproject/xos-synchronizer-vtr'
913 TAG = 'latest'
914 PREFIX = ''
915 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtr')
916
917 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700918 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700919 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
920
921 @classmethod
922 def build_image(cls, image = IMAGE):
923 Xos.build_image(image, cls.dockerfile_path)
924
925class XosSyncVsg(Xos):
926 ports = [8080,]
927 env = None
928 NAME = 'xos-synchronizer-vsg'
929 IMAGE = 'xosproject/xos-synchronizer-vsg'
930 TAG = 'latest'
931 PREFIX = ''
932 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vsg')
933
934 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700935 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700936 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
937
938 @classmethod
939 def build_image(cls, image = IMAGE):
940 Xos.build_image(image, cls.dockerfile_path)
941
942
943class XosSyncOnos(Xos):
944 ports = [8080,]
945 env = None
946 NAME = 'xos-synchronizer-onos'
947 IMAGE = 'xosproject/xos-synchronizer-onos'
948 TAG = 'latest'
949 PREFIX = ''
950 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-onos')
951
952 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700953 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700954 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
955
956 @classmethod
957 def build_image(cls, image = IMAGE):
958 Xos.build_image(image, cls.dockerfile_path)
959
960class XosSyncFabric(Xos):
961 ports = [8080,]
962 env = None
963 NAME = 'xos-synchronizer-fabric'
964 IMAGE = 'xosproject/xos-synchronizer-fabric'
965 TAG = 'latest'
966 PREFIX = ''
967 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-fabric')
968
969 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700970 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700971 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
972
973 @classmethod
974 def build_image(cls, image = IMAGE):
975 Xos.build_image(image, cls.dockerfile_path)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800976
977if __name__ == '__main__':
978 onos = Onos(boot_delay = 10, restart = True)