blob: c4a73a0b3676c7b99b29443134cae8fbbabbaac3 [file] [log] [blame]
A R Karthick41adfce2016-06-10 09:51:25 -07001#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07002# Copyright 2016-present Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
A R Karthick41adfce2016-06-10 09:51:25 -07007#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07008# http://www.apache.org/licenses/LICENSE-2.0
A R Karthick41adfce2016-06-10 09:51:25 -07009#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070010# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
Chetan Gaonker3533faa2016-04-25 17:50:14 -070016import os,time
17import io
18import json
A R Karthickd44cea12016-07-20 12:16:41 -070019import yaml
Chetan Gaonker3533faa2016-04-25 17:50:14 -070020from pyroute2 import IPRoute
21from itertools import chain
22from nsenter import Namespace
23from docker import Client
24from shutil import copy
A.R Karthick95d044e2016-06-10 18:44:36 -070025from OnosCtrl import OnosCtrl
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 Karthickf2f4ca62016-08-17 10:34:08 -0700317 onos_gen_partitions = os.path.join(setup_dir, 'onos-gen-partitions')
A R Karthick2b93d6a2016-09-06 15:19:09 -0700318 onos_form_cluster = os.path.join(setup_dir, 'onos-form-cluster')
A.R Karthick95d044e2016-06-10 18:44:36 -0700319 cord_apps_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'apps')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700320 host_guest_map = ( (host_config_dir, guest_config_dir), )
A R Karthick2b93d6a2016-09-06 15:19:09 -0700321 cluster_cfg = os.path.join(host_config_dir, 'cluster.json')
322 cluster_mode = False
323 cluster_instances = []
Chetan Gaonker503032a2016-05-12 12:06:29 -0700324 NAME = 'cord-onos'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700325 ##the ip of ONOS in default cluster.json in setup/onos-config
326 CLUSTER_CFG_IP = '172.17.0.2'
A R Karthick07608ef2016-08-23 16:51:19 -0700327 IMAGE = 'onosproject/onos'
328 TAG = 'latest'
329 PREFIX = ''
A R Karthickf2f4ca62016-08-17 10:34:08 -0700330
331 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700332 def generate_cluster_cfg(cls, ip):
333 if type(ip) in [ list, tuple ]:
334 ips = ' '.join(ip)
335 else:
336 ips = ip
A R Karthickf2f4ca62016-08-17 10:34:08 -0700337 try:
A R Karthick2b93d6a2016-09-06 15:19:09 -0700338 cmd = '{} {} {}'.format(cls.onos_gen_partitions, cls.cluster_cfg, ips)
339 os.system(cmd)
340 except: pass
341
342 @classmethod
343 def form_cluster(cls, ips):
344 nodes = ' '.join(ips)
345 try:
346 cmd = '{} {}'.format(cls.onos_form_cluster, nodes)
A R Karthickf2f4ca62016-08-17 10:34:08 -0700347 os.system(cmd)
348 except: pass
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700349
A R Karthick9d48c652016-09-15 09:16:36 -0700350 @classmethod
351 def cleanup_runtime(cls):
352 '''Cleanup ONOS runtime generated files'''
353 files = ( Onos.cluster_cfg, os.path.join(Onos.host_config_dir, 'network-cfg.json') )
354 for f in files:
355 if os.access(f, os.F_OK):
356 try:
357 os.unlink(f)
358 except: pass
359
A.R Karthick1700e0e2016-10-06 18:16:57 -0700360 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthick19aaf5c2016-11-09 17:47:57 -0800361 boot_delay = 20, restart = False, network_cfg = None, cluster = False):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700362 if restart is True:
363 ##Find the right image to restart
364 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
365 if running_image:
366 image_name = running_image[0]['Image']
367 try:
368 image = image_name.split(':')[0]
369 tag = image_name.split(':')[1]
370 except: pass
371
A R Karthick07608ef2016-08-23 16:51:19 -0700372 super(Onos, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.quagga_config)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700373 self.boot_delay = boot_delay
374 if cluster is True:
375 self.ports = []
A R Karthick1f908202016-11-16 17:32:20 -0800376 self.env['JAVA_OPTS'] = self.JAVA_OPTS_CLUSTER
A R Karthick2b93d6a2016-09-06 15:19:09 -0700377 if os.access(self.cluster_cfg, os.F_OK):
378 try:
379 os.unlink(self.cluster_cfg)
380 except: pass
381
382 self.host_config = self.create_host_config(port_list = self.ports,
383 host_guest_map = self.host_guest_map)
384 self.volumes = []
385 for _,g in self.host_guest_map:
386 self.volumes.append(g)
387
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700388 if restart is True and self.exists():
389 self.kill()
A R Karthick2b93d6a2016-09-06 15:19:09 -0700390
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700391 if not self.exists():
392 self.remove_container(name, force=True)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700393 host_config = self.create_host_config(port_list = self.ports,
394 host_guest_map = self.host_guest_map)
395 volumes = []
396 for _,g in self.host_guest_map:
397 volumes.append(g)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700398 if network_cfg is not None:
A R Karthick81acbff2016-06-17 14:45:16 -0700399 json_data = json.dumps(network_cfg, indent=4)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700400 with open('{}/network-cfg.json'.format(self.host_config_dir), 'w') as f:
401 f.write(json_data)
402 print('Starting ONOS container %s' %self.name)
A R Karthick41adfce2016-06-10 09:51:25 -0700403 self.start(ports = self.ports, environment = self.env,
A R Karthick2b93d6a2016-09-06 15:19:09 -0700404 host_config = self.host_config, volumes = self.volumes, tty = True)
A R Karthickf2f4ca62016-08-17 10:34:08 -0700405 if not restart:
406 ##wait a bit before fetching IP to regenerate cluster cfg
407 time.sleep(5)
408 ip = self.ip()
409 ##Just a quick hack/check to ensure we don't regenerate in the common case.
410 ##As ONOS is usually the first test container that is started
A R Karthick2b93d6a2016-09-06 15:19:09 -0700411 if cluster is False:
412 if ip != self.CLUSTER_CFG_IP or not os.access(self.cluster_cfg, os.F_OK):
413 print('Regenerating ONOS cluster cfg for ip %s' %ip)
414 self.generate_cluster_cfg(ip)
415 self.kill()
416 self.remove_container(self.name, force=True)
417 print('Restarting ONOS container %s' %self.name)
418 self.start(ports = self.ports, environment = self.env,
419 host_config = self.host_config, volumes = self.volumes, tty = True)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800420 print('Waiting for ONOS to boot')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700421 time.sleep(boot_delay)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800422 self.wait_for_onos_start(self.ip())
423
A R Karthick2b93d6a2016-09-06 15:19:09 -0700424 self.ipaddr = self.ip()
425 if cluster is False:
426 self.install_cord_apps(self.ipaddr)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700427
A R Karthick2b93d6a2016-09-06 15:19:09 -0700428 @classmethod
A R Karthick19aaf5c2016-11-09 17:47:57 -0800429 def wait_for_onos_start(cls, ip, tries = 30):
430 onos_log = OnosLog(host = ip)
431 num_tries = 0
432 started = None
433 while not started and num_tries < tries:
434 time.sleep(3)
435 started = onos_log.search_log_pattern('ApplicationManager .* Started')
436 num_tries += 1
437
A R Karthick19aaf5c2016-11-09 17:47:57 -0800438 if not started:
439 print('ONOS did not start')
440 else:
441 print('ONOS started')
442 return started
443
444 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700445 def setup_cluster_deprecated(cls, onos_instances, image_name = None):
446 if not onos_instances or len(onos_instances) < 2:
447 return
448 ips = []
449 if image_name is not None:
450 ips = Container.ips(image_name)
451 else:
452 for onos in onos_instances:
453 ips.append(onos.ipaddr)
454 Onos.cluster_instances = onos_instances
455 Onos.cluster_mode = True
456 ##regenerate the cluster json with the 3 instance ips before restarting them back
457 print('Generating cluster cfg for ONOS instances with ips %s' %ips)
458 Onos.generate_cluster_cfg(ips)
459 for onos in onos_instances:
460 onos.kill()
461 onos.remove_container(onos.name, force=True)
462 print('Restarting ONOS container %s for forming cluster' %onos.name)
463 onos.start(ports = onos.ports, environment = onos.env,
464 host_config = onos.host_config, volumes = onos.volumes, tty = True)
465 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
466 time.sleep(onos.boot_delay)
467 onos.ipaddr = onos.ip()
468 onos.install_cord_apps(onos.ipaddr)
469
470 @classmethod
471 def setup_cluster(cls, onos_instances, image_name = None):
472 if not onos_instances or len(onos_instances) < 2:
473 return
474 ips = []
475 if image_name is not None:
476 ips = Container.ips(image_name)
477 else:
478 for onos in onos_instances:
479 ips.append(onos.ipaddr)
480 Onos.cluster_instances = onos_instances
481 Onos.cluster_mode = True
482 ##regenerate the cluster json with the 3 instance ips before restarting them back
483 print('Forming cluster for ONOS instances with ips %s' %ips)
484 Onos.form_cluster(ips)
485 ##wait for the cluster to be formed
486 print('Waiting for the cluster to be formed')
487 time.sleep(60)
488 for onos in onos_instances:
489 onos.install_cord_apps(onos.ipaddr)
490
491 @classmethod
A R Karthicke2c24bd2016-10-07 14:51:38 -0700492 def add_cluster(cls, count = 1, network_cfg = None):
493 if not cls.cluster_instances or Onos.cluster_mode is False:
494 return
495 for i in range(count):
496 name = '{}-{}'.format(Onos.NAME, len(cls.cluster_instances)+1)
497 onos = cls(name = name, image = Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX,
498 cluster = True, network_cfg = network_cfg)
499 cls.cluster_instances.append(onos)
500
501 cls.setup_cluster(cls.cluster_instances)
502
503 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700504 def restart_cluster(cls, network_cfg = None):
505 if cls.cluster_mode is False:
506 return
507 if not cls.cluster_instances:
508 return
509
510 if network_cfg is not None:
511 json_data = json.dumps(network_cfg, indent=4)
512 with open('{}/network-cfg.json'.format(cls.host_config_dir), 'w') as f:
513 f.write(json_data)
514
515 for onos in cls.cluster_instances:
516 if onos.exists():
517 onos.kill()
518 onos.remove_container(onos.name, force=True)
519 print('Restarting ONOS container %s' %onos.name)
520 onos.start(ports = onos.ports, environment = onos.env,
521 host_config = onos.host_config, volumes = onos.volumes, tty = True)
522 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
523 time.sleep(onos.boot_delay)
524 onos.ipaddr = onos.ip()
525
526 ##form the cluster
527 cls.setup_cluster(cls.cluster_instances)
528
529 @classmethod
530 def cluster_ips(cls):
531 if cls.cluster_mode is False:
532 return []
533 if not cls.cluster_instances:
534 return []
535 ips = [ onos.ipaddr for onos in cls.cluster_instances ]
536 return ips
537
538 @classmethod
539 def cleanup_cluster(cls):
540 if cls.cluster_mode is False:
541 return
542 if not cls.cluster_instances:
543 return
544 for onos in cls.cluster_instances:
545 if onos.exists():
546 onos.kill()
547 onos.remove_container(onos.name, force=True)
A R Karthickd44cea12016-07-20 12:16:41 -0700548
A.R Karthick95d044e2016-06-10 18:44:36 -0700549 @classmethod
A R Karthick889d9652016-10-03 14:13:45 -0700550 def restart_node(cls, node = None, network_cfg = None):
551 if node is None:
552 cls(restart = True, network_cfg = network_cfg, image = cls.IMAGE, tag = cls.TAG)
553 else:
554 #Restarts a node in the cluster
555 valid_node = filter(lambda onos: node in [ onos.ipaddr, onos.name ], cls.cluster_instances)
556 if valid_node:
557 onos = valid_node.pop()
558 if onos.exists():
559 onos.kill()
560 onos.remove_container(onos.name, force=True)
561 print('Restarting ONOS container %s' %onos.name)
562 onos.start(ports = onos.ports, environment = onos.env,
563 host_config = onos.host_config, volumes = onos.volumes, tty = True)
564 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
565 time.sleep(onos.boot_delay)
566 onos.ipaddr = onos.ip()
567
568 @classmethod
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700569 def install_cord_apps(cls, onos_ip = None):
A.R Karthick95d044e2016-06-10 18:44:36 -0700570 for app, version in cls.onos_cord_apps:
571 app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version)
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700572 ok, code = OnosCtrl.install_app(app_file, onos_ip = onos_ip)
A.R Karthick95d044e2016-06-10 18:44:36 -0700573 ##app already installed (conflicts)
574 if code in [ 409 ]:
575 ok = True
576 print('ONOS app %s, version %s %s' %(app, version, 'installed' if ok else 'failed to install'))
577 time.sleep(2)
578
A.R Karthick1700e0e2016-10-06 18:16:57 -0700579class OnosStopWrapper(Container):
580 def __init__(self, name):
581 super(OnosStopWrapper, self).__init__(name, Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX)
582 if self.exists():
583 self.kill()
584 else:
585 if Onos.cluster_mode is True:
586 valid_node = filter(lambda onos: name in [ onos.ipaddr, onos.name ], Onos.cluster_instances)
587 if valid_node:
588 onos = valid_node.pop()
589 if onos.exists():
590 onos.kill()
591
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700592class Radius(Container):
593 ports = [ 1812, 1813 ]
A R Karthick41adfce2016-06-10 09:51:25 -0700594 env = {'TIMEZONE':'America/Los_Angeles',
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700595 'DEBUG': 'true', 'cert_password':'whatever', 'primary_shared_secret':'radius_password'
596 }
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700597 host_db_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/db')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700598 guest_db_dir = os.path.join(os.path.sep, 'opt', 'db')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700599 host_config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/freeradius')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700600 guest_config_dir = os.path.join(os.path.sep, 'etc', 'freeradius')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700601 start_command = os.path.join(guest_config_dir, 'start-radius.py')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700602 host_guest_map = ( (host_db_dir, guest_db_dir),
603 (host_config_dir, guest_config_dir)
604 )
Chetan Gaonker503032a2016-05-12 12:06:29 -0700605 IMAGE = 'cord-test/radius'
606 NAME = 'cord-radius'
607
A R Karthick07608ef2016-08-23 16:51:19 -0700608 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
Chetan Gaonker503032a2016-05-12 12:06:29 -0700609 boot_delay = 10, restart = False, update = False):
A R Karthick07608ef2016-08-23 16:51:19 -0700610 super(Radius, self).__init__(name, image, prefix = prefix, tag = tag, command = self.start_command)
Chetan Gaonker503032a2016-05-12 12:06:29 -0700611 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -0700612 self.build_image(self.image_name)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700613 if restart is True and self.exists():
614 self.kill()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700615 if not self.exists():
616 self.remove_container(name, force=True)
617 host_config = self.create_host_config(port_list = self.ports,
618 host_guest_map = self.host_guest_map)
619 volumes = []
620 for _,g in self.host_guest_map:
621 volumes.append(g)
A R Karthick41adfce2016-06-10 09:51:25 -0700622 self.start(ports = self.ports, environment = self.env,
623 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700624 host_config = host_config, tty = True)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700625 time.sleep(boot_delay)
626
627 @classmethod
628 def build_image(cls, image):
629 print('Building Radius image %s' %image)
630 dockerfile = '''
631FROM hbouvier/docker-radius
632MAINTAINER chetan@ciena.com
633LABEL RUN docker pull hbouvier/docker-radius
634LABEL RUN docker run -it --name cord-radius hbouvier/docker-radius
A R Karthickc762df42016-05-25 10:09:21 -0700635RUN apt-get update && \
636 apt-get -y install python python-pexpect strace
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700637WORKDIR /root
638CMD ["/etc/freeradius/start-radius.py"]
639'''
640 super(Radius, cls).build_image(dockerfile, image)
641 print('Done building image %s' %image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700642
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700643class Quagga(Container):
A R Karthick41adfce2016-06-10 09:51:25 -0700644 quagga_config = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 },
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700645 { 'bridge' : 'quagga-br', 'ip': '192.168.10.3', 'mask': 16 },
646 )
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700647 ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ]
648 host_quagga_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/quagga-config')
649 guest_quagga_config = '/root/config'
650 quagga_config_file = os.path.join(guest_quagga_config, 'testrib.conf')
651 host_guest_map = ( (host_quagga_config, guest_quagga_config), )
Chetan Gaonker503032a2016-05-12 12:06:29 -0700652 IMAGE = 'cord-test/quagga'
653 NAME = 'cord-quagga'
654
A R Karthick07608ef2016-08-23 16:51:19 -0700655 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
Chetan Gaonker503032a2016-05-12 12:06:29 -0700656 boot_delay = 15, restart = False, config_file = quagga_config_file, update = False):
A R Karthick07608ef2016-08-23 16:51:19 -0700657 super(Quagga, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.quagga_config)
Chetan Gaonker503032a2016-05-12 12:06:29 -0700658 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -0700659 self.build_image(self.image_name)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700660 if restart is True and self.exists():
661 self.kill()
662 if not self.exists():
663 self.remove_container(name, force=True)
A R Karthick41adfce2016-06-10 09:51:25 -0700664 host_config = self.create_host_config(port_list = self.ports,
665 host_guest_map = self.host_guest_map,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700666 privileged = True)
667 volumes = []
668 for _,g in self.host_guest_map:
669 volumes.append(g)
670 self.start(ports = self.ports,
A R Karthick41adfce2016-06-10 09:51:25 -0700671 host_config = host_config,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700672 volumes = volumes, tty = True)
673 print('Starting Quagga on container %s' %self.name)
674 self.execute('{0}/start.sh {1}'.format(self.guest_quagga_config, config_file))
675 time.sleep(boot_delay)
676
677 @classmethod
678 def build_image(cls, image):
Chetan Gaonker2a6601b2016-05-02 17:28:26 -0700679 onos_quagga_ip = Onos.quagga_config[0]['ip']
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700680 print('Building Quagga image %s' %image)
681 dockerfile = '''
A R Karthick41adfce2016-06-10 09:51:25 -0700682FROM ubuntu:14.04
683MAINTAINER chetan@ciena.com
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700684WORKDIR /root
685RUN useradd -M quagga
686RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga
687RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga
A R Karthick973ea692016-10-17 12:23:02 -0700688RUN 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 -0700689RUN git clone git://git.savannah.nongnu.org/quagga.git quagga && \
A R Karthick8f69c2c2016-10-21 11:43:26 -0700690(cd quagga && git checkout quagga-1.0.20160315 && ./bootstrap.sh && \
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700691sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \
692./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install)
693RUN ldconfig
694'''.format(onos_quagga_ip)
695 super(Quagga, cls).build_image(dockerfile, image)
696 print('Done building image %s' %image)
A R Karthick81acbff2016-06-17 14:45:16 -0700697
A.R Karthick1700e0e2016-10-06 18:16:57 -0700698class QuaggaStopWrapper(Container):
699 def __init__(self, name = Quagga.NAME, image = Quagga.IMAGE, tag = 'candidate'):
700 super(QuaggaStopWrapper, self).__init__(name, image, prefix = Container.IMAGE_PREFIX, tag = tag)
701 if self.exists():
702 self.kill()
703
704
A R Karthick81acbff2016-06-17 14:45:16 -0700705def reinitContainerClients():
706 docker_netns.dckr = Client()
707 Container.dckr = Client()
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700708
709class Xos(Container):
710 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
711 TAG = 'latest'
712 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700713 host_guest_map = None
714 env = None
715 ports = None
716 volumes = None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700717
A R Karthick6e80afd2016-10-10 16:03:12 -0700718 @classmethod
719 def get_cmd(cls, img_name):
720 cmd = cls.dckr.inspect_image(img_name)['Config']['Cmd']
721 return ' '.join(cmd)
722
A R Karthicke3bde962016-09-27 15:06:35 -0700723 def __init__(self, name, image, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700724 boot_delay = 20, restart = False, network_cfg = None, update = False):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700725 if restart is True:
726 ##Find the right image to restart
727 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
728 if running_image:
729 image_name = running_image[0]['Image']
730 try:
731 image = image_name.split(':')[0]
732 tag = image_name.split(':')[1]
733 except: pass
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700734 super(Xos, self).__init__(name, image, prefix = prefix, tag = tag)
735 if update is True or not self.img_exists():
736 self.build_image(self.image_name)
A R Karthick6e80afd2016-10-10 16:03:12 -0700737 self.command = self.get_cmd(self.image_name).strip() or None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700738 if restart is True and self.exists():
739 self.kill()
740 if not self.exists():
741 self.remove_container(name, force=True)
A R Karthicke3bde962016-09-27 15:06:35 -0700742 host_config = self.create_host_config(port_list = self.ports,
743 host_guest_map = self.host_guest_map,
744 privileged = True)
745 print('Starting XOS container %s' %self.name)
746 self.start(ports = self.ports, environment = self.env, host_config = host_config,
747 volumes = self.volumes, tty = True)
748 print('Waiting %d seconds for XOS Base Container to boot' %(boot_delay))
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700749 time.sleep(boot_delay)
750
751 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700752 def build_image(cls, image, dockerfile_path, image_target = 'build'):
753 cmd = 'cd {} && make {}'.format(dockerfile_path, image_target)
754 print('Building XOS %s' %image)
755 res = os.system(cmd)
756 print('Done building image %s. Image build %s' %(image, 'successful' if res == 0 else 'failed'))
757 return res
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700758
A R Karthicke3bde962016-09-27 15:06:35 -0700759class XosServer(Xos):
760 ports = [8000,9998,9999]
761 NAME = 'xos-server'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700762 IMAGE = 'xosproject/xos'
A R Karthicke3bde962016-09-27 15:06:35 -0700763 BASE_IMAGE = 'xosproject/xos-base'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700764 TAG = 'latest'
765 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700766 dockerfile_path = os.path.join(Xos.setup_dir, 'xos')
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700767
A R Karthicke3bde962016-09-27 15:06:35 -0700768 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700769 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700770 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700771
772 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700773 def build_image(cls, image = IMAGE):
774 ##build the base image and then build the server image
775 Xos.build_image(cls.BASE_IMAGE, cls.dockerfile_path, image_target = 'base')
776 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700777
A R Karthicke3bde962016-09-27 15:06:35 -0700778class XosSynchronizerOpenstack(Xos):
779 ports = [2375,]
780 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer')
781 NAME = 'xos-synchronizer'
782 IMAGE = 'xosproject/xos-synchronizer-openstack'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700783 TAG = 'latest'
784 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700785 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700786
A R Karthicke3bde962016-09-27 15:06:35 -0700787 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700788 tag = TAG, boot_delay = 20, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700789 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700790
791 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700792 def build_image(cls, image = IMAGE):
793 XosServer.build_image()
794 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700795
A R Karthicke3bde962016-09-27 15:06:35 -0700796class XosSynchronizerOnboarding(Xos):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700797 NAME = 'xos-synchronizer-onboarding'
798 IMAGE = 'xosproject/xos-synchronizer-onboarding'
799 TAG = 'latest'
800 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700801 dockerfile_path = os.path.join(Xos.setup_dir, 'onboarding_synchronizer')
802 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700803
A R Karthicke3bde962016-09-27 15:06:35 -0700804 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700805 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700806 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700807
808 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700809 def build_image(cls, image = IMAGE):
810 XosSynchronizerOpenstack.build_image()
811 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700812
A R Karthicke3bde962016-09-27 15:06:35 -0700813class XosSynchronizerOpenvpn(Xos):
814 NAME = 'xos-synchronizer-openvpn'
815 IMAGE = 'xosproject/xos-openvpn'
816 TAG = 'latest'
817 PREFIX = ''
818 dockerfile_path = os.path.join(Xos.setup_dir, 'openvpn')
819 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700820
A R Karthicke3bde962016-09-27 15:06:35 -0700821 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700822 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700823 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
824
825 @classmethod
826 def build_image(cls, image = IMAGE):
827 XosSynchronizerOpenstack.build_image()
828 Xos.build_image(image, cls.dockerfile_path)
829
830class XosPostgresql(Xos):
831 ports = [5432,]
832 NAME = 'xos-db-postgres'
833 IMAGE = 'xosproject/xos-postgres'
834 TAG = 'latest'
835 PREFIX = ''
836 volumes = ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
837 dockerfile_path = os.path.join(Xos.setup_dir, 'postgresql')
838
839 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700840 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700841 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
842
843 @classmethod
844 def build_image(cls, image = IMAGE):
845 Xos.build_image(image, cls.dockerfile_path)
846
847class XosSyndicateMs(Xos):
848 ports = [8080,]
849 env = None
850 NAME = 'xos-syndicate-ms'
851 IMAGE = 'xosproject/syndicate-ms'
852 TAG = 'latest'
853 PREFIX = ''
854 dockerfile_path = os.path.join(Xos.setup_dir, 'syndicate-ms')
855
856 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700857 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700858 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
859
860 @classmethod
861 def build_image(cls, image = IMAGE):
862 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700863
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700864class XosSyncVtn(Xos):
865 ports = [8080,]
866 env = None
867 NAME = 'xos-synchronizer-vtn'
868 IMAGE = 'xosproject/xos-synchronizer-vtn'
869 TAG = 'latest'
870 PREFIX = ''
871 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtn')
872
873 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700874 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700875 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
876
877 @classmethod
878 def build_image(cls, image = IMAGE):
879 Xos.build_image(image, cls.dockerfile_path)
880
881class XosSyncVtr(Xos):
882 ports = [8080,]
883 env = None
884 NAME = 'xos-synchronizer-vtr'
885 IMAGE = 'xosproject/xos-synchronizer-vtr'
886 TAG = 'latest'
887 PREFIX = ''
888 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtr')
889
890 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700891 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700892 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
893
894 @classmethod
895 def build_image(cls, image = IMAGE):
896 Xos.build_image(image, cls.dockerfile_path)
897
898class XosSyncVsg(Xos):
899 ports = [8080,]
900 env = None
901 NAME = 'xos-synchronizer-vsg'
902 IMAGE = 'xosproject/xos-synchronizer-vsg'
903 TAG = 'latest'
904 PREFIX = ''
905 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vsg')
906
907 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700908 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700909 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
910
911 @classmethod
912 def build_image(cls, image = IMAGE):
913 Xos.build_image(image, cls.dockerfile_path)
914
915
916class XosSyncOnos(Xos):
917 ports = [8080,]
918 env = None
919 NAME = 'xos-synchronizer-onos'
920 IMAGE = 'xosproject/xos-synchronizer-onos'
921 TAG = 'latest'
922 PREFIX = ''
923 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-onos')
924
925 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700926 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700927 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
928
929 @classmethod
930 def build_image(cls, image = IMAGE):
931 Xos.build_image(image, cls.dockerfile_path)
932
933class XosSyncFabric(Xos):
934 ports = [8080,]
935 env = None
936 NAME = 'xos-synchronizer-fabric'
937 IMAGE = 'xosproject/xos-synchronizer-fabric'
938 TAG = 'latest'
939 PREFIX = ''
940 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-fabric')
941
942 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700943 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700944 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
945
946 @classmethod
947 def build_image(cls, image = IMAGE):
948 Xos.build_image(image, cls.dockerfile_path)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800949
950if __name__ == '__main__':
951 onos = Onos(boot_delay = 10, restart = True)