blob: a228819a19768c886b303e156b7e1bb27a9ec882 [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 }
308 onos_cord_apps = ( ('cord-config', '1.0-SNAPSHOT'),
309 ('aaa', '1.0-SNAPSHOT'),
310 ('igmp', '1.0-SNAPSHOT'),
A R Karthickedab01c2016-09-08 14:05:44 -0700311 #('vtn', '1.0-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 Karthick2b93d6a2016-09-06 15:19:09 -0700527 def restart_cluster(cls, network_cfg = None):
528 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
538 for onos in cls.cluster_instances:
539 if onos.exists():
540 onos.kill()
541 onos.remove_container(onos.name, force=True)
542 print('Restarting ONOS container %s' %onos.name)
543 onos.start(ports = onos.ports, environment = onos.env,
544 host_config = onos.host_config, volumes = onos.volumes, tty = True)
545 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
546 time.sleep(onos.boot_delay)
547 onos.ipaddr = onos.ip()
548
549 ##form the cluster
550 cls.setup_cluster(cls.cluster_instances)
551
552 @classmethod
553 def cluster_ips(cls):
554 if cls.cluster_mode is False:
555 return []
556 if not cls.cluster_instances:
557 return []
558 ips = [ onos.ipaddr for onos in cls.cluster_instances ]
559 return ips
560
561 @classmethod
562 def cleanup_cluster(cls):
563 if cls.cluster_mode is False:
564 return
565 if not cls.cluster_instances:
566 return
567 for onos in cls.cluster_instances:
568 if onos.exists():
569 onos.kill()
570 onos.remove_container(onos.name, force=True)
A R Karthickd44cea12016-07-20 12:16:41 -0700571
A.R Karthick95d044e2016-06-10 18:44:36 -0700572 @classmethod
A R Karthick889d9652016-10-03 14:13:45 -0700573 def restart_node(cls, node = None, network_cfg = None):
574 if node is None:
575 cls(restart = True, network_cfg = network_cfg, image = cls.IMAGE, tag = cls.TAG)
576 else:
577 #Restarts a node in the cluster
578 valid_node = filter(lambda onos: node in [ onos.ipaddr, onos.name ], cls.cluster_instances)
579 if valid_node:
580 onos = valid_node.pop()
581 if onos.exists():
582 onos.kill()
583 onos.remove_container(onos.name, force=True)
584 print('Restarting ONOS container %s' %onos.name)
585 onos.start(ports = onos.ports, environment = onos.env,
586 host_config = onos.host_config, volumes = onos.volumes, tty = True)
A R Karthickec2db322016-11-17 15:06:01 -0800587 #onos.ipaddr = onos.ip()
588 #onos.wait_for_onos_start(onos.ipaddr)
A R Karthick889d9652016-10-03 14:13:45 -0700589 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
590 time.sleep(onos.boot_delay)
591 onos.ipaddr = onos.ip()
592
593 @classmethod
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700594 def install_cord_apps(cls, onos_ip = None):
A.R Karthick95d044e2016-06-10 18:44:36 -0700595 for app, version in cls.onos_cord_apps:
596 app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version)
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700597 ok, code = OnosCtrl.install_app(app_file, onos_ip = onos_ip)
A.R Karthick95d044e2016-06-10 18:44:36 -0700598 ##app already installed (conflicts)
599 if code in [ 409 ]:
600 ok = True
601 print('ONOS app %s, version %s %s' %(app, version, 'installed' if ok else 'failed to install'))
602 time.sleep(2)
603
A.R Karthick1700e0e2016-10-06 18:16:57 -0700604class OnosStopWrapper(Container):
605 def __init__(self, name):
606 super(OnosStopWrapper, self).__init__(name, Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX)
607 if self.exists():
608 self.kill()
609 else:
610 if Onos.cluster_mode is True:
611 valid_node = filter(lambda onos: name in [ onos.ipaddr, onos.name ], Onos.cluster_instances)
612 if valid_node:
613 onos = valid_node.pop()
614 if onos.exists():
615 onos.kill()
616
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700617class Radius(Container):
618 ports = [ 1812, 1813 ]
A R Karthick41adfce2016-06-10 09:51:25 -0700619 env = {'TIMEZONE':'America/Los_Angeles',
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700620 'DEBUG': 'true', 'cert_password':'whatever', 'primary_shared_secret':'radius_password'
621 }
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700622 host_db_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/db')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700623 guest_db_dir = os.path.join(os.path.sep, 'opt', 'db')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700624 host_config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/freeradius')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700625 guest_config_dir = os.path.join(os.path.sep, 'etc', 'freeradius')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700626 start_command = os.path.join(guest_config_dir, 'start-radius.py')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700627 host_guest_map = ( (host_db_dir, guest_db_dir),
628 (host_config_dir, guest_config_dir)
629 )
Chetan Gaonker503032a2016-05-12 12:06:29 -0700630 IMAGE = 'cord-test/radius'
631 NAME = 'cord-radius'
632
A R Karthick07608ef2016-08-23 16:51:19 -0700633 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
Chetan Gaonker503032a2016-05-12 12:06:29 -0700634 boot_delay = 10, restart = False, update = False):
A R Karthick07608ef2016-08-23 16:51:19 -0700635 super(Radius, self).__init__(name, image, prefix = prefix, tag = tag, command = self.start_command)
Chetan Gaonker503032a2016-05-12 12:06:29 -0700636 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -0700637 self.build_image(self.image_name)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700638 if restart is True and self.exists():
639 self.kill()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700640 if not self.exists():
641 self.remove_container(name, force=True)
642 host_config = self.create_host_config(port_list = self.ports,
643 host_guest_map = self.host_guest_map)
644 volumes = []
645 for _,g in self.host_guest_map:
646 volumes.append(g)
A R Karthick41adfce2016-06-10 09:51:25 -0700647 self.start(ports = self.ports, environment = self.env,
648 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700649 host_config = host_config, tty = True)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700650 time.sleep(boot_delay)
651
652 @classmethod
653 def build_image(cls, image):
654 print('Building Radius image %s' %image)
655 dockerfile = '''
656FROM hbouvier/docker-radius
657MAINTAINER chetan@ciena.com
658LABEL RUN docker pull hbouvier/docker-radius
659LABEL RUN docker run -it --name cord-radius hbouvier/docker-radius
A R Karthickc762df42016-05-25 10:09:21 -0700660RUN apt-get update && \
661 apt-get -y install python python-pexpect strace
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700662WORKDIR /root
663CMD ["/etc/freeradius/start-radius.py"]
664'''
665 super(Radius, cls).build_image(dockerfile, image)
666 print('Done building image %s' %image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700667
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700668class Quagga(Container):
A R Karthick41adfce2016-06-10 09:51:25 -0700669 quagga_config = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 },
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700670 { 'bridge' : 'quagga-br', 'ip': '192.168.10.3', 'mask': 16 },
671 )
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700672 ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ]
673 host_quagga_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/quagga-config')
674 guest_quagga_config = '/root/config'
675 quagga_config_file = os.path.join(guest_quagga_config, 'testrib.conf')
676 host_guest_map = ( (host_quagga_config, guest_quagga_config), )
Chetan Gaonker503032a2016-05-12 12:06:29 -0700677 IMAGE = 'cord-test/quagga'
678 NAME = 'cord-quagga'
679
A R Karthick07608ef2016-08-23 16:51:19 -0700680 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
Chetan Gaonker503032a2016-05-12 12:06:29 -0700681 boot_delay = 15, restart = False, config_file = quagga_config_file, update = False):
A R Karthick07608ef2016-08-23 16:51:19 -0700682 super(Quagga, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.quagga_config)
Chetan Gaonker503032a2016-05-12 12:06:29 -0700683 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -0700684 self.build_image(self.image_name)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700685 if restart is True and self.exists():
686 self.kill()
687 if not self.exists():
688 self.remove_container(name, force=True)
A R Karthick41adfce2016-06-10 09:51:25 -0700689 host_config = self.create_host_config(port_list = self.ports,
690 host_guest_map = self.host_guest_map,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700691 privileged = True)
692 volumes = []
693 for _,g in self.host_guest_map:
694 volumes.append(g)
695 self.start(ports = self.ports,
A R Karthick41adfce2016-06-10 09:51:25 -0700696 host_config = host_config,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700697 volumes = volumes, tty = True)
698 print('Starting Quagga on container %s' %self.name)
699 self.execute('{0}/start.sh {1}'.format(self.guest_quagga_config, config_file))
700 time.sleep(boot_delay)
701
702 @classmethod
703 def build_image(cls, image):
Chetan Gaonker2a6601b2016-05-02 17:28:26 -0700704 onos_quagga_ip = Onos.quagga_config[0]['ip']
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700705 print('Building Quagga image %s' %image)
706 dockerfile = '''
A R Karthick41adfce2016-06-10 09:51:25 -0700707FROM ubuntu:14.04
708MAINTAINER chetan@ciena.com
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700709WORKDIR /root
710RUN useradd -M quagga
711RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga
712RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga
A R Karthick973ea692016-10-17 12:23:02 -0700713RUN 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 -0700714RUN git clone git://git.savannah.nongnu.org/quagga.git quagga && \
A R Karthick8f69c2c2016-10-21 11:43:26 -0700715(cd quagga && git checkout quagga-1.0.20160315 && ./bootstrap.sh && \
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700716sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \
717./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install)
718RUN ldconfig
719'''.format(onos_quagga_ip)
720 super(Quagga, cls).build_image(dockerfile, image)
721 print('Done building image %s' %image)
A R Karthick81acbff2016-06-17 14:45:16 -0700722
A.R Karthick1700e0e2016-10-06 18:16:57 -0700723class QuaggaStopWrapper(Container):
724 def __init__(self, name = Quagga.NAME, image = Quagga.IMAGE, tag = 'candidate'):
725 super(QuaggaStopWrapper, self).__init__(name, image, prefix = Container.IMAGE_PREFIX, tag = tag)
726 if self.exists():
727 self.kill()
728
729
A R Karthick81acbff2016-06-17 14:45:16 -0700730def reinitContainerClients():
731 docker_netns.dckr = Client()
732 Container.dckr = Client()
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700733
734class Xos(Container):
735 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
736 TAG = 'latest'
737 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700738 host_guest_map = None
739 env = None
740 ports = None
741 volumes = None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700742
A R Karthick6e80afd2016-10-10 16:03:12 -0700743 @classmethod
744 def get_cmd(cls, img_name):
745 cmd = cls.dckr.inspect_image(img_name)['Config']['Cmd']
746 return ' '.join(cmd)
747
A R Karthicke3bde962016-09-27 15:06:35 -0700748 def __init__(self, name, image, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700749 boot_delay = 20, restart = False, network_cfg = None, update = False):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700750 if restart is True:
751 ##Find the right image to restart
752 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
753 if running_image:
754 image_name = running_image[0]['Image']
755 try:
756 image = image_name.split(':')[0]
757 tag = image_name.split(':')[1]
758 except: pass
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700759 super(Xos, self).__init__(name, image, prefix = prefix, tag = tag)
760 if update is True or not self.img_exists():
761 self.build_image(self.image_name)
A R Karthick6e80afd2016-10-10 16:03:12 -0700762 self.command = self.get_cmd(self.image_name).strip() or None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700763 if restart is True and self.exists():
764 self.kill()
765 if not self.exists():
766 self.remove_container(name, force=True)
A R Karthicke3bde962016-09-27 15:06:35 -0700767 host_config = self.create_host_config(port_list = self.ports,
768 host_guest_map = self.host_guest_map,
769 privileged = True)
770 print('Starting XOS container %s' %self.name)
771 self.start(ports = self.ports, environment = self.env, host_config = host_config,
772 volumes = self.volumes, tty = True)
773 print('Waiting %d seconds for XOS Base Container to boot' %(boot_delay))
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700774 time.sleep(boot_delay)
775
776 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700777 def build_image(cls, image, dockerfile_path, image_target = 'build'):
778 cmd = 'cd {} && make {}'.format(dockerfile_path, image_target)
779 print('Building XOS %s' %image)
780 res = os.system(cmd)
781 print('Done building image %s. Image build %s' %(image, 'successful' if res == 0 else 'failed'))
782 return res
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700783
A R Karthicke3bde962016-09-27 15:06:35 -0700784class XosServer(Xos):
785 ports = [8000,9998,9999]
786 NAME = 'xos-server'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700787 IMAGE = 'xosproject/xos'
A R Karthicke3bde962016-09-27 15:06:35 -0700788 BASE_IMAGE = 'xosproject/xos-base'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700789 TAG = 'latest'
790 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700791 dockerfile_path = os.path.join(Xos.setup_dir, 'xos')
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700792
A R Karthicke3bde962016-09-27 15:06:35 -0700793 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700794 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700795 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700796
797 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700798 def build_image(cls, image = IMAGE):
799 ##build the base image and then build the server image
800 Xos.build_image(cls.BASE_IMAGE, cls.dockerfile_path, image_target = 'base')
801 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700802
A R Karthicke3bde962016-09-27 15:06:35 -0700803class XosSynchronizerOpenstack(Xos):
804 ports = [2375,]
805 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer')
806 NAME = 'xos-synchronizer'
807 IMAGE = 'xosproject/xos-synchronizer-openstack'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700808 TAG = 'latest'
809 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700810 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700811
A R Karthicke3bde962016-09-27 15:06:35 -0700812 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700813 tag = TAG, boot_delay = 20, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700814 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700815
816 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700817 def build_image(cls, image = IMAGE):
818 XosServer.build_image()
819 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700820
A R Karthicke3bde962016-09-27 15:06:35 -0700821class XosSynchronizerOnboarding(Xos):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700822 NAME = 'xos-synchronizer-onboarding'
823 IMAGE = 'xosproject/xos-synchronizer-onboarding'
824 TAG = 'latest'
825 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700826 dockerfile_path = os.path.join(Xos.setup_dir, 'onboarding_synchronizer')
827 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700828
A R Karthicke3bde962016-09-27 15:06:35 -0700829 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700830 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700831 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700832
833 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700834 def build_image(cls, image = IMAGE):
835 XosSynchronizerOpenstack.build_image()
836 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700837
A R Karthicke3bde962016-09-27 15:06:35 -0700838class XosSynchronizerOpenvpn(Xos):
839 NAME = 'xos-synchronizer-openvpn'
840 IMAGE = 'xosproject/xos-openvpn'
841 TAG = 'latest'
842 PREFIX = ''
843 dockerfile_path = os.path.join(Xos.setup_dir, 'openvpn')
844 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700845
A R Karthicke3bde962016-09-27 15:06:35 -0700846 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700847 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700848 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
849
850 @classmethod
851 def build_image(cls, image = IMAGE):
852 XosSynchronizerOpenstack.build_image()
853 Xos.build_image(image, cls.dockerfile_path)
854
855class XosPostgresql(Xos):
856 ports = [5432,]
857 NAME = 'xos-db-postgres'
858 IMAGE = 'xosproject/xos-postgres'
859 TAG = 'latest'
860 PREFIX = ''
861 volumes = ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
862 dockerfile_path = os.path.join(Xos.setup_dir, 'postgresql')
863
864 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700865 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700866 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
867
868 @classmethod
869 def build_image(cls, image = IMAGE):
870 Xos.build_image(image, cls.dockerfile_path)
871
872class XosSyndicateMs(Xos):
873 ports = [8080,]
874 env = None
875 NAME = 'xos-syndicate-ms'
876 IMAGE = 'xosproject/syndicate-ms'
877 TAG = 'latest'
878 PREFIX = ''
879 dockerfile_path = os.path.join(Xos.setup_dir, 'syndicate-ms')
880
881 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700882 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700883 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
884
885 @classmethod
886 def build_image(cls, image = IMAGE):
887 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700888
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700889class XosSyncVtn(Xos):
890 ports = [8080,]
891 env = None
892 NAME = 'xos-synchronizer-vtn'
893 IMAGE = 'xosproject/xos-synchronizer-vtn'
894 TAG = 'latest'
895 PREFIX = ''
896 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtn')
897
898 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700899 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700900 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
901
902 @classmethod
903 def build_image(cls, image = IMAGE):
904 Xos.build_image(image, cls.dockerfile_path)
905
906class XosSyncVtr(Xos):
907 ports = [8080,]
908 env = None
909 NAME = 'xos-synchronizer-vtr'
910 IMAGE = 'xosproject/xos-synchronizer-vtr'
911 TAG = 'latest'
912 PREFIX = ''
913 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtr')
914
915 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700916 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700917 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
918
919 @classmethod
920 def build_image(cls, image = IMAGE):
921 Xos.build_image(image, cls.dockerfile_path)
922
923class XosSyncVsg(Xos):
924 ports = [8080,]
925 env = None
926 NAME = 'xos-synchronizer-vsg'
927 IMAGE = 'xosproject/xos-synchronizer-vsg'
928 TAG = 'latest'
929 PREFIX = ''
930 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vsg')
931
932 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700933 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700934 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
935
936 @classmethod
937 def build_image(cls, image = IMAGE):
938 Xos.build_image(image, cls.dockerfile_path)
939
940
941class XosSyncOnos(Xos):
942 ports = [8080,]
943 env = None
944 NAME = 'xos-synchronizer-onos'
945 IMAGE = 'xosproject/xos-synchronizer-onos'
946 TAG = 'latest'
947 PREFIX = ''
948 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-onos')
949
950 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700951 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700952 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
953
954 @classmethod
955 def build_image(cls, image = IMAGE):
956 Xos.build_image(image, cls.dockerfile_path)
957
958class XosSyncFabric(Xos):
959 ports = [8080,]
960 env = None
961 NAME = 'xos-synchronizer-fabric'
962 IMAGE = 'xosproject/xos-synchronizer-fabric'
963 TAG = 'latest'
964 PREFIX = ''
965 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-fabric')
966
967 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700968 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700969 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
970
971 @classmethod
972 def build_image(cls, image = IMAGE):
973 Xos.build_image(image, cls.dockerfile_path)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800974
975if __name__ == '__main__':
976 onos = Onos(boot_delay = 10, restart = True)