blob: 4d0c5bb368d60a663a85baa890636ccf3ceb3bef [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
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700204def get_mem():
205 with open('/proc/meminfo', 'r') as fd:
206 meminfo = fd.readlines()
207 mem = 0
208 for m in meminfo:
209 if m.startswith('MemTotal:') or m.startswith('SwapTotal:'):
210 mem += int(m.split(':')[1].strip().split()[0])
211
Chetan Gaonkerc0421e82016-05-04 17:23:08 -0700212 mem = max(mem/1024/1024/2, 1)
Chetan Gaonker6d0a7b02016-05-03 16:57:28 -0700213 mem = min(mem, 16)
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700214 return str(mem) + 'G'
215
A R Karthickd44cea12016-07-20 12:16:41 -0700216class OnosCord(Container):
217 """Use this when running the cord tester agent on the onos compute node"""
218 onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord')
219 onos_config_dir_guest = '/root/onos/config'
220 onos_config_dir = os.path.join(onos_cord_dir, 'config')
221 docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml')
222
A R Karthickbd9b8a32016-07-21 09:56:45 -0700223 def __init__(self, onos_ip, conf, boot_delay = 60):
224 self.onos_ip = onos_ip
A R Karthickd44cea12016-07-20 12:16:41 -0700225 self.cord_conf_dir = conf
A R Karthickbd9b8a32016-07-21 09:56:45 -0700226 self.boot_delay = boot_delay
A R Karthickd44cea12016-07-20 12:16:41 -0700227 if os.access(self.cord_conf_dir, os.F_OK) and not os.access(self.onos_cord_dir, os.F_OK):
228 os.mkdir(self.onos_cord_dir)
229 os.mkdir(self.onos_config_dir)
230 ##copy the config file from cord-tester-config
231 cmd = 'cp {}/* {}'.format(self.cord_conf_dir, self.onos_cord_dir)
232 os.system(cmd)
233
234 ##update the docker yaml with the config volume
235 with open(self.docker_yaml, 'r') as f:
236 yaml_config = yaml.load(f)
237 image = yaml_config['services'].keys()[0]
238 name = 'cordtestercord_{}_1'.format(image)
239 volumes = yaml_config['services'][image]['volumes']
240 config_volumes = filter(lambda e: e.find(self.onos_config_dir_guest) >= 0, volumes)
241 if not config_volumes:
242 config_volume = '{}:{}'.format(self.onos_config_dir, self.onos_config_dir_guest)
243 volumes.append(config_volume)
244 docker_yaml_changed = '{}-changed'.format(self.docker_yaml)
245 with open(docker_yaml_changed, 'w') as wf:
246 yaml.dump(yaml_config, wf)
247
248 os.rename(docker_yaml_changed, self.docker_yaml)
249 self.volumes = volumes
250
251 super(OnosCord, self).__init__(name, image, tag = '')
252 cord_conf_dir_basename = os.path.basename(self.cord_conf_dir.replace('-', ''))
253 self.xos_onos_name = '{}_{}_1'.format(cord_conf_dir_basename, image)
254 ##Create an container instance of xos onos
255 self.xos_onos = Container(self.xos_onos_name, image, tag = '')
256
257 def start(self, restart = False, network_cfg = None):
258 if restart is True:
259 if self.exists():
260 ##Kill the existing instance
261 print('Killing container %s' %self.name)
262 self.kill()
263 if self.xos_onos.exists():
264 print('Killing container %s' %self.xos_onos.name)
265 self.xos_onos.kill()
266
267 if network_cfg is not None:
268 json_data = json.dumps(network_cfg, indent=4)
269 with open('{}/network-cfg.json'.format(self.onos_config_dir), 'w') as f:
270 f.write(json_data)
271
272 #start the container using docker-compose
273 cmd = 'cd {} && docker-compose up -d'.format(self.onos_cord_dir)
274 os.system(cmd)
A R Karthickbd9b8a32016-07-21 09:56:45 -0700275 #Delay to make sure ONOS fully boots
276 time.sleep(self.boot_delay)
277 Onos.install_cord_apps(onos_ip = self.onos_ip)
A R Karthickd44cea12016-07-20 12:16:41 -0700278
279 def build_image(self):
280 build_cmd = 'cd {} && docker-compose build'.format(self.onos_cord_dir)
281 os.system(build_cmd)
282
A.R Karthick1700e0e2016-10-06 18:16:57 -0700283class OnosCordStopWrapper(Container):
284 onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord')
285 docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml')
286
287 def __init__(self):
288 if os.access(self.docker_yaml, os.F_OK):
289 with open(self.docker_yaml, 'r') as f:
290 yaml_config = yaml.load(f)
291 image = yaml_config['services'].keys()[0]
292 name = 'cordtestercord_{}_1'.format(image)
293 super(OnosCordStopWrapper, self).__init__(name, image, tag = '')
294 if self.exists():
295 print('Killing container %s' %self.name)
296 self.kill()
297
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700298class Onos(Container):
299
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700300 quagga_config = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.4', 'mask' : 16 }, )
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700301 SYSTEM_MEMORY = (get_mem(),) * 2
302 JAVA_OPTS = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode'.format(*SYSTEM_MEMORY)#-XX:+PrintGCDetails -XX:+PrintGCTimeStamps'
A.R Karthick95d044e2016-06-10 18:44:36 -0700303 env = { 'ONOS_APPS' : 'drivers,openflow,proxyarp,vrouter', 'JAVA_OPTS' : JAVA_OPTS }
304 onos_cord_apps = ( ('cord-config', '1.0-SNAPSHOT'),
305 ('aaa', '1.0-SNAPSHOT'),
306 ('igmp', '1.0-SNAPSHOT'),
A R Karthickedab01c2016-09-08 14:05:44 -0700307 #('vtn', '1.0-SNAPSHOT'),
A.R Karthick95d044e2016-06-10 18:44:36 -0700308 )
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700309 ports = [ 8181, 8101, 9876, 6653, 6633, 2000, 2620 ]
A R Karthickf2f4ca62016-08-17 10:34:08 -0700310 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
311 host_config_dir = os.path.join(setup_dir, 'onos-config')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700312 guest_config_dir = '/root/onos/config'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700313 onos_gen_partitions = os.path.join(setup_dir, 'onos-gen-partitions')
A R Karthick2b93d6a2016-09-06 15:19:09 -0700314 onos_form_cluster = os.path.join(setup_dir, 'onos-form-cluster')
A.R Karthick95d044e2016-06-10 18:44:36 -0700315 cord_apps_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'apps')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700316 host_guest_map = ( (host_config_dir, guest_config_dir), )
A R Karthick2b93d6a2016-09-06 15:19:09 -0700317 cluster_cfg = os.path.join(host_config_dir, 'cluster.json')
318 cluster_mode = False
319 cluster_instances = []
Chetan Gaonker503032a2016-05-12 12:06:29 -0700320 NAME = 'cord-onos'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700321 ##the ip of ONOS in default cluster.json in setup/onos-config
322 CLUSTER_CFG_IP = '172.17.0.2'
A R Karthick07608ef2016-08-23 16:51:19 -0700323 IMAGE = 'onosproject/onos'
324 TAG = 'latest'
325 PREFIX = ''
A R Karthickf2f4ca62016-08-17 10:34:08 -0700326
327 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700328 def generate_cluster_cfg(cls, ip):
329 if type(ip) in [ list, tuple ]:
330 ips = ' '.join(ip)
331 else:
332 ips = ip
A R Karthickf2f4ca62016-08-17 10:34:08 -0700333 try:
A R Karthick2b93d6a2016-09-06 15:19:09 -0700334 cmd = '{} {} {}'.format(cls.onos_gen_partitions, cls.cluster_cfg, ips)
335 os.system(cmd)
336 except: pass
337
338 @classmethod
339 def form_cluster(cls, ips):
340 nodes = ' '.join(ips)
341 try:
342 cmd = '{} {}'.format(cls.onos_form_cluster, nodes)
A R Karthickf2f4ca62016-08-17 10:34:08 -0700343 os.system(cmd)
344 except: pass
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700345
A R Karthick9d48c652016-09-15 09:16:36 -0700346 @classmethod
347 def cleanup_runtime(cls):
348 '''Cleanup ONOS runtime generated files'''
349 files = ( Onos.cluster_cfg, os.path.join(Onos.host_config_dir, 'network-cfg.json') )
350 for f in files:
351 if os.access(f, os.F_OK):
352 try:
353 os.unlink(f)
354 except: pass
355
A.R Karthick1700e0e2016-10-06 18:16:57 -0700356 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthick19aaf5c2016-11-09 17:47:57 -0800357 boot_delay = 20, restart = False, network_cfg = None, cluster = False):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700358 if restart is True:
359 ##Find the right image to restart
360 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
361 if running_image:
362 image_name = running_image[0]['Image']
363 try:
364 image = image_name.split(':')[0]
365 tag = image_name.split(':')[1]
366 except: pass
367
A R Karthick07608ef2016-08-23 16:51:19 -0700368 super(Onos, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.quagga_config)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700369 self.boot_delay = boot_delay
370 if cluster is True:
371 self.ports = []
372 if os.access(self.cluster_cfg, os.F_OK):
373 try:
374 os.unlink(self.cluster_cfg)
375 except: pass
376
377 self.host_config = self.create_host_config(port_list = self.ports,
378 host_guest_map = self.host_guest_map)
379 self.volumes = []
380 for _,g in self.host_guest_map:
381 self.volumes.append(g)
382
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700383 if restart is True and self.exists():
384 self.kill()
A R Karthick2b93d6a2016-09-06 15:19:09 -0700385
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700386 if not self.exists():
387 self.remove_container(name, force=True)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700388 host_config = self.create_host_config(port_list = self.ports,
389 host_guest_map = self.host_guest_map)
390 volumes = []
391 for _,g in self.host_guest_map:
392 volumes.append(g)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700393 if network_cfg is not None:
A R Karthick81acbff2016-06-17 14:45:16 -0700394 json_data = json.dumps(network_cfg, indent=4)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700395 with open('{}/network-cfg.json'.format(self.host_config_dir), 'w') as f:
396 f.write(json_data)
397 print('Starting ONOS container %s' %self.name)
A R Karthick41adfce2016-06-10 09:51:25 -0700398 self.start(ports = self.ports, environment = self.env,
A R Karthick2b93d6a2016-09-06 15:19:09 -0700399 host_config = self.host_config, volumes = self.volumes, tty = True)
A R Karthickf2f4ca62016-08-17 10:34:08 -0700400 if not restart:
401 ##wait a bit before fetching IP to regenerate cluster cfg
402 time.sleep(5)
403 ip = self.ip()
404 ##Just a quick hack/check to ensure we don't regenerate in the common case.
405 ##As ONOS is usually the first test container that is started
A R Karthick2b93d6a2016-09-06 15:19:09 -0700406 if cluster is False:
407 if ip != self.CLUSTER_CFG_IP or not os.access(self.cluster_cfg, os.F_OK):
408 print('Regenerating ONOS cluster cfg for ip %s' %ip)
409 self.generate_cluster_cfg(ip)
410 self.kill()
411 self.remove_container(self.name, force=True)
412 print('Restarting ONOS container %s' %self.name)
413 self.start(ports = self.ports, environment = self.env,
414 host_config = self.host_config, volumes = self.volumes, tty = True)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800415 print('Waiting for ONOS to boot')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700416 time.sleep(boot_delay)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800417 self.wait_for_onos_start(self.ip())
418
A R Karthick2b93d6a2016-09-06 15:19:09 -0700419 self.ipaddr = self.ip()
420 if cluster is False:
421 self.install_cord_apps(self.ipaddr)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700422
A R Karthick2b93d6a2016-09-06 15:19:09 -0700423 @classmethod
A R Karthick19aaf5c2016-11-09 17:47:57 -0800424 def wait_for_onos_start(cls, ip, tries = 30):
425 onos_log = OnosLog(host = ip)
426 num_tries = 0
427 started = None
428 while not started and num_tries < tries:
429 time.sleep(3)
430 started = onos_log.search_log_pattern('ApplicationManager .* Started')
431 num_tries += 1
432
433 onos_log.close()
434 if not started:
435 print('ONOS did not start')
436 else:
437 print('ONOS started')
438 return started
439
440 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700441 def setup_cluster_deprecated(cls, onos_instances, image_name = None):
442 if not onos_instances or len(onos_instances) < 2:
443 return
444 ips = []
445 if image_name is not None:
446 ips = Container.ips(image_name)
447 else:
448 for onos in onos_instances:
449 ips.append(onos.ipaddr)
450 Onos.cluster_instances = onos_instances
451 Onos.cluster_mode = True
452 ##regenerate the cluster json with the 3 instance ips before restarting them back
453 print('Generating cluster cfg for ONOS instances with ips %s' %ips)
454 Onos.generate_cluster_cfg(ips)
455 for onos in onos_instances:
456 onos.kill()
457 onos.remove_container(onos.name, force=True)
458 print('Restarting ONOS container %s for forming cluster' %onos.name)
459 onos.start(ports = onos.ports, environment = onos.env,
460 host_config = onos.host_config, volumes = onos.volumes, tty = True)
461 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
462 time.sleep(onos.boot_delay)
463 onos.ipaddr = onos.ip()
464 onos.install_cord_apps(onos.ipaddr)
465
466 @classmethod
467 def setup_cluster(cls, onos_instances, image_name = None):
468 if not onos_instances or len(onos_instances) < 2:
469 return
470 ips = []
471 if image_name is not None:
472 ips = Container.ips(image_name)
473 else:
474 for onos in onos_instances:
475 ips.append(onos.ipaddr)
476 Onos.cluster_instances = onos_instances
477 Onos.cluster_mode = True
478 ##regenerate the cluster json with the 3 instance ips before restarting them back
479 print('Forming cluster for ONOS instances with ips %s' %ips)
480 Onos.form_cluster(ips)
481 ##wait for the cluster to be formed
482 print('Waiting for the cluster to be formed')
483 time.sleep(60)
484 for onos in onos_instances:
485 onos.install_cord_apps(onos.ipaddr)
486
487 @classmethod
A R Karthicke2c24bd2016-10-07 14:51:38 -0700488 def add_cluster(cls, count = 1, network_cfg = None):
489 if not cls.cluster_instances or Onos.cluster_mode is False:
490 return
491 for i in range(count):
492 name = '{}-{}'.format(Onos.NAME, len(cls.cluster_instances)+1)
493 onos = cls(name = name, image = Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX,
494 cluster = True, network_cfg = network_cfg)
495 cls.cluster_instances.append(onos)
496
497 cls.setup_cluster(cls.cluster_instances)
498
499 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700500 def restart_cluster(cls, network_cfg = None):
501 if cls.cluster_mode is False:
502 return
503 if not cls.cluster_instances:
504 return
505
506 if network_cfg is not None:
507 json_data = json.dumps(network_cfg, indent=4)
508 with open('{}/network-cfg.json'.format(cls.host_config_dir), 'w') as f:
509 f.write(json_data)
510
511 for onos in cls.cluster_instances:
512 if onos.exists():
513 onos.kill()
514 onos.remove_container(onos.name, force=True)
515 print('Restarting ONOS container %s' %onos.name)
516 onos.start(ports = onos.ports, environment = onos.env,
517 host_config = onos.host_config, volumes = onos.volumes, tty = True)
518 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
519 time.sleep(onos.boot_delay)
520 onos.ipaddr = onos.ip()
521
522 ##form the cluster
523 cls.setup_cluster(cls.cluster_instances)
524
525 @classmethod
526 def cluster_ips(cls):
527 if cls.cluster_mode is False:
528 return []
529 if not cls.cluster_instances:
530 return []
531 ips = [ onos.ipaddr for onos in cls.cluster_instances ]
532 return ips
533
534 @classmethod
535 def cleanup_cluster(cls):
536 if cls.cluster_mode is False:
537 return
538 if not cls.cluster_instances:
539 return
540 for onos in cls.cluster_instances:
541 if onos.exists():
542 onos.kill()
543 onos.remove_container(onos.name, force=True)
A R Karthickd44cea12016-07-20 12:16:41 -0700544
A.R Karthick95d044e2016-06-10 18:44:36 -0700545 @classmethod
A R Karthick889d9652016-10-03 14:13:45 -0700546 def restart_node(cls, node = None, network_cfg = None):
547 if node is None:
548 cls(restart = True, network_cfg = network_cfg, image = cls.IMAGE, tag = cls.TAG)
549 else:
550 #Restarts a node in the cluster
551 valid_node = filter(lambda onos: node in [ onos.ipaddr, onos.name ], cls.cluster_instances)
552 if valid_node:
553 onos = valid_node.pop()
554 if onos.exists():
555 onos.kill()
556 onos.remove_container(onos.name, force=True)
557 print('Restarting ONOS container %s' %onos.name)
558 onos.start(ports = onos.ports, environment = onos.env,
559 host_config = onos.host_config, volumes = onos.volumes, tty = True)
560 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
561 time.sleep(onos.boot_delay)
562 onos.ipaddr = onos.ip()
563
564 @classmethod
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700565 def install_cord_apps(cls, onos_ip = None):
A.R Karthick95d044e2016-06-10 18:44:36 -0700566 for app, version in cls.onos_cord_apps:
567 app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version)
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700568 ok, code = OnosCtrl.install_app(app_file, onos_ip = onos_ip)
A.R Karthick95d044e2016-06-10 18:44:36 -0700569 ##app already installed (conflicts)
570 if code in [ 409 ]:
571 ok = True
572 print('ONOS app %s, version %s %s' %(app, version, 'installed' if ok else 'failed to install'))
573 time.sleep(2)
574
A.R Karthick1700e0e2016-10-06 18:16:57 -0700575class OnosStopWrapper(Container):
576 def __init__(self, name):
577 super(OnosStopWrapper, self).__init__(name, Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX)
578 if self.exists():
579 self.kill()
580 else:
581 if Onos.cluster_mode is True:
582 valid_node = filter(lambda onos: name in [ onos.ipaddr, onos.name ], Onos.cluster_instances)
583 if valid_node:
584 onos = valid_node.pop()
585 if onos.exists():
586 onos.kill()
587
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700588class Radius(Container):
589 ports = [ 1812, 1813 ]
A R Karthick41adfce2016-06-10 09:51:25 -0700590 env = {'TIMEZONE':'America/Los_Angeles',
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700591 'DEBUG': 'true', 'cert_password':'whatever', 'primary_shared_secret':'radius_password'
592 }
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700593 host_db_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/db')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700594 guest_db_dir = os.path.join(os.path.sep, 'opt', 'db')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700595 host_config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/freeradius')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700596 guest_config_dir = os.path.join(os.path.sep, 'etc', 'freeradius')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700597 start_command = os.path.join(guest_config_dir, 'start-radius.py')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700598 host_guest_map = ( (host_db_dir, guest_db_dir),
599 (host_config_dir, guest_config_dir)
600 )
Chetan Gaonker503032a2016-05-12 12:06:29 -0700601 IMAGE = 'cord-test/radius'
602 NAME = 'cord-radius'
603
A R Karthick07608ef2016-08-23 16:51:19 -0700604 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
Chetan Gaonker503032a2016-05-12 12:06:29 -0700605 boot_delay = 10, restart = False, update = False):
A R Karthick07608ef2016-08-23 16:51:19 -0700606 super(Radius, self).__init__(name, image, prefix = prefix, tag = tag, command = self.start_command)
Chetan Gaonker503032a2016-05-12 12:06:29 -0700607 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -0700608 self.build_image(self.image_name)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700609 if restart is True and self.exists():
610 self.kill()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700611 if not self.exists():
612 self.remove_container(name, force=True)
613 host_config = self.create_host_config(port_list = self.ports,
614 host_guest_map = self.host_guest_map)
615 volumes = []
616 for _,g in self.host_guest_map:
617 volumes.append(g)
A R Karthick41adfce2016-06-10 09:51:25 -0700618 self.start(ports = self.ports, environment = self.env,
619 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700620 host_config = host_config, tty = True)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700621 time.sleep(boot_delay)
622
623 @classmethod
624 def build_image(cls, image):
625 print('Building Radius image %s' %image)
626 dockerfile = '''
627FROM hbouvier/docker-radius
628MAINTAINER chetan@ciena.com
629LABEL RUN docker pull hbouvier/docker-radius
630LABEL RUN docker run -it --name cord-radius hbouvier/docker-radius
A R Karthickc762df42016-05-25 10:09:21 -0700631RUN apt-get update && \
632 apt-get -y install python python-pexpect strace
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700633WORKDIR /root
634CMD ["/etc/freeradius/start-radius.py"]
635'''
636 super(Radius, cls).build_image(dockerfile, image)
637 print('Done building image %s' %image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700638
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700639class Quagga(Container):
A R Karthick41adfce2016-06-10 09:51:25 -0700640 quagga_config = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 },
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700641 { 'bridge' : 'quagga-br', 'ip': '192.168.10.3', 'mask': 16 },
642 )
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700643 ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ]
644 host_quagga_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/quagga-config')
645 guest_quagga_config = '/root/config'
646 quagga_config_file = os.path.join(guest_quagga_config, 'testrib.conf')
647 host_guest_map = ( (host_quagga_config, guest_quagga_config), )
Chetan Gaonker503032a2016-05-12 12:06:29 -0700648 IMAGE = 'cord-test/quagga'
649 NAME = 'cord-quagga'
650
A R Karthick07608ef2016-08-23 16:51:19 -0700651 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
Chetan Gaonker503032a2016-05-12 12:06:29 -0700652 boot_delay = 15, restart = False, config_file = quagga_config_file, update = False):
A R Karthick07608ef2016-08-23 16:51:19 -0700653 super(Quagga, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.quagga_config)
Chetan Gaonker503032a2016-05-12 12:06:29 -0700654 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -0700655 self.build_image(self.image_name)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700656 if restart is True and self.exists():
657 self.kill()
658 if not self.exists():
659 self.remove_container(name, force=True)
A R Karthick41adfce2016-06-10 09:51:25 -0700660 host_config = self.create_host_config(port_list = self.ports,
661 host_guest_map = self.host_guest_map,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700662 privileged = True)
663 volumes = []
664 for _,g in self.host_guest_map:
665 volumes.append(g)
666 self.start(ports = self.ports,
A R Karthick41adfce2016-06-10 09:51:25 -0700667 host_config = host_config,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700668 volumes = volumes, tty = True)
669 print('Starting Quagga on container %s' %self.name)
670 self.execute('{0}/start.sh {1}'.format(self.guest_quagga_config, config_file))
671 time.sleep(boot_delay)
672
673 @classmethod
674 def build_image(cls, image):
Chetan Gaonker2a6601b2016-05-02 17:28:26 -0700675 onos_quagga_ip = Onos.quagga_config[0]['ip']
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700676 print('Building Quagga image %s' %image)
677 dockerfile = '''
A R Karthick41adfce2016-06-10 09:51:25 -0700678FROM ubuntu:14.04
679MAINTAINER chetan@ciena.com
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700680WORKDIR /root
681RUN useradd -M quagga
682RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga
683RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga
A R Karthick973ea692016-10-17 12:23:02 -0700684RUN 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 -0700685RUN git clone git://git.savannah.nongnu.org/quagga.git quagga && \
A R Karthick8f69c2c2016-10-21 11:43:26 -0700686(cd quagga && git checkout quagga-1.0.20160315 && ./bootstrap.sh && \
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700687sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \
688./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install)
689RUN ldconfig
690'''.format(onos_quagga_ip)
691 super(Quagga, cls).build_image(dockerfile, image)
692 print('Done building image %s' %image)
A R Karthick81acbff2016-06-17 14:45:16 -0700693
A.R Karthick1700e0e2016-10-06 18:16:57 -0700694class QuaggaStopWrapper(Container):
695 def __init__(self, name = Quagga.NAME, image = Quagga.IMAGE, tag = 'candidate'):
696 super(QuaggaStopWrapper, self).__init__(name, image, prefix = Container.IMAGE_PREFIX, tag = tag)
697 if self.exists():
698 self.kill()
699
700
A R Karthick81acbff2016-06-17 14:45:16 -0700701def reinitContainerClients():
702 docker_netns.dckr = Client()
703 Container.dckr = Client()
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700704
705class Xos(Container):
706 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
707 TAG = 'latest'
708 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700709 host_guest_map = None
710 env = None
711 ports = None
712 volumes = None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700713
A R Karthick6e80afd2016-10-10 16:03:12 -0700714 @classmethod
715 def get_cmd(cls, img_name):
716 cmd = cls.dckr.inspect_image(img_name)['Config']['Cmd']
717 return ' '.join(cmd)
718
A R Karthicke3bde962016-09-27 15:06:35 -0700719 def __init__(self, name, image, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700720 boot_delay = 20, restart = False, network_cfg = None, update = False):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700721 if restart is True:
722 ##Find the right image to restart
723 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
724 if running_image:
725 image_name = running_image[0]['Image']
726 try:
727 image = image_name.split(':')[0]
728 tag = image_name.split(':')[1]
729 except: pass
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700730 super(Xos, self).__init__(name, image, prefix = prefix, tag = tag)
731 if update is True or not self.img_exists():
732 self.build_image(self.image_name)
A R Karthick6e80afd2016-10-10 16:03:12 -0700733 self.command = self.get_cmd(self.image_name).strip() or None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700734 if restart is True and self.exists():
735 self.kill()
736 if not self.exists():
737 self.remove_container(name, force=True)
A R Karthicke3bde962016-09-27 15:06:35 -0700738 host_config = self.create_host_config(port_list = self.ports,
739 host_guest_map = self.host_guest_map,
740 privileged = True)
741 print('Starting XOS container %s' %self.name)
742 self.start(ports = self.ports, environment = self.env, host_config = host_config,
743 volumes = self.volumes, tty = True)
744 print('Waiting %d seconds for XOS Base Container to boot' %(boot_delay))
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700745 time.sleep(boot_delay)
746
747 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700748 def build_image(cls, image, dockerfile_path, image_target = 'build'):
749 cmd = 'cd {} && make {}'.format(dockerfile_path, image_target)
750 print('Building XOS %s' %image)
751 res = os.system(cmd)
752 print('Done building image %s. Image build %s' %(image, 'successful' if res == 0 else 'failed'))
753 return res
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700754
A R Karthicke3bde962016-09-27 15:06:35 -0700755class XosServer(Xos):
756 ports = [8000,9998,9999]
757 NAME = 'xos-server'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700758 IMAGE = 'xosproject/xos'
A R Karthicke3bde962016-09-27 15:06:35 -0700759 BASE_IMAGE = 'xosproject/xos-base'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700760 TAG = 'latest'
761 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700762 dockerfile_path = os.path.join(Xos.setup_dir, 'xos')
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700763
A R Karthicke3bde962016-09-27 15:06:35 -0700764 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700765 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700766 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700767
768 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700769 def build_image(cls, image = IMAGE):
770 ##build the base image and then build the server image
771 Xos.build_image(cls.BASE_IMAGE, cls.dockerfile_path, image_target = 'base')
772 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700773
A R Karthicke3bde962016-09-27 15:06:35 -0700774class XosSynchronizerOpenstack(Xos):
775 ports = [2375,]
776 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer')
777 NAME = 'xos-synchronizer'
778 IMAGE = 'xosproject/xos-synchronizer-openstack'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700779 TAG = 'latest'
780 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700781 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700782
A R Karthicke3bde962016-09-27 15:06:35 -0700783 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700784 tag = TAG, boot_delay = 20, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700785 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700786
787 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700788 def build_image(cls, image = IMAGE):
789 XosServer.build_image()
790 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700791
A R Karthicke3bde962016-09-27 15:06:35 -0700792class XosSynchronizerOnboarding(Xos):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700793 NAME = 'xos-synchronizer-onboarding'
794 IMAGE = 'xosproject/xos-synchronizer-onboarding'
795 TAG = 'latest'
796 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700797 dockerfile_path = os.path.join(Xos.setup_dir, 'onboarding_synchronizer')
798 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700799
A R Karthicke3bde962016-09-27 15:06:35 -0700800 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700801 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700802 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700803
804 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700805 def build_image(cls, image = IMAGE):
806 XosSynchronizerOpenstack.build_image()
807 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700808
A R Karthicke3bde962016-09-27 15:06:35 -0700809class XosSynchronizerOpenvpn(Xos):
810 NAME = 'xos-synchronizer-openvpn'
811 IMAGE = 'xosproject/xos-openvpn'
812 TAG = 'latest'
813 PREFIX = ''
814 dockerfile_path = os.path.join(Xos.setup_dir, 'openvpn')
815 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700816
A R Karthicke3bde962016-09-27 15:06:35 -0700817 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700818 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700819 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
820
821 @classmethod
822 def build_image(cls, image = IMAGE):
823 XosSynchronizerOpenstack.build_image()
824 Xos.build_image(image, cls.dockerfile_path)
825
826class XosPostgresql(Xos):
827 ports = [5432,]
828 NAME = 'xos-db-postgres'
829 IMAGE = 'xosproject/xos-postgres'
830 TAG = 'latest'
831 PREFIX = ''
832 volumes = ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
833 dockerfile_path = os.path.join(Xos.setup_dir, 'postgresql')
834
835 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700836 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700837 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
838
839 @classmethod
840 def build_image(cls, image = IMAGE):
841 Xos.build_image(image, cls.dockerfile_path)
842
843class XosSyndicateMs(Xos):
844 ports = [8080,]
845 env = None
846 NAME = 'xos-syndicate-ms'
847 IMAGE = 'xosproject/syndicate-ms'
848 TAG = 'latest'
849 PREFIX = ''
850 dockerfile_path = os.path.join(Xos.setup_dir, 'syndicate-ms')
851
852 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700853 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700854 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
855
856 @classmethod
857 def build_image(cls, image = IMAGE):
858 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700859
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700860class XosSyncVtn(Xos):
861 ports = [8080,]
862 env = None
863 NAME = 'xos-synchronizer-vtn'
864 IMAGE = 'xosproject/xos-synchronizer-vtn'
865 TAG = 'latest'
866 PREFIX = ''
867 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtn')
868
869 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700870 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700871 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
872
873 @classmethod
874 def build_image(cls, image = IMAGE):
875 Xos.build_image(image, cls.dockerfile_path)
876
877class XosSyncVtr(Xos):
878 ports = [8080,]
879 env = None
880 NAME = 'xos-synchronizer-vtr'
881 IMAGE = 'xosproject/xos-synchronizer-vtr'
882 TAG = 'latest'
883 PREFIX = ''
884 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtr')
885
886 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700887 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700888 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
889
890 @classmethod
891 def build_image(cls, image = IMAGE):
892 Xos.build_image(image, cls.dockerfile_path)
893
894class XosSyncVsg(Xos):
895 ports = [8080,]
896 env = None
897 NAME = 'xos-synchronizer-vsg'
898 IMAGE = 'xosproject/xos-synchronizer-vsg'
899 TAG = 'latest'
900 PREFIX = ''
901 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vsg')
902
903 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700904 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700905 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
906
907 @classmethod
908 def build_image(cls, image = IMAGE):
909 Xos.build_image(image, cls.dockerfile_path)
910
911
912class XosSyncOnos(Xos):
913 ports = [8080,]
914 env = None
915 NAME = 'xos-synchronizer-onos'
916 IMAGE = 'xosproject/xos-synchronizer-onos'
917 TAG = 'latest'
918 PREFIX = ''
919 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-onos')
920
921 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700922 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700923 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
924
925 @classmethod
926 def build_image(cls, image = IMAGE):
927 Xos.build_image(image, cls.dockerfile_path)
928
929class XosSyncFabric(Xos):
930 ports = [8080,]
931 env = None
932 NAME = 'xos-synchronizer-fabric'
933 IMAGE = 'xosproject/xos-synchronizer-fabric'
934 TAG = 'latest'
935 PREFIX = ''
936 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-fabric')
937
938 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700939 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700940 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
941
942 @classmethod
943 def build_image(cls, image = IMAGE):
944 Xos.build_image(image, cls.dockerfile_path)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800945
946if __name__ == '__main__':
947 onos = Onos(boot_delay = 10, restart = True)