blob: fb71403488037e8e3c83060df0bcc8c2603a6c92 [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
A R Karthick19aaf5c2016-11-09 17:47:57 -0800433 if not started:
434 print('ONOS did not start')
435 else:
436 print('ONOS started')
437 return started
438
439 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700440 def setup_cluster_deprecated(cls, onos_instances, image_name = None):
441 if not onos_instances or len(onos_instances) < 2:
442 return
443 ips = []
444 if image_name is not None:
445 ips = Container.ips(image_name)
446 else:
447 for onos in onos_instances:
448 ips.append(onos.ipaddr)
449 Onos.cluster_instances = onos_instances
450 Onos.cluster_mode = True
451 ##regenerate the cluster json with the 3 instance ips before restarting them back
452 print('Generating cluster cfg for ONOS instances with ips %s' %ips)
453 Onos.generate_cluster_cfg(ips)
454 for onos in onos_instances:
455 onos.kill()
456 onos.remove_container(onos.name, force=True)
457 print('Restarting ONOS container %s for forming cluster' %onos.name)
458 onos.start(ports = onos.ports, environment = onos.env,
459 host_config = onos.host_config, volumes = onos.volumes, tty = True)
460 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
461 time.sleep(onos.boot_delay)
462 onos.ipaddr = onos.ip()
463 onos.install_cord_apps(onos.ipaddr)
464
465 @classmethod
466 def setup_cluster(cls, onos_instances, image_name = None):
467 if not onos_instances or len(onos_instances) < 2:
468 return
469 ips = []
470 if image_name is not None:
471 ips = Container.ips(image_name)
472 else:
473 for onos in onos_instances:
474 ips.append(onos.ipaddr)
475 Onos.cluster_instances = onos_instances
476 Onos.cluster_mode = True
477 ##regenerate the cluster json with the 3 instance ips before restarting them back
478 print('Forming cluster for ONOS instances with ips %s' %ips)
479 Onos.form_cluster(ips)
480 ##wait for the cluster to be formed
481 print('Waiting for the cluster to be formed')
482 time.sleep(60)
483 for onos in onos_instances:
484 onos.install_cord_apps(onos.ipaddr)
485
486 @classmethod
A R Karthicke2c24bd2016-10-07 14:51:38 -0700487 def add_cluster(cls, count = 1, network_cfg = None):
488 if not cls.cluster_instances or Onos.cluster_mode is False:
489 return
490 for i in range(count):
491 name = '{}-{}'.format(Onos.NAME, len(cls.cluster_instances)+1)
492 onos = cls(name = name, image = Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX,
493 cluster = True, network_cfg = network_cfg)
494 cls.cluster_instances.append(onos)
495
496 cls.setup_cluster(cls.cluster_instances)
497
498 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700499 def restart_cluster(cls, network_cfg = None):
500 if cls.cluster_mode is False:
501 return
502 if not cls.cluster_instances:
503 return
504
505 if network_cfg is not None:
506 json_data = json.dumps(network_cfg, indent=4)
507 with open('{}/network-cfg.json'.format(cls.host_config_dir), 'w') as f:
508 f.write(json_data)
509
510 for onos in cls.cluster_instances:
511 if onos.exists():
512 onos.kill()
513 onos.remove_container(onos.name, force=True)
514 print('Restarting ONOS container %s' %onos.name)
515 onos.start(ports = onos.ports, environment = onos.env,
516 host_config = onos.host_config, volumes = onos.volumes, tty = True)
517 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
518 time.sleep(onos.boot_delay)
519 onos.ipaddr = onos.ip()
520
521 ##form the cluster
522 cls.setup_cluster(cls.cluster_instances)
523
524 @classmethod
525 def cluster_ips(cls):
526 if cls.cluster_mode is False:
527 return []
528 if not cls.cluster_instances:
529 return []
530 ips = [ onos.ipaddr for onos in cls.cluster_instances ]
531 return ips
532
533 @classmethod
534 def cleanup_cluster(cls):
535 if cls.cluster_mode is False:
536 return
537 if not cls.cluster_instances:
538 return
539 for onos in cls.cluster_instances:
540 if onos.exists():
541 onos.kill()
542 onos.remove_container(onos.name, force=True)
A R Karthickd44cea12016-07-20 12:16:41 -0700543
A.R Karthick95d044e2016-06-10 18:44:36 -0700544 @classmethod
A R Karthick889d9652016-10-03 14:13:45 -0700545 def restart_node(cls, node = None, network_cfg = None):
546 if node is None:
547 cls(restart = True, network_cfg = network_cfg, image = cls.IMAGE, tag = cls.TAG)
548 else:
549 #Restarts a node in the cluster
550 valid_node = filter(lambda onos: node in [ onos.ipaddr, onos.name ], cls.cluster_instances)
551 if valid_node:
552 onos = valid_node.pop()
553 if onos.exists():
554 onos.kill()
555 onos.remove_container(onos.name, force=True)
556 print('Restarting ONOS container %s' %onos.name)
557 onos.start(ports = onos.ports, environment = onos.env,
558 host_config = onos.host_config, volumes = onos.volumes, tty = True)
559 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
560 time.sleep(onos.boot_delay)
561 onos.ipaddr = onos.ip()
562
563 @classmethod
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700564 def install_cord_apps(cls, onos_ip = None):
A.R Karthick95d044e2016-06-10 18:44:36 -0700565 for app, version in cls.onos_cord_apps:
566 app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version)
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700567 ok, code = OnosCtrl.install_app(app_file, onos_ip = onos_ip)
A.R Karthick95d044e2016-06-10 18:44:36 -0700568 ##app already installed (conflicts)
569 if code in [ 409 ]:
570 ok = True
571 print('ONOS app %s, version %s %s' %(app, version, 'installed' if ok else 'failed to install'))
572 time.sleep(2)
573
A.R Karthick1700e0e2016-10-06 18:16:57 -0700574class OnosStopWrapper(Container):
575 def __init__(self, name):
576 super(OnosStopWrapper, self).__init__(name, Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX)
577 if self.exists():
578 self.kill()
579 else:
580 if Onos.cluster_mode is True:
581 valid_node = filter(lambda onos: name in [ onos.ipaddr, onos.name ], Onos.cluster_instances)
582 if valid_node:
583 onos = valid_node.pop()
584 if onos.exists():
585 onos.kill()
586
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700587class Radius(Container):
588 ports = [ 1812, 1813 ]
A R Karthick41adfce2016-06-10 09:51:25 -0700589 env = {'TIMEZONE':'America/Los_Angeles',
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700590 'DEBUG': 'true', 'cert_password':'whatever', 'primary_shared_secret':'radius_password'
591 }
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700592 host_db_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/db')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700593 guest_db_dir = os.path.join(os.path.sep, 'opt', 'db')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700594 host_config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/freeradius')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700595 guest_config_dir = os.path.join(os.path.sep, 'etc', 'freeradius')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700596 start_command = os.path.join(guest_config_dir, 'start-radius.py')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700597 host_guest_map = ( (host_db_dir, guest_db_dir),
598 (host_config_dir, guest_config_dir)
599 )
Chetan Gaonker503032a2016-05-12 12:06:29 -0700600 IMAGE = 'cord-test/radius'
601 NAME = 'cord-radius'
602
A R Karthick07608ef2016-08-23 16:51:19 -0700603 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
Chetan Gaonker503032a2016-05-12 12:06:29 -0700604 boot_delay = 10, restart = False, update = False):
A R Karthick07608ef2016-08-23 16:51:19 -0700605 super(Radius, self).__init__(name, image, prefix = prefix, tag = tag, command = self.start_command)
Chetan Gaonker503032a2016-05-12 12:06:29 -0700606 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -0700607 self.build_image(self.image_name)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700608 if restart is True and self.exists():
609 self.kill()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700610 if not self.exists():
611 self.remove_container(name, force=True)
612 host_config = self.create_host_config(port_list = self.ports,
613 host_guest_map = self.host_guest_map)
614 volumes = []
615 for _,g in self.host_guest_map:
616 volumes.append(g)
A R Karthick41adfce2016-06-10 09:51:25 -0700617 self.start(ports = self.ports, environment = self.env,
618 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700619 host_config = host_config, tty = True)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700620 time.sleep(boot_delay)
621
622 @classmethod
623 def build_image(cls, image):
624 print('Building Radius image %s' %image)
625 dockerfile = '''
626FROM hbouvier/docker-radius
627MAINTAINER chetan@ciena.com
628LABEL RUN docker pull hbouvier/docker-radius
629LABEL RUN docker run -it --name cord-radius hbouvier/docker-radius
A R Karthickc762df42016-05-25 10:09:21 -0700630RUN apt-get update && \
631 apt-get -y install python python-pexpect strace
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700632WORKDIR /root
633CMD ["/etc/freeradius/start-radius.py"]
634'''
635 super(Radius, cls).build_image(dockerfile, image)
636 print('Done building image %s' %image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700637
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700638class Quagga(Container):
A R Karthick41adfce2016-06-10 09:51:25 -0700639 quagga_config = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 },
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700640 { 'bridge' : 'quagga-br', 'ip': '192.168.10.3', 'mask': 16 },
641 )
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700642 ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ]
643 host_quagga_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/quagga-config')
644 guest_quagga_config = '/root/config'
645 quagga_config_file = os.path.join(guest_quagga_config, 'testrib.conf')
646 host_guest_map = ( (host_quagga_config, guest_quagga_config), )
Chetan Gaonker503032a2016-05-12 12:06:29 -0700647 IMAGE = 'cord-test/quagga'
648 NAME = 'cord-quagga'
649
A R Karthick07608ef2016-08-23 16:51:19 -0700650 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
Chetan Gaonker503032a2016-05-12 12:06:29 -0700651 boot_delay = 15, restart = False, config_file = quagga_config_file, update = False):
A R Karthick07608ef2016-08-23 16:51:19 -0700652 super(Quagga, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.quagga_config)
Chetan Gaonker503032a2016-05-12 12:06:29 -0700653 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -0700654 self.build_image(self.image_name)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700655 if restart is True and self.exists():
656 self.kill()
657 if not self.exists():
658 self.remove_container(name, force=True)
A R Karthick41adfce2016-06-10 09:51:25 -0700659 host_config = self.create_host_config(port_list = self.ports,
660 host_guest_map = self.host_guest_map,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700661 privileged = True)
662 volumes = []
663 for _,g in self.host_guest_map:
664 volumes.append(g)
665 self.start(ports = self.ports,
A R Karthick41adfce2016-06-10 09:51:25 -0700666 host_config = host_config,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700667 volumes = volumes, tty = True)
668 print('Starting Quagga on container %s' %self.name)
669 self.execute('{0}/start.sh {1}'.format(self.guest_quagga_config, config_file))
670 time.sleep(boot_delay)
671
672 @classmethod
673 def build_image(cls, image):
Chetan Gaonker2a6601b2016-05-02 17:28:26 -0700674 onos_quagga_ip = Onos.quagga_config[0]['ip']
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700675 print('Building Quagga image %s' %image)
676 dockerfile = '''
A R Karthick41adfce2016-06-10 09:51:25 -0700677FROM ubuntu:14.04
678MAINTAINER chetan@ciena.com
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700679WORKDIR /root
680RUN useradd -M quagga
681RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga
682RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga
A R Karthick973ea692016-10-17 12:23:02 -0700683RUN 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 -0700684RUN git clone git://git.savannah.nongnu.org/quagga.git quagga && \
A R Karthick8f69c2c2016-10-21 11:43:26 -0700685(cd quagga && git checkout quagga-1.0.20160315 && ./bootstrap.sh && \
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700686sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \
687./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install)
688RUN ldconfig
689'''.format(onos_quagga_ip)
690 super(Quagga, cls).build_image(dockerfile, image)
691 print('Done building image %s' %image)
A R Karthick81acbff2016-06-17 14:45:16 -0700692
A.R Karthick1700e0e2016-10-06 18:16:57 -0700693class QuaggaStopWrapper(Container):
694 def __init__(self, name = Quagga.NAME, image = Quagga.IMAGE, tag = 'candidate'):
695 super(QuaggaStopWrapper, self).__init__(name, image, prefix = Container.IMAGE_PREFIX, tag = tag)
696 if self.exists():
697 self.kill()
698
699
A R Karthick81acbff2016-06-17 14:45:16 -0700700def reinitContainerClients():
701 docker_netns.dckr = Client()
702 Container.dckr = Client()
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700703
704class Xos(Container):
705 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
706 TAG = 'latest'
707 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700708 host_guest_map = None
709 env = None
710 ports = None
711 volumes = None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700712
A R Karthick6e80afd2016-10-10 16:03:12 -0700713 @classmethod
714 def get_cmd(cls, img_name):
715 cmd = cls.dckr.inspect_image(img_name)['Config']['Cmd']
716 return ' '.join(cmd)
717
A R Karthicke3bde962016-09-27 15:06:35 -0700718 def __init__(self, name, image, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700719 boot_delay = 20, restart = False, network_cfg = None, update = False):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700720 if restart is True:
721 ##Find the right image to restart
722 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
723 if running_image:
724 image_name = running_image[0]['Image']
725 try:
726 image = image_name.split(':')[0]
727 tag = image_name.split(':')[1]
728 except: pass
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700729 super(Xos, self).__init__(name, image, prefix = prefix, tag = tag)
730 if update is True or not self.img_exists():
731 self.build_image(self.image_name)
A R Karthick6e80afd2016-10-10 16:03:12 -0700732 self.command = self.get_cmd(self.image_name).strip() or None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700733 if restart is True and self.exists():
734 self.kill()
735 if not self.exists():
736 self.remove_container(name, force=True)
A R Karthicke3bde962016-09-27 15:06:35 -0700737 host_config = self.create_host_config(port_list = self.ports,
738 host_guest_map = self.host_guest_map,
739 privileged = True)
740 print('Starting XOS container %s' %self.name)
741 self.start(ports = self.ports, environment = self.env, host_config = host_config,
742 volumes = self.volumes, tty = True)
743 print('Waiting %d seconds for XOS Base Container to boot' %(boot_delay))
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700744 time.sleep(boot_delay)
745
746 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700747 def build_image(cls, image, dockerfile_path, image_target = 'build'):
748 cmd = 'cd {} && make {}'.format(dockerfile_path, image_target)
749 print('Building XOS %s' %image)
750 res = os.system(cmd)
751 print('Done building image %s. Image build %s' %(image, 'successful' if res == 0 else 'failed'))
752 return res
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700753
A R Karthicke3bde962016-09-27 15:06:35 -0700754class XosServer(Xos):
755 ports = [8000,9998,9999]
756 NAME = 'xos-server'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700757 IMAGE = 'xosproject/xos'
A R Karthicke3bde962016-09-27 15:06:35 -0700758 BASE_IMAGE = 'xosproject/xos-base'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700759 TAG = 'latest'
760 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700761 dockerfile_path = os.path.join(Xos.setup_dir, 'xos')
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700762
A R Karthicke3bde962016-09-27 15:06:35 -0700763 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700764 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700765 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700766
767 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700768 def build_image(cls, image = IMAGE):
769 ##build the base image and then build the server image
770 Xos.build_image(cls.BASE_IMAGE, cls.dockerfile_path, image_target = 'base')
771 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700772
A R Karthicke3bde962016-09-27 15:06:35 -0700773class XosSynchronizerOpenstack(Xos):
774 ports = [2375,]
775 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer')
776 NAME = 'xos-synchronizer'
777 IMAGE = 'xosproject/xos-synchronizer-openstack'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700778 TAG = 'latest'
779 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700780 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700781
A R Karthicke3bde962016-09-27 15:06:35 -0700782 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700783 tag = TAG, boot_delay = 20, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700784 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700785
786 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700787 def build_image(cls, image = IMAGE):
788 XosServer.build_image()
789 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700790
A R Karthicke3bde962016-09-27 15:06:35 -0700791class XosSynchronizerOnboarding(Xos):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700792 NAME = 'xos-synchronizer-onboarding'
793 IMAGE = 'xosproject/xos-synchronizer-onboarding'
794 TAG = 'latest'
795 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -0700796 dockerfile_path = os.path.join(Xos.setup_dir, 'onboarding_synchronizer')
797 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700798
A R Karthicke3bde962016-09-27 15:06:35 -0700799 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700800 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700801 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700802
803 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -0700804 def build_image(cls, image = IMAGE):
805 XosSynchronizerOpenstack.build_image()
806 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700807
A R Karthicke3bde962016-09-27 15:06:35 -0700808class XosSynchronizerOpenvpn(Xos):
809 NAME = 'xos-synchronizer-openvpn'
810 IMAGE = 'xosproject/xos-openvpn'
811 TAG = 'latest'
812 PREFIX = ''
813 dockerfile_path = os.path.join(Xos.setup_dir, 'openvpn')
814 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700815
A R Karthicke3bde962016-09-27 15:06:35 -0700816 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700817 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700818 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
819
820 @classmethod
821 def build_image(cls, image = IMAGE):
822 XosSynchronizerOpenstack.build_image()
823 Xos.build_image(image, cls.dockerfile_path)
824
825class XosPostgresql(Xos):
826 ports = [5432,]
827 NAME = 'xos-db-postgres'
828 IMAGE = 'xosproject/xos-postgres'
829 TAG = 'latest'
830 PREFIX = ''
831 volumes = ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
832 dockerfile_path = os.path.join(Xos.setup_dir, 'postgresql')
833
834 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -0700835 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700836 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
837
838 @classmethod
839 def build_image(cls, image = IMAGE):
840 Xos.build_image(image, cls.dockerfile_path)
841
842class XosSyndicateMs(Xos):
843 ports = [8080,]
844 env = None
845 NAME = 'xos-syndicate-ms'
846 IMAGE = 'xosproject/syndicate-ms'
847 TAG = 'latest'
848 PREFIX = ''
849 dockerfile_path = os.path.join(Xos.setup_dir, 'syndicate-ms')
850
851 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700852 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -0700853 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
854
855 @classmethod
856 def build_image(cls, image = IMAGE):
857 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700858
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700859class XosSyncVtn(Xos):
860 ports = [8080,]
861 env = None
862 NAME = 'xos-synchronizer-vtn'
863 IMAGE = 'xosproject/xos-synchronizer-vtn'
864 TAG = 'latest'
865 PREFIX = ''
866 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtn')
867
868 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700869 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700870 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
871
872 @classmethod
873 def build_image(cls, image = IMAGE):
874 Xos.build_image(image, cls.dockerfile_path)
875
876class XosSyncVtr(Xos):
877 ports = [8080,]
878 env = None
879 NAME = 'xos-synchronizer-vtr'
880 IMAGE = 'xosproject/xos-synchronizer-vtr'
881 TAG = 'latest'
882 PREFIX = ''
883 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtr')
884
885 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700886 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700887 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
888
889 @classmethod
890 def build_image(cls, image = IMAGE):
891 Xos.build_image(image, cls.dockerfile_path)
892
893class XosSyncVsg(Xos):
894 ports = [8080,]
895 env = None
896 NAME = 'xos-synchronizer-vsg'
897 IMAGE = 'xosproject/xos-synchronizer-vsg'
898 TAG = 'latest'
899 PREFIX = ''
900 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vsg')
901
902 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700903 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700904 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
905
906 @classmethod
907 def build_image(cls, image = IMAGE):
908 Xos.build_image(image, cls.dockerfile_path)
909
910
911class XosSyncOnos(Xos):
912 ports = [8080,]
913 env = None
914 NAME = 'xos-synchronizer-onos'
915 IMAGE = 'xosproject/xos-synchronizer-onos'
916 TAG = 'latest'
917 PREFIX = ''
918 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-onos')
919
920 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700921 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700922 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
923
924 @classmethod
925 def build_image(cls, image = IMAGE):
926 Xos.build_image(image, cls.dockerfile_path)
927
928class XosSyncFabric(Xos):
929 ports = [8080,]
930 env = None
931 NAME = 'xos-synchronizer-fabric'
932 IMAGE = 'xosproject/xos-synchronizer-fabric'
933 TAG = 'latest'
934 PREFIX = ''
935 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-fabric')
936
937 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -0700938 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -0700939 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
940
941 @classmethod
942 def build_image(cls, image = IMAGE):
943 Xos.build_image(image, cls.dockerfile_path)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800944
945if __name__ == '__main__':
946 onos = Onos(boot_delay = 10, restart = True)