blob: 841fcd03f033d96da498cffa8acac1edd3c627f1 [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:
A R Karthick184945a2017-07-25 17:23:57 -070099 if type(p) is tuple:
100 port_bindings[str(p[0])] = str(p[1])
101 else:
102 port_bindings[str(p)] = str(p)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700103
104 if host_guest_map:
105 binds = []
106 for h, g in host_guest_map:
107 binds.append('{0}:{1}'.format(h, g))
108
109 return cls.dckr.create_host_config(binds = binds, port_bindings = port_bindings, privileged = privileged)
110
111 @classmethod
A R Karthick85eb1862017-01-23 16:10:57 -0800112 def connect_to_network(cls, name, network):
113 try:
114 cls.dckr.connect_container_to_network(name, network)
115 return True
116 except:
117 return False
118
119 @classmethod
120 def create_network(cls, network, subnet = None, gateway = None):
121 ipam_config = None
122 if subnet is not None and gateway is not None:
123 ipam_pool = dockerutils.create_ipam_pool(subnet = subnet, gateway = gateway)
124 ipam_config = dockerutils.create_ipam_config(pool_configs = [ipam_pool])
125 cls.dckr.create_network(network, driver='bridge', ipam = ipam_config)
126
127 @classmethod
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700128 def cleanup(cls, image):
A R Karthick09b1f4e2016-05-12 14:31:50 -0700129 cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True))
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700130 for cnt in cnt_list:
131 print('Cleaning container %s' %cnt['Id'])
A.R Karthick95d044e2016-06-10 18:44:36 -0700132 if cnt.has_key('State') and cnt['State'] == 'running':
A R Karthick09b1f4e2016-05-12 14:31:50 -0700133 cls.dckr.kill(cnt['Id'])
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700134 cls.dckr.remove_container(cnt['Id'], force=True)
135
136 @classmethod
137 def remove_container(cls, name, force=True):
138 try:
139 cls.dckr.remove_container(name, force = force)
140 except: pass
141
142 def exists(self):
143 return '/{0}'.format(self.name) in list(flatten(n['Names'] for n in self.dckr.containers()))
144
145 def img_exists(self):
A R Karthicke07fc3a2017-02-27 10:49:29 -0800146 #return self.image_name in [ctn['RepoTags'][0] if ctn['RepoTags'] else '' for ctn in self.dckr.images()]
147 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 -0700148
A R Karthick75844572017-01-23 16:57:44 -0800149 def ip(self, network = None):
A R Karthick2b93d6a2016-09-06 15:19:09 -0700150 cnt_list = filter(lambda c: c['Names'][0] == '/{}'.format(self.name), self.dckr.containers())
151 #if not cnt_list:
152 # cnt_list = filter(lambda c: c['Image'] == self.image_name, self.dckr.containers())
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700153 cnt_settings = cnt_list.pop()
A R Karthick75844572017-01-23 16:57:44 -0800154 if network is not None and cnt_settings['NetworkSettings']['Networks'].has_key(network):
155 return cnt_settings['NetworkSettings']['Networks'][network]['IPAddress']
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700156 return cnt_settings['NetworkSettings']['Networks']['bridge']['IPAddress']
157
A R Karthick2b93d6a2016-09-06 15:19:09 -0700158 @classmethod
159 def ips(cls, image_name):
160 cnt_list = filter(lambda c: c['Image'] == image_name, cls.dckr.containers())
161 ips = [ cnt['NetworkSettings']['Networks']['bridge']['IPAddress'] for cnt in cnt_list ]
162 return ips
163
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700164 def kill(self, remove = True):
165 self.dckr.kill(self.name)
166 self.dckr.remove_container(self.name, force=True)
167
A R Karthick41adfce2016-06-10 09:51:25 -0700168 def start(self, rm = True, ports = None, volumes = None, host_config = None,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700169 environment = None, tty = False, stdin_open = True):
170
171 if rm and self.exists():
172 print('Removing container:', self.name)
173 self.dckr.remove_container(self.name, force=True)
174
A R Karthick41adfce2016-06-10 09:51:25 -0700175 ctn = self.dckr.create_container(image=self.image_name, ports = ports, command=self.command,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700176 detach=True, name=self.name,
A R Karthick41adfce2016-06-10 09:51:25 -0700177 environment = environment,
178 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700179 host_config = host_config, stdin_open=stdin_open, tty = tty)
180 self.dckr.start(container=self.name)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700181 if self.quagga_config:
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700182 self.connect_to_br()
183 self.id = ctn['Id']
184 return ctn
185
Thangavelu K Sef6f0a52016-12-14 19:57:05 +0000186 @classmethod
187 def pause_container(cls, image, delay):
188 cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True))
189 for cnt in cnt_list:
190 print('Pause the container %s' %cnt['Id'])
191 if cnt.has_key('State') and cnt['State'] == 'running':
192 cls.dckr.pause(cnt['Id'])
193 if delay != 0:
194 time.sleep(delay)
195 for cnt in cnt_list:
196 print('Unpause the container %s' %cnt['Id'])
197 cls.dckr.unpause(cnt['Id'])
198 else:
199 print('Infinity time pause the container %s' %cnt['Id'])
200 return 'success'
201
A R Karthick52414732017-01-31 09:59:47 -0800202 def connect_to_br(self, index = 0):
A R Karthickaa54a1c2016-12-15 11:42:08 -0800203 self.CONFIG_LOCK.acquire()
204 try:
205 with docker_netns(self.name) as pid:
206 for quagga_config in self.quagga_config:
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700207 ip = IPRoute()
A R Karthickaa54a1c2016-12-15 11:42:08 -0800208 br = ip.link_lookup(ifname=quagga_config['bridge'])
209 if len(br) == 0:
210 try:
211 ip.link_create(ifname=quagga_config['bridge'], kind='bridge')
212 except NetlinkError as e:
213 err, _ = e.args
214 if err == errno.EEXIST:
215 pass
216 else:
217 raise NetlinkError(*e.args)
218 br = ip.link_lookup(ifname=quagga_config['bridge'])
219 br = br[0]
220 ip.link('set', index=br, state='up')
A R Karthick52414732017-01-31 09:59:47 -0800221 ifname = '{0}-{1}'.format(self.name[:12], index)
A R Karthickaa54a1c2016-12-15 11:42:08 -0800222 ifs = ip.link_lookup(ifname=ifname)
223 if len(ifs) > 0:
224 ip.link_remove(ifs[0])
225 peer_ifname = '{0}-{1}'.format(pid, index)
226 ip.link_create(ifname=ifname, kind='veth', peer=peer_ifname)
227 host = ip.link_lookup(ifname=ifname)[0]
228 ip.link('set', index=host, master=br)
229 ip.link('set', index=host, state='up')
230 guest = ip.link_lookup(ifname=peer_ifname)[0]
231 ip.link('set', index=guest, net_ns_fd=pid)
232 with Namespace(pid, 'net'):
233 ip = IPRoute()
234 ip.link('set', index=guest, ifname='eth{}'.format(index+1))
235 ip.addr('add', index=guest, address=quagga_config['ip'], mask=quagga_config['mask'])
236 ip.link('set', index=guest, state='up')
237 index += 1
238 finally:
239 self.CONFIG_LOCK.release()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700240
Thangavelu K Sef6f0a52016-12-14 19:57:05 +0000241 def execute(self, cmd, tty = True, stream = False, shell = False, detach = True):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700242 res = 0
243 if type(cmd) == str:
244 cmds = (cmd,)
245 else:
246 cmds = cmd
247 if shell:
248 for c in cmds:
249 res += os.system('docker exec {0} {1}'.format(self.name, c))
250 return res
251 for c in cmds:
252 i = self.dckr.exec_create(container=self.name, cmd=c, tty = tty, privileged = True)
A R Karthickd6dd9b22017-02-24 15:17:22 -0800253 s = self.dckr.exec_start(i['Id'], stream = stream, detach=detach, socket=True)
254 try:
255 s.close()
256 except: pass
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700257 result = self.dckr.exec_inspect(i['Id'])
258 res += 0 if result['ExitCode'] == None else result['ExitCode']
259 return res
260
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700261 def restart(self, timeout =10):
262 return self.dckr.restart(self.name, timeout)
263
A R Karthickc69d73e2017-01-20 11:44:34 -0800264def get_mem(jvm_heap_size = None, instances = 1):
A R Karthick1f908202016-11-16 17:32:20 -0800265 if instances <= 0:
266 instances = 1
A R Karthickc69d73e2017-01-20 11:44:34 -0800267 heap_size = jvm_heap_size
268 heap_size_i = 0
269 #sanitize the heap size config
270 if heap_size is not None:
271 if not heap_size.isdigit():
272 try:
273 heap_size_i = int(heap_size[:-1])
274 suffix = heap_size[-1]
275 if suffix == 'M':
276 heap_size_i /= 1024 #convert to gigs
A.R Karthick99044822017-02-09 14:04:20 -0800277 #allow to specific minimum heap size
278 if heap_size_i == 0:
279 return heap_size
A R Karthickc69d73e2017-01-20 11:44:34 -0800280 except:
281 ##invalid suffix length probably. Fall back to default
282 heap_size = None
283 else:
284 heap_size_i = int(heap_size)
285
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700286 with open('/proc/meminfo', 'r') as fd:
287 meminfo = fd.readlines()
288 mem = 0
289 for m in meminfo:
290 if m.startswith('MemTotal:') or m.startswith('SwapTotal:'):
291 mem += int(m.split(':')[1].strip().split()[0])
292
A R Karthick1f908202016-11-16 17:32:20 -0800293 mem = max(mem/1024/1024/2/instances, 1)
Chetan Gaonker6d0a7b02016-05-03 16:57:28 -0700294 mem = min(mem, 16)
A R Karthickc69d73e2017-01-20 11:44:34 -0800295
296 if heap_size_i:
297 #we take the minimum of the provided heap size and max allowed heap size
298 heap_size_i = min(heap_size_i, mem)
299 else:
300 heap_size_i = mem
301
302 return '{}G'.format(heap_size_i)
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700303
A R Karthickd44cea12016-07-20 12:16:41 -0700304class OnosCord(Container):
305 """Use this when running the cord tester agent on the onos compute node"""
A R Karthickd44cea12016-07-20 12:16:41 -0700306 onos_config_dir_guest = '/root/onos/config'
A R Karthick03bd2812017-03-03 17:49:17 -0800307 synchronizer_map = { 'vtn' : { 'install':
308 ('http://mavenrepo:8080/repository/org/opencord/cord-config/1.2-SNAPSHOT/cord-config-1.2-SNAPSHOT.oar',
309 'http://mavenrepo:8080/repository/org/opencord/vtn/1.2-SNAPSHOT/vtn-1.2-SNAPSHOT.oar',),
310 'activate':
311 ('org.onosproject.ovsdb-base', 'org.onosproject.drivers.ovsdb',
312 'org.onosproject.dhcp', 'org.onosproject.optical-model',
313 'org.onosproject.openflow-base', 'org.onosproject.proxyarp',
314 'org.onosproject.hostprovider'),
315 },
316 'fabric' : { 'activate':
317 ('org.onosproject.hostprovider', 'org.onosproject.optical-model',
318 'org.onosproject.openflow-base', 'org.onosproject.vrouter',
319 'org.onosproject.netcfghostprovider', 'org.onosproject.netcfglinksprovider',
320 'org.onosproject.segmentrouting', 'org.onosproject.proxyarp'),
321 }
322 }
323 tester_apps = ('http://mavenrepo:8080/repository/org/opencord/aaa/1.2-SNAPSHOT/aaa-1.2-SNAPSHOT.oar',
324 'http://mavenrepo:8080/repository/org/opencord/igmp/1.2-SNAPSHOT/igmp-1.2-SNAPSHOT.oar',)
A R Karthickd44cea12016-07-20 12:16:41 -0700325
A.R Karthickddf12772017-05-17 13:49:47 -0700326 old_service_profile = '/opt/cord/orchestration/service-profile/cord-pod'
A R Karthick49529c52017-05-19 09:43:01 -0700327 cord_profile = '/opt/cord_profile'
A.R Karthickddf12772017-05-17 13:49:47 -0700328
A R Karthick03bd2812017-03-03 17:49:17 -0800329 def __init__(self, onos_ip, conf, service_profile, synchronizer, start = True, boot_delay = 5):
A.R Karthickf184b342017-01-27 19:30:50 -0800330 if not os.access(conf, os.F_OK):
331 raise Exception('ONOS cord configuration location %s is invalid' %conf)
A.R Karthickddf12772017-05-17 13:49:47 -0700332 self.old_cord = False
333 if os.access(self.old_service_profile, os.F_OK):
334 self.old_cord = True
A R Karthickbd9b8a32016-07-21 09:56:45 -0700335 self.onos_ip = onos_ip
A.R Karthickf184b342017-01-27 19:30:50 -0800336 self.onos_cord_dir = conf
A R Karthickbd9b8a32016-07-21 09:56:45 -0700337 self.boot_delay = boot_delay
A.R Karthickf184b342017-01-27 19:30:50 -0800338 self.synchronizer = synchronizer
339 self.service_profile = service_profile
340 self.docker_yaml = os.path.join(conf, 'docker-compose.yml')
341 self.docker_yaml_saved = os.path.join(conf, 'docker-compose.yml.saved')
342 self.onos_config_dir = os.path.join(conf, 'config')
343 self.onos_cfg_save_loc = os.path.join(conf, 'network-cfg.json.saved')
344 instance_active = False
345 #if we have a wrapper onos instance already active, back out
346 if os.access(self.onos_config_dir, os.F_OK) or os.access(self.docker_yaml_saved, os.F_OK):
347 instance_active = True
348 else:
349 if start is True:
350 os.mkdir(self.onos_config_dir)
351 shutil.copy(self.docker_yaml, self.docker_yaml_saved)
A R Karthickd44cea12016-07-20 12:16:41 -0700352
A.R Karthickf184b342017-01-27 19:30:50 -0800353 self.start_wrapper = instance_active is False and start is True
A R Karthickd44cea12016-07-20 12:16:41 -0700354 ##update the docker yaml with the config volume
355 with open(self.docker_yaml, 'r') as f:
356 yaml_config = yaml.load(f)
357 image = yaml_config['services'].keys()[0]
A R Karthick8983cb02017-06-09 11:32:53 -0700358 cord_conf_dir_basename = os.path.basename(self.onos_cord_dir.replace('-', '').replace('_', ''))
A.R Karthickf184b342017-01-27 19:30:50 -0800359 xos_onos_name = '{}_{}_1'.format(cord_conf_dir_basename, image)
A R Karthick5778a792017-01-31 13:47:16 -0800360 if not yaml_config['services'][image].has_key('volumes'):
361 yaml_config['services'][image]['volumes'] = []
A R Karthickd44cea12016-07-20 12:16:41 -0700362 volumes = yaml_config['services'][image]['volumes']
363 config_volumes = filter(lambda e: e.find(self.onos_config_dir_guest) >= 0, volumes)
364 if not config_volumes:
365 config_volume = '{}:{}'.format(self.onos_config_dir, self.onos_config_dir_guest)
366 volumes.append(config_volume)
A.R Karthickf184b342017-01-27 19:30:50 -0800367 if self.start_wrapper:
368 docker_yaml_changed = '{}-changed'.format(self.docker_yaml)
369 with open(docker_yaml_changed, 'w') as wf:
370 yaml.dump(yaml_config, wf)
371 os.rename(docker_yaml_changed, self.docker_yaml)
A R Karthickd44cea12016-07-20 12:16:41 -0700372 self.volumes = volumes
373
A R Karthickd44cea12016-07-20 12:16:41 -0700374 ##Create an container instance of xos onos
A R Karthick52414732017-01-31 09:59:47 -0800375 super(OnosCord, self).__init__(xos_onos_name, image, tag = '', quagga_config = Onos.QUAGGA_CONFIG)
A.R Karthickf184b342017-01-27 19:30:50 -0800376 self.last_cfg = None
377 if self.start_wrapper:
378 #fetch the current config of onos cord instance and save it
379 try:
380 self.last_cfg = OnosCtrl.get_config(controller = onos_ip)
381 json_data = json.dumps(self.last_cfg, indent=4)
382 with open(self.onos_cfg_save_loc, 'w') as f:
383 f.write(json_data)
384 except:
385 pass
386 #start the container back with the shared onos config volume
387 self.start()
A R Karthickd44cea12016-07-20 12:16:41 -0700388
A R Karthick03bd2812017-03-03 17:49:17 -0800389 def cliEnter(self):
390 retries = 0
391 while retries < 30:
392 cli = OnosCliDriver(controller = self.onos_ip, connect = True)
393 if cli.handle:
394 return cli
395 else:
396 retries += 1
A R Karthick72fcbc52017-03-06 12:35:17 -0800397 time.sleep(3)
A R Karthick03bd2812017-03-03 17:49:17 -0800398
399 return None
400
401 def cliExit(self, cli):
402 if cli:
403 cli.disconnect()
404
A.R Karthickddf12772017-05-17 13:49:47 -0700405 def synchronize_fabric(self, cfg = None):
406 if self.old_cord is True:
407 cmds = [ 'cd {} && make {}'.format(self.old_service_profile, self.synchronizer),
408 'sleep 30'
409 ]
410 for cmd in cmds:
411 try:
412 os.system(cmd)
413 except:
414 pass
415
A R Karthick03bd2812017-03-03 17:49:17 -0800416 def synchronize_vtn(self, cfg = None):
A.R Karthickddf12772017-05-17 13:49:47 -0700417 if self.old_cord is True:
418 cmds = [ 'cd {} && make {}'.format(self.old_service_profile, self.synchronizer),
419 'sleep 30'
420 ]
421 for cmd in cmds:
422 try:
423 os.system(cmd)
424 except:
425 pass
426 return
A R Karthick03bd2812017-03-03 17:49:17 -0800427 if cfg is None:
428 return
429 if not cfg.has_key('apps'):
430 return
431 if not cfg['apps'].has_key('org.opencord.vtn'):
432 return
433 vtn_neutron_cfg = cfg['apps']['org.opencord.vtn']['cordvtn']['openstack']
434 password = vtn_neutron_cfg['password']
435 endpoint = vtn_neutron_cfg['endpoint']
436 user = vtn_neutron_cfg['user']
437 tenant = vtn_neutron_cfg['tenant']
438 vtn_host = cfg['apps']['org.opencord.vtn']['cordvtn']['nodes'][0]['hostname']
439 cli = self.cliEnter()
440 if cli is None:
441 return
442 cli.cordVtnSyncNeutronStates(endpoint, password, tenant = tenant, user = user)
443 time.sleep(2)
444 cli.cordVtnNodeInit(vtn_host)
445 self.cliExit(cli)
446
447 def synchronize(self, cfg_unlink = False):
A R Karthick03bd2812017-03-03 17:49:17 -0800448
449 if not self.synchronizer_map.has_key(self.synchronizer):
450 return
451
452 install_list = ()
453 if self.synchronizer_map[self.synchronizer].has_key('install'):
454 install_list = self.synchronizer_map[self.synchronizer]['install']
455
456 activate_list = ()
457 if self.synchronizer_map[self.synchronizer].has_key('activate'):
458 activate_list = self.synchronizer_map[self.synchronizer]['activate']
459
460 for app_url in install_list:
461 print('Installing app from url: %s' %app_url)
462 OnosCtrl.install_app_from_url(None, None, app_url = app_url, onos_ip = self.onos_ip)
463
464 for app in activate_list:
465 print('Activating app %s' %app)
466 OnosCtrl(app, controller = self.onos_ip).activate()
467 time.sleep(2)
468
469 for app_url in self.tester_apps:
470 print('Installing tester app from url: %s' %app_url)
471 OnosCtrl.install_app_from_url(None, None, app_url = app_url, onos_ip = self.onos_ip)
472
A R Karthick72fcbc52017-03-06 12:35:17 -0800473 cfg = None
474 #restore the saved config after applications are activated
475 if os.access(self.onos_cfg_save_loc, os.F_OK):
476 with open(self.onos_cfg_save_loc, 'r') as f:
477 cfg = json.load(f)
478 try:
479 OnosCtrl.config(cfg, controller = self.onos_ip)
480 if cfg_unlink is True:
481 os.unlink(self.onos_cfg_save_loc)
482 except:
483 pass
484
485 if hasattr(self, 'synchronize_{}'.format(self.synchronizer)):
486 getattr(self, 'synchronize_{}'.format(self.synchronizer))(cfg = cfg)
487
488 #now restart the xos synchronizer container
A R Karthick49529c52017-05-19 09:43:01 -0700489 cmd = None
490 if os.access('{}/onboarding-docker-compose/docker-compose.yml'.format(self.cord_profile), os.F_OK):
491 cmd = 'cd {}/onboarding-docker-compose && \
492 docker-compose -p {} restart xos_synchronizer_{}'.format(self.cord_profile,
493 self.service_profile,
494 self.synchronizer)
495 else:
496 if os.access('{}/docker-compose.yml'.format(self.cord_profile), os.F_OK):
497 cmd = 'cd {} && \
498 docker-compose -p {} restart {}-synchronizer'.format(self.cord_profile,
499 self.service_profile,
500 self.synchronizer)
501 if cmd is not None:
502 try:
503 print(cmd)
504 os.system(cmd)
505 except:
506 pass
A R Karthick03bd2812017-03-03 17:49:17 -0800507
A R Karthickd44cea12016-07-20 12:16:41 -0700508 def start(self, restart = False, network_cfg = None):
A R Karthick928ad622017-01-30 12:18:32 -0800509 if network_cfg is not None:
A R Karthickd44cea12016-07-20 12:16:41 -0700510 json_data = json.dumps(network_cfg, indent=4)
511 with open('{}/network-cfg.json'.format(self.onos_config_dir), 'w') as f:
512 f.write(json_data)
A R Karthick52414732017-01-31 09:59:47 -0800513
514 #we avoid using docker-compose restart for now.
515 #since we don't want to retain the metadata across restarts
A R Karthick03bd2812017-03-03 17:49:17 -0800516 #stop and start and synchronize the services before installing tester cord apps
517 cmds = [ 'cd {} && docker-compose down'.format(self.onos_cord_dir),
518 'cd {} && docker-compose up -d'.format(self.onos_cord_dir),
A R Karthickbc894372017-05-12 16:34:08 -0700519 'sleep 150',
A R Karthick03bd2812017-03-03 17:49:17 -0800520 ]
521 for cmd in cmds:
A.R Karthickf184b342017-01-27 19:30:50 -0800522 try:
A R Karthick03bd2812017-03-03 17:49:17 -0800523 print(cmd)
A.R Karthickf184b342017-01-27 19:30:50 -0800524 os.system(cmd)
A R Karthick03bd2812017-03-03 17:49:17 -0800525 except:pass
A R Karthick52414732017-01-31 09:59:47 -0800526
A R Karthick03bd2812017-03-03 17:49:17 -0800527 self.synchronize()
A R Karthick52414732017-01-31 09:59:47 -0800528 ##we could also connect container to default docker network but disabled for now
529 #Container.connect_to_network(self.name, 'bridge')
A R Karthick52414732017-01-31 09:59:47 -0800530 #connect container to the quagga bridge
531 self.connect_to_br(index = 0)
A.R Karthickf184b342017-01-27 19:30:50 -0800532 print('Waiting %d seconds for ONOS instance to start' %self.boot_delay)
A R Karthickbd9b8a32016-07-21 09:56:45 -0700533 time.sleep(self.boot_delay)
A R Karthickd44cea12016-07-20 12:16:41 -0700534
535 def build_image(self):
536 build_cmd = 'cd {} && docker-compose build'.format(self.onos_cord_dir)
537 os.system(build_cmd)
538
A.R Karthickf184b342017-01-27 19:30:50 -0800539 def restore(self, force = False):
540 restore = self.start_wrapper is True or force is True
541 if not restore:
A.R Karthick263d3fc2017-01-27 12:52:53 -0800542 return
A R Karthick394976f2017-01-31 14:25:16 -0800543 #nothing to restore
544 if not os.access(self.docker_yaml_saved, os.F_OK):
545 return
A R Karthick03bd2812017-03-03 17:49:17 -0800546
A.R Karthickf184b342017-01-27 19:30:50 -0800547 #restore the config files back. The synchronizer restore should bring the last config back
548 cmds = ['cd {} && docker-compose down'.format(self.onos_cord_dir),
549 'rm -rf {}'.format(self.onos_config_dir),
550 'mv {} {}'.format(self.docker_yaml_saved, self.docker_yaml),
551 'cd {} && docker-compose up -d'.format(self.onos_cord_dir),
A R Karthickbc894372017-05-12 16:34:08 -0700552 'sleep 150',
A.R Karthickf184b342017-01-27 19:30:50 -0800553 ]
554 for cmd in cmds:
A.R Karthickb17e2022017-01-27 11:29:26 -0800555 try:
A.R Karthickf184b342017-01-27 19:30:50 -0800556 print(cmd)
557 os.system(cmd)
A.R Karthickb17e2022017-01-27 11:29:26 -0800558 except: pass
559
A R Karthick03bd2812017-03-03 17:49:17 -0800560 self.synchronize(cfg_unlink = True)
A.R Karthickb17e2022017-01-27 11:29:26 -0800561
A.R Karthick1700e0e2016-10-06 18:16:57 -0700562class OnosCordStopWrapper(Container):
563 onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord')
564 docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml')
565
566 def __init__(self):
567 if os.access(self.docker_yaml, os.F_OK):
568 with open(self.docker_yaml, 'r') as f:
569 yaml_config = yaml.load(f)
570 image = yaml_config['services'].keys()[0]
571 name = 'cordtestercord_{}_1'.format(image)
572 super(OnosCordStopWrapper, self).__init__(name, image, tag = '')
573 if self.exists():
574 print('Killing container %s' %self.name)
575 self.kill()
576
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700577class Onos(Container):
A R Karthickaa54a1c2016-12-15 11:42:08 -0800578 QUAGGA_CONFIG = [ { 'bridge' : 'quagga-br', 'ip': '10.10.0.4', 'mask' : 16 }, ]
A R Karthicka2492c12016-12-16 10:31:51 -0800579 MAX_INSTANCES = 3
A R Karthickc69d73e2017-01-20 11:44:34 -0800580 JVM_HEAP_SIZE = None
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700581 SYSTEM_MEMORY = (get_mem(),) * 2
A R Karthicka2492c12016-12-16 10:31:51 -0800582 INSTANCE_MEMORY = (get_mem(instances=MAX_INSTANCES),) * 2
A R Karthickc69d73e2017-01-20 11:44:34 -0800583 JAVA_OPTS_FORMAT = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode'
584 JAVA_OPTS_DEFAULT = JAVA_OPTS_FORMAT.format(*SYSTEM_MEMORY) #-XX:+PrintGCDetails -XX:+PrintGCTimeStamps'
585 JAVA_OPTS_CLUSTER_DEFAULT = JAVA_OPTS_FORMAT.format(*INSTANCE_MEMORY)
586 env = { 'ONOS_APPS' : 'drivers,openflow,proxyarp,vrouter', 'JAVA_OPTS' : JAVA_OPTS_DEFAULT }
A R Karthickb608d402017-06-02 11:48:41 -0700587 onos_cord_apps = ( ['cord-config', '1.2-SNAPSHOT'],
588 ['aaa', '1.2-SNAPSHOT'],
589 ['igmp', '1.2-SNAPSHOT'],
A.R Karthick95d044e2016-06-10 18:44:36 -0700590 )
A R Karthickb608d402017-06-02 11:48:41 -0700591 cord_apps_version_updated = False
A R Karthick184945a2017-07-25 17:23:57 -0700592 expose_port = False
593 expose_ports = [ 8181, 8101, 9876, 6653, 6633, 2000, 2620, 5005 ]
594 ports = []
A R Karthickf2f4ca62016-08-17 10:34:08 -0700595 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
596 host_config_dir = os.path.join(setup_dir, 'onos-config')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700597 guest_config_dir = '/root/onos/config'
A.R Karthickdda22062017-02-09 14:39:20 -0800598 guest_data_dir = '/root/onos/apache-karaf-3.0.8/data'
599 guest_log_file = '/root/onos/apache-karaf-3.0.8/data/log/karaf.log'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700600 onos_gen_partitions = os.path.join(setup_dir, 'onos-gen-partitions')
A R Karthick2b93d6a2016-09-06 15:19:09 -0700601 onos_form_cluster = os.path.join(setup_dir, 'onos-form-cluster')
A.R Karthick95d044e2016-06-10 18:44:36 -0700602 cord_apps_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'apps')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700603 host_guest_map = ( (host_config_dir, guest_config_dir), )
A R Karthickd52ca8a2017-07-24 17:38:55 -0700604 ssl_key = None
A R Karthick2b93d6a2016-09-06 15:19:09 -0700605 cluster_cfg = os.path.join(host_config_dir, 'cluster.json')
606 cluster_mode = False
607 cluster_instances = []
Chetan Gaonker503032a2016-05-12 12:06:29 -0700608 NAME = 'cord-onos'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700609 ##the ip of ONOS in default cluster.json in setup/onos-config
610 CLUSTER_CFG_IP = '172.17.0.2'
A R Karthick07608ef2016-08-23 16:51:19 -0700611 IMAGE = 'onosproject/onos'
612 TAG = 'latest'
613 PREFIX = ''
A R Karthickf2f4ca62016-08-17 10:34:08 -0700614
615 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700616 def generate_cluster_cfg(cls, ip):
617 if type(ip) in [ list, tuple ]:
618 ips = ' '.join(ip)
619 else:
620 ips = ip
A R Karthickf2f4ca62016-08-17 10:34:08 -0700621 try:
A R Karthick2b93d6a2016-09-06 15:19:09 -0700622 cmd = '{} {} {}'.format(cls.onos_gen_partitions, cls.cluster_cfg, ips)
623 os.system(cmd)
624 except: pass
625
626 @classmethod
627 def form_cluster(cls, ips):
628 nodes = ' '.join(ips)
629 try:
630 cmd = '{} {}'.format(cls.onos_form_cluster, nodes)
A R Karthickf2f4ca62016-08-17 10:34:08 -0700631 os.system(cmd)
632 except: pass
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700633
A R Karthick9d48c652016-09-15 09:16:36 -0700634 @classmethod
635 def cleanup_runtime(cls):
636 '''Cleanup ONOS runtime generated files'''
637 files = ( Onos.cluster_cfg, os.path.join(Onos.host_config_dir, 'network-cfg.json') )
638 for f in files:
639 if os.access(f, os.F_OK):
640 try:
641 os.unlink(f)
642 except: pass
643
A R Karthickec2db322016-11-17 15:06:01 -0800644 @classmethod
645 def get_data_map(cls, host_volume, guest_volume_dir):
646 host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume))
647 if not os.path.exists(host_volume_dir):
648 os.mkdir(host_volume_dir)
649 return ( (host_volume_dir, guest_volume_dir), )
650
651 @classmethod
652 def remove_data_map(cls, host_volume, guest_volume_dir):
653 host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume))
654 if os.path.exists(host_volume_dir):
A.R Karthickf184b342017-01-27 19:30:50 -0800655 shutil.rmtree(host_volume_dir)
A R Karthickec2db322016-11-17 15:06:01 -0800656
A R Karthick973010f2017-02-06 16:41:51 -0800657 @classmethod
658 def update_data_dir(cls, karaf):
659 Onos.guest_data_dir = '/root/onos/apache-karaf-{}/data'.format(karaf)
660 Onos.guest_log_file = '/root/onos/apache-karaf-{}/data/log/karaf.log'.format(karaf)
661
A R Karthickd52ca8a2017-07-24 17:38:55 -0700662 @classmethod
663 def update_ssl_key(cls, key):
664 if os.access(key, os.F_OK):
665 try:
666 shutil.copy(key, cls.host_config_dir)
667 cls.ssl_key = os.path.join(cls.host_config_dir, os.path.basename(key))
668 except:pass
669
A R Karthick184945a2017-07-25 17:23:57 -0700670 @classmethod
671 def set_expose_port(cls, flag):
672 cls.expose_port = flag
673
674 def get_port_map(self, instance=0):
675 if self.expose_port is False:
676 return self.ports
677 return map(lambda p: (p, p + instance), self.expose_ports)
678
A R Karthickec2db322016-11-17 15:06:01 -0800679 def remove_data_volume(self):
680 if self.data_map is not None:
681 self.remove_data_map(*self.data_map)
682
A.R Karthick1700e0e2016-10-06 18:16:57 -0700683 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthickec2db322016-11-17 15:06:01 -0800684 boot_delay = 20, restart = False, network_cfg = None,
A R Karthick85eb1862017-01-23 16:10:57 -0800685 cluster = False, data_volume = None, async = False, quagga_config = None,
A R Karthick184945a2017-07-25 17:23:57 -0700686 network = None, instance = 0):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700687 if restart is True:
688 ##Find the right image to restart
689 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
690 if running_image:
691 image_name = running_image[0]['Image']
692 try:
693 image = image_name.split(':')[0]
694 tag = image_name.split(':')[1]
695 except: pass
696
A R Karthickaa54a1c2016-12-15 11:42:08 -0800697 if quagga_config is None:
698 quagga_config = Onos.QUAGGA_CONFIG
699 super(Onos, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = quagga_config)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700700 self.boot_delay = boot_delay
A R Karthickec2db322016-11-17 15:06:01 -0800701 self.data_map = None
A R Karthickc69d73e2017-01-20 11:44:34 -0800702 instance_memory = (get_mem(jvm_heap_size = Onos.JVM_HEAP_SIZE, instances = Onos.MAX_INSTANCES),) * 2
703 self.env['JAVA_OPTS'] = self.JAVA_OPTS_FORMAT.format(*instance_memory)
A R Karthick184945a2017-07-25 17:23:57 -0700704 self.ports = self.get_port_map(instance = instance)
A R Karthickd52ca8a2017-07-24 17:38:55 -0700705 if self.ssl_key:
706 key_files = ( os.path.join(self.guest_config_dir, os.path.basename(self.ssl_key)), ) * 2
707 self.env['JAVA_OPTS'] += ' -DenableOFTLS=true -Djavax.net.ssl.keyStore={} -Djavax.net.ssl.keyStorePassword=222222 -Djavax.net.ssl.trustStore={} -Djavax.net.ssl.trustStorePassword=222222'.format(*key_files)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700708 if cluster is True:
A R Karthickec2db322016-11-17 15:06:01 -0800709 if data_volume is not None:
710 self.data_map = self.get_data_map(data_volume, self.guest_data_dir)
711 self.host_guest_map = self.host_guest_map + self.data_map
A R Karthick2b93d6a2016-09-06 15:19:09 -0700712 if os.access(self.cluster_cfg, os.F_OK):
713 try:
714 os.unlink(self.cluster_cfg)
715 except: pass
716
717 self.host_config = self.create_host_config(port_list = self.ports,
718 host_guest_map = self.host_guest_map)
719 self.volumes = []
720 for _,g in self.host_guest_map:
721 self.volumes.append(g)
722
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700723 if restart is True and self.exists():
724 self.kill()
A R Karthick2b93d6a2016-09-06 15:19:09 -0700725
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700726 if not self.exists():
727 self.remove_container(name, force=True)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700728 host_config = self.create_host_config(port_list = self.ports,
729 host_guest_map = self.host_guest_map)
730 volumes = []
731 for _,g in self.host_guest_map:
732 volumes.append(g)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700733 if network_cfg is not None:
A R Karthick81acbff2016-06-17 14:45:16 -0700734 json_data = json.dumps(network_cfg, indent=4)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700735 with open('{}/network-cfg.json'.format(self.host_config_dir), 'w') as f:
736 f.write(json_data)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800737 if cluster is False or async is False:
738 print('Starting ONOS container %s' %self.name)
739 self.start(ports = self.ports, environment = self.env,
740 host_config = self.host_config, volumes = self.volumes, tty = True)
741 if not restart:
742 ##wait a bit before fetching IP to regenerate cluster cfg
743 time.sleep(5)
744 ip = self.ip()
745 ##Just a quick hack/check to ensure we don't regenerate in the common case.
746 ##As ONOS is usually the first test container that is started
747 if cluster is False:
748 if ip != self.CLUSTER_CFG_IP or not os.access(self.cluster_cfg, os.F_OK):
749 print('Regenerating ONOS cluster cfg for ip %s' %ip)
750 self.generate_cluster_cfg(ip)
751 self.kill()
752 self.remove_container(self.name, force=True)
753 print('Restarting ONOS container %s' %self.name)
754 self.start(ports = self.ports, environment = self.env,
755 host_config = self.host_config, volumes = self.volumes, tty = True)
756 print('Waiting for ONOS to boot')
757 time.sleep(boot_delay)
758 self.wait_for_onos_start(self.ip())
759 self.running = True
760 else:
761 self.running = False
762 else:
763 self.running = True
764 if self.running:
765 self.ipaddr = self.ip()
766 if cluster is False:
767 self.install_cord_apps(self.ipaddr)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800768
A.R Karthickc4e474d2016-12-12 15:24:57 -0800769 @classmethod
770 def get_quagga_config(cls, instance = 0):
A R Karthickaa54a1c2016-12-15 11:42:08 -0800771 quagga_config = copy.deepcopy(cls.QUAGGA_CONFIG)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800772 if instance == 0:
773 return quagga_config
774 ip = quagga_config[0]['ip']
775 octets = ip.split('.')
A R Karthickaa54a1c2016-12-15 11:42:08 -0800776 octets[3] = str((int(octets[3]) + instance) & 255)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800777 ip = '.'.join(octets)
778 quagga_config[0]['ip'] = ip
779 return quagga_config
780
781 @classmethod
782 def start_cluster_async(cls, onos_instances):
783 instances = filter(lambda o: o.running == False, onos_instances)
784 if not instances:
785 return
786 tpool = ThreadPool(len(instances), queue_size = 1, wait_timeout = 1)
787 for onos in instances:
788 tpool.addTask(onos.start_async)
789 tpool.cleanUpThreads()
790
791 def start_async(self):
792 print('Starting ONOS container %s' %self.name)
793 self.start(ports = self.ports, environment = self.env,
794 host_config = self.host_config, volumes = self.volumes, tty = True)
795 time.sleep(3)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700796 self.ipaddr = self.ip()
A.R Karthickc4e474d2016-12-12 15:24:57 -0800797 print('Waiting for ONOS container %s to start' %self.name)
798 self.wait_for_onos_start(self.ipaddr)
799 self.running = True
800 print('ONOS container %s started' %self.name)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700801
A R Karthick2b93d6a2016-09-06 15:19:09 -0700802 @classmethod
A R Karthick19aaf5c2016-11-09 17:47:57 -0800803 def wait_for_onos_start(cls, ip, tries = 30):
A R Karthick973010f2017-02-06 16:41:51 -0800804 onos_log = OnosLog(host = ip, log_file = Onos.guest_log_file)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800805 num_tries = 0
806 started = None
807 while not started and num_tries < tries:
808 time.sleep(3)
809 started = onos_log.search_log_pattern('ApplicationManager .* Started')
810 num_tries += 1
811
A R Karthick19aaf5c2016-11-09 17:47:57 -0800812 if not started:
813 print('ONOS did not start')
814 else:
815 print('ONOS started')
816 return started
817
818 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700819 def setup_cluster_deprecated(cls, onos_instances, image_name = None):
820 if not onos_instances or len(onos_instances) < 2:
821 return
822 ips = []
823 if image_name is not None:
824 ips = Container.ips(image_name)
825 else:
826 for onos in onos_instances:
827 ips.append(onos.ipaddr)
828 Onos.cluster_instances = onos_instances
829 Onos.cluster_mode = True
830 ##regenerate the cluster json with the 3 instance ips before restarting them back
831 print('Generating cluster cfg for ONOS instances with ips %s' %ips)
832 Onos.generate_cluster_cfg(ips)
833 for onos in onos_instances:
834 onos.kill()
835 onos.remove_container(onos.name, force=True)
836 print('Restarting ONOS container %s for forming cluster' %onos.name)
837 onos.start(ports = onos.ports, environment = onos.env,
838 host_config = onos.host_config, volumes = onos.volumes, tty = True)
839 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
840 time.sleep(onos.boot_delay)
841 onos.ipaddr = onos.ip()
842 onos.install_cord_apps(onos.ipaddr)
843
844 @classmethod
845 def setup_cluster(cls, onos_instances, image_name = None):
846 if not onos_instances or len(onos_instances) < 2:
847 return
848 ips = []
849 if image_name is not None:
850 ips = Container.ips(image_name)
851 else:
852 for onos in onos_instances:
853 ips.append(onos.ipaddr)
854 Onos.cluster_instances = onos_instances
855 Onos.cluster_mode = True
856 ##regenerate the cluster json with the 3 instance ips before restarting them back
857 print('Forming cluster for ONOS instances with ips %s' %ips)
858 Onos.form_cluster(ips)
859 ##wait for the cluster to be formed
860 print('Waiting for the cluster to be formed')
861 time.sleep(60)
862 for onos in onos_instances:
863 onos.install_cord_apps(onos.ipaddr)
864
865 @classmethod
A R Karthicke2c24bd2016-10-07 14:51:38 -0700866 def add_cluster(cls, count = 1, network_cfg = None):
867 if not cls.cluster_instances or Onos.cluster_mode is False:
868 return
869 for i in range(count):
A R Karthick184945a2017-07-25 17:23:57 -0700870 instance = len(cls.cluster_instances)
871 name = '{}-{}'.format(Onos.NAME, instance+1)
A R Karthicke2c24bd2016-10-07 14:51:38 -0700872 onos = cls(name = name, image = Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX,
A R Karthick184945a2017-07-25 17:23:57 -0700873 cluster = True, network_cfg = network_cfg, instance = instance)
A R Karthicke2c24bd2016-10-07 14:51:38 -0700874 cls.cluster_instances.append(onos)
875
876 cls.setup_cluster(cls.cluster_instances)
877
878 @classmethod
A.R Karthick2560f042016-11-30 14:38:52 -0800879 def restart_cluster(cls, network_cfg = None, timeout = 10, setup = False):
A R Karthick2b93d6a2016-09-06 15:19:09 -0700880 if cls.cluster_mode is False:
881 return
882 if not cls.cluster_instances:
883 return
884
885 if network_cfg is not None:
886 json_data = json.dumps(network_cfg, indent=4)
887 with open('{}/network-cfg.json'.format(cls.host_config_dir), 'w') as f:
888 f.write(json_data)
889
A.R Karthick2560f042016-11-30 14:38:52 -0800890 cls.cleanup_cluster()
891 if timeout > 0:
892 time.sleep(timeout)
893
A R Karthickaa54a1c2016-12-15 11:42:08 -0800894 #start the instances asynchronously
895 cls.start_cluster_async(cls.cluster_instances)
896 time.sleep(5)
A.R Karthick2560f042016-11-30 14:38:52 -0800897 ##form the cluster as appropriate
898 if setup is True:
899 cls.setup_cluster(cls.cluster_instances)
A R Karthickaa54a1c2016-12-15 11:42:08 -0800900 else:
901 for onos in cls.cluster_instances:
902 onos.install_cord_apps(onos.ipaddr)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700903
904 @classmethod
905 def cluster_ips(cls):
906 if cls.cluster_mode is False:
907 return []
908 if not cls.cluster_instances:
909 return []
910 ips = [ onos.ipaddr for onos in cls.cluster_instances ]
911 return ips
912
913 @classmethod
914 def cleanup_cluster(cls):
915 if cls.cluster_mode is False:
916 return
917 if not cls.cluster_instances:
918 return
919 for onos in cls.cluster_instances:
920 if onos.exists():
921 onos.kill()
A R Karthickaa54a1c2016-12-15 11:42:08 -0800922 onos.running = False
A R Karthick2b93d6a2016-09-06 15:19:09 -0700923 onos.remove_container(onos.name, force=True)
A R Karthickd44cea12016-07-20 12:16:41 -0700924
A.R Karthick95d044e2016-06-10 18:44:36 -0700925 @classmethod
A R Karthickde6b9dc2016-11-29 17:46:16 -0800926 def restart_node(cls, node = None, network_cfg = None, timeout = 10):
A R Karthick889d9652016-10-03 14:13:45 -0700927 if node is None:
928 cls(restart = True, network_cfg = network_cfg, image = cls.IMAGE, tag = cls.TAG)
929 else:
930 #Restarts a node in the cluster
931 valid_node = filter(lambda onos: node in [ onos.ipaddr, onos.name ], cls.cluster_instances)
932 if valid_node:
933 onos = valid_node.pop()
934 if onos.exists():
935 onos.kill()
936 onos.remove_container(onos.name, force=True)
A R Karthickde6b9dc2016-11-29 17:46:16 -0800937 if timeout > 0:
938 time.sleep(timeout)
A R Karthick889d9652016-10-03 14:13:45 -0700939 print('Restarting ONOS container %s' %onos.name)
940 onos.start(ports = onos.ports, environment = onos.env,
941 host_config = onos.host_config, volumes = onos.volumes, tty = True)
A R Karthick889d9652016-10-03 14:13:45 -0700942 onos.ipaddr = onos.ip()
A.R Karthick2560f042016-11-30 14:38:52 -0800943 onos.wait_for_onos_start(onos.ipaddr)
944 onos.install_cord_apps(onos.ipaddr)
A R Karthick889d9652016-10-03 14:13:45 -0700945
946 @classmethod
A R Karthickb608d402017-06-02 11:48:41 -0700947 def cliEnter(cls, onos_ip = None):
948 retries = 0
949 while retries < 10:
950 cli = OnosCliDriver(controller = onos_ip, connect = True)
951 if cli.handle:
952 return cli
953 else:
954 retries += 1
955 time.sleep(3)
956
957 return None
958
959 @classmethod
960 def cliExit(cls, cli):
961 if cli:
962 cli.disconnect()
963
964 @classmethod
965 def getVersion(cls, onos_ip = None):
966 cli = cls.cliEnter(onos_ip = onos_ip)
967 try:
968 summary = json.loads(cli.summary(jsonFormat = True))
969 except:
970 cls.cliExit(cli)
971 return '1.8.0'
972 cls.cliExit(cli)
973 return summary['version']
974
975 @classmethod
976 def update_cord_apps_version(cls, onos_ip = None):
977 if cls.cord_apps_version_updated == True:
978 return
979 version = cls.getVersion(onos_ip = onos_ip)
980 major = int(version.split('.')[0])
981 minor = int(version.split('.')[1])
982 app_version = '1.2-SNAPSHOT'
983 if major > 1:
984 app_version = '2.0-SNAPSHOT'
985 elif major == 1 and minor > 10:
986 app_version = '2.0-SNAPSHOT'
987 for apps in cls.onos_cord_apps:
988 apps[1] = app_version
989 cls.cord_apps_version_updated = True
990
991 @classmethod
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700992 def install_cord_apps(cls, onos_ip = None):
A R Karthickb608d402017-06-02 11:48:41 -0700993 cls.update_cord_apps_version(onos_ip = onos_ip)
A.R Karthick95d044e2016-06-10 18:44:36 -0700994 for app, version in cls.onos_cord_apps:
995 app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version)
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700996 ok, code = OnosCtrl.install_app(app_file, onos_ip = onos_ip)
A.R Karthick95d044e2016-06-10 18:44:36 -0700997 ##app already installed (conflicts)
998 if code in [ 409 ]:
999 ok = True
1000 print('ONOS app %s, version %s %s' %(app, version, 'installed' if ok else 'failed to install'))
1001 time.sleep(2)
1002
A.R Karthick1700e0e2016-10-06 18:16:57 -07001003class OnosStopWrapper(Container):
1004 def __init__(self, name):
1005 super(OnosStopWrapper, self).__init__(name, Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX)
1006 if self.exists():
1007 self.kill()
A R Karthickaa54a1c2016-12-15 11:42:08 -08001008 self.running = False
A.R Karthick1700e0e2016-10-06 18:16:57 -07001009 else:
1010 if Onos.cluster_mode is True:
1011 valid_node = filter(lambda onos: name in [ onos.ipaddr, onos.name ], Onos.cluster_instances)
1012 if valid_node:
1013 onos = valid_node.pop()
1014 if onos.exists():
1015 onos.kill()
A R Karthickaa54a1c2016-12-15 11:42:08 -08001016 onos.running = False
A.R Karthick1700e0e2016-10-06 18:16:57 -07001017
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001018class Radius(Container):
1019 ports = [ 1812, 1813 ]
A R Karthick41adfce2016-06-10 09:51:25 -07001020 env = {'TIMEZONE':'America/Los_Angeles',
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001021 'DEBUG': 'true', 'cert_password':'whatever', 'primary_shared_secret':'radius_password'
1022 }
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001023 host_db_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/db')
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001024 guest_db_dir = os.path.join(os.path.sep, 'opt', 'db')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001025 host_config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/freeradius')
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001026 guest_config_dir = os.path.join(os.path.sep, 'etc', 'freeradius')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001027 start_command = os.path.join(guest_config_dir, 'start-radius.py')
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001028 host_guest_map = ( (host_db_dir, guest_db_dir),
1029 (host_config_dir, guest_config_dir)
1030 )
A R Karthickf7a613b2017-02-24 09:36:44 -08001031 IMAGE = 'cordtest/radius'
Chetan Gaonker503032a2016-05-12 12:06:29 -07001032 NAME = 'cord-radius'
1033
A R Karthick07608ef2016-08-23 16:51:19 -07001034 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
A R Karthick85eb1862017-01-23 16:10:57 -08001035 boot_delay = 10, restart = False, update = False, network = None):
A R Karthick07608ef2016-08-23 16:51:19 -07001036 super(Radius, self).__init__(name, image, prefix = prefix, tag = tag, command = self.start_command)
Chetan Gaonker503032a2016-05-12 12:06:29 -07001037 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -07001038 self.build_image(self.image_name)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001039 if restart is True and self.exists():
1040 self.kill()
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001041 if not self.exists():
1042 self.remove_container(name, force=True)
1043 host_config = self.create_host_config(port_list = self.ports,
1044 host_guest_map = self.host_guest_map)
1045 volumes = []
1046 for _,g in self.host_guest_map:
1047 volumes.append(g)
A R Karthick41adfce2016-06-10 09:51:25 -07001048 self.start(ports = self.ports, environment = self.env,
1049 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001050 host_config = host_config, tty = True)
A R Karthick85eb1862017-01-23 16:10:57 -08001051 if network is not None:
1052 Container.connect_to_network(self.name, network)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001053 time.sleep(boot_delay)
1054
1055 @classmethod
1056 def build_image(cls, image):
1057 print('Building Radius image %s' %image)
1058 dockerfile = '''
1059FROM hbouvier/docker-radius
1060MAINTAINER chetan@ciena.com
1061LABEL RUN docker pull hbouvier/docker-radius
1062LABEL RUN docker run -it --name cord-radius hbouvier/docker-radius
A R Karthickc762df42016-05-25 10:09:21 -07001063RUN apt-get update && \
1064 apt-get -y install python python-pexpect strace
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001065WORKDIR /root
1066CMD ["/etc/freeradius/start-radius.py"]
1067'''
1068 super(Radius, cls).build_image(dockerfile, image)
1069 print('Done building image %s' %image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001070
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001071class Quagga(Container):
A R Karthickaa54a1c2016-12-15 11:42:08 -08001072 QUAGGA_CONFIG = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 },
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -07001073 { 'bridge' : 'quagga-br', 'ip': '192.168.10.3', 'mask': 16 },
1074 )
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001075 ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ]
1076 host_quagga_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/quagga-config')
1077 guest_quagga_config = '/root/config'
1078 quagga_config_file = os.path.join(guest_quagga_config, 'testrib.conf')
1079 host_guest_map = ( (host_quagga_config, guest_quagga_config), )
A R Karthickf7a613b2017-02-24 09:36:44 -08001080 IMAGE = 'cordtest/quagga'
Chetan Gaonker503032a2016-05-12 12:06:29 -07001081 NAME = 'cord-quagga'
1082
A R Karthick07608ef2016-08-23 16:51:19 -07001083 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
A R Karthick85eb1862017-01-23 16:10:57 -08001084 boot_delay = 15, restart = False, config_file = quagga_config_file, update = False,
1085 network = None):
A R Karthickaa54a1c2016-12-15 11:42:08 -08001086 super(Quagga, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.QUAGGA_CONFIG)
Chetan Gaonker503032a2016-05-12 12:06:29 -07001087 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -07001088 self.build_image(self.image_name)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001089 if restart is True and self.exists():
1090 self.kill()
1091 if not self.exists():
1092 self.remove_container(name, force=True)
A R Karthick41adfce2016-06-10 09:51:25 -07001093 host_config = self.create_host_config(port_list = self.ports,
1094 host_guest_map = self.host_guest_map,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001095 privileged = True)
1096 volumes = []
1097 for _,g in self.host_guest_map:
1098 volumes.append(g)
1099 self.start(ports = self.ports,
A R Karthick41adfce2016-06-10 09:51:25 -07001100 host_config = host_config,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001101 volumes = volumes, tty = True)
A R Karthick85eb1862017-01-23 16:10:57 -08001102 if network is not None:
1103 Container.connect_to_network(self.name, network)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001104 print('Starting Quagga on container %s' %self.name)
1105 self.execute('{0}/start.sh {1}'.format(self.guest_quagga_config, config_file))
1106 time.sleep(boot_delay)
1107
1108 @classmethod
1109 def build_image(cls, image):
A R Karthickaa54a1c2016-12-15 11:42:08 -08001110 onos_quagga_ip = Onos.QUAGGA_CONFIG[0]['ip']
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001111 print('Building Quagga image %s' %image)
1112 dockerfile = '''
A R Karthick41adfce2016-06-10 09:51:25 -07001113FROM ubuntu:14.04
1114MAINTAINER chetan@ciena.com
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001115WORKDIR /root
1116RUN useradd -M quagga
1117RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga
1118RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga
A R Karthick973ea692016-10-17 12:23:02 -07001119RUN 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 -07001120RUN git clone git://git.savannah.nongnu.org/quagga.git quagga && \
A R Karthick8f69c2c2016-10-21 11:43:26 -07001121(cd quagga && git checkout quagga-1.0.20160315 && ./bootstrap.sh && \
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001122sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \
1123./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install)
1124RUN ldconfig
1125'''.format(onos_quagga_ip)
1126 super(Quagga, cls).build_image(dockerfile, image)
1127 print('Done building image %s' %image)
A R Karthick81acbff2016-06-17 14:45:16 -07001128
A.R Karthick1700e0e2016-10-06 18:16:57 -07001129class QuaggaStopWrapper(Container):
1130 def __init__(self, name = Quagga.NAME, image = Quagga.IMAGE, tag = 'candidate'):
1131 super(QuaggaStopWrapper, self).__init__(name, image, prefix = Container.IMAGE_PREFIX, tag = tag)
1132 if self.exists():
1133 self.kill()
1134
1135
A R Karthick81acbff2016-06-17 14:45:16 -07001136def reinitContainerClients():
1137 docker_netns.dckr = Client()
1138 Container.dckr = Client()
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001139
1140class Xos(Container):
1141 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
1142 TAG = 'latest'
1143 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -07001144 host_guest_map = None
1145 env = None
1146 ports = None
1147 volumes = None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001148
A R Karthick6e80afd2016-10-10 16:03:12 -07001149 @classmethod
1150 def get_cmd(cls, img_name):
1151 cmd = cls.dckr.inspect_image(img_name)['Config']['Cmd']
1152 return ' '.join(cmd)
1153
A R Karthicke3bde962016-09-27 15:06:35 -07001154 def __init__(self, name, image, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001155 boot_delay = 20, restart = False, network_cfg = None, update = False):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001156 if restart is True:
1157 ##Find the right image to restart
1158 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
1159 if running_image:
1160 image_name = running_image[0]['Image']
1161 try:
1162 image = image_name.split(':')[0]
1163 tag = image_name.split(':')[1]
1164 except: pass
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001165 super(Xos, self).__init__(name, image, prefix = prefix, tag = tag)
1166 if update is True or not self.img_exists():
1167 self.build_image(self.image_name)
A R Karthick6e80afd2016-10-10 16:03:12 -07001168 self.command = self.get_cmd(self.image_name).strip() or None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001169 if restart is True and self.exists():
1170 self.kill()
1171 if not self.exists():
1172 self.remove_container(name, force=True)
A R Karthicke3bde962016-09-27 15:06:35 -07001173 host_config = self.create_host_config(port_list = self.ports,
1174 host_guest_map = self.host_guest_map,
1175 privileged = True)
1176 print('Starting XOS container %s' %self.name)
1177 self.start(ports = self.ports, environment = self.env, host_config = host_config,
1178 volumes = self.volumes, tty = True)
1179 print('Waiting %d seconds for XOS Base Container to boot' %(boot_delay))
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001180 time.sleep(boot_delay)
1181
1182 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -07001183 def build_image(cls, image, dockerfile_path, image_target = 'build'):
1184 cmd = 'cd {} && make {}'.format(dockerfile_path, image_target)
1185 print('Building XOS %s' %image)
1186 res = os.system(cmd)
1187 print('Done building image %s. Image build %s' %(image, 'successful' if res == 0 else 'failed'))
1188 return res
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001189
A R Karthicke3bde962016-09-27 15:06:35 -07001190class XosServer(Xos):
1191 ports = [8000,9998,9999]
1192 NAME = 'xos-server'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001193 IMAGE = 'xosproject/xos'
A R Karthicke3bde962016-09-27 15:06:35 -07001194 BASE_IMAGE = 'xosproject/xos-base'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001195 TAG = 'latest'
1196 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -07001197 dockerfile_path = os.path.join(Xos.setup_dir, 'xos')
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001198
A R Karthicke3bde962016-09-27 15:06:35 -07001199 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001200 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001201 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001202
1203 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -07001204 def build_image(cls, image = IMAGE):
1205 ##build the base image and then build the server image
1206 Xos.build_image(cls.BASE_IMAGE, cls.dockerfile_path, image_target = 'base')
1207 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001208
A R Karthicke3bde962016-09-27 15:06:35 -07001209class XosSynchronizerOpenstack(Xos):
1210 ports = [2375,]
1211 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer')
1212 NAME = 'xos-synchronizer'
1213 IMAGE = 'xosproject/xos-synchronizer-openstack'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001214 TAG = 'latest'
1215 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -07001216 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001217
A R Karthicke3bde962016-09-27 15:06:35 -07001218 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -07001219 tag = TAG, boot_delay = 20, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001220 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001221
1222 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -07001223 def build_image(cls, image = IMAGE):
1224 XosServer.build_image()
1225 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001226
A R Karthicke3bde962016-09-27 15:06:35 -07001227class XosSynchronizerOnboarding(Xos):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001228 NAME = 'xos-synchronizer-onboarding'
1229 IMAGE = 'xosproject/xos-synchronizer-onboarding'
1230 TAG = 'latest'
1231 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -07001232 dockerfile_path = os.path.join(Xos.setup_dir, 'onboarding_synchronizer')
1233 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001234
A R Karthicke3bde962016-09-27 15:06:35 -07001235 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -07001236 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001237 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001238
1239 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -07001240 def build_image(cls, image = IMAGE):
1241 XosSynchronizerOpenstack.build_image()
1242 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001243
A R Karthicke3bde962016-09-27 15:06:35 -07001244class XosSynchronizerOpenvpn(Xos):
1245 NAME = 'xos-synchronizer-openvpn'
1246 IMAGE = 'xosproject/xos-openvpn'
1247 TAG = 'latest'
1248 PREFIX = ''
1249 dockerfile_path = os.path.join(Xos.setup_dir, 'openvpn')
1250 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001251
A R Karthicke3bde962016-09-27 15:06:35 -07001252 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -07001253 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001254 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1255
1256 @classmethod
1257 def build_image(cls, image = IMAGE):
1258 XosSynchronizerOpenstack.build_image()
1259 Xos.build_image(image, cls.dockerfile_path)
1260
1261class XosPostgresql(Xos):
1262 ports = [5432,]
1263 NAME = 'xos-db-postgres'
1264 IMAGE = 'xosproject/xos-postgres'
1265 TAG = 'latest'
1266 PREFIX = ''
1267 volumes = ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
1268 dockerfile_path = os.path.join(Xos.setup_dir, 'postgresql')
1269
1270 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -07001271 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001272 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1273
1274 @classmethod
1275 def build_image(cls, image = IMAGE):
1276 Xos.build_image(image, cls.dockerfile_path)
1277
1278class XosSyndicateMs(Xos):
1279 ports = [8080,]
1280 env = None
1281 NAME = 'xos-syndicate-ms'
1282 IMAGE = 'xosproject/syndicate-ms'
1283 TAG = 'latest'
1284 PREFIX = ''
1285 dockerfile_path = os.path.join(Xos.setup_dir, 'syndicate-ms')
1286
1287 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001288 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001289 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1290
1291 @classmethod
1292 def build_image(cls, image = IMAGE):
1293 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001294
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001295class XosSyncVtn(Xos):
1296 ports = [8080,]
1297 env = None
1298 NAME = 'xos-synchronizer-vtn'
1299 IMAGE = 'xosproject/xos-synchronizer-vtn'
1300 TAG = 'latest'
1301 PREFIX = ''
1302 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtn')
1303
1304 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001305 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001306 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1307
1308 @classmethod
1309 def build_image(cls, image = IMAGE):
1310 Xos.build_image(image, cls.dockerfile_path)
1311
1312class XosSyncVtr(Xos):
1313 ports = [8080,]
1314 env = None
1315 NAME = 'xos-synchronizer-vtr'
1316 IMAGE = 'xosproject/xos-synchronizer-vtr'
1317 TAG = 'latest'
1318 PREFIX = ''
1319 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtr')
1320
1321 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001322 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001323 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1324
1325 @classmethod
1326 def build_image(cls, image = IMAGE):
1327 Xos.build_image(image, cls.dockerfile_path)
1328
1329class XosSyncVsg(Xos):
1330 ports = [8080,]
1331 env = None
1332 NAME = 'xos-synchronizer-vsg'
1333 IMAGE = 'xosproject/xos-synchronizer-vsg'
1334 TAG = 'latest'
1335 PREFIX = ''
1336 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vsg')
1337
1338 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001339 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001340 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1341
1342 @classmethod
1343 def build_image(cls, image = IMAGE):
1344 Xos.build_image(image, cls.dockerfile_path)
1345
1346
1347class XosSyncOnos(Xos):
1348 ports = [8080,]
1349 env = None
1350 NAME = 'xos-synchronizer-onos'
1351 IMAGE = 'xosproject/xos-synchronizer-onos'
1352 TAG = 'latest'
1353 PREFIX = ''
1354 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-onos')
1355
1356 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001357 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001358 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1359
1360 @classmethod
1361 def build_image(cls, image = IMAGE):
1362 Xos.build_image(image, cls.dockerfile_path)
1363
1364class XosSyncFabric(Xos):
1365 ports = [8080,]
1366 env = None
1367 NAME = 'xos-synchronizer-fabric'
1368 IMAGE = 'xosproject/xos-synchronizer-fabric'
1369 TAG = 'latest'
1370 PREFIX = ''
1371 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-fabric')
1372
1373 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001374 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001375 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1376
1377 @classmethod
1378 def build_image(cls, image = IMAGE):
1379 Xos.build_image(image, cls.dockerfile_path)
A R Karthick19aaf5c2016-11-09 17:47:57 -08001380
1381if __name__ == '__main__':
1382 onos = Onos(boot_delay = 10, restart = True)