blob: b7933f8dea021421598cc08752e5c2610422149b [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
A R Karthick6f2ac6f2017-07-26 12:55:24 -070026try:
27 from docker import APIClient as Client
28except:
29 from docker import Client
A R Karthick85eb1862017-01-23 16:10:57 -080030from docker import utils as dockerutils
A.R Karthickf184b342017-01-27 19:30:50 -080031import shutil
A.R Karthick95d044e2016-06-10 18:44:36 -070032from OnosCtrl import OnosCtrl
A R Karthick19aaf5c2016-11-09 17:47:57 -080033from OnosLog import OnosLog
A R Karthick03bd2812017-03-03 17:49:17 -080034from onosclidriver import OnosCliDriver
A.R Karthickc4e474d2016-12-12 15:24:57 -080035from threadPool import ThreadPool
A R Karthickaa54a1c2016-12-15 11:42:08 -080036from threading import Lock
Chetan Gaonker3533faa2016-04-25 17:50:14 -070037
38class docker_netns(object):
39
40 dckr = Client()
41 def __init__(self, name):
42 pid = int(self.dckr.inspect_container(name)['State']['Pid'])
43 if pid == 0:
44 raise Exception('no container named {0}'.format(name))
45 self.pid = pid
46
47 def __enter__(self):
48 pid = self.pid
49 if not os.path.exists('/var/run/netns'):
50 os.mkdir('/var/run/netns')
51 os.symlink('/proc/{0}/ns/net'.format(pid), '/var/run/netns/{0}'.format(pid))
52 return str(pid)
53
54 def __exit__(self, type, value, traceback):
55 pid = self.pid
56 os.unlink('/var/run/netns/{0}'.format(pid))
57
58flatten = lambda l: chain.from_iterable(l)
59
60class Container(object):
61 dckr = Client()
A R Karthick07608ef2016-08-23 16:51:19 -070062 IMAGE_PREFIX = '' ##for saving global prefix for all test classes
A R Karthickaa54a1c2016-12-15 11:42:08 -080063 CONFIG_LOCK = Lock()
A R Karthick07608ef2016-08-23 16:51:19 -070064
65 def __init__(self, name, image, prefix='', tag = 'candidate', command = 'bash', quagga_config = None):
Chetan Gaonker3533faa2016-04-25 17:50:14 -070066 self.name = name
A R Karthick07608ef2016-08-23 16:51:19 -070067 self.prefix = prefix
68 if prefix:
69 self.prefix += '/'
70 image = '{}{}'.format(self.prefix, image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -070071 self.image = image
72 self.tag = tag
A R Karthickd44cea12016-07-20 12:16:41 -070073 if tag:
74 self.image_name = image + ':' + tag
75 else:
76 self.image_name = image
Chetan Gaonker3533faa2016-04-25 17:50:14 -070077 self.id = None
78 self.command = command
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -070079 self.quagga_config = quagga_config
Chetan Gaonker3533faa2016-04-25 17:50:14 -070080
81 @classmethod
82 def build_image(cls, dockerfile, tag, force=True, nocache=False):
83 f = io.BytesIO(dockerfile.encode('utf-8'))
84 if force or not cls.image_exists(tag):
85 print('Build {0}...'.format(tag))
86 for line in cls.dckr.build(fileobj=f, rm=True, tag=tag, decode=True, nocache=nocache):
87 if 'stream' in line:
88 print(line['stream'].strip())
89
90 @classmethod
91 def image_exists(cls, name):
A R Karthicke07fc3a2017-02-27 10:49:29 -080092 #return name in [ctn['RepoTags'][0] for ctn in cls.dckr.images()]
93 return name in list( flatten(ctn['RepoTags'] if ctn['RepoTags'] else '' for ctn in cls.dckr.images()) )
Chetan Gaonker3533faa2016-04-25 17:50:14 -070094
95 @classmethod
96 def create_host_config(cls, port_list = None, host_guest_map = None, privileged = False):
97 port_bindings = None
98 binds = None
99 if port_list:
100 port_bindings = {}
101 for p in port_list:
A R Karthick184945a2017-07-25 17:23:57 -0700102 if type(p) is tuple:
103 port_bindings[str(p[0])] = str(p[1])
104 else:
105 port_bindings[str(p)] = str(p)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700106
107 if host_guest_map:
108 binds = []
109 for h, g in host_guest_map:
110 binds.append('{0}:{1}'.format(h, g))
111
112 return cls.dckr.create_host_config(binds = binds, port_bindings = port_bindings, privileged = privileged)
113
114 @classmethod
A R Karthick85eb1862017-01-23 16:10:57 -0800115 def connect_to_network(cls, name, network):
116 try:
117 cls.dckr.connect_container_to_network(name, network)
118 return True
119 except:
120 return False
121
122 @classmethod
123 def create_network(cls, network, subnet = None, gateway = None):
124 ipam_config = None
125 if subnet is not None and gateway is not None:
126 ipam_pool = dockerutils.create_ipam_pool(subnet = subnet, gateway = gateway)
127 ipam_config = dockerutils.create_ipam_config(pool_configs = [ipam_pool])
128 cls.dckr.create_network(network, driver='bridge', ipam = ipam_config)
129
130 @classmethod
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700131 def cleanup(cls, image):
A R Karthick09b1f4e2016-05-12 14:31:50 -0700132 cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True))
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700133 for cnt in cnt_list:
134 print('Cleaning container %s' %cnt['Id'])
A.R Karthick95d044e2016-06-10 18:44:36 -0700135 if cnt.has_key('State') and cnt['State'] == 'running':
A R Karthick09b1f4e2016-05-12 14:31:50 -0700136 cls.dckr.kill(cnt['Id'])
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700137 cls.dckr.remove_container(cnt['Id'], force=True)
138
139 @classmethod
140 def remove_container(cls, name, force=True):
141 try:
142 cls.dckr.remove_container(name, force = force)
143 except: pass
144
145 def exists(self):
146 return '/{0}'.format(self.name) in list(flatten(n['Names'] for n in self.dckr.containers()))
147
148 def img_exists(self):
A R Karthicke07fc3a2017-02-27 10:49:29 -0800149 #return self.image_name in [ctn['RepoTags'][0] if ctn['RepoTags'] else '' for ctn in self.dckr.images()]
150 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 -0700151
A R Karthick75844572017-01-23 16:57:44 -0800152 def ip(self, network = None):
A R Karthick2b93d6a2016-09-06 15:19:09 -0700153 cnt_list = filter(lambda c: c['Names'][0] == '/{}'.format(self.name), self.dckr.containers())
154 #if not cnt_list:
155 # cnt_list = filter(lambda c: c['Image'] == self.image_name, self.dckr.containers())
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700156 cnt_settings = cnt_list.pop()
A R Karthick75844572017-01-23 16:57:44 -0800157 if network is not None and cnt_settings['NetworkSettings']['Networks'].has_key(network):
158 return cnt_settings['NetworkSettings']['Networks'][network]['IPAddress']
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700159 return cnt_settings['NetworkSettings']['Networks']['bridge']['IPAddress']
160
A R Karthick2b93d6a2016-09-06 15:19:09 -0700161 @classmethod
162 def ips(cls, image_name):
163 cnt_list = filter(lambda c: c['Image'] == image_name, cls.dckr.containers())
164 ips = [ cnt['NetworkSettings']['Networks']['bridge']['IPAddress'] for cnt in cnt_list ]
165 return ips
166
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700167 def kill(self, remove = True):
168 self.dckr.kill(self.name)
169 self.dckr.remove_container(self.name, force=True)
170
A R Karthick41adfce2016-06-10 09:51:25 -0700171 def start(self, rm = True, ports = None, volumes = None, host_config = None,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700172 environment = None, tty = False, stdin_open = True):
173
174 if rm and self.exists():
175 print('Removing container:', self.name)
176 self.dckr.remove_container(self.name, force=True)
177
A R Karthick41adfce2016-06-10 09:51:25 -0700178 ctn = self.dckr.create_container(image=self.image_name, ports = ports, command=self.command,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700179 detach=True, name=self.name,
A R Karthick41adfce2016-06-10 09:51:25 -0700180 environment = environment,
181 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700182 host_config = host_config, stdin_open=stdin_open, tty = tty)
183 self.dckr.start(container=self.name)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700184 if self.quagga_config:
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700185 self.connect_to_br()
186 self.id = ctn['Id']
187 return ctn
188
Thangavelu K Sef6f0a52016-12-14 19:57:05 +0000189 @classmethod
190 def pause_container(cls, image, delay):
191 cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True))
192 for cnt in cnt_list:
193 print('Pause the container %s' %cnt['Id'])
194 if cnt.has_key('State') and cnt['State'] == 'running':
195 cls.dckr.pause(cnt['Id'])
196 if delay != 0:
197 time.sleep(delay)
198 for cnt in cnt_list:
199 print('Unpause the container %s' %cnt['Id'])
200 cls.dckr.unpause(cnt['Id'])
201 else:
202 print('Infinity time pause the container %s' %cnt['Id'])
203 return 'success'
204
A R Karthick52414732017-01-31 09:59:47 -0800205 def connect_to_br(self, index = 0):
A R Karthickaa54a1c2016-12-15 11:42:08 -0800206 self.CONFIG_LOCK.acquire()
207 try:
208 with docker_netns(self.name) as pid:
209 for quagga_config in self.quagga_config:
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700210 ip = IPRoute()
A R Karthickaa54a1c2016-12-15 11:42:08 -0800211 br = ip.link_lookup(ifname=quagga_config['bridge'])
212 if len(br) == 0:
213 try:
214 ip.link_create(ifname=quagga_config['bridge'], kind='bridge')
215 except NetlinkError as e:
216 err, _ = e.args
217 if err == errno.EEXIST:
218 pass
219 else:
220 raise NetlinkError(*e.args)
221 br = ip.link_lookup(ifname=quagga_config['bridge'])
222 br = br[0]
223 ip.link('set', index=br, state='up')
A R Karthick52414732017-01-31 09:59:47 -0800224 ifname = '{0}-{1}'.format(self.name[:12], index)
A R Karthickaa54a1c2016-12-15 11:42:08 -0800225 ifs = ip.link_lookup(ifname=ifname)
226 if len(ifs) > 0:
227 ip.link_remove(ifs[0])
228 peer_ifname = '{0}-{1}'.format(pid, index)
229 ip.link_create(ifname=ifname, kind='veth', peer=peer_ifname)
230 host = ip.link_lookup(ifname=ifname)[0]
231 ip.link('set', index=host, master=br)
232 ip.link('set', index=host, state='up')
233 guest = ip.link_lookup(ifname=peer_ifname)[0]
234 ip.link('set', index=guest, net_ns_fd=pid)
235 with Namespace(pid, 'net'):
236 ip = IPRoute()
237 ip.link('set', index=guest, ifname='eth{}'.format(index+1))
238 ip.addr('add', index=guest, address=quagga_config['ip'], mask=quagga_config['mask'])
239 ip.link('set', index=guest, state='up')
240 index += 1
241 finally:
242 self.CONFIG_LOCK.release()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700243
Thangavelu K Sef6f0a52016-12-14 19:57:05 +0000244 def execute(self, cmd, tty = True, stream = False, shell = False, detach = True):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700245 res = 0
246 if type(cmd) == str:
247 cmds = (cmd,)
248 else:
249 cmds = cmd
250 if shell:
251 for c in cmds:
252 res += os.system('docker exec {0} {1}'.format(self.name, c))
253 return res
254 for c in cmds:
255 i = self.dckr.exec_create(container=self.name, cmd=c, tty = tty, privileged = True)
A R Karthickd6dd9b22017-02-24 15:17:22 -0800256 s = self.dckr.exec_start(i['Id'], stream = stream, detach=detach, socket=True)
257 try:
258 s.close()
259 except: pass
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700260 result = self.dckr.exec_inspect(i['Id'])
261 res += 0 if result['ExitCode'] == None else result['ExitCode']
262 return res
263
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700264 def restart(self, timeout =10):
265 return self.dckr.restart(self.name, timeout)
266
A R Karthickc69d73e2017-01-20 11:44:34 -0800267def get_mem(jvm_heap_size = None, instances = 1):
A R Karthick1f908202016-11-16 17:32:20 -0800268 if instances <= 0:
269 instances = 1
A R Karthickc69d73e2017-01-20 11:44:34 -0800270 heap_size = jvm_heap_size
271 heap_size_i = 0
272 #sanitize the heap size config
273 if heap_size is not None:
274 if not heap_size.isdigit():
275 try:
276 heap_size_i = int(heap_size[:-1])
277 suffix = heap_size[-1]
278 if suffix == 'M':
279 heap_size_i /= 1024 #convert to gigs
A.R Karthick99044822017-02-09 14:04:20 -0800280 #allow to specific minimum heap size
281 if heap_size_i == 0:
282 return heap_size
A R Karthickc69d73e2017-01-20 11:44:34 -0800283 except:
284 ##invalid suffix length probably. Fall back to default
285 heap_size = None
286 else:
287 heap_size_i = int(heap_size)
288
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700289 with open('/proc/meminfo', 'r') as fd:
290 meminfo = fd.readlines()
291 mem = 0
292 for m in meminfo:
293 if m.startswith('MemTotal:') or m.startswith('SwapTotal:'):
294 mem += int(m.split(':')[1].strip().split()[0])
295
A R Karthick1f908202016-11-16 17:32:20 -0800296 mem = max(mem/1024/1024/2/instances, 1)
Chetan Gaonker6d0a7b02016-05-03 16:57:28 -0700297 mem = min(mem, 16)
A R Karthickc69d73e2017-01-20 11:44:34 -0800298
299 if heap_size_i:
300 #we take the minimum of the provided heap size and max allowed heap size
301 heap_size_i = min(heap_size_i, mem)
302 else:
303 heap_size_i = mem
304
305 return '{}G'.format(heap_size_i)
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700306
A R Karthickd44cea12016-07-20 12:16:41 -0700307class OnosCord(Container):
308 """Use this when running the cord tester agent on the onos compute node"""
A R Karthickd44cea12016-07-20 12:16:41 -0700309 onos_config_dir_guest = '/root/onos/config'
A R Karthick03bd2812017-03-03 17:49:17 -0800310 synchronizer_map = { 'vtn' : { 'install':
311 ('http://mavenrepo:8080/repository/org/opencord/cord-config/1.2-SNAPSHOT/cord-config-1.2-SNAPSHOT.oar',
312 'http://mavenrepo:8080/repository/org/opencord/vtn/1.2-SNAPSHOT/vtn-1.2-SNAPSHOT.oar',),
313 'activate':
314 ('org.onosproject.ovsdb-base', 'org.onosproject.drivers.ovsdb',
315 'org.onosproject.dhcp', 'org.onosproject.optical-model',
316 'org.onosproject.openflow-base', 'org.onosproject.proxyarp',
317 'org.onosproject.hostprovider'),
318 },
319 'fabric' : { 'activate':
320 ('org.onosproject.hostprovider', 'org.onosproject.optical-model',
321 'org.onosproject.openflow-base', 'org.onosproject.vrouter',
322 'org.onosproject.netcfghostprovider', 'org.onosproject.netcfglinksprovider',
323 'org.onosproject.segmentrouting', 'org.onosproject.proxyarp'),
324 }
325 }
326 tester_apps = ('http://mavenrepo:8080/repository/org/opencord/aaa/1.2-SNAPSHOT/aaa-1.2-SNAPSHOT.oar',
327 'http://mavenrepo:8080/repository/org/opencord/igmp/1.2-SNAPSHOT/igmp-1.2-SNAPSHOT.oar',)
A R Karthickd44cea12016-07-20 12:16:41 -0700328
A.R Karthickddf12772017-05-17 13:49:47 -0700329 old_service_profile = '/opt/cord/orchestration/service-profile/cord-pod'
A R Karthick49529c52017-05-19 09:43:01 -0700330 cord_profile = '/opt/cord_profile'
A.R Karthickddf12772017-05-17 13:49:47 -0700331
A R Karthick03bd2812017-03-03 17:49:17 -0800332 def __init__(self, onos_ip, conf, service_profile, synchronizer, start = True, boot_delay = 5):
A.R Karthickf184b342017-01-27 19:30:50 -0800333 if not os.access(conf, os.F_OK):
334 raise Exception('ONOS cord configuration location %s is invalid' %conf)
A.R Karthickddf12772017-05-17 13:49:47 -0700335 self.old_cord = False
336 if os.access(self.old_service_profile, os.F_OK):
337 self.old_cord = True
A R Karthickbd9b8a32016-07-21 09:56:45 -0700338 self.onos_ip = onos_ip
A.R Karthickf184b342017-01-27 19:30:50 -0800339 self.onos_cord_dir = conf
A R Karthickbd9b8a32016-07-21 09:56:45 -0700340 self.boot_delay = boot_delay
A.R Karthickf184b342017-01-27 19:30:50 -0800341 self.synchronizer = synchronizer
342 self.service_profile = service_profile
343 self.docker_yaml = os.path.join(conf, 'docker-compose.yml')
344 self.docker_yaml_saved = os.path.join(conf, 'docker-compose.yml.saved')
345 self.onos_config_dir = os.path.join(conf, 'config')
346 self.onos_cfg_save_loc = os.path.join(conf, 'network-cfg.json.saved')
347 instance_active = False
348 #if we have a wrapper onos instance already active, back out
349 if os.access(self.onos_config_dir, os.F_OK) or os.access(self.docker_yaml_saved, os.F_OK):
350 instance_active = True
351 else:
352 if start is True:
353 os.mkdir(self.onos_config_dir)
354 shutil.copy(self.docker_yaml, self.docker_yaml_saved)
A R Karthickd44cea12016-07-20 12:16:41 -0700355
A.R Karthickf184b342017-01-27 19:30:50 -0800356 self.start_wrapper = instance_active is False and start is True
A R Karthickd44cea12016-07-20 12:16:41 -0700357 ##update the docker yaml with the config volume
358 with open(self.docker_yaml, 'r') as f:
359 yaml_config = yaml.load(f)
360 image = yaml_config['services'].keys()[0]
A R Karthick8983cb02017-06-09 11:32:53 -0700361 cord_conf_dir_basename = os.path.basename(self.onos_cord_dir.replace('-', '').replace('_', ''))
A.R Karthickf184b342017-01-27 19:30:50 -0800362 xos_onos_name = '{}_{}_1'.format(cord_conf_dir_basename, image)
A R Karthick5778a792017-01-31 13:47:16 -0800363 if not yaml_config['services'][image].has_key('volumes'):
364 yaml_config['services'][image]['volumes'] = []
A R Karthickd44cea12016-07-20 12:16:41 -0700365 volumes = yaml_config['services'][image]['volumes']
366 config_volumes = filter(lambda e: e.find(self.onos_config_dir_guest) >= 0, volumes)
367 if not config_volumes:
368 config_volume = '{}:{}'.format(self.onos_config_dir, self.onos_config_dir_guest)
369 volumes.append(config_volume)
A.R Karthickf184b342017-01-27 19:30:50 -0800370 if self.start_wrapper:
371 docker_yaml_changed = '{}-changed'.format(self.docker_yaml)
372 with open(docker_yaml_changed, 'w') as wf:
373 yaml.dump(yaml_config, wf)
374 os.rename(docker_yaml_changed, self.docker_yaml)
A R Karthickd44cea12016-07-20 12:16:41 -0700375 self.volumes = volumes
376
A R Karthickd44cea12016-07-20 12:16:41 -0700377 ##Create an container instance of xos onos
A R Karthick52414732017-01-31 09:59:47 -0800378 super(OnosCord, self).__init__(xos_onos_name, image, tag = '', quagga_config = Onos.QUAGGA_CONFIG)
A.R Karthickf184b342017-01-27 19:30:50 -0800379 self.last_cfg = None
380 if self.start_wrapper:
381 #fetch the current config of onos cord instance and save it
382 try:
383 self.last_cfg = OnosCtrl.get_config(controller = onos_ip)
384 json_data = json.dumps(self.last_cfg, indent=4)
385 with open(self.onos_cfg_save_loc, 'w') as f:
386 f.write(json_data)
387 except:
388 pass
389 #start the container back with the shared onos config volume
390 self.start()
A R Karthickd44cea12016-07-20 12:16:41 -0700391
A R Karthick03bd2812017-03-03 17:49:17 -0800392 def cliEnter(self):
393 retries = 0
394 while retries < 30:
395 cli = OnosCliDriver(controller = self.onos_ip, connect = True)
396 if cli.handle:
397 return cli
398 else:
399 retries += 1
A R Karthick72fcbc52017-03-06 12:35:17 -0800400 time.sleep(3)
A R Karthick03bd2812017-03-03 17:49:17 -0800401
402 return None
403
404 def cliExit(self, cli):
405 if cli:
406 cli.disconnect()
407
A.R Karthickddf12772017-05-17 13:49:47 -0700408 def synchronize_fabric(self, cfg = None):
409 if self.old_cord is True:
410 cmds = [ 'cd {} && make {}'.format(self.old_service_profile, self.synchronizer),
411 'sleep 30'
412 ]
413 for cmd in cmds:
414 try:
415 os.system(cmd)
416 except:
417 pass
418
A R Karthick03bd2812017-03-03 17:49:17 -0800419 def synchronize_vtn(self, cfg = None):
A.R Karthickddf12772017-05-17 13:49:47 -0700420 if self.old_cord is True:
421 cmds = [ 'cd {} && make {}'.format(self.old_service_profile, self.synchronizer),
422 'sleep 30'
423 ]
424 for cmd in cmds:
425 try:
426 os.system(cmd)
427 except:
428 pass
429 return
A R Karthick03bd2812017-03-03 17:49:17 -0800430 if cfg is None:
431 return
432 if not cfg.has_key('apps'):
433 return
434 if not cfg['apps'].has_key('org.opencord.vtn'):
435 return
436 vtn_neutron_cfg = cfg['apps']['org.opencord.vtn']['cordvtn']['openstack']
437 password = vtn_neutron_cfg['password']
438 endpoint = vtn_neutron_cfg['endpoint']
439 user = vtn_neutron_cfg['user']
440 tenant = vtn_neutron_cfg['tenant']
441 vtn_host = cfg['apps']['org.opencord.vtn']['cordvtn']['nodes'][0]['hostname']
442 cli = self.cliEnter()
443 if cli is None:
444 return
445 cli.cordVtnSyncNeutronStates(endpoint, password, tenant = tenant, user = user)
446 time.sleep(2)
447 cli.cordVtnNodeInit(vtn_host)
448 self.cliExit(cli)
449
450 def synchronize(self, cfg_unlink = False):
A R Karthick03bd2812017-03-03 17:49:17 -0800451
452 if not self.synchronizer_map.has_key(self.synchronizer):
453 return
454
455 install_list = ()
456 if self.synchronizer_map[self.synchronizer].has_key('install'):
457 install_list = self.synchronizer_map[self.synchronizer]['install']
458
459 activate_list = ()
460 if self.synchronizer_map[self.synchronizer].has_key('activate'):
461 activate_list = self.synchronizer_map[self.synchronizer]['activate']
462
463 for app_url in install_list:
464 print('Installing app from url: %s' %app_url)
465 OnosCtrl.install_app_from_url(None, None, app_url = app_url, onos_ip = self.onos_ip)
466
467 for app in activate_list:
468 print('Activating app %s' %app)
469 OnosCtrl(app, controller = self.onos_ip).activate()
470 time.sleep(2)
471
472 for app_url in self.tester_apps:
473 print('Installing tester app from url: %s' %app_url)
474 OnosCtrl.install_app_from_url(None, None, app_url = app_url, onos_ip = self.onos_ip)
475
A R Karthick72fcbc52017-03-06 12:35:17 -0800476 cfg = None
477 #restore the saved config after applications are activated
478 if os.access(self.onos_cfg_save_loc, os.F_OK):
479 with open(self.onos_cfg_save_loc, 'r') as f:
480 cfg = json.load(f)
481 try:
482 OnosCtrl.config(cfg, controller = self.onos_ip)
483 if cfg_unlink is True:
484 os.unlink(self.onos_cfg_save_loc)
485 except:
486 pass
487
488 if hasattr(self, 'synchronize_{}'.format(self.synchronizer)):
489 getattr(self, 'synchronize_{}'.format(self.synchronizer))(cfg = cfg)
490
491 #now restart the xos synchronizer container
A R Karthick49529c52017-05-19 09:43:01 -0700492 cmd = None
493 if os.access('{}/onboarding-docker-compose/docker-compose.yml'.format(self.cord_profile), os.F_OK):
494 cmd = 'cd {}/onboarding-docker-compose && \
495 docker-compose -p {} restart xos_synchronizer_{}'.format(self.cord_profile,
496 self.service_profile,
497 self.synchronizer)
498 else:
499 if os.access('{}/docker-compose.yml'.format(self.cord_profile), os.F_OK):
500 cmd = 'cd {} && \
501 docker-compose -p {} restart {}-synchronizer'.format(self.cord_profile,
502 self.service_profile,
503 self.synchronizer)
504 if cmd is not None:
505 try:
506 print(cmd)
507 os.system(cmd)
508 except:
509 pass
A R Karthick03bd2812017-03-03 17:49:17 -0800510
A R Karthickd44cea12016-07-20 12:16:41 -0700511 def start(self, restart = False, network_cfg = None):
A R Karthick928ad622017-01-30 12:18:32 -0800512 if network_cfg is not None:
A R Karthickd44cea12016-07-20 12:16:41 -0700513 json_data = json.dumps(network_cfg, indent=4)
514 with open('{}/network-cfg.json'.format(self.onos_config_dir), 'w') as f:
515 f.write(json_data)
A R Karthick52414732017-01-31 09:59:47 -0800516
517 #we avoid using docker-compose restart for now.
518 #since we don't want to retain the metadata across restarts
A R Karthick03bd2812017-03-03 17:49:17 -0800519 #stop and start and synchronize the services before installing tester cord apps
520 cmds = [ 'cd {} && docker-compose down'.format(self.onos_cord_dir),
521 'cd {} && docker-compose up -d'.format(self.onos_cord_dir),
A R Karthickbc894372017-05-12 16:34:08 -0700522 'sleep 150',
A R Karthick03bd2812017-03-03 17:49:17 -0800523 ]
524 for cmd in cmds:
A.R Karthickf184b342017-01-27 19:30:50 -0800525 try:
A R Karthick03bd2812017-03-03 17:49:17 -0800526 print(cmd)
A.R Karthickf184b342017-01-27 19:30:50 -0800527 os.system(cmd)
A R Karthick03bd2812017-03-03 17:49:17 -0800528 except:pass
A R Karthick52414732017-01-31 09:59:47 -0800529
A R Karthick03bd2812017-03-03 17:49:17 -0800530 self.synchronize()
A R Karthick52414732017-01-31 09:59:47 -0800531 ##we could also connect container to default docker network but disabled for now
532 #Container.connect_to_network(self.name, 'bridge')
A R Karthick52414732017-01-31 09:59:47 -0800533 #connect container to the quagga bridge
534 self.connect_to_br(index = 0)
A.R Karthickf184b342017-01-27 19:30:50 -0800535 print('Waiting %d seconds for ONOS instance to start' %self.boot_delay)
A R Karthickbd9b8a32016-07-21 09:56:45 -0700536 time.sleep(self.boot_delay)
A R Karthickd44cea12016-07-20 12:16:41 -0700537
538 def build_image(self):
539 build_cmd = 'cd {} && docker-compose build'.format(self.onos_cord_dir)
540 os.system(build_cmd)
541
A.R Karthickf184b342017-01-27 19:30:50 -0800542 def restore(self, force = False):
543 restore = self.start_wrapper is True or force is True
544 if not restore:
A.R Karthick263d3fc2017-01-27 12:52:53 -0800545 return
A R Karthick394976f2017-01-31 14:25:16 -0800546 #nothing to restore
547 if not os.access(self.docker_yaml_saved, os.F_OK):
548 return
A R Karthick03bd2812017-03-03 17:49:17 -0800549
A.R Karthickf184b342017-01-27 19:30:50 -0800550 #restore the config files back. The synchronizer restore should bring the last config back
551 cmds = ['cd {} && docker-compose down'.format(self.onos_cord_dir),
552 'rm -rf {}'.format(self.onos_config_dir),
553 'mv {} {}'.format(self.docker_yaml_saved, self.docker_yaml),
554 'cd {} && docker-compose up -d'.format(self.onos_cord_dir),
A R Karthickbc894372017-05-12 16:34:08 -0700555 'sleep 150',
A.R Karthickf184b342017-01-27 19:30:50 -0800556 ]
557 for cmd in cmds:
A.R Karthickb17e2022017-01-27 11:29:26 -0800558 try:
A.R Karthickf184b342017-01-27 19:30:50 -0800559 print(cmd)
560 os.system(cmd)
A.R Karthickb17e2022017-01-27 11:29:26 -0800561 except: pass
562
A R Karthick03bd2812017-03-03 17:49:17 -0800563 self.synchronize(cfg_unlink = True)
A.R Karthickb17e2022017-01-27 11:29:26 -0800564
A.R Karthick1700e0e2016-10-06 18:16:57 -0700565class OnosCordStopWrapper(Container):
566 onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord')
567 docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml')
568
569 def __init__(self):
570 if os.access(self.docker_yaml, os.F_OK):
571 with open(self.docker_yaml, 'r') as f:
572 yaml_config = yaml.load(f)
573 image = yaml_config['services'].keys()[0]
574 name = 'cordtestercord_{}_1'.format(image)
575 super(OnosCordStopWrapper, self).__init__(name, image, tag = '')
576 if self.exists():
577 print('Killing container %s' %self.name)
578 self.kill()
579
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700580class Onos(Container):
A R Karthickaa54a1c2016-12-15 11:42:08 -0800581 QUAGGA_CONFIG = [ { 'bridge' : 'quagga-br', 'ip': '10.10.0.4', 'mask' : 16 }, ]
A R Karthicka2492c12016-12-16 10:31:51 -0800582 MAX_INSTANCES = 3
A R Karthickc69d73e2017-01-20 11:44:34 -0800583 JVM_HEAP_SIZE = None
Chetan Gaonker462d9fa2016-05-03 16:39:10 -0700584 SYSTEM_MEMORY = (get_mem(),) * 2
A R Karthicka2492c12016-12-16 10:31:51 -0800585 INSTANCE_MEMORY = (get_mem(instances=MAX_INSTANCES),) * 2
A R Karthickc69d73e2017-01-20 11:44:34 -0800586 JAVA_OPTS_FORMAT = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode'
587 JAVA_OPTS_DEFAULT = JAVA_OPTS_FORMAT.format(*SYSTEM_MEMORY) #-XX:+PrintGCDetails -XX:+PrintGCTimeStamps'
588 JAVA_OPTS_CLUSTER_DEFAULT = JAVA_OPTS_FORMAT.format(*INSTANCE_MEMORY)
589 env = { 'ONOS_APPS' : 'drivers,openflow,proxyarp,vrouter', 'JAVA_OPTS' : JAVA_OPTS_DEFAULT }
A R Karthick6e70e142017-07-28 15:25:38 -0700590 onos_cord_apps = ( ['cord-config', '1.2-SNAPSHOT', 'org.opencord.config'],
591 ['aaa', '1.2-SNAPSHOT', 'org.opencord.aaa'],
592 ['igmp', '1.2-SNAPSHOT', 'org.opencord.igmp'],
A.R Karthick95d044e2016-06-10 18:44:36 -0700593 )
A R Karthickb608d402017-06-02 11:48:41 -0700594 cord_apps_version_updated = False
A R Karthick184945a2017-07-25 17:23:57 -0700595 expose_port = False
596 expose_ports = [ 8181, 8101, 9876, 6653, 6633, 2000, 2620, 5005 ]
597 ports = []
A R Karthickf2f4ca62016-08-17 10:34:08 -0700598 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
599 host_config_dir = os.path.join(setup_dir, 'onos-config')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700600 guest_config_dir = '/root/onos/config'
A.R Karthickdda22062017-02-09 14:39:20 -0800601 guest_data_dir = '/root/onos/apache-karaf-3.0.8/data'
602 guest_log_file = '/root/onos/apache-karaf-3.0.8/data/log/karaf.log'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700603 onos_gen_partitions = os.path.join(setup_dir, 'onos-gen-partitions')
A R Karthick2b93d6a2016-09-06 15:19:09 -0700604 onos_form_cluster = os.path.join(setup_dir, 'onos-form-cluster')
A.R Karthick95d044e2016-06-10 18:44:36 -0700605 cord_apps_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'apps')
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700606 host_guest_map = ( (host_config_dir, guest_config_dir), )
A R Karthickd52ca8a2017-07-24 17:38:55 -0700607 ssl_key = None
A R Karthick2b93d6a2016-09-06 15:19:09 -0700608 cluster_cfg = os.path.join(host_config_dir, 'cluster.json')
609 cluster_mode = False
610 cluster_instances = []
Chetan Gaonker503032a2016-05-12 12:06:29 -0700611 NAME = 'cord-onos'
A R Karthickf2f4ca62016-08-17 10:34:08 -0700612 ##the ip of ONOS in default cluster.json in setup/onos-config
613 CLUSTER_CFG_IP = '172.17.0.2'
A R Karthick07608ef2016-08-23 16:51:19 -0700614 IMAGE = 'onosproject/onos'
615 TAG = 'latest'
616 PREFIX = ''
A R Karthickf2f4ca62016-08-17 10:34:08 -0700617
618 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700619 def generate_cluster_cfg(cls, ip):
620 if type(ip) in [ list, tuple ]:
621 ips = ' '.join(ip)
622 else:
623 ips = ip
A R Karthickf2f4ca62016-08-17 10:34:08 -0700624 try:
A R Karthick2b93d6a2016-09-06 15:19:09 -0700625 cmd = '{} {} {}'.format(cls.onos_gen_partitions, cls.cluster_cfg, ips)
626 os.system(cmd)
627 except: pass
628
629 @classmethod
630 def form_cluster(cls, ips):
631 nodes = ' '.join(ips)
632 try:
633 cmd = '{} {}'.format(cls.onos_form_cluster, nodes)
A R Karthickf2f4ca62016-08-17 10:34:08 -0700634 os.system(cmd)
635 except: pass
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700636
A R Karthick9d48c652016-09-15 09:16:36 -0700637 @classmethod
638 def cleanup_runtime(cls):
639 '''Cleanup ONOS runtime generated files'''
640 files = ( Onos.cluster_cfg, os.path.join(Onos.host_config_dir, 'network-cfg.json') )
641 for f in files:
642 if os.access(f, os.F_OK):
643 try:
644 os.unlink(f)
645 except: pass
646
A R Karthickec2db322016-11-17 15:06:01 -0800647 @classmethod
648 def get_data_map(cls, host_volume, guest_volume_dir):
649 host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume))
650 if not os.path.exists(host_volume_dir):
651 os.mkdir(host_volume_dir)
652 return ( (host_volume_dir, guest_volume_dir), )
653
654 @classmethod
655 def remove_data_map(cls, host_volume, guest_volume_dir):
656 host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume))
657 if os.path.exists(host_volume_dir):
A.R Karthickf184b342017-01-27 19:30:50 -0800658 shutil.rmtree(host_volume_dir)
A R Karthickec2db322016-11-17 15:06:01 -0800659
A R Karthick973010f2017-02-06 16:41:51 -0800660 @classmethod
661 def update_data_dir(cls, karaf):
662 Onos.guest_data_dir = '/root/onos/apache-karaf-{}/data'.format(karaf)
663 Onos.guest_log_file = '/root/onos/apache-karaf-{}/data/log/karaf.log'.format(karaf)
664
A R Karthickd52ca8a2017-07-24 17:38:55 -0700665 @classmethod
666 def update_ssl_key(cls, key):
667 if os.access(key, os.F_OK):
668 try:
669 shutil.copy(key, cls.host_config_dir)
670 cls.ssl_key = os.path.join(cls.host_config_dir, os.path.basename(key))
671 except:pass
672
A R Karthick184945a2017-07-25 17:23:57 -0700673 @classmethod
674 def set_expose_port(cls, flag):
675 cls.expose_port = flag
676
677 def get_port_map(self, instance=0):
678 if self.expose_port is False:
679 return self.ports
680 return map(lambda p: (p, p + instance), self.expose_ports)
681
A R Karthickec2db322016-11-17 15:06:01 -0800682 def remove_data_volume(self):
683 if self.data_map is not None:
684 self.remove_data_map(*self.data_map)
685
A.R Karthick1700e0e2016-10-06 18:16:57 -0700686 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthickec2db322016-11-17 15:06:01 -0800687 boot_delay = 20, restart = False, network_cfg = None,
A R Karthick85eb1862017-01-23 16:10:57 -0800688 cluster = False, data_volume = None, async = False, quagga_config = None,
A R Karthick184945a2017-07-25 17:23:57 -0700689 network = None, instance = 0):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700690 if restart is True:
691 ##Find the right image to restart
692 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
693 if running_image:
694 image_name = running_image[0]['Image']
695 try:
696 image = image_name.split(':')[0]
697 tag = image_name.split(':')[1]
698 except: pass
699
A R Karthickaa54a1c2016-12-15 11:42:08 -0800700 if quagga_config is None:
701 quagga_config = Onos.QUAGGA_CONFIG
702 super(Onos, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = quagga_config)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700703 self.boot_delay = boot_delay
A R Karthickec2db322016-11-17 15:06:01 -0800704 self.data_map = None
A R Karthickc69d73e2017-01-20 11:44:34 -0800705 instance_memory = (get_mem(jvm_heap_size = Onos.JVM_HEAP_SIZE, instances = Onos.MAX_INSTANCES),) * 2
706 self.env['JAVA_OPTS'] = self.JAVA_OPTS_FORMAT.format(*instance_memory)
A R Karthick184945a2017-07-25 17:23:57 -0700707 self.ports = self.get_port_map(instance = instance)
A R Karthickd52ca8a2017-07-24 17:38:55 -0700708 if self.ssl_key:
709 key_files = ( os.path.join(self.guest_config_dir, os.path.basename(self.ssl_key)), ) * 2
710 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 -0700711 if cluster is True:
A R Karthickec2db322016-11-17 15:06:01 -0800712 if data_volume is not None:
713 self.data_map = self.get_data_map(data_volume, self.guest_data_dir)
714 self.host_guest_map = self.host_guest_map + self.data_map
A R Karthick2b93d6a2016-09-06 15:19:09 -0700715 if os.access(self.cluster_cfg, os.F_OK):
716 try:
717 os.unlink(self.cluster_cfg)
718 except: pass
719
720 self.host_config = self.create_host_config(port_list = self.ports,
721 host_guest_map = self.host_guest_map)
722 self.volumes = []
723 for _,g in self.host_guest_map:
724 self.volumes.append(g)
725
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700726 if restart is True and self.exists():
727 self.kill()
A R Karthick2b93d6a2016-09-06 15:19:09 -0700728
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700729 if not self.exists():
730 self.remove_container(name, force=True)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -0700731 host_config = self.create_host_config(port_list = self.ports,
732 host_guest_map = self.host_guest_map)
733 volumes = []
734 for _,g in self.host_guest_map:
735 volumes.append(g)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700736 if network_cfg is not None:
A R Karthick81acbff2016-06-17 14:45:16 -0700737 json_data = json.dumps(network_cfg, indent=4)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700738 with open('{}/network-cfg.json'.format(self.host_config_dir), 'w') as f:
739 f.write(json_data)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800740 if cluster is False or async is False:
741 print('Starting ONOS container %s' %self.name)
742 self.start(ports = self.ports, environment = self.env,
743 host_config = self.host_config, volumes = self.volumes, tty = True)
744 if not restart:
745 ##wait a bit before fetching IP to regenerate cluster cfg
746 time.sleep(5)
747 ip = self.ip()
748 ##Just a quick hack/check to ensure we don't regenerate in the common case.
749 ##As ONOS is usually the first test container that is started
750 if cluster is False:
751 if ip != self.CLUSTER_CFG_IP or not os.access(self.cluster_cfg, os.F_OK):
752 print('Regenerating ONOS cluster cfg for ip %s' %ip)
753 self.generate_cluster_cfg(ip)
754 self.kill()
755 self.remove_container(self.name, force=True)
756 print('Restarting ONOS container %s' %self.name)
757 self.start(ports = self.ports, environment = self.env,
758 host_config = self.host_config, volumes = self.volumes, tty = True)
759 print('Waiting for ONOS to boot')
760 time.sleep(boot_delay)
761 self.wait_for_onos_start(self.ip())
762 self.running = True
763 else:
764 self.running = False
765 else:
766 self.running = True
767 if self.running:
768 self.ipaddr = self.ip()
769 if cluster is False:
770 self.install_cord_apps(self.ipaddr)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800771
A.R Karthickc4e474d2016-12-12 15:24:57 -0800772 @classmethod
773 def get_quagga_config(cls, instance = 0):
A R Karthickaa54a1c2016-12-15 11:42:08 -0800774 quagga_config = copy.deepcopy(cls.QUAGGA_CONFIG)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800775 if instance == 0:
776 return quagga_config
777 ip = quagga_config[0]['ip']
778 octets = ip.split('.')
A R Karthickaa54a1c2016-12-15 11:42:08 -0800779 octets[3] = str((int(octets[3]) + instance) & 255)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800780 ip = '.'.join(octets)
781 quagga_config[0]['ip'] = ip
782 return quagga_config
783
784 @classmethod
785 def start_cluster_async(cls, onos_instances):
786 instances = filter(lambda o: o.running == False, onos_instances)
787 if not instances:
788 return
789 tpool = ThreadPool(len(instances), queue_size = 1, wait_timeout = 1)
790 for onos in instances:
791 tpool.addTask(onos.start_async)
792 tpool.cleanUpThreads()
793
794 def start_async(self):
795 print('Starting ONOS container %s' %self.name)
796 self.start(ports = self.ports, environment = self.env,
797 host_config = self.host_config, volumes = self.volumes, tty = True)
798 time.sleep(3)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700799 self.ipaddr = self.ip()
A.R Karthickc4e474d2016-12-12 15:24:57 -0800800 print('Waiting for ONOS container %s to start' %self.name)
801 self.wait_for_onos_start(self.ipaddr)
802 self.running = True
803 print('ONOS container %s started' %self.name)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700804
A R Karthick2b93d6a2016-09-06 15:19:09 -0700805 @classmethod
A R Karthick19aaf5c2016-11-09 17:47:57 -0800806 def wait_for_onos_start(cls, ip, tries = 30):
A R Karthick973010f2017-02-06 16:41:51 -0800807 onos_log = OnosLog(host = ip, log_file = Onos.guest_log_file)
A R Karthick19aaf5c2016-11-09 17:47:57 -0800808 num_tries = 0
809 started = None
810 while not started and num_tries < tries:
811 time.sleep(3)
812 started = onos_log.search_log_pattern('ApplicationManager .* Started')
813 num_tries += 1
814
A R Karthick19aaf5c2016-11-09 17:47:57 -0800815 if not started:
816 print('ONOS did not start')
817 else:
818 print('ONOS started')
819 return started
820
821 @classmethod
A R Karthick2b93d6a2016-09-06 15:19:09 -0700822 def setup_cluster_deprecated(cls, onos_instances, image_name = None):
823 if not onos_instances or len(onos_instances) < 2:
824 return
825 ips = []
826 if image_name is not None:
827 ips = Container.ips(image_name)
828 else:
829 for onos in onos_instances:
830 ips.append(onos.ipaddr)
831 Onos.cluster_instances = onos_instances
832 Onos.cluster_mode = True
833 ##regenerate the cluster json with the 3 instance ips before restarting them back
834 print('Generating cluster cfg for ONOS instances with ips %s' %ips)
835 Onos.generate_cluster_cfg(ips)
836 for onos in onos_instances:
837 onos.kill()
838 onos.remove_container(onos.name, force=True)
839 print('Restarting ONOS container %s for forming cluster' %onos.name)
840 onos.start(ports = onos.ports, environment = onos.env,
841 host_config = onos.host_config, volumes = onos.volumes, tty = True)
842 print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name))
843 time.sleep(onos.boot_delay)
844 onos.ipaddr = onos.ip()
845 onos.install_cord_apps(onos.ipaddr)
846
847 @classmethod
848 def setup_cluster(cls, onos_instances, image_name = None):
849 if not onos_instances or len(onos_instances) < 2:
850 return
851 ips = []
852 if image_name is not None:
853 ips = Container.ips(image_name)
854 else:
855 for onos in onos_instances:
856 ips.append(onos.ipaddr)
857 Onos.cluster_instances = onos_instances
858 Onos.cluster_mode = True
859 ##regenerate the cluster json with the 3 instance ips before restarting them back
860 print('Forming cluster for ONOS instances with ips %s' %ips)
861 Onos.form_cluster(ips)
862 ##wait for the cluster to be formed
863 print('Waiting for the cluster to be formed')
864 time.sleep(60)
865 for onos in onos_instances:
866 onos.install_cord_apps(onos.ipaddr)
867
868 @classmethod
A R Karthicke2c24bd2016-10-07 14:51:38 -0700869 def add_cluster(cls, count = 1, network_cfg = None):
870 if not cls.cluster_instances or Onos.cluster_mode is False:
871 return
872 for i in range(count):
A R Karthick184945a2017-07-25 17:23:57 -0700873 instance = len(cls.cluster_instances)
874 name = '{}-{}'.format(Onos.NAME, instance+1)
A R Karthicke2c24bd2016-10-07 14:51:38 -0700875 onos = cls(name = name, image = Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX,
A R Karthick184945a2017-07-25 17:23:57 -0700876 cluster = True, network_cfg = network_cfg, instance = instance)
A R Karthicke2c24bd2016-10-07 14:51:38 -0700877 cls.cluster_instances.append(onos)
878
879 cls.setup_cluster(cls.cluster_instances)
880
881 @classmethod
A.R Karthick2560f042016-11-30 14:38:52 -0800882 def restart_cluster(cls, network_cfg = None, timeout = 10, setup = False):
A R Karthick2b93d6a2016-09-06 15:19:09 -0700883 if cls.cluster_mode is False:
884 return
885 if not cls.cluster_instances:
886 return
887
888 if network_cfg is not None:
889 json_data = json.dumps(network_cfg, indent=4)
890 with open('{}/network-cfg.json'.format(cls.host_config_dir), 'w') as f:
891 f.write(json_data)
892
A.R Karthick2560f042016-11-30 14:38:52 -0800893 cls.cleanup_cluster()
894 if timeout > 0:
895 time.sleep(timeout)
896
A R Karthickaa54a1c2016-12-15 11:42:08 -0800897 #start the instances asynchronously
898 cls.start_cluster_async(cls.cluster_instances)
899 time.sleep(5)
A.R Karthick2560f042016-11-30 14:38:52 -0800900 ##form the cluster as appropriate
901 if setup is True:
902 cls.setup_cluster(cls.cluster_instances)
A R Karthickaa54a1c2016-12-15 11:42:08 -0800903 else:
904 for onos in cls.cluster_instances:
905 onos.install_cord_apps(onos.ipaddr)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700906
907 @classmethod
908 def cluster_ips(cls):
909 if cls.cluster_mode is False:
910 return []
911 if not cls.cluster_instances:
912 return []
913 ips = [ onos.ipaddr for onos in cls.cluster_instances ]
914 return ips
915
916 @classmethod
917 def cleanup_cluster(cls):
918 if cls.cluster_mode is False:
919 return
920 if not cls.cluster_instances:
921 return
922 for onos in cls.cluster_instances:
923 if onos.exists():
924 onos.kill()
A R Karthickaa54a1c2016-12-15 11:42:08 -0800925 onos.running = False
A R Karthick2b93d6a2016-09-06 15:19:09 -0700926 onos.remove_container(onos.name, force=True)
A R Karthickd44cea12016-07-20 12:16:41 -0700927
A.R Karthick95d044e2016-06-10 18:44:36 -0700928 @classmethod
A R Karthickde6b9dc2016-11-29 17:46:16 -0800929 def restart_node(cls, node = None, network_cfg = None, timeout = 10):
A R Karthick889d9652016-10-03 14:13:45 -0700930 if node is None:
931 cls(restart = True, network_cfg = network_cfg, image = cls.IMAGE, tag = cls.TAG)
932 else:
933 #Restarts a node in the cluster
934 valid_node = filter(lambda onos: node in [ onos.ipaddr, onos.name ], cls.cluster_instances)
935 if valid_node:
936 onos = valid_node.pop()
937 if onos.exists():
938 onos.kill()
939 onos.remove_container(onos.name, force=True)
A R Karthickde6b9dc2016-11-29 17:46:16 -0800940 if timeout > 0:
941 time.sleep(timeout)
A R Karthick889d9652016-10-03 14:13:45 -0700942 print('Restarting ONOS container %s' %onos.name)
943 onos.start(ports = onos.ports, environment = onos.env,
944 host_config = onos.host_config, volumes = onos.volumes, tty = True)
A R Karthick889d9652016-10-03 14:13:45 -0700945 onos.ipaddr = onos.ip()
A.R Karthick2560f042016-11-30 14:38:52 -0800946 onos.wait_for_onos_start(onos.ipaddr)
947 onos.install_cord_apps(onos.ipaddr)
A R Karthick889d9652016-10-03 14:13:45 -0700948
949 @classmethod
A R Karthickb608d402017-06-02 11:48:41 -0700950 def cliEnter(cls, onos_ip = None):
951 retries = 0
952 while retries < 10:
953 cli = OnosCliDriver(controller = onos_ip, connect = True)
954 if cli.handle:
955 return cli
956 else:
957 retries += 1
958 time.sleep(3)
959
960 return None
961
962 @classmethod
963 def cliExit(cls, cli):
964 if cli:
965 cli.disconnect()
966
967 @classmethod
968 def getVersion(cls, onos_ip = None):
969 cli = cls.cliEnter(onos_ip = onos_ip)
970 try:
971 summary = json.loads(cli.summary(jsonFormat = True))
972 except:
973 cls.cliExit(cli)
974 return '1.8.0'
975 cls.cliExit(cli)
976 return summary['version']
977
978 @classmethod
979 def update_cord_apps_version(cls, onos_ip = None):
980 if cls.cord_apps_version_updated == True:
981 return
982 version = cls.getVersion(onos_ip = onos_ip)
983 major = int(version.split('.')[0])
984 minor = int(version.split('.')[1])
985 app_version = '1.2-SNAPSHOT'
986 if major > 1:
987 app_version = '2.0-SNAPSHOT'
988 elif major == 1 and minor > 10:
989 app_version = '2.0-SNAPSHOT'
990 for apps in cls.onos_cord_apps:
991 apps[1] = app_version
992 cls.cord_apps_version_updated = True
993
994 @classmethod
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700995 def install_cord_apps(cls, onos_ip = None):
A R Karthickb608d402017-06-02 11:48:41 -0700996 cls.update_cord_apps_version(onos_ip = onos_ip)
A R Karthick6e70e142017-07-28 15:25:38 -0700997 for app, version,_ in cls.onos_cord_apps:
A.R Karthick95d044e2016-06-10 18:44:36 -0700998 app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version)
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700999 ok, code = OnosCtrl.install_app(app_file, onos_ip = onos_ip)
A.R Karthick95d044e2016-06-10 18:44:36 -07001000 ##app already installed (conflicts)
1001 if code in [ 409 ]:
1002 ok = True
1003 print('ONOS app %s, version %s %s' %(app, version, 'installed' if ok else 'failed to install'))
1004 time.sleep(2)
1005
A R Karthick6e70e142017-07-28 15:25:38 -07001006 @classmethod
1007 def activate_apps(cls, apps, onos_ip = None, deactivate = False):
1008 for app in apps:
1009 if deactivate is True:
1010 OnosCtrl(app, controller = onos_ip).deactivate()
1011 time.sleep(2)
1012 OnosCtrl(app, controller = onos_ip).activate()
1013
1014 time.sleep(5)
1015
1016 @classmethod
1017 def activate_cord_apps(cls, onos_ip = None, deactivate = True):
1018 cord_apps = map(lambda a: a[2], cls.onos_cord_apps)
1019 cls.activate_apps(cord_apps, onos_ip = onos_ip, deactivate = deactivate)
1020
A.R Karthick1700e0e2016-10-06 18:16:57 -07001021class OnosStopWrapper(Container):
1022 def __init__(self, name):
1023 super(OnosStopWrapper, self).__init__(name, Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX)
1024 if self.exists():
1025 self.kill()
A R Karthickaa54a1c2016-12-15 11:42:08 -08001026 self.running = False
A.R Karthick1700e0e2016-10-06 18:16:57 -07001027 else:
1028 if Onos.cluster_mode is True:
1029 valid_node = filter(lambda onos: name in [ onos.ipaddr, onos.name ], Onos.cluster_instances)
1030 if valid_node:
1031 onos = valid_node.pop()
1032 if onos.exists():
1033 onos.kill()
A R Karthickaa54a1c2016-12-15 11:42:08 -08001034 onos.running = False
A.R Karthick1700e0e2016-10-06 18:16:57 -07001035
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001036class Radius(Container):
1037 ports = [ 1812, 1813 ]
A R Karthick41adfce2016-06-10 09:51:25 -07001038 env = {'TIMEZONE':'America/Los_Angeles',
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001039 'DEBUG': 'true', 'cert_password':'whatever', 'primary_shared_secret':'radius_password'
1040 }
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001041 host_db_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/db')
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001042 guest_db_dir = os.path.join(os.path.sep, 'opt', 'db')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001043 host_config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/freeradius')
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001044 guest_config_dir = os.path.join(os.path.sep, 'etc', 'freeradius')
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001045 start_command = os.path.join(guest_config_dir, 'start-radius.py')
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001046 host_guest_map = ( (host_db_dir, guest_db_dir),
1047 (host_config_dir, guest_config_dir)
1048 )
A R Karthickf7a613b2017-02-24 09:36:44 -08001049 IMAGE = 'cordtest/radius'
Chetan Gaonker503032a2016-05-12 12:06:29 -07001050 NAME = 'cord-radius'
1051
A R Karthick07608ef2016-08-23 16:51:19 -07001052 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
A R Karthick85eb1862017-01-23 16:10:57 -08001053 boot_delay = 10, restart = False, update = False, network = None):
A R Karthick07608ef2016-08-23 16:51:19 -07001054 super(Radius, self).__init__(name, image, prefix = prefix, tag = tag, command = self.start_command)
Chetan Gaonker503032a2016-05-12 12:06:29 -07001055 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -07001056 self.build_image(self.image_name)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001057 if restart is True and self.exists():
1058 self.kill()
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001059 if not self.exists():
1060 self.remove_container(name, force=True)
1061 host_config = self.create_host_config(port_list = self.ports,
1062 host_guest_map = self.host_guest_map)
1063 volumes = []
1064 for _,g in self.host_guest_map:
1065 volumes.append(g)
A R Karthick41adfce2016-06-10 09:51:25 -07001066 self.start(ports = self.ports, environment = self.env,
1067 volumes = volumes,
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001068 host_config = host_config, tty = True)
A R Karthick85eb1862017-01-23 16:10:57 -08001069 if network is not None:
1070 Container.connect_to_network(self.name, network)
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001071 time.sleep(boot_delay)
1072
1073 @classmethod
1074 def build_image(cls, image):
1075 print('Building Radius image %s' %image)
1076 dockerfile = '''
1077FROM hbouvier/docker-radius
1078MAINTAINER chetan@ciena.com
1079LABEL RUN docker pull hbouvier/docker-radius
1080LABEL RUN docker run -it --name cord-radius hbouvier/docker-radius
A R Karthickc762df42016-05-25 10:09:21 -07001081RUN apt-get update && \
1082 apt-get -y install python python-pexpect strace
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001083WORKDIR /root
1084CMD ["/etc/freeradius/start-radius.py"]
1085'''
1086 super(Radius, cls).build_image(dockerfile, image)
1087 print('Done building image %s' %image)
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001088
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001089class Quagga(Container):
A R Karthickaa54a1c2016-12-15 11:42:08 -08001090 QUAGGA_CONFIG = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 },
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -07001091 { 'bridge' : 'quagga-br', 'ip': '192.168.10.3', 'mask': 16 },
1092 )
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001093 ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ]
1094 host_quagga_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/quagga-config')
1095 guest_quagga_config = '/root/config'
1096 quagga_config_file = os.path.join(guest_quagga_config, 'testrib.conf')
1097 host_guest_map = ( (host_quagga_config, guest_quagga_config), )
A R Karthickf7a613b2017-02-24 09:36:44 -08001098 IMAGE = 'cordtest/quagga'
Chetan Gaonker503032a2016-05-12 12:06:29 -07001099 NAME = 'cord-quagga'
1100
A R Karthick07608ef2016-08-23 16:51:19 -07001101 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
A R Karthick85eb1862017-01-23 16:10:57 -08001102 boot_delay = 15, restart = False, config_file = quagga_config_file, update = False,
1103 network = None):
A R Karthickaa54a1c2016-12-15 11:42:08 -08001104 super(Quagga, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.QUAGGA_CONFIG)
Chetan Gaonker503032a2016-05-12 12:06:29 -07001105 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -07001106 self.build_image(self.image_name)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001107 if restart is True and self.exists():
1108 self.kill()
1109 if not self.exists():
1110 self.remove_container(name, force=True)
A R Karthick41adfce2016-06-10 09:51:25 -07001111 host_config = self.create_host_config(port_list = self.ports,
1112 host_guest_map = self.host_guest_map,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001113 privileged = True)
1114 volumes = []
1115 for _,g in self.host_guest_map:
1116 volumes.append(g)
1117 self.start(ports = self.ports,
A R Karthick41adfce2016-06-10 09:51:25 -07001118 host_config = host_config,
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001119 volumes = volumes, tty = True)
A R Karthick85eb1862017-01-23 16:10:57 -08001120 if network is not None:
1121 Container.connect_to_network(self.name, network)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001122 print('Starting Quagga on container %s' %self.name)
1123 self.execute('{0}/start.sh {1}'.format(self.guest_quagga_config, config_file))
1124 time.sleep(boot_delay)
1125
1126 @classmethod
1127 def build_image(cls, image):
A R Karthickaa54a1c2016-12-15 11:42:08 -08001128 onos_quagga_ip = Onos.QUAGGA_CONFIG[0]['ip']
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001129 print('Building Quagga image %s' %image)
1130 dockerfile = '''
A R Karthick41adfce2016-06-10 09:51:25 -07001131FROM ubuntu:14.04
1132MAINTAINER chetan@ciena.com
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001133WORKDIR /root
1134RUN useradd -M quagga
1135RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga
1136RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga
A R Karthick973ea692016-10-17 12:23:02 -07001137RUN 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 -07001138RUN git clone git://git.savannah.nongnu.org/quagga.git quagga && \
A R Karthick8f69c2c2016-10-21 11:43:26 -07001139(cd quagga && git checkout quagga-1.0.20160315 && ./bootstrap.sh && \
Chetan Gaonker6cf6e472016-04-26 14:41:51 -07001140sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \
1141./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install)
1142RUN ldconfig
1143'''.format(onos_quagga_ip)
1144 super(Quagga, cls).build_image(dockerfile, image)
1145 print('Done building image %s' %image)
A R Karthick81acbff2016-06-17 14:45:16 -07001146
A.R Karthick1700e0e2016-10-06 18:16:57 -07001147class QuaggaStopWrapper(Container):
1148 def __init__(self, name = Quagga.NAME, image = Quagga.IMAGE, tag = 'candidate'):
1149 super(QuaggaStopWrapper, self).__init__(name, image, prefix = Container.IMAGE_PREFIX, tag = tag)
1150 if self.exists():
1151 self.kill()
1152
1153
A R Karthick81acbff2016-06-17 14:45:16 -07001154def reinitContainerClients():
1155 docker_netns.dckr = Client()
1156 Container.dckr = Client()
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001157
1158class Xos(Container):
1159 setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
1160 TAG = 'latest'
1161 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -07001162 host_guest_map = None
1163 env = None
1164 ports = None
1165 volumes = None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001166
A R Karthick6e80afd2016-10-10 16:03:12 -07001167 @classmethod
1168 def get_cmd(cls, img_name):
1169 cmd = cls.dckr.inspect_image(img_name)['Config']['Cmd']
1170 return ' '.join(cmd)
1171
A R Karthicke3bde962016-09-27 15:06:35 -07001172 def __init__(self, name, image, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001173 boot_delay = 20, restart = False, network_cfg = None, update = False):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001174 if restart is True:
1175 ##Find the right image to restart
1176 running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
1177 if running_image:
1178 image_name = running_image[0]['Image']
1179 try:
1180 image = image_name.split(':')[0]
1181 tag = image_name.split(':')[1]
1182 except: pass
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001183 super(Xos, self).__init__(name, image, prefix = prefix, tag = tag)
1184 if update is True or not self.img_exists():
1185 self.build_image(self.image_name)
A R Karthick6e80afd2016-10-10 16:03:12 -07001186 self.command = self.get_cmd(self.image_name).strip() or None
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001187 if restart is True and self.exists():
1188 self.kill()
1189 if not self.exists():
1190 self.remove_container(name, force=True)
A R Karthicke3bde962016-09-27 15:06:35 -07001191 host_config = self.create_host_config(port_list = self.ports,
1192 host_guest_map = self.host_guest_map,
1193 privileged = True)
1194 print('Starting XOS container %s' %self.name)
1195 self.start(ports = self.ports, environment = self.env, host_config = host_config,
1196 volumes = self.volumes, tty = True)
1197 print('Waiting %d seconds for XOS Base Container to boot' %(boot_delay))
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001198 time.sleep(boot_delay)
1199
1200 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -07001201 def build_image(cls, image, dockerfile_path, image_target = 'build'):
1202 cmd = 'cd {} && make {}'.format(dockerfile_path, image_target)
1203 print('Building XOS %s' %image)
1204 res = os.system(cmd)
1205 print('Done building image %s. Image build %s' %(image, 'successful' if res == 0 else 'failed'))
1206 return res
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001207
A R Karthicke3bde962016-09-27 15:06:35 -07001208class XosServer(Xos):
1209 ports = [8000,9998,9999]
1210 NAME = 'xos-server'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001211 IMAGE = 'xosproject/xos'
A R Karthicke3bde962016-09-27 15:06:35 -07001212 BASE_IMAGE = 'xosproject/xos-base'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001213 TAG = 'latest'
1214 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -07001215 dockerfile_path = os.path.join(Xos.setup_dir, 'xos')
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001216
A R Karthicke3bde962016-09-27 15:06:35 -07001217 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001218 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001219 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001220
1221 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -07001222 def build_image(cls, image = IMAGE):
1223 ##build the base image and then build the server image
1224 Xos.build_image(cls.BASE_IMAGE, cls.dockerfile_path, image_target = 'base')
1225 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001226
A R Karthicke3bde962016-09-27 15:06:35 -07001227class XosSynchronizerOpenstack(Xos):
1228 ports = [2375,]
1229 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer')
1230 NAME = 'xos-synchronizer'
1231 IMAGE = 'xosproject/xos-synchronizer-openstack'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001232 TAG = 'latest'
1233 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -07001234 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001235
A R Karthicke3bde962016-09-27 15:06:35 -07001236 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -07001237 tag = TAG, boot_delay = 20, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001238 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001239
1240 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -07001241 def build_image(cls, image = IMAGE):
1242 XosServer.build_image()
1243 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001244
A R Karthicke3bde962016-09-27 15:06:35 -07001245class XosSynchronizerOnboarding(Xos):
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001246 NAME = 'xos-synchronizer-onboarding'
1247 IMAGE = 'xosproject/xos-synchronizer-onboarding'
1248 TAG = 'latest'
1249 PREFIX = ''
A R Karthicke3bde962016-09-27 15:06:35 -07001250 dockerfile_path = os.path.join(Xos.setup_dir, 'onboarding_synchronizer')
1251 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001252
A R Karthicke3bde962016-09-27 15:06:35 -07001253 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -07001254 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001255 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001256
1257 @classmethod
A R Karthicke3bde962016-09-27 15:06:35 -07001258 def build_image(cls, image = IMAGE):
1259 XosSynchronizerOpenstack.build_image()
1260 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001261
A R Karthicke3bde962016-09-27 15:06:35 -07001262class XosSynchronizerOpenvpn(Xos):
1263 NAME = 'xos-synchronizer-openvpn'
1264 IMAGE = 'xosproject/xos-openvpn'
1265 TAG = 'latest'
1266 PREFIX = ''
1267 dockerfile_path = os.path.join(Xos.setup_dir, 'openvpn')
1268 host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001269
A R Karthicke3bde962016-09-27 15:06:35 -07001270 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 XosSynchronizerOpenstack.build_image()
1277 Xos.build_image(image, cls.dockerfile_path)
1278
1279class XosPostgresql(Xos):
1280 ports = [5432,]
1281 NAME = 'xos-db-postgres'
1282 IMAGE = 'xosproject/xos-postgres'
1283 TAG = 'latest'
1284 PREFIX = ''
1285 volumes = ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
1286 dockerfile_path = os.path.join(Xos.setup_dir, 'postgresql')
1287
1288 def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX,
A R Karthick6e80afd2016-10-10 16:03:12 -07001289 tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001290 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1291
1292 @classmethod
1293 def build_image(cls, image = IMAGE):
1294 Xos.build_image(image, cls.dockerfile_path)
1295
1296class XosSyndicateMs(Xos):
1297 ports = [8080,]
1298 env = None
1299 NAME = 'xos-syndicate-ms'
1300 IMAGE = 'xosproject/syndicate-ms'
1301 TAG = 'latest'
1302 PREFIX = ''
1303 dockerfile_path = os.path.join(Xos.setup_dir, 'syndicate-ms')
1304
1305 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001306 boot_delay = 10, restart = False, network_cfg = None, update = False):
A R Karthicke3bde962016-09-27 15:06:35 -07001307 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1308
1309 @classmethod
1310 def build_image(cls, image = IMAGE):
1311 Xos.build_image(image, cls.dockerfile_path)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001312
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001313class XosSyncVtn(Xos):
1314 ports = [8080,]
1315 env = None
1316 NAME = 'xos-synchronizer-vtn'
1317 IMAGE = 'xosproject/xos-synchronizer-vtn'
1318 TAG = 'latest'
1319 PREFIX = ''
1320 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtn')
1321
1322 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001323 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001324 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1325
1326 @classmethod
1327 def build_image(cls, image = IMAGE):
1328 Xos.build_image(image, cls.dockerfile_path)
1329
1330class XosSyncVtr(Xos):
1331 ports = [8080,]
1332 env = None
1333 NAME = 'xos-synchronizer-vtr'
1334 IMAGE = 'xosproject/xos-synchronizer-vtr'
1335 TAG = 'latest'
1336 PREFIX = ''
1337 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtr')
1338
1339 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001340 boot_delay = 10, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001341 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1342
1343 @classmethod
1344 def build_image(cls, image = IMAGE):
1345 Xos.build_image(image, cls.dockerfile_path)
1346
1347class XosSyncVsg(Xos):
1348 ports = [8080,]
1349 env = None
1350 NAME = 'xos-synchronizer-vsg'
1351 IMAGE = 'xosproject/xos-synchronizer-vsg'
1352 TAG = 'latest'
1353 PREFIX = ''
1354 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vsg')
1355
1356 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001357 boot_delay = 10, 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
1364
1365class XosSyncOnos(Xos):
1366 ports = [8080,]
1367 env = None
1368 NAME = 'xos-synchronizer-onos'
1369 IMAGE = 'xosproject/xos-synchronizer-onos'
1370 TAG = 'latest'
1371 PREFIX = ''
1372 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-onos')
1373
1374 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001375 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001376 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1377
1378 @classmethod
1379 def build_image(cls, image = IMAGE):
1380 Xos.build_image(image, cls.dockerfile_path)
1381
1382class XosSyncFabric(Xos):
1383 ports = [8080,]
1384 env = None
1385 NAME = 'xos-synchronizer-fabric'
1386 IMAGE = 'xosproject/xos-synchronizer-fabric'
1387 TAG = 'latest'
1388 PREFIX = ''
1389 dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-fabric')
1390
1391 def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG,
A R Karthick6e80afd2016-10-10 16:03:12 -07001392 boot_delay = 30, restart = False, network_cfg = None, update = False):
ChetanGaonkerc220e0d2016-10-05 05:06:25 -07001393 Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update)
1394
1395 @classmethod
1396 def build_image(cls, image = IMAGE):
1397 Xos.build_image(image, cls.dockerfile_path)
A R Karthick19aaf5c2016-11-09 17:47:57 -08001398
1399if __name__ == '__main__':
1400 onos = Onos(boot_delay = 10, restart = True)