blob: 4e9cc2503c33bc79025b87d6c5bd494334b016d7 [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
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
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# 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
16
A R Karthick41adfce2016-06-10 09:51:25 -070017#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070018# Copyright 2016-present Ciena Corporation
19#
20# Licensed under the Apache License, Version 2.0 (the "License");
21# you may not use this file except in compliance with the License.
22# You may obtain a copy of the License at
A R Karthick41adfce2016-06-10 09:51:25 -070023#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070024# http://www.apache.org/licenses/LICENSE-2.0
A R Karthick41adfce2016-06-10 09:51:25 -070025#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070026# Unless required by applicable law or agreed to in writing, software
27# distributed under the License is distributed on an "AS IS" BASIS,
28# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29# See the License for the specific language governing permissions and
30# limitations under the License.
31#
Chetan Gaonker3533faa2016-04-25 17:50:14 -070032import os,time
33import io
34import json
A R Karthickd44cea12016-07-20 12:16:41 -070035import yaml
A.R Karthickc4e474d2016-12-12 15:24:57 -080036import errno
A R Karthickaa54a1c2016-12-15 11:42:08 -080037import copy
Chetan Gaonker3533faa2016-04-25 17:50:14 -070038from pyroute2 import IPRoute
A.R Karthickc4e474d2016-12-12 15:24:57 -080039from pyroute2.netlink import NetlinkError
Chetan Gaonker3533faa2016-04-25 17:50:14 -070040from itertools import chain
41from nsenter import Namespace
A R Karthick6f2ac6f2017-07-26 12:55:24 -070042try:
43 from docker import APIClient as Client
44except:
45 from docker import Client
A R Karthick85eb1862017-01-23 16:10:57 -080046from docker import utils as dockerutils
A.R Karthickf184b342017-01-27 19:30:50 -080047import shutil
A.R Karthick95d044e2016-06-10 18:44:36 -070048from OnosCtrl import OnosCtrl
A R Karthick19aaf5c2016-11-09 17:47:57 -080049from OnosLog import OnosLog
A R Karthick03bd2812017-03-03 17:49:17 -080050from onosclidriver import OnosCliDriver
A.R Karthickc4e474d2016-12-12 15:24:57 -080051from threadPool import ThreadPool
A R Karthickaa54a1c2016-12-15 11:42:08 -080052from threading import Lock
Chetan Gaonker3533faa2016-04-25 17:50:14 -070053
54class docker_netns(object):
55
56 dckr = Client()
57 def __init__(self, name):
58 pid = int(self.dckr.inspect_container(name)['State']['Pid'])
59 if pid == 0:
60 raise Exception('no container named {0}'.format(name))
61 self.pid = pid
62
63 def __enter__(self):
64 pid = self.pid
65 if not os.path.exists('/var/run/netns'):
66 os.mkdir('/var/run/netns')
67 os.symlink('/proc/{0}/ns/net'.format(pid), '/var/run/netns/{0}'.format(pid))
68 return str(pid)
69
70 def __exit__(self, type, value, traceback):
71 pid = self.pid
72 os.unlink('/var/run/netns/{0}'.format(pid))
73
74flatten = lambda l: chain.from_iterable(l)
75
76class Container(object):
77 dckr = Client()
A R Karthick07608ef2016-08-23 16:51:19 -070078 IMAGE_PREFIX = '' ##for saving global prefix for all test classes
A R Karthickaa54a1c2016-12-15 11:42:08 -080079 CONFIG_LOCK = Lock()
A R Karthick07608ef2016-08-23 16:51:19 -070080
81 def __init__(self, name, image, prefix='', tag = 'candidate', command = 'bash', quagga_config = None):
Chetan Gaonker3533faa2016-04-25 17:50:14 -070082 self.name = name
A R Karthick07608ef2016-08-23 16:51:19 -070083 self.prefix = prefix
84 if prefix:
85 self.prefix += '/'
86 image = '{}{}'.format(self.prefix, image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -070087 self.image = image
88 self.tag = tag
A R Karthickd44cea12016-07-20 12:16:41 -070089 if tag:
90 self.image_name = image + ':' + tag
91 else:
92 self.image_name = image
Chetan Gaonker3533faa2016-04-25 17:50:14 -070093 self.id = None
94 self.command = command
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -070095 self.quagga_config = quagga_config
Chetan Gaonker3533faa2016-04-25 17:50:14 -070096
97 @classmethod
98 def build_image(cls, dockerfile, tag, force=True, nocache=False):
99 f = io.BytesIO(dockerfile.encode('utf-8'))
100 if force or not cls.image_exists(tag):
101 print('Build {0}...'.format(tag))
102 for line in cls.dckr.build(fileobj=f, rm=True, tag=tag, decode=True, nocache=nocache):
103 if 'stream' in line:
104 print(line['stream'].strip())
105
106 @classmethod
107 def image_exists(cls, name):
A R Karthicke07fc3a2017-02-27 10:49:29 -0800108 #return name in [ctn['RepoTags'][0] for ctn in cls.dckr.images()]
109 return name in list( flatten(ctn['RepoTags'] if ctn['RepoTags'] else '' for ctn in cls.dckr.images()) )
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700110
111 @classmethod
112 def create_host_config(cls, port_list = None, host_guest_map = None, privileged = False):
113 port_bindings = None
114 binds = None
115 if port_list:
116 port_bindings = {}
117 for p in port_list:
A R Karthick184945a2017-07-25 17:23:57 -0700118 if type(p) is tuple:
119 port_bindings[str(p[0])] = str(p[1])
120 else:
121 port_bindings[str(p)] = str(p)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700122
123 if host_guest_map:
124 binds = []
125 for h, g in host_guest_map:
126 binds.append('{0}:{1}'.format(h, g))
127
128 return cls.dckr.create_host_config(binds = binds, port_bindings = port_bindings, privileged = privileged)
129
130 @classmethod
A R Karthick85eb1862017-01-23 16:10:57 -0800131 def connect_to_network(cls, name, network):
132 try:
133 cls.dckr.connect_container_to_network(name, network)
134 return True
135 except:
136 return False
137
138 @classmethod
139 def create_network(cls, network, subnet = None, gateway = None):
140 ipam_config = None
141 if subnet is not None and gateway is not None:
142 ipam_pool = dockerutils.create_ipam_pool(subnet = subnet, gateway = gateway)
143 ipam_config = dockerutils.create_ipam_config(pool_configs = [ipam_pool])
144 cls.dckr.create_network(network, driver='bridge', ipam = ipam_config)
145
146 @classmethod
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700147 def cleanup(cls, image):
A R Karthick09b1f4e2016-05-12 14:31:50 -0700148 cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True))
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700149 for cnt in cnt_list:
150 print('Cleaning container %s' %cnt['Id'])
A.R Karthick95d044e2016-06-10 18:44:36 -0700151 if cnt.has_key('State') and cnt['State'] == 'running':
A R Karthick09b1f4e2016-05-12 14:31:50 -0700152 cls.dckr.kill(cnt['Id'])
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700153 cls.dckr.remove_container(cnt['Id'], force=True)
154
155 @classmethod
156 def remove_container(cls, name, force=True):
157 try:
158 cls.dckr.remove_container(name, force = force)
159 except: pass
160
161 def exists(self):
162 return '/{0}'.format(self.name) in list(flatten(n['Names'] for n in self.dckr.containers()))
163
164 def img_exists(self):
A R Karthicke07fc3a2017-02-27 10:49:29 -0800165 #return self.image_name in [ctn['RepoTags'][0] if ctn['RepoTags'] else '' for ctn in self.dckr.images()]
166 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 -0700167
A R Karthick75844572017-01-23 16:57:44 -0800168 def ip(self, network = None):
A R Karthick2b93d6a2016-09-06 15:19:09 -0700169 cnt_list = filter(lambda c: c['Names'][0] == '/{}'.format(self.name), self.dckr.containers())
170 #if not cnt_list:
171 # cnt_list = filter(lambda c: c['Image'] == self.image_name, self.dckr.containers())
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700172 cnt_settings = cnt_list.pop()
A R Karthick75844572017-01-23 16:57:44 -0800173 if network is not None and cnt_settings['NetworkSettings']['Networks'].has_key(network):
174 return cnt_settings['NetworkSettings']['Networks'][network]['IPAddress']
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700175 return cnt_settings['NetworkSettings']['Networks']['bridge']['IPAddress']
176
A R Karthick2b93d6a2016-09-06 15:19:09 -0700177 @classmethod
178 def ips(cls, image_name):
179 cnt_list = filter(lambda c: c['Image'] == image_name, cls.dckr.containers())
180 ips = [ cnt['NetworkSettings']['Networks']['bridge']['IPAddress'] for cnt in cnt_list ]
181 return ips
182
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700183 def kill(self, remove = True):
184 self.dckr.kill(self.name)
185 self.dckr.remove_container(self.name, force=True)
186
A R Karthick41adfce2016-06-10 09:51:25 -0700187 def start(self, rm = True, ports = None, volumes = None, host_config = None,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700188 environment = None, tty = False, stdin_open = True):
189
190 if rm and self.exists():
191 print('Removing container:', self.name)
192 self.dckr.remove_container(self.name, force=True)
193
A R Karthick41adfce2016-06-10 09:51:25 -0700194 ctn = self.dckr.create_container(image=self.image_name, ports = ports, command=self.command,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700195 detach=True, name=self.name,
A R Karthick41adfce2016-06-10 09:51:25 -0700196 environment = environment,
197 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700198 host_config = host_config, stdin_open=stdin_open, tty = tty)
199 self.dckr.start(container=self.name)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700200 if self.quagga_config:
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700201 self.connect_to_br()
202 self.id = ctn['Id']
203 return ctn
204
Thangavelu K Sef6f0a52016-12-14 19:57:05 +0000205 @classmethod
206 def pause_container(cls, image, delay):
207 cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True))
208 for cnt in cnt_list:
209 print('Pause the container %s' %cnt['Id'])
210 if cnt.has_key('State') and cnt['State'] == 'running':
211 cls.dckr.pause(cnt['Id'])
212 if delay != 0:
213 time.sleep(delay)
214 for cnt in cnt_list:
215 print('Unpause the container %s' %cnt['Id'])
216 cls.dckr.unpause(cnt['Id'])
217 else:
218 print('Infinity time pause the container %s' %cnt['Id'])
219 return 'success'
220
A R Karthick52414732017-01-31 09:59:47 -0800221 def connect_to_br(self, index = 0):
A R Karthickaa54a1c2016-12-15 11:42:08 -0800222 self.CONFIG_LOCK.acquire()
223 try:
224 with docker_netns(self.name) as pid:
225 for quagga_config in self.quagga_config:
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700226 ip = IPRoute()
A R Karthickaa54a1c2016-12-15 11:42:08 -0800227 br = ip.link_lookup(ifname=quagga_config['bridge'])
228 if len(br) == 0:
229 try:
230 ip.link_create(ifname=quagga_config['bridge'], kind='bridge')
231 except NetlinkError as e:
232 err, _ = e.args
233 if err == errno.EEXIST:
234 pass
235 else:
236 raise NetlinkError(*e.args)
237 br = ip.link_lookup(ifname=quagga_config['bridge'])
238 br = br[0]
239 ip.link('set', index=br, state='up')
A R Karthick52414732017-01-31 09:59:47 -0800240 ifname = '{0}-{1}'.format(self.name[:12], index)
A R Karthickaa54a1c2016-12-15 11:42:08 -0800241 ifs = ip.link_lookup(ifname=ifname)
242 if len(ifs) > 0:
243 ip.link_remove(ifs[0])
244 peer_ifname = '{0}-{1}'.format(pid, index)
245 ip.link_create(ifname=ifname, kind='veth', peer=peer_ifname)
246 host = ip.link_lookup(ifname=ifname)[0]
247 ip.link('set', index=host, master=br)
248 ip.link('set', index=host, state='up')
249 guest = ip.link_lookup(ifname=peer_ifname)[0]
250 ip.link('set', index=guest, net_ns_fd=pid)
251 with Namespace(pid, 'net'):
252 ip = IPRoute()
253 ip.link('set', index=guest, ifname='eth{}'.format(index+1))
254 ip.addr('add', index=guest, address=quagga_config['ip'], mask=quagga_config['mask'])
255 ip.link('set', index=guest, state='up')
256 index += 1
257 finally:
258 self.CONFIG_LOCK.release()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700259
Thangavelu K Sef6f0a52016-12-14 19:57:05 +0000260 def execute(self, cmd, tty = True, stream = False, shell = False, detach = True):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700261 res = 0
262 if type(cmd) == str:
263 cmds = (cmd,)
264 else:
265 cmds = cmd
266 if shell:
267 for c in cmds:
268 res += os.system('docker exec {0} {1}'.format(self.name, c))
269 return res
270 for c in cmds:
271 i = self.dckr.exec_create(container=self.name, cmd=c, tty = tty, privileged = True)
A R Karthickd6dd9b22017-02-24 15:17:22 -0800272 s = self.dckr.exec_start(i['Id'], stream = stream, detach=detach, socket=True)
273 try:
274 s.close()
275 except: pass
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700276 result = self.dckr.exec_inspect(i['Id'])
277 res += 0 if result['ExitCode'] == None else result['ExitCode']
278 return res
279
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700280 def restart(self, timeout =10):
281 return self.dckr.restart(self.name, timeout)
282
A R Karthickc69d73e2017-01-20 11:44:34 -0800283def get_mem(jvm_heap_size = None, instances = 1):
A R Karthick1f908202016-11-16 17:32:20 -0800284 if instances <= 0:
285 instances = 1
A R Karthickc69d73e2017-01-20 11:44:34 -0800286 heap_size = jvm_heap_size
287 heap_size_i = 0
288 #sanitize the heap size config
289 if heap_size is not None:
290 if not heap_size.isdigit():
291 try:
292 heap_size_i = int(heap_size[:-1])
293 suffix = heap_size[-1]
294 if suffix == 'M':
295 heap_size_i /= 1024 #convert to gigs
A.R Karthick99044822017-02-09 14:04:20 -0800296 #allow to specific minimum heap size
297 if heap_size_i == 0:
298 return heap_size
A R Karthickc69d73e2017-01-20 11:44:34 -0800299 except:
300 ##invalid suffix length probably. Fall back to default
301 heap_size = None
302 else:
303 heap_size_i = int(heap_size)
304
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700305 with open('/proc/meminfo', 'r') as fd:
306 meminfo = fd.readlines()
307 mem = 0
308 for m in meminfo:
309 if m.startswith('MemTotal:') or m.startswith('SwapTotal:'):
310 mem += int(m.split(':')[1].strip().split()[0])
311
A R Karthick1f908202016-11-16 17:32:20 -0800312 mem = max(mem/1024/1024/2/instances, 1)
Chetan Gaonker6d0a7b02016-05-03 16:57:28 -0700313 mem = min(mem, 16)
A R Karthickc69d73e2017-01-20 11:44:34 -0800314
315 if heap_size_i:
316 #we take the minimum of the provided heap size and max allowed heap size
317 heap_size_i = min(heap_size_i, mem)
318 else:
319 heap_size_i = mem
320
321 return '{}G'.format(heap_size_i)
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700322
A R Karthickd44cea12016-07-20 12:16:41 -0700323class OnosCord(Container):
324 """Use this when running the cord tester agent on the onos compute node"""
A R Karthickd44cea12016-07-20 12:16:41 -0700325 onos_config_dir_guest = '/root/onos/config'
A R Karthick03bd2812017-03-03 17:49:17 -0800326 synchronizer_map = { 'vtn' : { 'install':
327 ('http://mavenrepo:8080/repository/org/opencord/cord-config/1.2-SNAPSHOT/cord-config-1.2-SNAPSHOT.oar',
328 'http://mavenrepo:8080/repository/org/opencord/vtn/1.2-SNAPSHOT/vtn-1.2-SNAPSHOT.oar',),
329 'activate':
330 ('org.onosproject.ovsdb-base', 'org.onosproject.drivers.ovsdb',
331 'org.onosproject.dhcp', 'org.onosproject.optical-model',
332 'org.onosproject.openflow-base', 'org.onosproject.proxyarp',
333 'org.onosproject.hostprovider'),
334 },
335 'fabric' : { 'activate':
336 ('org.onosproject.hostprovider', 'org.onosproject.optical-model',
337 'org.onosproject.openflow-base', 'org.onosproject.vrouter',
338 'org.onosproject.netcfghostprovider', 'org.onosproject.netcfglinksprovider',
339 'org.onosproject.segmentrouting', 'org.onosproject.proxyarp'),
340 }
341 }
342 tester_apps = ('http://mavenrepo:8080/repository/org/opencord/aaa/1.2-SNAPSHOT/aaa-1.2-SNAPSHOT.oar',
343 'http://mavenrepo:8080/repository/org/opencord/igmp/1.2-SNAPSHOT/igmp-1.2-SNAPSHOT.oar',)
A R Karthickd44cea12016-07-20 12:16:41 -0700344
A.R Karthickddf12772017-05-17 13:49:47 -0700345 old_service_profile = '/opt/cord/orchestration/service-profile/cord-pod'
A R Karthick49529c52017-05-19 09:43:01 -0700346 cord_profile = '/opt/cord_profile'
A.R Karthickddf12772017-05-17 13:49:47 -0700347
A R Karthick03bd2812017-03-03 17:49:17 -0800348 def __init__(self, onos_ip, conf, service_profile, synchronizer, start = True, boot_delay = 5):
A.R Karthickf184b342017-01-27 19:30:50 -0800349 if not os.access(conf, os.F_OK):
350 raise Exception('ONOS cord configuration location %s is invalid' %conf)
A.R Karthickddf12772017-05-17 13:49:47 -0700351 self.old_cord = False
352 if os.access(self.old_service_profile, os.F_OK):
353 self.old_cord = True
A R Karthickbd9b8a32016-07-21 09:56:45 -0700354 self.onos_ip = onos_ip
A.R Karthickf184b342017-01-27 19:30:50 -0800355 self.onos_cord_dir = conf
A R Karthickbd9b8a32016-07-21 09:56:45 -0700356 self.boot_delay = boot_delay
A.R Karthickf184b342017-01-27 19:30:50 -0800357 self.synchronizer = synchronizer
358 self.service_profile = service_profile
359 self.docker_yaml = os.path.join(conf, 'docker-compose.yml')
360 self.docker_yaml_saved = os.path.join(conf, 'docker-compose.yml.saved')
361 self.onos_config_dir = os.path.join(conf, 'config')
362 self.onos_cfg_save_loc = os.path.join(conf, 'network-cfg.json.saved')
363 instance_active = False
364 #if we have a wrapper onos instance already active, back out
365 if os.access(self.onos_config_dir, os.F_OK) or os.access(self.docker_yaml_saved, os.F_OK):
366 instance_active = True
367 else:
368 if start is True:
369 os.mkdir(self.onos_config_dir)
370 shutil.copy(self.docker_yaml, self.docker_yaml_saved)
A R Karthickd44cea12016-07-20 12:16:41 -0700371
A.R Karthickf184b342017-01-27 19:30:50 -0800372 self.start_wrapper = instance_active is False and start is True
A R Karthickd44cea12016-07-20 12:16:41 -0700373 ##update the docker yaml with the config volume
374 with open(self.docker_yaml, 'r') as f:
375 yaml_config = yaml.load(f)
376 image = yaml_config['services'].keys()[0]
A R Karthick8983cb02017-06-09 11:32:53 -0700377 cord_conf_dir_basename = os.path.basename(self.onos_cord_dir.replace('-', '').replace('_', ''))
A.R Karthickf184b342017-01-27 19:30:50 -0800378 xos_onos_name = '{}_{}_1'.format(cord_conf_dir_basename, image)
A R Karthick5778a792017-01-31 13:47:16 -0800379 if not yaml_config['services'][image].has_key('volumes'):
380 yaml_config['services'][image]['volumes'] = []
A R Karthickd44cea12016-07-20 12:16:41 -0700381 volumes = yaml_config['services'][image]['volumes']
382 config_volumes = filter(lambda e: e.find(self.onos_config_dir_guest) >= 0, volumes)
383 if not config_volumes:
384 config_volume = '{}:{}'.format(self.onos_config_dir, self.onos_config_dir_guest)
385 volumes.append(config_volume)
A.R Karthickf184b342017-01-27 19:30:50 -0800386 if self.start_wrapper:
387 docker_yaml_changed = '{}-changed'.format(self.docker_yaml)
388 with open(docker_yaml_changed, 'w') as wf:
389 yaml.dump(yaml_config, wf)
390 os.rename(docker_yaml_changed, self.docker_yaml)
A R Karthickd44cea12016-07-20 12:16:41 -0700391 self.volumes = volumes
392
A R Karthickd44cea12016-07-20 12:16:41 -0700393 ##Create an container instance of xos onos
A R Karthick52414732017-01-31 09:59:47 -0800394 super(OnosCord, self).__init__(xos_onos_name, image, tag = '', quagga_config = Onos.QUAGGA_CONFIG)
A.R Karthickf184b342017-01-27 19:30:50 -0800395 self.last_cfg = None
396 if self.start_wrapper:
397 #fetch the current config of onos cord instance and save it
398 try:
399 self.last_cfg = OnosCtrl.get_config(controller = onos_ip)
400 json_data = json.dumps(self.last_cfg, indent=4)
401 with open(self.onos_cfg_save_loc, 'w') as f:
402 f.write(json_data)
403 except:
404 pass
405 #start the container back with the shared onos config volume
406 self.start()
A R Karthickd44cea12016-07-20 12:16:41 -0700407
A R Karthick03bd2812017-03-03 17:49:17 -0800408 def cliEnter(self):
409 retries = 0
410 while retries < 30:
411 cli = OnosCliDriver(controller = self.onos_ip, connect = True)
412 if cli.handle:
413 return cli
414 else:
415 retries += 1
A R Karthick72fcbc52017-03-06 12:35:17 -0800416 time.sleep(3)
A R Karthick03bd2812017-03-03 17:49:17 -0800417
418 return None
419
420 def cliExit(self, cli):
421 if cli:
422 cli.disconnect()
423
A.R Karthickddf12772017-05-17 13:49:47 -0700424 def synchronize_fabric(self, cfg = None):
425 if self.old_cord is True:
426 cmds = [ 'cd {} && make {}'.format(self.old_service_profile, self.synchronizer),
427 'sleep 30'
428 ]
429 for cmd in cmds:
430 try:
431 os.system(cmd)
432 except:
433 pass
434
A R Karthick03bd2812017-03-03 17:49:17 -0800435 def synchronize_vtn(self, cfg = None):
A.R Karthickddf12772017-05-17 13:49:47 -0700436 if self.old_cord is True:
437 cmds = [ 'cd {} && make {}'.format(self.old_service_profile, self.synchronizer),
438 'sleep 30'
439 ]
440 for cmd in cmds:
441 try:
442 os.system(cmd)
443 except:
444 pass
445 return
A R Karthick03bd2812017-03-03 17:49:17 -0800446 if cfg is None:
447 return
448 if not cfg.has_key('apps'):
449 return
450 if not cfg['apps'].has_key('org.opencord.vtn'):
451 return
452 vtn_neutron_cfg = cfg['apps']['org.opencord.vtn']['cordvtn']['openstack']
453 password = vtn_neutron_cfg['password']
454 endpoint = vtn_neutron_cfg['endpoint']
455 user = vtn_neutron_cfg['user']
456 tenant = vtn_neutron_cfg['tenant']
457 vtn_host = cfg['apps']['org.opencord.vtn']['cordvtn']['nodes'][0]['hostname']
458 cli = self.cliEnter()
459 if cli is None:
460 return
461 cli.cordVtnSyncNeutronStates(endpoint, password, tenant = tenant, user = user)
462 time.sleep(2)
463 cli.cordVtnNodeInit(vtn_host)
464 self.cliExit(cli)
465
466 def synchronize(self, cfg_unlink = False):
A R Karthick03bd2812017-03-03 17:49:17 -0800467
468 if not self.synchronizer_map.has_key(self.synchronizer):
469 return
470
471 install_list = ()
472 if self.synchronizer_map[self.synchronizer].has_key('install'):
473 install_list = self.synchronizer_map[self.synchronizer]['install']
474
475 activate_list = ()
476 if self.synchronizer_map[self.synchronizer].has_key('activate'):
477 activate_list = self.synchronizer_map[self.synchronizer]['activate']
478
479 for app_url in install_list:
480 print('Installing app from url: %s' %app_url)
481 OnosCtrl.install_app_from_url(None, None, app_url = app_url, onos_ip = self.onos_ip)
482
483 for app in activate_list:
484 print('Activating app %s' %app)
485 OnosCtrl(app, controller = self.onos_ip).activate()
486 time.sleep(2)
487
488 for app_url in self.tester_apps:
489 print('Installing tester app from url: %s' %app_url)
490 OnosCtrl.install_app_from_url(None, None, app_url = app_url, onos_ip = self.onos_ip)
491
A R Karthick72fcbc52017-03-06 12:35:17 -0800492 cfg = None
493 #restore the saved config after applications are activated
494 if os.access(self.onos_cfg_save_loc, os.F_OK):
495 with open(self.onos_cfg_save_loc, 'r') as f:
496 cfg = json.load(f)
497 try:
498 OnosCtrl.config(cfg, controller = self.onos_ip)
499 if cfg_unlink is True:
500 os.unlink(self.onos_cfg_save_loc)
501 except:
502 pass
503
504 if hasattr(self, 'synchronize_{}'.format(self.synchronizer)):
505 getattr(self, 'synchronize_{}'.format(self.synchronizer))(cfg = cfg)
506
507 #now restart the xos synchronizer container
A R Karthick49529c52017-05-19 09:43:01 -0700508 cmd = None
509 if os.access('{}/onboarding-docker-compose/docker-compose.yml'.format(self.cord_profile), os.F_OK):
510 cmd = 'cd {}/onboarding-docker-compose && \
511 docker-compose -p {} restart xos_synchronizer_{}'.format(self.cord_profile,
512 self.service_profile,
513 self.synchronizer)
514 else:
515 if os.access('{}/docker-compose.yml'.format(self.cord_profile), os.F_OK):
516 cmd = 'cd {} && \
517 docker-compose -p {} restart {}-synchronizer'.format(self.cord_profile,
518 self.service_profile,
519 self.synchronizer)
520 if cmd is not None:
521 try:
522 print(cmd)
523 os.system(cmd)
524 except:
525 pass
A R Karthick03bd2812017-03-03 17:49:17 -0800526
A R Karthickd44cea12016-07-20 12:16:41 -0700527 def start(self, restart = False, network_cfg = None):
A R Karthick928ad622017-01-30 12:18:32 -0800528 if network_cfg is not None:
A R Karthickd44cea12016-07-20 12:16:41 -0700529 json_data = json.dumps(network_cfg, indent=4)
530 with open('{}/network-cfg.json'.format(self.onos_config_dir), 'w') as f:
531 f.write(json_data)
A R Karthick52414732017-01-31 09:59:47 -0800532
533 #we avoid using docker-compose restart for now.
534 #since we don't want to retain the metadata across restarts
A R Karthick03bd2812017-03-03 17:49:17 -0800535 #stop and start and synchronize the services before installing tester cord apps
536 cmds = [ 'cd {} && docker-compose down'.format(self.onos_cord_dir),
537 'cd {} && docker-compose up -d'.format(self.onos_cord_dir),
A R Karthickbc894372017-05-12 16:34:08 -0700538 'sleep 150',
A R Karthick03bd2812017-03-03 17:49:17 -0800539 ]
540 for cmd in cmds:
A.R Karthickf184b342017-01-27 19:30:50 -0800541 try:
A R Karthick03bd2812017-03-03 17:49:17 -0800542 print(cmd)
A.R Karthickf184b342017-01-27 19:30:50 -0800543 os.system(cmd)
A R Karthick03bd2812017-03-03 17:49:17 -0800544 except:pass
A R Karthick52414732017-01-31 09:59:47 -0800545
A R Karthick03bd2812017-03-03 17:49:17 -0800546 self.synchronize()
A R Karthick52414732017-01-31 09:59:47 -0800547 ##we could also connect container to default docker network but disabled for now
548 #Container.connect_to_network(self.name, 'bridge')
A R Karthick52414732017-01-31 09:59:47 -0800549 #connect container to the quagga bridge
550 self.connect_to_br(index = 0)
A.R Karthickf184b342017-01-27 19:30:50 -0800551 print('Waiting %d seconds for ONOS instance to start' %self.boot_delay)
A R Karthickbd9b8a32016-07-21 09:56:45 -0700552 time.sleep(self.boot_delay)
A R Karthickd44cea12016-07-20 12:16:41 -0700553
554 def build_image(self):
555 build_cmd = 'cd {} && docker-compose build'.format(self.onos_cord_dir)
556 os.system(build_cmd)
557
A.R Karthickf184b342017-01-27 19:30:50 -0800558 def restore(self, force = False):
559 restore = self.start_wrapper is True or force is True
560 if not restore:
A.R Karthick263d3fc2017-01-27 12:52:53 -0800561 return
A R Karthick394976f2017-01-31 14:25:16 -0800562 #nothing to restore
563 if not os.access(self.docker_yaml_saved, os.F_OK):
564 return
A R Karthick03bd2812017-03-03 17:49:17 -0800565
A.R Karthickf184b342017-01-27 19:30:50 -0800566 #restore the config files back. The synchronizer restore should bring the last config back
567 cmds = ['cd {} && docker-compose down'.format(self.onos_cord_dir),
568 'rm -rf {}'.format(self.onos_config_dir),
569 'mv {} {}'.format(self.docker_yaml_saved, self.docker_yaml),
570 'cd {} && docker-compose up -d'.format(self.onos_cord_dir),
A R Karthickbc894372017-05-12 16:34:08 -0700571 'sleep 150',
A.R Karthickf184b342017-01-27 19:30:50 -0800572 ]
573 for cmd in cmds:
A.R Karthickb17e2022017-01-27 11:29:26 -0800574 try:
A.R Karthickf184b342017-01-27 19:30:50 -0800575 print(cmd)
576 os.system(cmd)
A.R Karthickb17e2022017-01-27 11:29:26 -0800577 except: pass
578
A R Karthick03bd2812017-03-03 17:49:17 -0800579 self.synchronize(cfg_unlink = True)
A.R Karthickb17e2022017-01-27 11:29:26 -0800580
A.R Karthick1700e0e2016-10-06 18:16:57 -0700581class OnosCordStopWrapper(Container):
582 onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord')
583 docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml')
584
585 def __init__(self):
586 if os.access(self.docker_yaml, os.F_OK):
587 with open(self.docker_yaml, 'r') as f:
588 yaml_config = yaml.load(f)
589 image = yaml_config['services'].keys()[0]
590 name = 'cordtestercord_{}_1'.format(image)
591 super(OnosCordStopWrapper, self).__init__(name, image, tag = '')
592 if self.exists():
593 print('Killing container %s' %self.name)
594 self.kill()
595
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700596class Onos(Container):
A R Karthickaa54a1c2016-12-15 11:42:08 -0800597 QUAGGA_CONFIG = [ { 'bridge' : 'quagga-br', 'ip': '10.10.0.4', 'mask' : 16 }, ]
A R Karthicka2492c12016-12-16 10:31:51 -0800598 MAX_INSTANCES = 3
A R Karthickc69d73e2017-01-20 11:44:34 -0800599 JVM_HEAP_SIZE = None
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700600 SYSTEM_MEMORY = (get_mem(),) * 2
A R Karthicka2492c12016-12-16 10:31:51 -0800601 INSTANCE_MEMORY = (get_mem(instances=MAX_INSTANCES),) * 2
A R Karthickc69d73e2017-01-20 11:44:34 -0800602 JAVA_OPTS_FORMAT = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode'
603 JAVA_OPTS_DEFAULT = JAVA_OPTS_FORMAT.format(*SYSTEM_MEMORY) #-XX:+PrintGCDetails -XX:+PrintGCTimeStamps'
604 JAVA_OPTS_CLUSTER_DEFAULT = JAVA_OPTS_FORMAT.format(*INSTANCE_MEMORY)
605 env = { 'ONOS_APPS' : 'drivers,openflow,proxyarp,vrouter', 'JAVA_OPTS' : JAVA_OPTS_DEFAULT }
A R Karthick6e70e142017-07-28 15:25:38 -0700606 onos_cord_apps = ( ['cord-config', '1.2-SNAPSHOT', 'org.opencord.config'],
607 ['aaa', '1.2-SNAPSHOT', 'org.opencord.aaa'],
608 ['igmp', '1.2-SNAPSHOT', 'org.opencord.igmp'],
A.R Karthick95d044e2016-06-10 18:44:36 -0700609 )
A R Karthickb608d402017-06-02 11:48:41 -0700610 cord_apps_version_updated = False
A R Karthick184945a2017-07-25 17:23:57 -0700611 expose_port = False
612 expose_ports = [ 8181, 8101, 9876, 6653, 6633, 2000, 2620, 5005 ]
613 ports = []
A R Karthickf2f4ca62016-08-17 10:34:08 -0700614 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
615 host_config_dir = os.path.join(setup_dir, 'onos-config')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700616 guest_config_dir = '/root/onos/config'
A.R Karthickdda22062017-02-09 14:39:20 -0800617 guest_data_dir = '/root/onos/apache-karaf-3.0.8/data'
618 guest_log_file = '/root/onos/apache-karaf-3.0.8/data/log/karaf.log'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700619 onos_gen_partitions = os.path.join(setup_dir, 'onos-gen-partitions')
A R Karthick2b93d6a2016-09-06 15:19:09 -0700620 onos_form_cluster = os.path.join(setup_dir, 'onos-form-cluster')
A.R Karthick95d044e2016-06-10 18:44:36 -0700621 cord_apps_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'apps')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700622 host_guest_map = ( (host_config_dir, guest_config_dir), )
A R Karthickd52ca8a2017-07-24 17:38:55 -0700623 ssl_key = None
A R Karthick2b93d6a2016-09-06 15:19:09 -0700624 cluster_cfg = os.path.join(host_config_dir, 'cluster.json')
625 cluster_mode = False
626 cluster_instances = []
Chetan Gaonker503032a2016-05-12 12:06:29 -0700627 NAME = 'cord-onos'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700628 ##the ip of ONOS in default cluster.json in setup/onos-config
629 CLUSTER_CFG_IP = '172.17.0.2'
A R Karthick07608ef2016-08-23 16:51:19 -0700630 IMAGE = 'onosproject/onos'
631 TAG = 'latest'
632 PREFIX = ''
A R Karthickf2f4ca62016-08-17 10:34:08 -0700633
634 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700635 def generate_cluster_cfg(cls, ip):
636 if type(ip) in [ list, tuple ]:
637 ips = ' '.join(ip)
638 else:
639 ips = ip
A R Karthickf2f4ca62016-08-17 10:34:08 -0700640 try:
A R Karthick2b93d6a2016-09-06 15:19:09 -0700641 cmd = '{} {} {}'.format(cls.onos_gen_partitions, cls.cluster_cfg, ips)
642 os.system(cmd)
643 except: pass
644
645 @classmethod
646 def form_cluster(cls, ips):
647 nodes = ' '.join(ips)
648 try:
649 cmd = '{} {}'.format(cls.onos_form_cluster, nodes)
A R Karthickf2f4ca62016-08-17 10:34:08 -0700650 os.system(cmd)
651 except: pass
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700652
A R Karthick9d48c652016-09-15 09:16:36 -0700653 @classmethod
654 def cleanup_runtime(cls):
655 '''Cleanup ONOS runtime generated files'''
656 files = ( Onos.cluster_cfg, os.path.join(Onos.host_config_dir, 'network-cfg.json') )
657 for f in files:
658 if os.access(f, os.F_OK):
659 try:
660 os.unlink(f)
661 except: pass
662
A R Karthickec2db322016-11-17 15:06:01 -0800663 @classmethod
664 def get_data_map(cls, host_volume, guest_volume_dir):
665 host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume))
666 if not os.path.exists(host_volume_dir):
667 os.mkdir(host_volume_dir)
668 return ( (host_volume_dir, guest_volume_dir), )
669
670 @classmethod
671 def remove_data_map(cls, host_volume, guest_volume_dir):
672 host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume))
673 if os.path.exists(host_volume_dir):
A.R Karthickf184b342017-01-27 19:30:50 -0800674 shutil.rmtree(host_volume_dir)
A R Karthickec2db322016-11-17 15:06:01 -0800675
A R Karthick973010f2017-02-06 16:41:51 -0800676 @classmethod
677 def update_data_dir(cls, karaf):
678 Onos.guest_data_dir = '/root/onos/apache-karaf-{}/data'.format(karaf)
679 Onos.guest_log_file = '/root/onos/apache-karaf-{}/data/log/karaf.log'.format(karaf)
680
A R Karthickd52ca8a2017-07-24 17:38:55 -0700681 @classmethod
682 def update_ssl_key(cls, key):
683 if os.access(key, os.F_OK):
684 try:
685 shutil.copy(key, cls.host_config_dir)
686 cls.ssl_key = os.path.join(cls.host_config_dir, os.path.basename(key))
687 except:pass
688
A R Karthick184945a2017-07-25 17:23:57 -0700689 @classmethod
690 def set_expose_port(cls, flag):
691 cls.expose_port = flag
692
693 def get_port_map(self, instance=0):
694 if self.expose_port is False:
695 return self.ports
696 return map(lambda p: (p, p + instance), self.expose_ports)
697
A R Karthickec2db322016-11-17 15:06:01 -0800698 def remove_data_volume(self):
699 if self.data_map is not None:
700 self.remove_data_map(*self.data_map)
701
A.R Karthick1700e0e2016-10-06 18:16:57 -0700702 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthickec2db322016-11-17 15:06:01 -0800703 boot_delay = 20, restart = False, network_cfg = None,
A R Karthick85eb1862017-01-23 16:10:57 -0800704 cluster = False, data_volume = None, async = False, quagga_config = None,
A R Karthick184945a2017-07-25 17:23:57 -0700705 network = None, instance = 0):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700706 if restart is True:
707 ##Find the right image to restart
708 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
709 if running_image:
710 image_name = running_image[0]['Image']
711 try:
712 image = image_name.split(':')[0]
713 tag = image_name.split(':')[1]
714 except: pass
715
A R Karthickaa54a1c2016-12-15 11:42:08 -0800716 if quagga_config is None:
717 quagga_config = Onos.QUAGGA_CONFIG
718 super(Onos, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = quagga_config)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700719 self.boot_delay = boot_delay
A R Karthickec2db322016-11-17 15:06:01 -0800720 self.data_map = None
A R Karthickc69d73e2017-01-20 11:44:34 -0800721 instance_memory = (get_mem(jvm_heap_size = Onos.JVM_HEAP_SIZE, instances = Onos.MAX_INSTANCES),) * 2
722 self.env['JAVA_OPTS'] = self.JAVA_OPTS_FORMAT.format(*instance_memory)
A R Karthick184945a2017-07-25 17:23:57 -0700723 self.ports = self.get_port_map(instance = instance)
A R Karthickd52ca8a2017-07-24 17:38:55 -0700724 if self.ssl_key:
725 key_files = ( os.path.join(self.guest_config_dir, os.path.basename(self.ssl_key)), ) * 2
726 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 -0700727 if cluster is True:
A R Karthickec2db322016-11-17 15:06:01 -0800728 if data_volume is not None:
729 self.data_map = self.get_data_map(data_volume, self.guest_data_dir)
730 self.host_guest_map = self.host_guest_map + self.data_map
A R Karthick2b93d6a2016-09-06 15:19:09 -0700731 if os.access(self.cluster_cfg, os.F_OK):
732 try:
733 os.unlink(self.cluster_cfg)
734 except: pass
735
736 self.host_config = self.create_host_config(port_list = self.ports,
737 host_guest_map = self.host_guest_map)
738 self.volumes = []
739 for _,g in self.host_guest_map:
740 self.volumes.append(g)
741
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700742 if restart is True and self.exists():
743 self.kill()
A R Karthick2b93d6a2016-09-06 15:19:09 -0700744
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700745 if not self.exists():
746 self.remove_container(name, force=True)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700747 host_config = self.create_host_config(port_list = self.ports,
748 host_guest_map = self.host_guest_map)
749 volumes = []
750 for _,g in self.host_guest_map:
751 volumes.append(g)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700752 if network_cfg is not None:
A R Karthick81acbff2016-06-17 14:45:16 -0700753 json_data = json.dumps(network_cfg, indent=4)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700754 with open('{}/network-cfg.json'.format(self.host_config_dir), 'w') as f:
755 f.write(json_data)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800756 if cluster is False or async is False:
757 print('Starting ONOS container %s' %self.name)
758 self.start(ports = self.ports, environment = self.env,
759 host_config = self.host_config, volumes = self.volumes, tty = True)
760 if not restart:
761 ##wait a bit before fetching IP to regenerate cluster cfg
762 time.sleep(5)
763 ip = self.ip()
764 ##Just a quick hack/check to ensure we don't regenerate in the common case.
765 ##As ONOS is usually the first test container that is started
766 if cluster is False:
767 if ip != self.CLUSTER_CFG_IP or not os.access(self.cluster_cfg, os.F_OK):
768 print('Regenerating ONOS cluster cfg for ip %s' %ip)
769 self.generate_cluster_cfg(ip)
770 self.kill()
771 self.remove_container(self.name, force=True)
772 print('Restarting ONOS container %s' %self.name)
773 self.start(ports = self.ports, environment = self.env,
774 host_config = self.host_config, volumes = self.volumes, tty = True)
775 print('Waiting for ONOS to boot')
776 time.sleep(boot_delay)
777 self.wait_for_onos_start(self.ip())
778 self.running = True
779 else:
780 self.running = False
781 else:
782 self.running = True
783 if self.running:
784 self.ipaddr = self.ip()
785 if cluster is False:
786 self.install_cord_apps(self.ipaddr)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800787
A.R Karthickc4e474d2016-12-12 15:24:57 -0800788 @classmethod
789 def get_quagga_config(cls, instance = 0):
A R Karthickaa54a1c2016-12-15 11:42:08 -0800790 quagga_config = copy.deepcopy(cls.QUAGGA_CONFIG)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800791 if instance == 0:
792 return quagga_config
793 ip = quagga_config[0]['ip']
794 octets = ip.split('.')
A R Karthickaa54a1c2016-12-15 11:42:08 -0800795 octets[3] = str((int(octets[3]) + instance) & 255)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800796 ip = '.'.join(octets)
797 quagga_config[0]['ip'] = ip
798 return quagga_config
799
800 @classmethod
801 def start_cluster_async(cls, onos_instances):
802 instances = filter(lambda o: o.running == False, onos_instances)
803 if not instances:
804 return
805 tpool = ThreadPool(len(instances), queue_size = 1, wait_timeout = 1)
806 for onos in instances:
807 tpool.addTask(onos.start_async)
808 tpool.cleanUpThreads()
809
810 def start_async(self):
811 print('Starting ONOS container %s' %self.name)
812 self.start(ports = self.ports, environment = self.env,
813 host_config = self.host_config, volumes = self.volumes, tty = True)
814 time.sleep(3)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700815 self.ipaddr = self.ip()
A.R Karthickc4e474d2016-12-12 15:24:57 -0800816 print('Waiting for ONOS container %s to start' %self.name)
817 self.wait_for_onos_start(self.ipaddr)
818 self.running = True
819 print('ONOS container %s started' %self.name)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700820
A R Karthick2b93d6a2016-09-06 15:19:09 -0700821 @classmethod
A R Karthick19aaf5c2016-11-09 17:47:57 -0800822 def wait_for_onos_start(cls, ip, tries = 30):
A R Karthick973010f2017-02-06 16:41:51 -0800823 onos_log = OnosLog(host = ip, log_file = Onos.guest_log_file)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800824 num_tries = 0
825 started = None
826 while not started and num_tries < tries:
827 time.sleep(3)
828 started = onos_log.search_log_pattern('ApplicationManager .* Started')
829 num_tries += 1
830
A R Karthick19aaf5c2016-11-09 17:47:57 -0800831 if not started:
832 print('ONOS did not start')
833 else:
834 print('ONOS started')
835 return started
836
837 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700838 def setup_cluster_deprecated(cls, onos_instances, image_name = None):
839 if not onos_instances or len(onos_instances) < 2:
840 return
841 ips = []
842 if image_name is not None:
843 ips = Container.ips(image_name)
844 else:
845 for onos in onos_instances:
846 ips.append(onos.ipaddr)
847 Onos.cluster_instances = onos_instances
848 Onos.cluster_mode = True
849 ##regenerate the cluster json with the 3 instance ips before restarting them back
850 print('Generating cluster cfg for ONOS instances with ips %s' %ips)
851 Onos.generate_cluster_cfg(ips)
852 for onos in onos_instances:
853 onos.kill()
854 onos.remove_container(onos.name, force=True)
855 print('Restarting ONOS container %s for forming cluster' %onos.name)
856 onos.start(ports = onos.ports, environment = onos.env,
857 host_config = onos.host_config, volumes = onos.volumes, tty = True)
858 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
859 time.sleep(onos.boot_delay)
860 onos.ipaddr = onos.ip()
861 onos.install_cord_apps(onos.ipaddr)
862
863 @classmethod
864 def setup_cluster(cls, onos_instances, image_name = None):
865 if not onos_instances or len(onos_instances) < 2:
866 return
867 ips = []
868 if image_name is not None:
869 ips = Container.ips(image_name)
870 else:
871 for onos in onos_instances:
872 ips.append(onos.ipaddr)
873 Onos.cluster_instances = onos_instances
874 Onos.cluster_mode = True
875 ##regenerate the cluster json with the 3 instance ips before restarting them back
876 print('Forming cluster for ONOS instances with ips %s' %ips)
877 Onos.form_cluster(ips)
878 ##wait for the cluster to be formed
879 print('Waiting for the cluster to be formed')
880 time.sleep(60)
881 for onos in onos_instances:
882 onos.install_cord_apps(onos.ipaddr)
883
884 @classmethod
A R Karthicke2c24bd2016-10-07 14:51:38 -0700885 def add_cluster(cls, count = 1, network_cfg = None):
886 if not cls.cluster_instances or Onos.cluster_mode is False:
887 return
888 for i in range(count):
A R Karthick184945a2017-07-25 17:23:57 -0700889 instance = len(cls.cluster_instances)
890 name = '{}-{}'.format(Onos.NAME, instance+1)
A R Karthicke2c24bd2016-10-07 14:51:38 -0700891 onos = cls(name = name, image = Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX,
A R Karthick184945a2017-07-25 17:23:57 -0700892 cluster = True, network_cfg = network_cfg, instance = instance)
A R Karthicke2c24bd2016-10-07 14:51:38 -0700893 cls.cluster_instances.append(onos)
894
895 cls.setup_cluster(cls.cluster_instances)
896
897 @classmethod
A.R Karthick2560f042016-11-30 14:38:52 -0800898 def restart_cluster(cls, network_cfg = None, timeout = 10, setup = False):
A R Karthick2b93d6a2016-09-06 15:19:09 -0700899 if cls.cluster_mode is False:
900 return
901 if not cls.cluster_instances:
902 return
903
904 if network_cfg is not None:
905 json_data = json.dumps(network_cfg, indent=4)
906 with open('{}/network-cfg.json'.format(cls.host_config_dir), 'w') as f:
907 f.write(json_data)
908
A.R Karthick2560f042016-11-30 14:38:52 -0800909 cls.cleanup_cluster()
910 if timeout > 0:
911 time.sleep(timeout)
912
A R Karthickaa54a1c2016-12-15 11:42:08 -0800913 #start the instances asynchronously
914 cls.start_cluster_async(cls.cluster_instances)
915 time.sleep(5)
A.R Karthick2560f042016-11-30 14:38:52 -0800916 ##form the cluster as appropriate
917 if setup is True:
918 cls.setup_cluster(cls.cluster_instances)
A R Karthickaa54a1c2016-12-15 11:42:08 -0800919 else:
920 for onos in cls.cluster_instances:
921 onos.install_cord_apps(onos.ipaddr)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700922
923 @classmethod
924 def cluster_ips(cls):
925 if cls.cluster_mode is False:
926 return []
927 if not cls.cluster_instances:
928 return []
929 ips = [ onos.ipaddr for onos in cls.cluster_instances ]
930 return ips
931
932 @classmethod
933 def cleanup_cluster(cls):
934 if cls.cluster_mode is False:
935 return
936 if not cls.cluster_instances:
937 return
938 for onos in cls.cluster_instances:
939 if onos.exists():
940 onos.kill()
A R Karthickaa54a1c2016-12-15 11:42:08 -0800941 onos.running = False
A R Karthick2b93d6a2016-09-06 15:19:09 -0700942 onos.remove_container(onos.name, force=True)
A R Karthickd44cea12016-07-20 12:16:41 -0700943
A.R Karthick95d044e2016-06-10 18:44:36 -0700944 @classmethod
A R Karthickde6b9dc2016-11-29 17:46:16 -0800945 def restart_node(cls, node = None, network_cfg = None, timeout = 10):
A R Karthick889d9652016-10-03 14:13:45 -0700946 if node is None:
947 cls(restart = True, network_cfg = network_cfg, image = cls.IMAGE, tag = cls.TAG)
948 else:
949 #Restarts a node in the cluster
950 valid_node = filter(lambda onos: node in [ onos.ipaddr, onos.name ], cls.cluster_instances)
951 if valid_node:
952 onos = valid_node.pop()
953 if onos.exists():
954 onos.kill()
955 onos.remove_container(onos.name, force=True)
A R Karthickde6b9dc2016-11-29 17:46:16 -0800956 if timeout > 0:
957 time.sleep(timeout)
A R Karthick889d9652016-10-03 14:13:45 -0700958 print('Restarting ONOS container %s' %onos.name)
959 onos.start(ports = onos.ports, environment = onos.env,
960 host_config = onos.host_config, volumes = onos.volumes, tty = True)
A R Karthick889d9652016-10-03 14:13:45 -0700961 onos.ipaddr = onos.ip()
A.R Karthick2560f042016-11-30 14:38:52 -0800962 onos.wait_for_onos_start(onos.ipaddr)
963 onos.install_cord_apps(onos.ipaddr)
A R Karthick889d9652016-10-03 14:13:45 -0700964
965 @classmethod
A R Karthickb608d402017-06-02 11:48:41 -0700966 def cliEnter(cls, onos_ip = None):
967 retries = 0
968 while retries < 10:
969 cli = OnosCliDriver(controller = onos_ip, connect = True)
970 if cli.handle:
971 return cli
972 else:
973 retries += 1
974 time.sleep(3)
975
976 return None
977
978 @classmethod
979 def cliExit(cls, cli):
980 if cli:
981 cli.disconnect()
982
983 @classmethod
984 def getVersion(cls, onos_ip = None):
985 cli = cls.cliEnter(onos_ip = onos_ip)
986 try:
987 summary = json.loads(cli.summary(jsonFormat = True))
988 except:
989 cls.cliExit(cli)
990 return '1.8.0'
991 cls.cliExit(cli)
992 return summary['version']
993
994 @classmethod
995 def update_cord_apps_version(cls, onos_ip = None):
996 if cls.cord_apps_version_updated == True:
997 return
998 version = cls.getVersion(onos_ip = onos_ip)
999 major = int(version.split('.')[0])
1000 minor = int(version.split('.')[1])
A R Karthick5b8310e2017-09-01 13:55:15 -07001001 try:
1002 patch = int(version.split('.')[2])
1003 except:
1004 patch = 0
A R Karthickb608d402017-06-02 11:48:41 -07001005 app_version = '1.2-SNAPSHOT'
1006 if major > 1:
1007 app_version = '2.0-SNAPSHOT'
A R Karthick5b8310e2017-09-01 13:55:15 -07001008 elif major == 1 and minor >= 10:
A R Karthickb608d402017-06-02 11:48:41 -07001009 app_version = '2.0-SNAPSHOT'
A R Karthick5b8310e2017-09-01 13:55:15 -07001010 if patch < 3:
1011 app_version = '1.2-SNAPSHOT'
A R Karthickb608d402017-06-02 11:48:41 -07001012 for apps in cls.onos_cord_apps:
1013 apps[1] = app_version
1014 cls.cord_apps_version_updated = True
1015
1016 @classmethod
A R Karthickeaf1c4e2016-07-19 12:22:35 -07001017 def install_cord_apps(cls, onos_ip = None):
A R Karthickb608d402017-06-02 11:48:41 -07001018 cls.update_cord_apps_version(onos_ip = onos_ip)
A R Karthick6e70e142017-07-28 15:25:38 -07001019 for app, version,_ in cls.onos_cord_apps:
A.R Karthick95d044e2016-06-10 18:44:36 -07001020 app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version)
A R Karthickeaf1c4e2016-07-19 12:22:35 -07001021 ok, code = OnosCtrl.install_app(app_file, onos_ip = onos_ip)
A.R Karthick95d044e2016-06-10 18:44:36 -07001022 ##app already installed (conflicts)
1023 if code in [ 409 ]:
1024 ok = True
1025 print('ONOS app %s, version %s %s' %(app, version, 'installed' if ok else 'failed to install'))
1026 time.sleep(2)
1027
A R Karthick6e70e142017-07-28 15:25:38 -07001028 @classmethod
1029 def activate_apps(cls, apps, onos_ip = None, deactivate = False):
1030 for app in apps:
1031 if deactivate is True:
1032 OnosCtrl(app, controller = onos_ip).deactivate()
1033 time.sleep(2)
1034 OnosCtrl(app, controller = onos_ip).activate()
1035
1036 time.sleep(5)
1037
1038 @classmethod
1039 def activate_cord_apps(cls, onos_ip = None, deactivate = True):
1040 cord_apps = map(lambda a: a[2], cls.onos_cord_apps)
1041 cls.activate_apps(cord_apps, onos_ip = onos_ip, deactivate = deactivate)
1042
A.R Karthick1700e0e2016-10-06 18:16:57 -07001043class OnosStopWrapper(Container):
1044 def __init__(self, name):
1045 super(OnosStopWrapper, self).__init__(name, Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX)
1046 if self.exists():
1047 self.kill()
A R Karthickaa54a1c2016-12-15 11:42:08 -08001048 self.running = False
A.R Karthick1700e0e2016-10-06 18:16:57 -07001049 else:
1050 if Onos.cluster_mode is True:
1051 valid_node = filter(lambda onos: name in [ onos.ipaddr, onos.name ], Onos.cluster_instances)
1052 if valid_node:
1053 onos = valid_node.pop()
1054 if onos.exists():
1055 onos.kill()
A R Karthickaa54a1c2016-12-15 11:42:08 -08001056 onos.running = False
A.R Karthick1700e0e2016-10-06 18:16:57 -07001057
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001058class Radius(Container):
1059 ports = [ 1812, 1813 ]
A R Karthick41adfce2016-06-10 09:51:25 -07001060 env = {'TIMEZONE':'America/Los_Angeles',
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001061 'DEBUG': 'true', 'cert_password':'whatever', 'primary_shared_secret':'radius_password'
1062 }
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001063 host_db_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/db')
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001064 guest_db_dir = os.path.join(os.path.sep, 'opt', 'db')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001065 host_config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/freeradius')
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001066 guest_config_dir = os.path.join(os.path.sep, 'etc', 'freeradius')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001067 start_command = os.path.join(guest_config_dir, 'start-radius.py')
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001068 host_guest_map = ( (host_db_dir, guest_db_dir),
1069 (host_config_dir, guest_config_dir)
1070 )
A R Karthickf7a613b2017-02-24 09:36:44 -08001071 IMAGE = 'cordtest/radius'
Chetan Gaonker503032a2016-05-12 12:06:29 -07001072 NAME = 'cord-radius'
1073
A R Karthick07608ef2016-08-23 16:51:19 -07001074 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
A R Karthick85eb1862017-01-23 16:10:57 -08001075 boot_delay = 10, restart = False, update = False, network = None):
A R Karthick07608ef2016-08-23 16:51:19 -07001076 super(Radius, self).__init__(name, image, prefix = prefix, tag = tag, command = self.start_command)
Chetan Gaonker503032a2016-05-12 12:06:29 -07001077 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -07001078 self.build_image(self.image_name)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001079 if restart is True and self.exists():
1080 self.kill()
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001081 if not self.exists():
1082 self.remove_container(name, force=True)
1083 host_config = self.create_host_config(port_list = self.ports,
1084 host_guest_map = self.host_guest_map)
1085 volumes = []
1086 for _,g in self.host_guest_map:
1087 volumes.append(g)
A R Karthick41adfce2016-06-10 09:51:25 -07001088 self.start(ports = self.ports, environment = self.env,
1089 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001090 host_config = host_config, tty = True)
A R Karthick85eb1862017-01-23 16:10:57 -08001091 if network is not None:
1092 Container.connect_to_network(self.name, network)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001093 time.sleep(boot_delay)
1094
1095 @classmethod
1096 def build_image(cls, image):
1097 print('Building Radius image %s' %image)
1098 dockerfile = '''
1099FROM hbouvier/docker-radius
1100MAINTAINER chetan@ciena.com
1101LABEL RUN docker pull hbouvier/docker-radius
1102LABEL RUN docker run -it --name cord-radius hbouvier/docker-radius
A R Karthickc762df42016-05-25 10:09:21 -07001103RUN apt-get update && \
1104 apt-get -y install python python-pexpect strace
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001105WORKDIR /root
1106CMD ["/etc/freeradius/start-radius.py"]
1107'''
1108 super(Radius, cls).build_image(dockerfile, image)
1109 print('Done building image %s' %image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001110
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001111class Quagga(Container):
A R Karthickaa54a1c2016-12-15 11:42:08 -08001112 QUAGGA_CONFIG = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 },
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -07001113 { 'bridge' : 'quagga-br', 'ip': '192.168.10.3', 'mask': 16 },
1114 )
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001115 ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ]
1116 host_quagga_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/quagga-config')
1117 guest_quagga_config = '/root/config'
1118 quagga_config_file = os.path.join(guest_quagga_config, 'testrib.conf')
1119 host_guest_map = ( (host_quagga_config, guest_quagga_config), )
A R Karthickf7a613b2017-02-24 09:36:44 -08001120 IMAGE = 'cordtest/quagga'
Chetan Gaonker503032a2016-05-12 12:06:29 -07001121 NAME = 'cord-quagga'
1122
A R Karthick07608ef2016-08-23 16:51:19 -07001123 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
A R Karthick85eb1862017-01-23 16:10:57 -08001124 boot_delay = 15, restart = False, config_file = quagga_config_file, update = False,
1125 network = None):
A R Karthickaa54a1c2016-12-15 11:42:08 -08001126 super(Quagga, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.QUAGGA_CONFIG)
Chetan Gaonker503032a2016-05-12 12:06:29 -07001127 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -07001128 self.build_image(self.image_name)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001129 if restart is True and self.exists():
1130 self.kill()
1131 if not self.exists():
1132 self.remove_container(name, force=True)
A R Karthick41adfce2016-06-10 09:51:25 -07001133 host_config = self.create_host_config(port_list = self.ports,
1134 host_guest_map = self.host_guest_map,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001135 privileged = True)
1136 volumes = []
1137 for _,g in self.host_guest_map:
1138 volumes.append(g)
1139 self.start(ports = self.ports,
A R Karthick41adfce2016-06-10 09:51:25 -07001140 host_config = host_config,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001141 volumes = volumes, tty = True)
A R Karthick85eb1862017-01-23 16:10:57 -08001142 if network is not None:
1143 Container.connect_to_network(self.name, network)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001144 print('Starting Quagga on container %s' %self.name)
1145 self.execute('{0}/start.sh {1}'.format(self.guest_quagga_config, config_file))
1146 time.sleep(boot_delay)
1147
1148 @classmethod
1149 def build_image(cls, image):
A R Karthickaa54a1c2016-12-15 11:42:08 -08001150 onos_quagga_ip = Onos.QUAGGA_CONFIG[0]['ip']
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001151 print('Building Quagga image %s' %image)
1152 dockerfile = '''
A R Karthick41adfce2016-06-10 09:51:25 -07001153FROM ubuntu:14.04
1154MAINTAINER chetan@ciena.com
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001155WORKDIR /root
1156RUN useradd -M quagga
1157RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga
1158RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga
A R Karthick973ea692016-10-17 12:23:02 -07001159RUN 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 -07001160RUN git clone git://git.savannah.nongnu.org/quagga.git quagga && \
A R Karthick8f69c2c2016-10-21 11:43:26 -07001161(cd quagga && git checkout quagga-1.0.20160315 && ./bootstrap.sh && \
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001162sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \
1163./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install)
1164RUN ldconfig
1165'''.format(onos_quagga_ip)
1166 super(Quagga, cls).build_image(dockerfile, image)
1167 print('Done building image %s' %image)
A R Karthick81acbff2016-06-17 14:45:16 -07001168
A.R Karthick1700e0e2016-10-06 18:16:57 -07001169class QuaggaStopWrapper(Container):
1170 def __init__(self, name = Quagga.NAME, image = Quagga.IMAGE, tag = 'candidate'):
1171 super(QuaggaStopWrapper, self).__init__(name, image, prefix = Container.IMAGE_PREFIX, tag = tag)
1172 if self.exists():
1173 self.kill()
1174
1175
A R Karthick81acbff2016-06-17 14:45:16 -07001176def reinitContainerClients():
1177 docker_netns.dckr = Client()
1178 Container.dckr = Client()
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001179
1180class Xos(Container):
1181 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
1182 TAG = 'latest'
1183 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -07001184 host_guest_map = None
1185 env = None
1186 ports = None
1187 volumes = None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001188
A R Karthick6e80afd2016-10-10 16:03:12 -07001189 @classmethod
1190 def get_cmd(cls, img_name):
1191 cmd = cls.dckr.inspect_image(img_name)['Config']['Cmd']
1192 return ' '.join(cmd)
1193
A R Karthicke3bde962016-09-27 15:06:35 -07001194 def __init__(self, name, image, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001195 boot_delay = 20, restart = False, network_cfg = None, update = False):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001196 if restart is True:
1197 ##Find the right image to restart
1198 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
1199 if running_image:
1200 image_name = running_image[0]['Image']
1201 try:
1202 image = image_name.split(':')[0]
1203 tag = image_name.split(':')[1]
1204 except: pass
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001205 super(Xos, self).__init__(name, image, prefix = prefix, tag = tag)
1206 if update is True or not self.img_exists():
1207 self.build_image(self.image_name)
A R Karthick6e80afd2016-10-10 16:03:12 -07001208 self.command = self.get_cmd(self.image_name).strip() or None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001209 if restart is True and self.exists():
1210 self.kill()
1211 if not self.exists():
1212 self.remove_container(name, force=True)
A R Karthicke3bde962016-09-27 15:06:35 -07001213 host_config = self.create_host_config(port_list = self.ports,
1214 host_guest_map = self.host_guest_map,
1215 privileged = True)
1216 print('Starting XOS container %s' %self.name)
1217 self.start(ports = self.ports, environment = self.env, host_config = host_config,
1218 volumes = self.volumes, tty = True)
1219 print('Waiting %d seconds for XOS Base Container to boot' %(boot_delay))
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001220 time.sleep(boot_delay)
1221
1222 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -07001223 def build_image(cls, image, dockerfile_path, image_target = 'build'):
1224 cmd = 'cd {} && make {}'.format(dockerfile_path, image_target)
1225 print('Building XOS %s' %image)
1226 res = os.system(cmd)
1227 print('Done building image %s. Image build %s' %(image, 'successful' if res == 0 else 'failed'))
1228 return res
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001229
A R Karthicke3bde962016-09-27 15:06:35 -07001230class XosServer(Xos):
1231 ports = [8000,9998,9999]
1232 NAME = 'xos-server'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001233 IMAGE = 'xosproject/xos'
A R Karthicke3bde962016-09-27 15:06:35 -07001234 BASE_IMAGE = 'xosproject/xos-base'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001235 TAG = 'latest'
1236 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -07001237 dockerfile_path = os.path.join(Xos.setup_dir, 'xos')
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001238
A R Karthicke3bde962016-09-27 15:06:35 -07001239 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001240 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001241 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001242
1243 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -07001244 def build_image(cls, image = IMAGE):
1245 ##build the base image and then build the server image
1246 Xos.build_image(cls.BASE_IMAGE, cls.dockerfile_path, image_target = 'base')
1247 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001248
A R Karthicke3bde962016-09-27 15:06:35 -07001249class XosSynchronizerOpenstack(Xos):
1250 ports = [2375,]
1251 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer')
1252 NAME = 'xos-synchronizer'
1253 IMAGE = 'xosproject/xos-synchronizer-openstack'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001254 TAG = 'latest'
1255 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -07001256 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001257
A R Karthicke3bde962016-09-27 15:06:35 -07001258 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -07001259 tag = TAG, boot_delay = 20, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001260 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001261
1262 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -07001263 def build_image(cls, image = IMAGE):
1264 XosServer.build_image()
1265 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001266
A R Karthicke3bde962016-09-27 15:06:35 -07001267class XosSynchronizerOnboarding(Xos):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001268 NAME = 'xos-synchronizer-onboarding'
1269 IMAGE = 'xosproject/xos-synchronizer-onboarding'
1270 TAG = 'latest'
1271 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -07001272 dockerfile_path = os.path.join(Xos.setup_dir, 'onboarding_synchronizer')
1273 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001274
A R Karthicke3bde962016-09-27 15:06:35 -07001275 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -07001276 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001277 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001278
1279 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -07001280 def build_image(cls, image = IMAGE):
1281 XosSynchronizerOpenstack.build_image()
1282 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001283
A R Karthicke3bde962016-09-27 15:06:35 -07001284class XosSynchronizerOpenvpn(Xos):
1285 NAME = 'xos-synchronizer-openvpn'
1286 IMAGE = 'xosproject/xos-openvpn'
1287 TAG = 'latest'
1288 PREFIX = ''
1289 dockerfile_path = os.path.join(Xos.setup_dir, 'openvpn')
1290 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001291
A R Karthicke3bde962016-09-27 15:06:35 -07001292 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -07001293 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001294 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1295
1296 @classmethod
1297 def build_image(cls, image = IMAGE):
1298 XosSynchronizerOpenstack.build_image()
1299 Xos.build_image(image, cls.dockerfile_path)
1300
1301class XosPostgresql(Xos):
1302 ports = [5432,]
1303 NAME = 'xos-db-postgres'
1304 IMAGE = 'xosproject/xos-postgres'
1305 TAG = 'latest'
1306 PREFIX = ''
1307 volumes = ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
1308 dockerfile_path = os.path.join(Xos.setup_dir, 'postgresql')
1309
1310 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -07001311 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001312 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1313
1314 @classmethod
1315 def build_image(cls, image = IMAGE):
1316 Xos.build_image(image, cls.dockerfile_path)
1317
1318class XosSyndicateMs(Xos):
1319 ports = [8080,]
1320 env = None
1321 NAME = 'xos-syndicate-ms'
1322 IMAGE = 'xosproject/syndicate-ms'
1323 TAG = 'latest'
1324 PREFIX = ''
1325 dockerfile_path = os.path.join(Xos.setup_dir, 'syndicate-ms')
1326
1327 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001328 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001329 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1330
1331 @classmethod
1332 def build_image(cls, image = IMAGE):
1333 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001334
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001335class XosSyncVtn(Xos):
1336 ports = [8080,]
1337 env = None
1338 NAME = 'xos-synchronizer-vtn'
1339 IMAGE = 'xosproject/xos-synchronizer-vtn'
1340 TAG = 'latest'
1341 PREFIX = ''
1342 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtn')
1343
1344 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001345 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001346 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1347
1348 @classmethod
1349 def build_image(cls, image = IMAGE):
1350 Xos.build_image(image, cls.dockerfile_path)
1351
1352class XosSyncVtr(Xos):
1353 ports = [8080,]
1354 env = None
1355 NAME = 'xos-synchronizer-vtr'
1356 IMAGE = 'xosproject/xos-synchronizer-vtr'
1357 TAG = 'latest'
1358 PREFIX = ''
1359 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtr')
1360
1361 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001362 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001363 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1364
1365 @classmethod
1366 def build_image(cls, image = IMAGE):
1367 Xos.build_image(image, cls.dockerfile_path)
1368
1369class XosSyncVsg(Xos):
1370 ports = [8080,]
1371 env = None
1372 NAME = 'xos-synchronizer-vsg'
1373 IMAGE = 'xosproject/xos-synchronizer-vsg'
1374 TAG = 'latest'
1375 PREFIX = ''
1376 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vsg')
1377
1378 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001379 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001380 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1381
1382 @classmethod
1383 def build_image(cls, image = IMAGE):
1384 Xos.build_image(image, cls.dockerfile_path)
1385
1386
1387class XosSyncOnos(Xos):
1388 ports = [8080,]
1389 env = None
1390 NAME = 'xos-synchronizer-onos'
1391 IMAGE = 'xosproject/xos-synchronizer-onos'
1392 TAG = 'latest'
1393 PREFIX = ''
1394 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-onos')
1395
1396 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001397 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001398 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1399
1400 @classmethod
1401 def build_image(cls, image = IMAGE):
1402 Xos.build_image(image, cls.dockerfile_path)
1403
1404class XosSyncFabric(Xos):
1405 ports = [8080,]
1406 env = None
1407 NAME = 'xos-synchronizer-fabric'
1408 IMAGE = 'xosproject/xos-synchronizer-fabric'
1409 TAG = 'latest'
1410 PREFIX = ''
1411 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-fabric')
1412
1413 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001414 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001415 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1416
1417 @classmethod
1418 def build_image(cls, image = IMAGE):
1419 Xos.build_image(image, cls.dockerfile_path)
A R Karthick19aaf5c2016-11-09 17:47:57 -08001420
1421if __name__ == '__main__':
1422 onos = Onos(boot_delay = 10, restart = True)