blob: a6f46f1d530a30ff67a6ac6781b10506c1637208 [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
A.R Karthickc4e474d2016-12-12 15:24:57 -080020import errno
A R Karthickaa54a1c2016-12-15 11:42:08 -080021import copy
Chetan Gaonker3533faa2016-04-25 17:50:14 -070022from pyroute2 import IPRoute
A.R Karthickc4e474d2016-12-12 15:24:57 -080023from pyroute2.netlink import NetlinkError
Chetan Gaonker3533faa2016-04-25 17:50:14 -070024from itertools import chain
25from nsenter import Namespace
26from docker import Client
A R Karthick85eb1862017-01-23 16:10:57 -080027from docker import utils as dockerutils
A.R Karthickf184b342017-01-27 19:30:50 -080028import shutil
A.R Karthick95d044e2016-06-10 18:44:36 -070029from OnosCtrl import OnosCtrl
A R Karthick19aaf5c2016-11-09 17:47:57 -080030from OnosLog import OnosLog
A R Karthick03bd2812017-03-03 17:49:17 -080031from onosclidriver import OnosCliDriver
A.R Karthickc4e474d2016-12-12 15:24:57 -080032from threadPool import ThreadPool
A R Karthickaa54a1c2016-12-15 11:42:08 -080033from threading import Lock
Chetan Gaonker3533faa2016-04-25 17:50:14 -070034
35class docker_netns(object):
36
37 dckr = Client()
38 def __init__(self, name):
39 pid = int(self.dckr.inspect_container(name)['State']['Pid'])
40 if pid == 0:
41 raise Exception('no container named {0}'.format(name))
42 self.pid = pid
43
44 def __enter__(self):
45 pid = self.pid
46 if not os.path.exists('/var/run/netns'):
47 os.mkdir('/var/run/netns')
48 os.symlink('/proc/{0}/ns/net'.format(pid), '/var/run/netns/{0}'.format(pid))
49 return str(pid)
50
51 def __exit__(self, type, value, traceback):
52 pid = self.pid
53 os.unlink('/var/run/netns/{0}'.format(pid))
54
55flatten = lambda l: chain.from_iterable(l)
56
57class Container(object):
58 dckr = Client()
A R Karthick07608ef2016-08-23 16:51:19 -070059 IMAGE_PREFIX = '' ##for saving global prefix for all test classes
A R Karthickaa54a1c2016-12-15 11:42:08 -080060 CONFIG_LOCK = Lock()
A R Karthick07608ef2016-08-23 16:51:19 -070061
62 def __init__(self, name, image, prefix='', tag = 'candidate', command = 'bash', quagga_config = None):
Chetan Gaonker3533faa2016-04-25 17:50:14 -070063 self.name = name
A R Karthick07608ef2016-08-23 16:51:19 -070064 self.prefix = prefix
65 if prefix:
66 self.prefix += '/'
67 image = '{}{}'.format(self.prefix, image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -070068 self.image = image
69 self.tag = tag
A R Karthickd44cea12016-07-20 12:16:41 -070070 if tag:
71 self.image_name = image + ':' + tag
72 else:
73 self.image_name = image
Chetan Gaonker3533faa2016-04-25 17:50:14 -070074 self.id = None
75 self.command = command
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -070076 self.quagga_config = quagga_config
Chetan Gaonker3533faa2016-04-25 17:50:14 -070077
78 @classmethod
79 def build_image(cls, dockerfile, tag, force=True, nocache=False):
80 f = io.BytesIO(dockerfile.encode('utf-8'))
81 if force or not cls.image_exists(tag):
82 print('Build {0}...'.format(tag))
83 for line in cls.dckr.build(fileobj=f, rm=True, tag=tag, decode=True, nocache=nocache):
84 if 'stream' in line:
85 print(line['stream'].strip())
86
87 @classmethod
88 def image_exists(cls, name):
A R Karthicke07fc3a2017-02-27 10:49:29 -080089 #return name in [ctn['RepoTags'][0] for ctn in cls.dckr.images()]
90 return name in list( flatten(ctn['RepoTags'] if ctn['RepoTags'] else '' for ctn in cls.dckr.images()) )
Chetan Gaonker3533faa2016-04-25 17:50:14 -070091
92 @classmethod
93 def create_host_config(cls, port_list = None, host_guest_map = None, privileged = False):
94 port_bindings = None
95 binds = None
96 if port_list:
97 port_bindings = {}
98 for p in port_list:
99 port_bindings[str(p)] = str(p)
100
101 if host_guest_map:
102 binds = []
103 for h, g in host_guest_map:
104 binds.append('{0}:{1}'.format(h, g))
105
106 return cls.dckr.create_host_config(binds = binds, port_bindings = port_bindings, privileged = privileged)
107
108 @classmethod
A R Karthick85eb1862017-01-23 16:10:57 -0800109 def connect_to_network(cls, name, network):
110 try:
111 cls.dckr.connect_container_to_network(name, network)
112 return True
113 except:
114 return False
115
116 @classmethod
117 def create_network(cls, network, subnet = None, gateway = None):
118 ipam_config = None
119 if subnet is not None and gateway is not None:
120 ipam_pool = dockerutils.create_ipam_pool(subnet = subnet, gateway = gateway)
121 ipam_config = dockerutils.create_ipam_config(pool_configs = [ipam_pool])
122 cls.dckr.create_network(network, driver='bridge', ipam = ipam_config)
123
124 @classmethod
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700125 def cleanup(cls, image):
A R Karthick09b1f4e2016-05-12 14:31:50 -0700126 cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True))
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700127 for cnt in cnt_list:
128 print('Cleaning container %s' %cnt['Id'])
A.R Karthick95d044e2016-06-10 18:44:36 -0700129 if cnt.has_key('State') and cnt['State'] == 'running':
A R Karthick09b1f4e2016-05-12 14:31:50 -0700130 cls.dckr.kill(cnt['Id'])
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700131 cls.dckr.remove_container(cnt['Id'], force=True)
132
133 @classmethod
134 def remove_container(cls, name, force=True):
135 try:
136 cls.dckr.remove_container(name, force = force)
137 except: pass
138
139 def exists(self):
140 return '/{0}'.format(self.name) in list(flatten(n['Names'] for n in self.dckr.containers()))
141
142 def img_exists(self):
A R Karthicke07fc3a2017-02-27 10:49:29 -0800143 #return self.image_name in [ctn['RepoTags'][0] if ctn['RepoTags'] else '' for ctn in self.dckr.images()]
144 return self.image_name in list( flatten(ctn['RepoTags'] if ctn['RepoTags'] else '' for ctn in self.dckr.images()) )
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700145
A R Karthick75844572017-01-23 16:57:44 -0800146 def ip(self, network = None):
A R Karthick2b93d6a2016-09-06 15:19:09 -0700147 cnt_list = filter(lambda c: c['Names'][0] == '/{}'.format(self.name), self.dckr.containers())
148 #if not cnt_list:
149 # cnt_list = filter(lambda c: c['Image'] == self.image_name, self.dckr.containers())
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700150 cnt_settings = cnt_list.pop()
A R Karthick75844572017-01-23 16:57:44 -0800151 if network is not None and cnt_settings['NetworkSettings']['Networks'].has_key(network):
152 return cnt_settings['NetworkSettings']['Networks'][network]['IPAddress']
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700153 return cnt_settings['NetworkSettings']['Networks']['bridge']['IPAddress']
154
A R Karthick2b93d6a2016-09-06 15:19:09 -0700155 @classmethod
156 def ips(cls, image_name):
157 cnt_list = filter(lambda c: c['Image'] == image_name, cls.dckr.containers())
158 ips = [ cnt['NetworkSettings']['Networks']['bridge']['IPAddress'] for cnt in cnt_list ]
159 return ips
160
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700161 def kill(self, remove = True):
162 self.dckr.kill(self.name)
163 self.dckr.remove_container(self.name, force=True)
164
A R Karthick41adfce2016-06-10 09:51:25 -0700165 def start(self, rm = True, ports = None, volumes = None, host_config = None,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700166 environment = None, tty = False, stdin_open = True):
167
168 if rm and self.exists():
169 print('Removing container:', self.name)
170 self.dckr.remove_container(self.name, force=True)
171
A R Karthick41adfce2016-06-10 09:51:25 -0700172 ctn = self.dckr.create_container(image=self.image_name, ports = ports, command=self.command,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700173 detach=True, name=self.name,
A R Karthick41adfce2016-06-10 09:51:25 -0700174 environment = environment,
175 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700176 host_config = host_config, stdin_open=stdin_open, tty = tty)
177 self.dckr.start(container=self.name)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700178 if self.quagga_config:
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700179 self.connect_to_br()
180 self.id = ctn['Id']
181 return ctn
182
Thangavelu K Sef6f0a52016-12-14 19:57:05 +0000183 @classmethod
184 def pause_container(cls, image, delay):
185 cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True))
186 for cnt in cnt_list:
187 print('Pause the container %s' %cnt['Id'])
188 if cnt.has_key('State') and cnt['State'] == 'running':
189 cls.dckr.pause(cnt['Id'])
190 if delay != 0:
191 time.sleep(delay)
192 for cnt in cnt_list:
193 print('Unpause the container %s' %cnt['Id'])
194 cls.dckr.unpause(cnt['Id'])
195 else:
196 print('Infinity time pause the container %s' %cnt['Id'])
197 return 'success'
198
A R Karthick52414732017-01-31 09:59:47 -0800199 def connect_to_br(self, index = 0):
A R Karthickaa54a1c2016-12-15 11:42:08 -0800200 self.CONFIG_LOCK.acquire()
201 try:
202 with docker_netns(self.name) as pid:
203 for quagga_config in self.quagga_config:
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700204 ip = IPRoute()
A R Karthickaa54a1c2016-12-15 11:42:08 -0800205 br = ip.link_lookup(ifname=quagga_config['bridge'])
206 if len(br) == 0:
207 try:
208 ip.link_create(ifname=quagga_config['bridge'], kind='bridge')
209 except NetlinkError as e:
210 err, _ = e.args
211 if err == errno.EEXIST:
212 pass
213 else:
214 raise NetlinkError(*e.args)
215 br = ip.link_lookup(ifname=quagga_config['bridge'])
216 br = br[0]
217 ip.link('set', index=br, state='up')
A R Karthick52414732017-01-31 09:59:47 -0800218 ifname = '{0}-{1}'.format(self.name[:12], index)
A R Karthickaa54a1c2016-12-15 11:42:08 -0800219 ifs = ip.link_lookup(ifname=ifname)
220 if len(ifs) > 0:
221 ip.link_remove(ifs[0])
222 peer_ifname = '{0}-{1}'.format(pid, index)
223 ip.link_create(ifname=ifname, kind='veth', peer=peer_ifname)
224 host = ip.link_lookup(ifname=ifname)[0]
225 ip.link('set', index=host, master=br)
226 ip.link('set', index=host, state='up')
227 guest = ip.link_lookup(ifname=peer_ifname)[0]
228 ip.link('set', index=guest, net_ns_fd=pid)
229 with Namespace(pid, 'net'):
230 ip = IPRoute()
231 ip.link('set', index=guest, ifname='eth{}'.format(index+1))
232 ip.addr('add', index=guest, address=quagga_config['ip'], mask=quagga_config['mask'])
233 ip.link('set', index=guest, state='up')
234 index += 1
235 finally:
236 self.CONFIG_LOCK.release()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700237
Thangavelu K Sef6f0a52016-12-14 19:57:05 +0000238 def execute(self, cmd, tty = True, stream = False, shell = False, detach = True):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700239 res = 0
240 if type(cmd) == str:
241 cmds = (cmd,)
242 else:
243 cmds = cmd
244 if shell:
245 for c in cmds:
246 res += os.system('docker exec {0} {1}'.format(self.name, c))
247 return res
248 for c in cmds:
249 i = self.dckr.exec_create(container=self.name, cmd=c, tty = tty, privileged = True)
A R Karthickd6dd9b22017-02-24 15:17:22 -0800250 s = self.dckr.exec_start(i['Id'], stream = stream, detach=detach, socket=True)
251 try:
252 s.close()
253 except: pass
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700254 result = self.dckr.exec_inspect(i['Id'])
255 res += 0 if result['ExitCode'] == None else result['ExitCode']
256 return res
257
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700258 def restart(self, timeout =10):
259 return self.dckr.restart(self.name, timeout)
260
A R Karthickc69d73e2017-01-20 11:44:34 -0800261def get_mem(jvm_heap_size = None, instances = 1):
A R Karthick1f908202016-11-16 17:32:20 -0800262 if instances <= 0:
263 instances = 1
A R Karthickc69d73e2017-01-20 11:44:34 -0800264 heap_size = jvm_heap_size
265 heap_size_i = 0
266 #sanitize the heap size config
267 if heap_size is not None:
268 if not heap_size.isdigit():
269 try:
270 heap_size_i = int(heap_size[:-1])
271 suffix = heap_size[-1]
272 if suffix == 'M':
273 heap_size_i /= 1024 #convert to gigs
A.R Karthick99044822017-02-09 14:04:20 -0800274 #allow to specific minimum heap size
275 if heap_size_i == 0:
276 return heap_size
A R Karthickc69d73e2017-01-20 11:44:34 -0800277 except:
278 ##invalid suffix length probably. Fall back to default
279 heap_size = None
280 else:
281 heap_size_i = int(heap_size)
282
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700283 with open('/proc/meminfo', 'r') as fd:
284 meminfo = fd.readlines()
285 mem = 0
286 for m in meminfo:
287 if m.startswith('MemTotal:') or m.startswith('SwapTotal:'):
288 mem += int(m.split(':')[1].strip().split()[0])
289
A R Karthick1f908202016-11-16 17:32:20 -0800290 mem = max(mem/1024/1024/2/instances, 1)
Chetan Gaonker6d0a7b02016-05-03 16:57:28 -0700291 mem = min(mem, 16)
A R Karthickc69d73e2017-01-20 11:44:34 -0800292
293 if heap_size_i:
294 #we take the minimum of the provided heap size and max allowed heap size
295 heap_size_i = min(heap_size_i, mem)
296 else:
297 heap_size_i = mem
298
299 return '{}G'.format(heap_size_i)
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700300
A R Karthickd44cea12016-07-20 12:16:41 -0700301class OnosCord(Container):
302 """Use this when running the cord tester agent on the onos compute node"""
A R Karthickd44cea12016-07-20 12:16:41 -0700303 onos_config_dir_guest = '/root/onos/config'
A R Karthick03bd2812017-03-03 17:49:17 -0800304 synchronizer_map = { 'vtn' : { 'install':
305 ('http://mavenrepo:8080/repository/org/opencord/cord-config/1.2-SNAPSHOT/cord-config-1.2-SNAPSHOT.oar',
306 'http://mavenrepo:8080/repository/org/opencord/vtn/1.2-SNAPSHOT/vtn-1.2-SNAPSHOT.oar',),
307 'activate':
308 ('org.onosproject.ovsdb-base', 'org.onosproject.drivers.ovsdb',
309 'org.onosproject.dhcp', 'org.onosproject.optical-model',
310 'org.onosproject.openflow-base', 'org.onosproject.proxyarp',
311 'org.onosproject.hostprovider'),
312 },
313 'fabric' : { 'activate':
314 ('org.onosproject.hostprovider', 'org.onosproject.optical-model',
315 'org.onosproject.openflow-base', 'org.onosproject.vrouter',
316 'org.onosproject.netcfghostprovider', 'org.onosproject.netcfglinksprovider',
317 'org.onosproject.segmentrouting', 'org.onosproject.proxyarp'),
318 }
319 }
320 tester_apps = ('http://mavenrepo:8080/repository/org/opencord/aaa/1.2-SNAPSHOT/aaa-1.2-SNAPSHOT.oar',
321 'http://mavenrepo:8080/repository/org/opencord/igmp/1.2-SNAPSHOT/igmp-1.2-SNAPSHOT.oar',)
A R Karthickd44cea12016-07-20 12:16:41 -0700322
A.R Karthickddf12772017-05-17 13:49:47 -0700323 old_service_profile = '/opt/cord/orchestration/service-profile/cord-pod'
324
A R Karthick03bd2812017-03-03 17:49:17 -0800325 def __init__(self, onos_ip, conf, service_profile, synchronizer, start = True, boot_delay = 5):
A.R Karthickf184b342017-01-27 19:30:50 -0800326 if not os.access(conf, os.F_OK):
327 raise Exception('ONOS cord configuration location %s is invalid' %conf)
A.R Karthickddf12772017-05-17 13:49:47 -0700328 self.old_cord = False
329 if os.access(self.old_service_profile, os.F_OK):
330 self.old_cord = True
A R Karthickbd9b8a32016-07-21 09:56:45 -0700331 self.onos_ip = onos_ip
A.R Karthickf184b342017-01-27 19:30:50 -0800332 self.onos_cord_dir = conf
A R Karthickbd9b8a32016-07-21 09:56:45 -0700333 self.boot_delay = boot_delay
A.R Karthickf184b342017-01-27 19:30:50 -0800334 self.synchronizer = synchronizer
335 self.service_profile = service_profile
336 self.docker_yaml = os.path.join(conf, 'docker-compose.yml')
337 self.docker_yaml_saved = os.path.join(conf, 'docker-compose.yml.saved')
338 self.onos_config_dir = os.path.join(conf, 'config')
339 self.onos_cfg_save_loc = os.path.join(conf, 'network-cfg.json.saved')
340 instance_active = False
341 #if we have a wrapper onos instance already active, back out
342 if os.access(self.onos_config_dir, os.F_OK) or os.access(self.docker_yaml_saved, os.F_OK):
343 instance_active = True
344 else:
345 if start is True:
346 os.mkdir(self.onos_config_dir)
347 shutil.copy(self.docker_yaml, self.docker_yaml_saved)
A R Karthickd44cea12016-07-20 12:16:41 -0700348
A.R Karthickf184b342017-01-27 19:30:50 -0800349 self.start_wrapper = instance_active is False and start is True
A R Karthickd44cea12016-07-20 12:16:41 -0700350 ##update the docker yaml with the config volume
351 with open(self.docker_yaml, 'r') as f:
352 yaml_config = yaml.load(f)
353 image = yaml_config['services'].keys()[0]
A.R Karthickf184b342017-01-27 19:30:50 -0800354 cord_conf_dir_basename = os.path.basename(self.onos_cord_dir.replace('-', ''))
355 xos_onos_name = '{}_{}_1'.format(cord_conf_dir_basename, image)
A R Karthick5778a792017-01-31 13:47:16 -0800356 if not yaml_config['services'][image].has_key('volumes'):
357 yaml_config['services'][image]['volumes'] = []
A R Karthickd44cea12016-07-20 12:16:41 -0700358 volumes = yaml_config['services'][image]['volumes']
359 config_volumes = filter(lambda e: e.find(self.onos_config_dir_guest) >= 0, volumes)
360 if not config_volumes:
361 config_volume = '{}:{}'.format(self.onos_config_dir, self.onos_config_dir_guest)
362 volumes.append(config_volume)
A.R Karthickf184b342017-01-27 19:30:50 -0800363 if self.start_wrapper:
364 docker_yaml_changed = '{}-changed'.format(self.docker_yaml)
365 with open(docker_yaml_changed, 'w') as wf:
366 yaml.dump(yaml_config, wf)
367 os.rename(docker_yaml_changed, self.docker_yaml)
A R Karthickd44cea12016-07-20 12:16:41 -0700368 self.volumes = volumes
369
A R Karthickd44cea12016-07-20 12:16:41 -0700370 ##Create an container instance of xos onos
A R Karthick52414732017-01-31 09:59:47 -0800371 super(OnosCord, self).__init__(xos_onos_name, image, tag = '', quagga_config = Onos.QUAGGA_CONFIG)
A.R Karthickf184b342017-01-27 19:30:50 -0800372 self.last_cfg = None
373 if self.start_wrapper:
374 #fetch the current config of onos cord instance and save it
375 try:
376 self.last_cfg = OnosCtrl.get_config(controller = onos_ip)
377 json_data = json.dumps(self.last_cfg, indent=4)
378 with open(self.onos_cfg_save_loc, 'w') as f:
379 f.write(json_data)
380 except:
381 pass
382 #start the container back with the shared onos config volume
383 self.start()
A R Karthickd44cea12016-07-20 12:16:41 -0700384
A R Karthick03bd2812017-03-03 17:49:17 -0800385 def cliEnter(self):
386 retries = 0
387 while retries < 30:
388 cli = OnosCliDriver(controller = self.onos_ip, connect = True)
389 if cli.handle:
390 return cli
391 else:
392 retries += 1
A R Karthick72fcbc52017-03-06 12:35:17 -0800393 time.sleep(3)
A R Karthick03bd2812017-03-03 17:49:17 -0800394
395 return None
396
397 def cliExit(self, cli):
398 if cli:
399 cli.disconnect()
400
A.R Karthickddf12772017-05-17 13:49:47 -0700401 def synchronize_fabric(self, cfg = None):
402 if self.old_cord is True:
403 cmds = [ 'cd {} && make {}'.format(self.old_service_profile, self.synchronizer),
404 'sleep 30'
405 ]
406 for cmd in cmds:
407 try:
408 os.system(cmd)
409 except:
410 pass
411
A R Karthick03bd2812017-03-03 17:49:17 -0800412 def synchronize_vtn(self, cfg = None):
A.R Karthickddf12772017-05-17 13:49:47 -0700413 if self.old_cord is True:
414 cmds = [ 'cd {} && make {}'.format(self.old_service_profile, self.synchronizer),
415 'sleep 30'
416 ]
417 for cmd in cmds:
418 try:
419 os.system(cmd)
420 except:
421 pass
422 return
A R Karthick03bd2812017-03-03 17:49:17 -0800423 if cfg is None:
424 return
425 if not cfg.has_key('apps'):
426 return
427 if not cfg['apps'].has_key('org.opencord.vtn'):
428 return
429 vtn_neutron_cfg = cfg['apps']['org.opencord.vtn']['cordvtn']['openstack']
430 password = vtn_neutron_cfg['password']
431 endpoint = vtn_neutron_cfg['endpoint']
432 user = vtn_neutron_cfg['user']
433 tenant = vtn_neutron_cfg['tenant']
434 vtn_host = cfg['apps']['org.opencord.vtn']['cordvtn']['nodes'][0]['hostname']
435 cli = self.cliEnter()
436 if cli is None:
437 return
438 cli.cordVtnSyncNeutronStates(endpoint, password, tenant = tenant, user = user)
439 time.sleep(2)
440 cli.cordVtnNodeInit(vtn_host)
441 self.cliExit(cli)
442
443 def synchronize(self, cfg_unlink = False):
A R Karthick03bd2812017-03-03 17:49:17 -0800444
445 if not self.synchronizer_map.has_key(self.synchronizer):
446 return
447
448 install_list = ()
449 if self.synchronizer_map[self.synchronizer].has_key('install'):
450 install_list = self.synchronizer_map[self.synchronizer]['install']
451
452 activate_list = ()
453 if self.synchronizer_map[self.synchronizer].has_key('activate'):
454 activate_list = self.synchronizer_map[self.synchronizer]['activate']
455
456 for app_url in install_list:
457 print('Installing app from url: %s' %app_url)
458 OnosCtrl.install_app_from_url(None, None, app_url = app_url, onos_ip = self.onos_ip)
459
460 for app in activate_list:
461 print('Activating app %s' %app)
462 OnosCtrl(app, controller = self.onos_ip).activate()
463 time.sleep(2)
464
465 for app_url in self.tester_apps:
466 print('Installing tester app from url: %s' %app_url)
467 OnosCtrl.install_app_from_url(None, None, app_url = app_url, onos_ip = self.onos_ip)
468
A R Karthick72fcbc52017-03-06 12:35:17 -0800469 cfg = None
470 #restore the saved config after applications are activated
471 if os.access(self.onos_cfg_save_loc, os.F_OK):
472 with open(self.onos_cfg_save_loc, 'r') as f:
473 cfg = json.load(f)
474 try:
475 OnosCtrl.config(cfg, controller = self.onos_ip)
476 if cfg_unlink is True:
477 os.unlink(self.onos_cfg_save_loc)
478 except:
479 pass
480
481 if hasattr(self, 'synchronize_{}'.format(self.synchronizer)):
482 getattr(self, 'synchronize_{}'.format(self.synchronizer))(cfg = cfg)
483
484 #now restart the xos synchronizer container
A R Karthick03bd2812017-03-03 17:49:17 -0800485 cmd = 'cd /opt/cord_profile/onboarding-docker-compose && \
486 docker-compose -p {} restart xos_synchronizer_{}'.format(self.service_profile, self.synchronizer)
487 try:
488 print(cmd)
489 os.system(cmd)
490 except: pass
491
A R Karthickd44cea12016-07-20 12:16:41 -0700492 def start(self, restart = False, network_cfg = None):
A R Karthick928ad622017-01-30 12:18:32 -0800493 if network_cfg is not None:
A R Karthickd44cea12016-07-20 12:16:41 -0700494 json_data = json.dumps(network_cfg, indent=4)
495 with open('{}/network-cfg.json'.format(self.onos_config_dir), 'w') as f:
496 f.write(json_data)
A R Karthick52414732017-01-31 09:59:47 -0800497
498 #we avoid using docker-compose restart for now.
499 #since we don't want to retain the metadata across restarts
A R Karthick03bd2812017-03-03 17:49:17 -0800500 #stop and start and synchronize the services before installing tester cord apps
501 cmds = [ 'cd {} && docker-compose down'.format(self.onos_cord_dir),
502 'cd {} && docker-compose up -d'.format(self.onos_cord_dir),
A R Karthickbc894372017-05-12 16:34:08 -0700503 'sleep 150',
A R Karthick03bd2812017-03-03 17:49:17 -0800504 ]
505 for cmd in cmds:
A.R Karthickf184b342017-01-27 19:30:50 -0800506 try:
A R Karthick03bd2812017-03-03 17:49:17 -0800507 print(cmd)
A.R Karthickf184b342017-01-27 19:30:50 -0800508 os.system(cmd)
A R Karthick03bd2812017-03-03 17:49:17 -0800509 except:pass
A R Karthick52414732017-01-31 09:59:47 -0800510
A R Karthick03bd2812017-03-03 17:49:17 -0800511 self.synchronize()
A R Karthick52414732017-01-31 09:59:47 -0800512 ##we could also connect container to default docker network but disabled for now
513 #Container.connect_to_network(self.name, 'bridge')
A R Karthick52414732017-01-31 09:59:47 -0800514 #connect container to the quagga bridge
515 self.connect_to_br(index = 0)
A.R Karthickf184b342017-01-27 19:30:50 -0800516 print('Waiting %d seconds for ONOS instance to start' %self.boot_delay)
A R Karthickbd9b8a32016-07-21 09:56:45 -0700517 time.sleep(self.boot_delay)
A R Karthickd44cea12016-07-20 12:16:41 -0700518
519 def build_image(self):
520 build_cmd = 'cd {} && docker-compose build'.format(self.onos_cord_dir)
521 os.system(build_cmd)
522
A.R Karthickf184b342017-01-27 19:30:50 -0800523 def restore(self, force = False):
524 restore = self.start_wrapper is True or force is True
525 if not restore:
A.R Karthick263d3fc2017-01-27 12:52:53 -0800526 return
A R Karthick394976f2017-01-31 14:25:16 -0800527 #nothing to restore
528 if not os.access(self.docker_yaml_saved, os.F_OK):
529 return
A R Karthick03bd2812017-03-03 17:49:17 -0800530
A.R Karthickf184b342017-01-27 19:30:50 -0800531 #restore the config files back. The synchronizer restore should bring the last config back
532 cmds = ['cd {} && docker-compose down'.format(self.onos_cord_dir),
533 'rm -rf {}'.format(self.onos_config_dir),
534 'mv {} {}'.format(self.docker_yaml_saved, self.docker_yaml),
535 'cd {} && docker-compose up -d'.format(self.onos_cord_dir),
A R Karthickbc894372017-05-12 16:34:08 -0700536 'sleep 150',
A.R Karthickf184b342017-01-27 19:30:50 -0800537 ]
538 for cmd in cmds:
A.R Karthickb17e2022017-01-27 11:29:26 -0800539 try:
A.R Karthickf184b342017-01-27 19:30:50 -0800540 print(cmd)
541 os.system(cmd)
A.R Karthickb17e2022017-01-27 11:29:26 -0800542 except: pass
543
A R Karthick03bd2812017-03-03 17:49:17 -0800544 self.synchronize(cfg_unlink = True)
A.R Karthickb17e2022017-01-27 11:29:26 -0800545
A.R Karthick1700e0e2016-10-06 18:16:57 -0700546class OnosCordStopWrapper(Container):
547 onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord')
548 docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml')
549
550 def __init__(self):
551 if os.access(self.docker_yaml, os.F_OK):
552 with open(self.docker_yaml, 'r') as f:
553 yaml_config = yaml.load(f)
554 image = yaml_config['services'].keys()[0]
555 name = 'cordtestercord_{}_1'.format(image)
556 super(OnosCordStopWrapper, self).__init__(name, image, tag = '')
557 if self.exists():
558 print('Killing container %s' %self.name)
559 self.kill()
560
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700561class Onos(Container):
A R Karthickaa54a1c2016-12-15 11:42:08 -0800562 QUAGGA_CONFIG = [ { 'bridge' : 'quagga-br', 'ip': '10.10.0.4', 'mask' : 16 }, ]
A R Karthicka2492c12016-12-16 10:31:51 -0800563 MAX_INSTANCES = 3
A R Karthickc69d73e2017-01-20 11:44:34 -0800564 JVM_HEAP_SIZE = None
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700565 SYSTEM_MEMORY = (get_mem(),) * 2
A R Karthicka2492c12016-12-16 10:31:51 -0800566 INSTANCE_MEMORY = (get_mem(instances=MAX_INSTANCES),) * 2
A R Karthickc69d73e2017-01-20 11:44:34 -0800567 JAVA_OPTS_FORMAT = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode'
568 JAVA_OPTS_DEFAULT = JAVA_OPTS_FORMAT.format(*SYSTEM_MEMORY) #-XX:+PrintGCDetails -XX:+PrintGCTimeStamps'
569 JAVA_OPTS_CLUSTER_DEFAULT = JAVA_OPTS_FORMAT.format(*INSTANCE_MEMORY)
570 env = { 'ONOS_APPS' : 'drivers,openflow,proxyarp,vrouter', 'JAVA_OPTS' : JAVA_OPTS_DEFAULT }
A.R Karthicka6c88fd2017-03-13 09:29:41 -0700571 onos_cord_apps = ( ('cord-config', '1.2-SNAPSHOT'),
A R Karthicka652c4a2017-03-10 17:47:08 -0800572 ('aaa', '1.2-SNAPSHOT'),
A.R Karthicka6c88fd2017-03-13 09:29:41 -0700573 ('igmp', '1.2-SNAPSHOT'),
A.R Karthick95d044e2016-06-10 18:44:36 -0700574 )
A.R Karthickdda22062017-02-09 14:39:20 -0800575 ports = [] #[ 8181, 8101, 9876, 6653, 6633, 2000, 2620, 5005 ]
A R Karthickf2f4ca62016-08-17 10:34:08 -0700576 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
577 host_config_dir = os.path.join(setup_dir, 'onos-config')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700578 guest_config_dir = '/root/onos/config'
A.R Karthickdda22062017-02-09 14:39:20 -0800579 guest_data_dir = '/root/onos/apache-karaf-3.0.8/data'
580 guest_log_file = '/root/onos/apache-karaf-3.0.8/data/log/karaf.log'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700581 onos_gen_partitions = os.path.join(setup_dir, 'onos-gen-partitions')
A R Karthick2b93d6a2016-09-06 15:19:09 -0700582 onos_form_cluster = os.path.join(setup_dir, 'onos-form-cluster')
A.R Karthick95d044e2016-06-10 18:44:36 -0700583 cord_apps_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'apps')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700584 host_guest_map = ( (host_config_dir, guest_config_dir), )
A R Karthick2b93d6a2016-09-06 15:19:09 -0700585 cluster_cfg = os.path.join(host_config_dir, 'cluster.json')
586 cluster_mode = False
587 cluster_instances = []
Chetan Gaonker503032a2016-05-12 12:06:29 -0700588 NAME = 'cord-onos'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700589 ##the ip of ONOS in default cluster.json in setup/onos-config
590 CLUSTER_CFG_IP = '172.17.0.2'
A R Karthick07608ef2016-08-23 16:51:19 -0700591 IMAGE = 'onosproject/onos'
592 TAG = 'latest'
593 PREFIX = ''
A R Karthickf2f4ca62016-08-17 10:34:08 -0700594
595 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700596 def generate_cluster_cfg(cls, ip):
597 if type(ip) in [ list, tuple ]:
598 ips = ' '.join(ip)
599 else:
600 ips = ip
A R Karthickf2f4ca62016-08-17 10:34:08 -0700601 try:
A R Karthick2b93d6a2016-09-06 15:19:09 -0700602 cmd = '{} {} {}'.format(cls.onos_gen_partitions, cls.cluster_cfg, ips)
603 os.system(cmd)
604 except: pass
605
606 @classmethod
607 def form_cluster(cls, ips):
608 nodes = ' '.join(ips)
609 try:
610 cmd = '{} {}'.format(cls.onos_form_cluster, nodes)
A R Karthickf2f4ca62016-08-17 10:34:08 -0700611 os.system(cmd)
612 except: pass
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700613
A R Karthick9d48c652016-09-15 09:16:36 -0700614 @classmethod
615 def cleanup_runtime(cls):
616 '''Cleanup ONOS runtime generated files'''
617 files = ( Onos.cluster_cfg, os.path.join(Onos.host_config_dir, 'network-cfg.json') )
618 for f in files:
619 if os.access(f, os.F_OK):
620 try:
621 os.unlink(f)
622 except: pass
623
A R Karthickec2db322016-11-17 15:06:01 -0800624 @classmethod
625 def get_data_map(cls, host_volume, guest_volume_dir):
626 host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume))
627 if not os.path.exists(host_volume_dir):
628 os.mkdir(host_volume_dir)
629 return ( (host_volume_dir, guest_volume_dir), )
630
631 @classmethod
632 def remove_data_map(cls, host_volume, guest_volume_dir):
633 host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume))
634 if os.path.exists(host_volume_dir):
A.R Karthickf184b342017-01-27 19:30:50 -0800635 shutil.rmtree(host_volume_dir)
A R Karthickec2db322016-11-17 15:06:01 -0800636
A R Karthick973010f2017-02-06 16:41:51 -0800637 @classmethod
638 def update_data_dir(cls, karaf):
639 Onos.guest_data_dir = '/root/onos/apache-karaf-{}/data'.format(karaf)
640 Onos.guest_log_file = '/root/onos/apache-karaf-{}/data/log/karaf.log'.format(karaf)
641
A R Karthickec2db322016-11-17 15:06:01 -0800642 def remove_data_volume(self):
643 if self.data_map is not None:
644 self.remove_data_map(*self.data_map)
645
A.R Karthick1700e0e2016-10-06 18:16:57 -0700646 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthickec2db322016-11-17 15:06:01 -0800647 boot_delay = 20, restart = False, network_cfg = None,
A R Karthick85eb1862017-01-23 16:10:57 -0800648 cluster = False, data_volume = None, async = False, quagga_config = None,
649 network = None):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700650 if restart is True:
651 ##Find the right image to restart
652 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
653 if running_image:
654 image_name = running_image[0]['Image']
655 try:
656 image = image_name.split(':')[0]
657 tag = image_name.split(':')[1]
658 except: pass
659
A R Karthickaa54a1c2016-12-15 11:42:08 -0800660 if quagga_config is None:
661 quagga_config = Onos.QUAGGA_CONFIG
662 super(Onos, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = quagga_config)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700663 self.boot_delay = boot_delay
A R Karthickec2db322016-11-17 15:06:01 -0800664 self.data_map = None
A R Karthickc69d73e2017-01-20 11:44:34 -0800665 instance_memory = (get_mem(jvm_heap_size = Onos.JVM_HEAP_SIZE, instances = Onos.MAX_INSTANCES),) * 2
666 self.env['JAVA_OPTS'] = self.JAVA_OPTS_FORMAT.format(*instance_memory)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700667 if cluster is True:
668 self.ports = []
A R Karthickec2db322016-11-17 15:06:01 -0800669 if data_volume is not None:
670 self.data_map = self.get_data_map(data_volume, self.guest_data_dir)
671 self.host_guest_map = self.host_guest_map + self.data_map
A R Karthick2b93d6a2016-09-06 15:19:09 -0700672 if os.access(self.cluster_cfg, os.F_OK):
673 try:
674 os.unlink(self.cluster_cfg)
675 except: pass
676
677 self.host_config = self.create_host_config(port_list = self.ports,
678 host_guest_map = self.host_guest_map)
679 self.volumes = []
680 for _,g in self.host_guest_map:
681 self.volumes.append(g)
682
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700683 if restart is True and self.exists():
684 self.kill()
A R Karthick2b93d6a2016-09-06 15:19:09 -0700685
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700686 if not self.exists():
687 self.remove_container(name, force=True)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700688 host_config = self.create_host_config(port_list = self.ports,
689 host_guest_map = self.host_guest_map)
690 volumes = []
691 for _,g in self.host_guest_map:
692 volumes.append(g)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700693 if network_cfg is not None:
A R Karthick81acbff2016-06-17 14:45:16 -0700694 json_data = json.dumps(network_cfg, indent=4)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700695 with open('{}/network-cfg.json'.format(self.host_config_dir), 'w') as f:
696 f.write(json_data)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800697 if cluster is False or async is False:
698 print('Starting ONOS container %s' %self.name)
699 self.start(ports = self.ports, environment = self.env,
700 host_config = self.host_config, volumes = self.volumes, tty = True)
701 if not restart:
702 ##wait a bit before fetching IP to regenerate cluster cfg
703 time.sleep(5)
704 ip = self.ip()
705 ##Just a quick hack/check to ensure we don't regenerate in the common case.
706 ##As ONOS is usually the first test container that is started
707 if cluster is False:
708 if ip != self.CLUSTER_CFG_IP or not os.access(self.cluster_cfg, os.F_OK):
709 print('Regenerating ONOS cluster cfg for ip %s' %ip)
710 self.generate_cluster_cfg(ip)
711 self.kill()
712 self.remove_container(self.name, force=True)
713 print('Restarting ONOS container %s' %self.name)
714 self.start(ports = self.ports, environment = self.env,
715 host_config = self.host_config, volumes = self.volumes, tty = True)
716 print('Waiting for ONOS to boot')
717 time.sleep(boot_delay)
718 self.wait_for_onos_start(self.ip())
719 self.running = True
720 else:
721 self.running = False
722 else:
723 self.running = True
724 if self.running:
725 self.ipaddr = self.ip()
726 if cluster is False:
727 self.install_cord_apps(self.ipaddr)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800728
A.R Karthickc4e474d2016-12-12 15:24:57 -0800729 @classmethod
730 def get_quagga_config(cls, instance = 0):
A R Karthickaa54a1c2016-12-15 11:42:08 -0800731 quagga_config = copy.deepcopy(cls.QUAGGA_CONFIG)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800732 if instance == 0:
733 return quagga_config
734 ip = quagga_config[0]['ip']
735 octets = ip.split('.')
A R Karthickaa54a1c2016-12-15 11:42:08 -0800736 octets[3] = str((int(octets[3]) + instance) & 255)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800737 ip = '.'.join(octets)
738 quagga_config[0]['ip'] = ip
739 return quagga_config
740
741 @classmethod
742 def start_cluster_async(cls, onos_instances):
743 instances = filter(lambda o: o.running == False, onos_instances)
744 if not instances:
745 return
746 tpool = ThreadPool(len(instances), queue_size = 1, wait_timeout = 1)
747 for onos in instances:
748 tpool.addTask(onos.start_async)
749 tpool.cleanUpThreads()
750
751 def start_async(self):
752 print('Starting ONOS container %s' %self.name)
753 self.start(ports = self.ports, environment = self.env,
754 host_config = self.host_config, volumes = self.volumes, tty = True)
755 time.sleep(3)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700756 self.ipaddr = self.ip()
A.R Karthickc4e474d2016-12-12 15:24:57 -0800757 print('Waiting for ONOS container %s to start' %self.name)
758 self.wait_for_onos_start(self.ipaddr)
759 self.running = True
760 print('ONOS container %s started' %self.name)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700761
A R Karthick2b93d6a2016-09-06 15:19:09 -0700762 @classmethod
A R Karthick19aaf5c2016-11-09 17:47:57 -0800763 def wait_for_onos_start(cls, ip, tries = 30):
A R Karthick973010f2017-02-06 16:41:51 -0800764 onos_log = OnosLog(host = ip, log_file = Onos.guest_log_file)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800765 num_tries = 0
766 started = None
767 while not started and num_tries < tries:
768 time.sleep(3)
769 started = onos_log.search_log_pattern('ApplicationManager .* Started')
770 num_tries += 1
771
A R Karthick19aaf5c2016-11-09 17:47:57 -0800772 if not started:
773 print('ONOS did not start')
774 else:
775 print('ONOS started')
776 return started
777
778 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700779 def setup_cluster_deprecated(cls, onos_instances, image_name = None):
780 if not onos_instances or len(onos_instances) < 2:
781 return
782 ips = []
783 if image_name is not None:
784 ips = Container.ips(image_name)
785 else:
786 for onos in onos_instances:
787 ips.append(onos.ipaddr)
788 Onos.cluster_instances = onos_instances
789 Onos.cluster_mode = True
790 ##regenerate the cluster json with the 3 instance ips before restarting them back
791 print('Generating cluster cfg for ONOS instances with ips %s' %ips)
792 Onos.generate_cluster_cfg(ips)
793 for onos in onos_instances:
794 onos.kill()
795 onos.remove_container(onos.name, force=True)
796 print('Restarting ONOS container %s for forming cluster' %onos.name)
797 onos.start(ports = onos.ports, environment = onos.env,
798 host_config = onos.host_config, volumes = onos.volumes, tty = True)
799 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
800 time.sleep(onos.boot_delay)
801 onos.ipaddr = onos.ip()
802 onos.install_cord_apps(onos.ipaddr)
803
804 @classmethod
805 def setup_cluster(cls, onos_instances, image_name = None):
806 if not onos_instances or len(onos_instances) < 2:
807 return
808 ips = []
809 if image_name is not None:
810 ips = Container.ips(image_name)
811 else:
812 for onos in onos_instances:
813 ips.append(onos.ipaddr)
814 Onos.cluster_instances = onos_instances
815 Onos.cluster_mode = True
816 ##regenerate the cluster json with the 3 instance ips before restarting them back
817 print('Forming cluster for ONOS instances with ips %s' %ips)
818 Onos.form_cluster(ips)
819 ##wait for the cluster to be formed
820 print('Waiting for the cluster to be formed')
821 time.sleep(60)
822 for onos in onos_instances:
823 onos.install_cord_apps(onos.ipaddr)
824
825 @classmethod
A R Karthicke2c24bd2016-10-07 14:51:38 -0700826 def add_cluster(cls, count = 1, network_cfg = None):
827 if not cls.cluster_instances or Onos.cluster_mode is False:
828 return
829 for i in range(count):
830 name = '{}-{}'.format(Onos.NAME, len(cls.cluster_instances)+1)
831 onos = cls(name = name, image = Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX,
832 cluster = True, network_cfg = network_cfg)
833 cls.cluster_instances.append(onos)
834
835 cls.setup_cluster(cls.cluster_instances)
836
837 @classmethod
A.R Karthick2560f042016-11-30 14:38:52 -0800838 def restart_cluster(cls, network_cfg = None, timeout = 10, setup = False):
A R Karthick2b93d6a2016-09-06 15:19:09 -0700839 if cls.cluster_mode is False:
840 return
841 if not cls.cluster_instances:
842 return
843
844 if network_cfg is not None:
845 json_data = json.dumps(network_cfg, indent=4)
846 with open('{}/network-cfg.json'.format(cls.host_config_dir), 'w') as f:
847 f.write(json_data)
848
A.R Karthick2560f042016-11-30 14:38:52 -0800849 cls.cleanup_cluster()
850 if timeout > 0:
851 time.sleep(timeout)
852
A R Karthickaa54a1c2016-12-15 11:42:08 -0800853 #start the instances asynchronously
854 cls.start_cluster_async(cls.cluster_instances)
855 time.sleep(5)
A.R Karthick2560f042016-11-30 14:38:52 -0800856 ##form the cluster as appropriate
857 if setup is True:
858 cls.setup_cluster(cls.cluster_instances)
A R Karthickaa54a1c2016-12-15 11:42:08 -0800859 else:
860 for onos in cls.cluster_instances:
861 onos.install_cord_apps(onos.ipaddr)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700862
863 @classmethod
864 def cluster_ips(cls):
865 if cls.cluster_mode is False:
866 return []
867 if not cls.cluster_instances:
868 return []
869 ips = [ onos.ipaddr for onos in cls.cluster_instances ]
870 return ips
871
872 @classmethod
873 def cleanup_cluster(cls):
874 if cls.cluster_mode is False:
875 return
876 if not cls.cluster_instances:
877 return
878 for onos in cls.cluster_instances:
879 if onos.exists():
880 onos.kill()
A R Karthickaa54a1c2016-12-15 11:42:08 -0800881 onos.running = False
A R Karthick2b93d6a2016-09-06 15:19:09 -0700882 onos.remove_container(onos.name, force=True)
A R Karthickd44cea12016-07-20 12:16:41 -0700883
A.R Karthick95d044e2016-06-10 18:44:36 -0700884 @classmethod
A R Karthickde6b9dc2016-11-29 17:46:16 -0800885 def restart_node(cls, node = None, network_cfg = None, timeout = 10):
A R Karthick889d9652016-10-03 14:13:45 -0700886 if node is None:
887 cls(restart = True, network_cfg = network_cfg, image = cls.IMAGE, tag = cls.TAG)
888 else:
889 #Restarts a node in the cluster
890 valid_node = filter(lambda onos: node in [ onos.ipaddr, onos.name ], cls.cluster_instances)
891 if valid_node:
892 onos = valid_node.pop()
893 if onos.exists():
894 onos.kill()
895 onos.remove_container(onos.name, force=True)
A R Karthickde6b9dc2016-11-29 17:46:16 -0800896 if timeout > 0:
897 time.sleep(timeout)
A R Karthick889d9652016-10-03 14:13:45 -0700898 print('Restarting ONOS container %s' %onos.name)
899 onos.start(ports = onos.ports, environment = onos.env,
900 host_config = onos.host_config, volumes = onos.volumes, tty = True)
A R Karthick889d9652016-10-03 14:13:45 -0700901 onos.ipaddr = onos.ip()
A.R Karthick2560f042016-11-30 14:38:52 -0800902 onos.wait_for_onos_start(onos.ipaddr)
903 onos.install_cord_apps(onos.ipaddr)
A R Karthick889d9652016-10-03 14:13:45 -0700904
905 @classmethod
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700906 def install_cord_apps(cls, onos_ip = None):
A.R Karthick95d044e2016-06-10 18:44:36 -0700907 for app, version in cls.onos_cord_apps:
908 app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version)
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700909 ok, code = OnosCtrl.install_app(app_file, onos_ip = onos_ip)
A.R Karthick95d044e2016-06-10 18:44:36 -0700910 ##app already installed (conflicts)
911 if code in [ 409 ]:
912 ok = True
913 print('ONOS app %s, version %s %s' %(app, version, 'installed' if ok else 'failed to install'))
914 time.sleep(2)
915
A.R Karthick1700e0e2016-10-06 18:16:57 -0700916class OnosStopWrapper(Container):
917 def __init__(self, name):
918 super(OnosStopWrapper, self).__init__(name, Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX)
919 if self.exists():
920 self.kill()
A R Karthickaa54a1c2016-12-15 11:42:08 -0800921 self.running = False
A.R Karthick1700e0e2016-10-06 18:16:57 -0700922 else:
923 if Onos.cluster_mode is True:
924 valid_node = filter(lambda onos: name in [ onos.ipaddr, onos.name ], Onos.cluster_instances)
925 if valid_node:
926 onos = valid_node.pop()
927 if onos.exists():
928 onos.kill()
A R Karthickaa54a1c2016-12-15 11:42:08 -0800929 onos.running = False
A.R Karthick1700e0e2016-10-06 18:16:57 -0700930
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700931class Radius(Container):
932 ports = [ 1812, 1813 ]
A R Karthick41adfce2016-06-10 09:51:25 -0700933 env = {'TIMEZONE':'America/Los_Angeles',
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700934 'DEBUG': 'true', 'cert_password':'whatever', 'primary_shared_secret':'radius_password'
935 }
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700936 host_db_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/db')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700937 guest_db_dir = os.path.join(os.path.sep, 'opt', 'db')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700938 host_config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/freeradius')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700939 guest_config_dir = os.path.join(os.path.sep, 'etc', 'freeradius')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700940 start_command = os.path.join(guest_config_dir, 'start-radius.py')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700941 host_guest_map = ( (host_db_dir, guest_db_dir),
942 (host_config_dir, guest_config_dir)
943 )
A R Karthickf7a613b2017-02-24 09:36:44 -0800944 IMAGE = 'cordtest/radius'
Chetan Gaonker503032a2016-05-12 12:06:29 -0700945 NAME = 'cord-radius'
946
A R Karthick07608ef2016-08-23 16:51:19 -0700947 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
A R Karthick85eb1862017-01-23 16:10:57 -0800948 boot_delay = 10, restart = False, update = False, network = None):
A R Karthick07608ef2016-08-23 16:51:19 -0700949 super(Radius, self).__init__(name, image, prefix = prefix, tag = tag, command = self.start_command)
Chetan Gaonker503032a2016-05-12 12:06:29 -0700950 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -0700951 self.build_image(self.image_name)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700952 if restart is True and self.exists():
953 self.kill()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700954 if not self.exists():
955 self.remove_container(name, force=True)
956 host_config = self.create_host_config(port_list = self.ports,
957 host_guest_map = self.host_guest_map)
958 volumes = []
959 for _,g in self.host_guest_map:
960 volumes.append(g)
A R Karthick41adfce2016-06-10 09:51:25 -0700961 self.start(ports = self.ports, environment = self.env,
962 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700963 host_config = host_config, tty = True)
A R Karthick85eb1862017-01-23 16:10:57 -0800964 if network is not None:
965 Container.connect_to_network(self.name, network)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700966 time.sleep(boot_delay)
967
968 @classmethod
969 def build_image(cls, image):
970 print('Building Radius image %s' %image)
971 dockerfile = '''
972FROM hbouvier/docker-radius
973MAINTAINER chetan@ciena.com
974LABEL RUN docker pull hbouvier/docker-radius
975LABEL RUN docker run -it --name cord-radius hbouvier/docker-radius
A R Karthickc762df42016-05-25 10:09:21 -0700976RUN apt-get update && \
977 apt-get -y install python python-pexpect strace
Chetan Gaonker7f4bf742016-05-04 15:56:08 -0700978WORKDIR /root
979CMD ["/etc/freeradius/start-radius.py"]
980'''
981 super(Radius, cls).build_image(dockerfile, image)
982 print('Done building image %s' %image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700983
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700984class Quagga(Container):
A R Karthickaa54a1c2016-12-15 11:42:08 -0800985 QUAGGA_CONFIG = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 },
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700986 { 'bridge' : 'quagga-br', 'ip': '192.168.10.3', 'mask': 16 },
987 )
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700988 ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ]
989 host_quagga_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/quagga-config')
990 guest_quagga_config = '/root/config'
991 quagga_config_file = os.path.join(guest_quagga_config, 'testrib.conf')
992 host_guest_map = ( (host_quagga_config, guest_quagga_config), )
A R Karthickf7a613b2017-02-24 09:36:44 -0800993 IMAGE = 'cordtest/quagga'
Chetan Gaonker503032a2016-05-12 12:06:29 -0700994 NAME = 'cord-quagga'
995
A R Karthick07608ef2016-08-23 16:51:19 -0700996 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
A R Karthick85eb1862017-01-23 16:10:57 -0800997 boot_delay = 15, restart = False, config_file = quagga_config_file, update = False,
998 network = None):
A R Karthickaa54a1c2016-12-15 11:42:08 -0800999 super(Quagga, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.QUAGGA_CONFIG)
Chetan Gaonker503032a2016-05-12 12:06:29 -07001000 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -07001001 self.build_image(self.image_name)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001002 if restart is True and self.exists():
1003 self.kill()
1004 if not self.exists():
1005 self.remove_container(name, force=True)
A R Karthick41adfce2016-06-10 09:51:25 -07001006 host_config = self.create_host_config(port_list = self.ports,
1007 host_guest_map = self.host_guest_map,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001008 privileged = True)
1009 volumes = []
1010 for _,g in self.host_guest_map:
1011 volumes.append(g)
1012 self.start(ports = self.ports,
A R Karthick41adfce2016-06-10 09:51:25 -07001013 host_config = host_config,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001014 volumes = volumes, tty = True)
A R Karthick85eb1862017-01-23 16:10:57 -08001015 if network is not None:
1016 Container.connect_to_network(self.name, network)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001017 print('Starting Quagga on container %s' %self.name)
1018 self.execute('{0}/start.sh {1}'.format(self.guest_quagga_config, config_file))
1019 time.sleep(boot_delay)
1020
1021 @classmethod
1022 def build_image(cls, image):
A R Karthickaa54a1c2016-12-15 11:42:08 -08001023 onos_quagga_ip = Onos.QUAGGA_CONFIG[0]['ip']
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001024 print('Building Quagga image %s' %image)
1025 dockerfile = '''
A R Karthick41adfce2016-06-10 09:51:25 -07001026FROM ubuntu:14.04
1027MAINTAINER chetan@ciena.com
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001028WORKDIR /root
1029RUN useradd -M quagga
1030RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga
1031RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga
A R Karthick973ea692016-10-17 12:23:02 -07001032RUN 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 -07001033RUN git clone git://git.savannah.nongnu.org/quagga.git quagga && \
A R Karthick8f69c2c2016-10-21 11:43:26 -07001034(cd quagga && git checkout quagga-1.0.20160315 && ./bootstrap.sh && \
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001035sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \
1036./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install)
1037RUN ldconfig
1038'''.format(onos_quagga_ip)
1039 super(Quagga, cls).build_image(dockerfile, image)
1040 print('Done building image %s' %image)
A R Karthick81acbff2016-06-17 14:45:16 -07001041
A.R Karthick1700e0e2016-10-06 18:16:57 -07001042class QuaggaStopWrapper(Container):
1043 def __init__(self, name = Quagga.NAME, image = Quagga.IMAGE, tag = 'candidate'):
1044 super(QuaggaStopWrapper, self).__init__(name, image, prefix = Container.IMAGE_PREFIX, tag = tag)
1045 if self.exists():
1046 self.kill()
1047
1048
A R Karthick81acbff2016-06-17 14:45:16 -07001049def reinitContainerClients():
1050 docker_netns.dckr = Client()
1051 Container.dckr = Client()
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001052
1053class Xos(Container):
1054 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
1055 TAG = 'latest'
1056 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -07001057 host_guest_map = None
1058 env = None
1059 ports = None
1060 volumes = None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001061
A R Karthick6e80afd2016-10-10 16:03:12 -07001062 @classmethod
1063 def get_cmd(cls, img_name):
1064 cmd = cls.dckr.inspect_image(img_name)['Config']['Cmd']
1065 return ' '.join(cmd)
1066
A R Karthicke3bde962016-09-27 15:06:35 -07001067 def __init__(self, name, image, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001068 boot_delay = 20, restart = False, network_cfg = None, update = False):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001069 if restart is True:
1070 ##Find the right image to restart
1071 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
1072 if running_image:
1073 image_name = running_image[0]['Image']
1074 try:
1075 image = image_name.split(':')[0]
1076 tag = image_name.split(':')[1]
1077 except: pass
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001078 super(Xos, self).__init__(name, image, prefix = prefix, tag = tag)
1079 if update is True or not self.img_exists():
1080 self.build_image(self.image_name)
A R Karthick6e80afd2016-10-10 16:03:12 -07001081 self.command = self.get_cmd(self.image_name).strip() or None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001082 if restart is True and self.exists():
1083 self.kill()
1084 if not self.exists():
1085 self.remove_container(name, force=True)
A R Karthicke3bde962016-09-27 15:06:35 -07001086 host_config = self.create_host_config(port_list = self.ports,
1087 host_guest_map = self.host_guest_map,
1088 privileged = True)
1089 print('Starting XOS container %s' %self.name)
1090 self.start(ports = self.ports, environment = self.env, host_config = host_config,
1091 volumes = self.volumes, tty = True)
1092 print('Waiting %d seconds for XOS Base Container to boot' %(boot_delay))
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001093 time.sleep(boot_delay)
1094
1095 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -07001096 def build_image(cls, image, dockerfile_path, image_target = 'build'):
1097 cmd = 'cd {} && make {}'.format(dockerfile_path, image_target)
1098 print('Building XOS %s' %image)
1099 res = os.system(cmd)
1100 print('Done building image %s. Image build %s' %(image, 'successful' if res == 0 else 'failed'))
1101 return res
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001102
A R Karthicke3bde962016-09-27 15:06:35 -07001103class XosServer(Xos):
1104 ports = [8000,9998,9999]
1105 NAME = 'xos-server'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001106 IMAGE = 'xosproject/xos'
A R Karthicke3bde962016-09-27 15:06:35 -07001107 BASE_IMAGE = 'xosproject/xos-base'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001108 TAG = 'latest'
1109 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -07001110 dockerfile_path = os.path.join(Xos.setup_dir, 'xos')
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001111
A R Karthicke3bde962016-09-27 15:06:35 -07001112 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001113 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001114 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001115
1116 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -07001117 def build_image(cls, image = IMAGE):
1118 ##build the base image and then build the server image
1119 Xos.build_image(cls.BASE_IMAGE, cls.dockerfile_path, image_target = 'base')
1120 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001121
A R Karthicke3bde962016-09-27 15:06:35 -07001122class XosSynchronizerOpenstack(Xos):
1123 ports = [2375,]
1124 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer')
1125 NAME = 'xos-synchronizer'
1126 IMAGE = 'xosproject/xos-synchronizer-openstack'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001127 TAG = 'latest'
1128 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -07001129 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001130
A R Karthicke3bde962016-09-27 15:06:35 -07001131 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -07001132 tag = TAG, boot_delay = 20, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001133 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001134
1135 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -07001136 def build_image(cls, image = IMAGE):
1137 XosServer.build_image()
1138 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001139
A R Karthicke3bde962016-09-27 15:06:35 -07001140class XosSynchronizerOnboarding(Xos):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001141 NAME = 'xos-synchronizer-onboarding'
1142 IMAGE = 'xosproject/xos-synchronizer-onboarding'
1143 TAG = 'latest'
1144 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -07001145 dockerfile_path = os.path.join(Xos.setup_dir, 'onboarding_synchronizer')
1146 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001147
A R Karthicke3bde962016-09-27 15:06:35 -07001148 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -07001149 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001150 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001151
1152 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -07001153 def build_image(cls, image = IMAGE):
1154 XosSynchronizerOpenstack.build_image()
1155 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001156
A R Karthicke3bde962016-09-27 15:06:35 -07001157class XosSynchronizerOpenvpn(Xos):
1158 NAME = 'xos-synchronizer-openvpn'
1159 IMAGE = 'xosproject/xos-openvpn'
1160 TAG = 'latest'
1161 PREFIX = ''
1162 dockerfile_path = os.path.join(Xos.setup_dir, 'openvpn')
1163 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001164
A R Karthicke3bde962016-09-27 15:06:35 -07001165 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -07001166 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001167 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1168
1169 @classmethod
1170 def build_image(cls, image = IMAGE):
1171 XosSynchronizerOpenstack.build_image()
1172 Xos.build_image(image, cls.dockerfile_path)
1173
1174class XosPostgresql(Xos):
1175 ports = [5432,]
1176 NAME = 'xos-db-postgres'
1177 IMAGE = 'xosproject/xos-postgres'
1178 TAG = 'latest'
1179 PREFIX = ''
1180 volumes = ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
1181 dockerfile_path = os.path.join(Xos.setup_dir, 'postgresql')
1182
1183 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -07001184 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001185 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1186
1187 @classmethod
1188 def build_image(cls, image = IMAGE):
1189 Xos.build_image(image, cls.dockerfile_path)
1190
1191class XosSyndicateMs(Xos):
1192 ports = [8080,]
1193 env = None
1194 NAME = 'xos-syndicate-ms'
1195 IMAGE = 'xosproject/syndicate-ms'
1196 TAG = 'latest'
1197 PREFIX = ''
1198 dockerfile_path = os.path.join(Xos.setup_dir, 'syndicate-ms')
1199
1200 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001201 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001202 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1203
1204 @classmethod
1205 def build_image(cls, image = IMAGE):
1206 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001207
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001208class XosSyncVtn(Xos):
1209 ports = [8080,]
1210 env = None
1211 NAME = 'xos-synchronizer-vtn'
1212 IMAGE = 'xosproject/xos-synchronizer-vtn'
1213 TAG = 'latest'
1214 PREFIX = ''
1215 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtn')
1216
1217 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001218 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001219 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1220
1221 @classmethod
1222 def build_image(cls, image = IMAGE):
1223 Xos.build_image(image, cls.dockerfile_path)
1224
1225class XosSyncVtr(Xos):
1226 ports = [8080,]
1227 env = None
1228 NAME = 'xos-synchronizer-vtr'
1229 IMAGE = 'xosproject/xos-synchronizer-vtr'
1230 TAG = 'latest'
1231 PREFIX = ''
1232 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtr')
1233
1234 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001235 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001236 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1237
1238 @classmethod
1239 def build_image(cls, image = IMAGE):
1240 Xos.build_image(image, cls.dockerfile_path)
1241
1242class XosSyncVsg(Xos):
1243 ports = [8080,]
1244 env = None
1245 NAME = 'xos-synchronizer-vsg'
1246 IMAGE = 'xosproject/xos-synchronizer-vsg'
1247 TAG = 'latest'
1248 PREFIX = ''
1249 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vsg')
1250
1251 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001252 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001253 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1254
1255 @classmethod
1256 def build_image(cls, image = IMAGE):
1257 Xos.build_image(image, cls.dockerfile_path)
1258
1259
1260class XosSyncOnos(Xos):
1261 ports = [8080,]
1262 env = None
1263 NAME = 'xos-synchronizer-onos'
1264 IMAGE = 'xosproject/xos-synchronizer-onos'
1265 TAG = 'latest'
1266 PREFIX = ''
1267 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-onos')
1268
1269 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001270 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001271 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1272
1273 @classmethod
1274 def build_image(cls, image = IMAGE):
1275 Xos.build_image(image, cls.dockerfile_path)
1276
1277class XosSyncFabric(Xos):
1278 ports = [8080,]
1279 env = None
1280 NAME = 'xos-synchronizer-fabric'
1281 IMAGE = 'xosproject/xos-synchronizer-fabric'
1282 TAG = 'latest'
1283 PREFIX = ''
1284 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-fabric')
1285
1286 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001287 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001288 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1289
1290 @classmethod
1291 def build_image(cls, image = IMAGE):
1292 Xos.build_image(image, cls.dockerfile_path)
A R Karthick19aaf5c2016-11-09 17:47:57 -08001293
1294if __name__ == '__main__':
1295 onos = Onos(boot_delay = 10, restart = True)