A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 1 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 2 | # 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 Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 7 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 9 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 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 | # |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 16 | import os,time |
| 17 | import io |
| 18 | import json |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 19 | import yaml |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 20 | import errno |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 21 | import copy |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 22 | from pyroute2 import IPRoute |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 23 | from pyroute2.netlink import NetlinkError |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 24 | from itertools import chain |
| 25 | from nsenter import Namespace |
| 26 | from docker import Client |
A R Karthick | 85eb186 | 2017-01-23 16:10:57 -0800 | [diff] [blame] | 27 | from docker import utils as dockerutils |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 28 | import shutil |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 29 | from OnosCtrl import OnosCtrl |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 30 | from OnosLog import OnosLog |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 31 | from onosclidriver import OnosCliDriver |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 32 | from threadPool import ThreadPool |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 33 | from threading import Lock |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 34 | |
| 35 | class docker_netns(object): |
| 36 | |
| 37 | dckr = Client() |
| 38 | def __init__(self, name): |
| 39 | pid = int(self.dckr.inspect_container(name)['State']['Pid']) |
| 40 | if pid == 0: |
| 41 | raise Exception('no container named {0}'.format(name)) |
| 42 | self.pid = pid |
| 43 | |
| 44 | def __enter__(self): |
| 45 | pid = self.pid |
| 46 | if not os.path.exists('/var/run/netns'): |
| 47 | os.mkdir('/var/run/netns') |
| 48 | os.symlink('/proc/{0}/ns/net'.format(pid), '/var/run/netns/{0}'.format(pid)) |
| 49 | return str(pid) |
| 50 | |
| 51 | def __exit__(self, type, value, traceback): |
| 52 | pid = self.pid |
| 53 | os.unlink('/var/run/netns/{0}'.format(pid)) |
| 54 | |
| 55 | flatten = lambda l: chain.from_iterable(l) |
| 56 | |
| 57 | class Container(object): |
| 58 | dckr = Client() |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 59 | IMAGE_PREFIX = '' ##for saving global prefix for all test classes |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 60 | CONFIG_LOCK = Lock() |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 61 | |
| 62 | def __init__(self, name, image, prefix='', tag = 'candidate', command = 'bash', quagga_config = None): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 63 | self.name = name |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 64 | self.prefix = prefix |
| 65 | if prefix: |
| 66 | self.prefix += '/' |
| 67 | image = '{}{}'.format(self.prefix, image) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 68 | self.image = image |
| 69 | self.tag = tag |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 70 | if tag: |
| 71 | self.image_name = image + ':' + tag |
| 72 | else: |
| 73 | self.image_name = image |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 74 | self.id = None |
| 75 | self.command = command |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 76 | self.quagga_config = quagga_config |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 77 | |
| 78 | @classmethod |
| 79 | def build_image(cls, dockerfile, tag, force=True, nocache=False): |
| 80 | f = io.BytesIO(dockerfile.encode('utf-8')) |
| 81 | if force or not cls.image_exists(tag): |
| 82 | print('Build {0}...'.format(tag)) |
| 83 | for line in cls.dckr.build(fileobj=f, rm=True, tag=tag, decode=True, nocache=nocache): |
| 84 | if 'stream' in line: |
| 85 | print(line['stream'].strip()) |
| 86 | |
| 87 | @classmethod |
| 88 | def image_exists(cls, name): |
A R Karthick | e07fc3a | 2017-02-27 10:49:29 -0800 | [diff] [blame] | 89 | #return name in [ctn['RepoTags'][0] for ctn in cls.dckr.images()] |
| 90 | return name in list( flatten(ctn['RepoTags'] if ctn['RepoTags'] else '' for ctn in cls.dckr.images()) ) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 91 | |
| 92 | @classmethod |
| 93 | def create_host_config(cls, port_list = None, host_guest_map = None, privileged = False): |
| 94 | port_bindings = None |
| 95 | binds = None |
| 96 | if port_list: |
| 97 | port_bindings = {} |
| 98 | for p in port_list: |
| 99 | port_bindings[str(p)] = str(p) |
| 100 | |
| 101 | if host_guest_map: |
| 102 | binds = [] |
| 103 | for h, g in host_guest_map: |
| 104 | binds.append('{0}:{1}'.format(h, g)) |
| 105 | |
| 106 | return cls.dckr.create_host_config(binds = binds, port_bindings = port_bindings, privileged = privileged) |
| 107 | |
| 108 | @classmethod |
A R Karthick | 85eb186 | 2017-01-23 16:10:57 -0800 | [diff] [blame] | 109 | def connect_to_network(cls, name, network): |
| 110 | try: |
| 111 | cls.dckr.connect_container_to_network(name, network) |
| 112 | return True |
| 113 | except: |
| 114 | return False |
| 115 | |
| 116 | @classmethod |
| 117 | def create_network(cls, network, subnet = None, gateway = None): |
| 118 | ipam_config = None |
| 119 | if subnet is not None and gateway is not None: |
| 120 | ipam_pool = dockerutils.create_ipam_pool(subnet = subnet, gateway = gateway) |
| 121 | ipam_config = dockerutils.create_ipam_config(pool_configs = [ipam_pool]) |
| 122 | cls.dckr.create_network(network, driver='bridge', ipam = ipam_config) |
| 123 | |
| 124 | @classmethod |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 125 | def cleanup(cls, image): |
A R Karthick | 09b1f4e | 2016-05-12 14:31:50 -0700 | [diff] [blame] | 126 | cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True)) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 127 | for cnt in cnt_list: |
| 128 | print('Cleaning container %s' %cnt['Id']) |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 129 | if cnt.has_key('State') and cnt['State'] == 'running': |
A R Karthick | 09b1f4e | 2016-05-12 14:31:50 -0700 | [diff] [blame] | 130 | cls.dckr.kill(cnt['Id']) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 131 | cls.dckr.remove_container(cnt['Id'], force=True) |
| 132 | |
| 133 | @classmethod |
| 134 | def remove_container(cls, name, force=True): |
| 135 | try: |
| 136 | cls.dckr.remove_container(name, force = force) |
| 137 | except: pass |
| 138 | |
| 139 | def exists(self): |
| 140 | return '/{0}'.format(self.name) in list(flatten(n['Names'] for n in self.dckr.containers())) |
| 141 | |
| 142 | def img_exists(self): |
A R Karthick | e07fc3a | 2017-02-27 10:49:29 -0800 | [diff] [blame] | 143 | #return self.image_name in [ctn['RepoTags'][0] if ctn['RepoTags'] else '' for ctn in self.dckr.images()] |
| 144 | return self.image_name in list( flatten(ctn['RepoTags'] if ctn['RepoTags'] else '' for ctn in self.dckr.images()) ) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 145 | |
A R Karthick | 7584457 | 2017-01-23 16:57:44 -0800 | [diff] [blame] | 146 | def ip(self, network = None): |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 147 | cnt_list = filter(lambda c: c['Names'][0] == '/{}'.format(self.name), self.dckr.containers()) |
| 148 | #if not cnt_list: |
| 149 | # cnt_list = filter(lambda c: c['Image'] == self.image_name, self.dckr.containers()) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 150 | cnt_settings = cnt_list.pop() |
A R Karthick | 7584457 | 2017-01-23 16:57:44 -0800 | [diff] [blame] | 151 | if network is not None and cnt_settings['NetworkSettings']['Networks'].has_key(network): |
| 152 | return cnt_settings['NetworkSettings']['Networks'][network]['IPAddress'] |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 153 | return cnt_settings['NetworkSettings']['Networks']['bridge']['IPAddress'] |
| 154 | |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 155 | @classmethod |
| 156 | def ips(cls, image_name): |
| 157 | cnt_list = filter(lambda c: c['Image'] == image_name, cls.dckr.containers()) |
| 158 | ips = [ cnt['NetworkSettings']['Networks']['bridge']['IPAddress'] for cnt in cnt_list ] |
| 159 | return ips |
| 160 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 161 | def kill(self, remove = True): |
| 162 | self.dckr.kill(self.name) |
| 163 | self.dckr.remove_container(self.name, force=True) |
| 164 | |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 165 | def start(self, rm = True, ports = None, volumes = None, host_config = None, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 166 | environment = None, tty = False, stdin_open = True): |
| 167 | |
| 168 | if rm and self.exists(): |
| 169 | print('Removing container:', self.name) |
| 170 | self.dckr.remove_container(self.name, force=True) |
| 171 | |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 172 | ctn = self.dckr.create_container(image=self.image_name, ports = ports, command=self.command, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 173 | detach=True, name=self.name, |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 174 | environment = environment, |
| 175 | volumes = volumes, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 176 | host_config = host_config, stdin_open=stdin_open, tty = tty) |
| 177 | self.dckr.start(container=self.name) |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 178 | if self.quagga_config: |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 179 | self.connect_to_br() |
| 180 | self.id = ctn['Id'] |
| 181 | return ctn |
| 182 | |
Thangavelu K S | ef6f0a5 | 2016-12-14 19:57:05 +0000 | [diff] [blame] | 183 | @classmethod |
| 184 | def pause_container(cls, image, delay): |
| 185 | cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True)) |
| 186 | for cnt in cnt_list: |
| 187 | print('Pause the container %s' %cnt['Id']) |
| 188 | if cnt.has_key('State') and cnt['State'] == 'running': |
| 189 | cls.dckr.pause(cnt['Id']) |
| 190 | if delay != 0: |
| 191 | time.sleep(delay) |
| 192 | for cnt in cnt_list: |
| 193 | print('Unpause the container %s' %cnt['Id']) |
| 194 | cls.dckr.unpause(cnt['Id']) |
| 195 | else: |
| 196 | print('Infinity time pause the container %s' %cnt['Id']) |
| 197 | return 'success' |
| 198 | |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 199 | def connect_to_br(self, index = 0): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 200 | self.CONFIG_LOCK.acquire() |
| 201 | try: |
| 202 | with docker_netns(self.name) as pid: |
| 203 | for quagga_config in self.quagga_config: |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 204 | ip = IPRoute() |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 205 | br = ip.link_lookup(ifname=quagga_config['bridge']) |
| 206 | if len(br) == 0: |
| 207 | try: |
| 208 | ip.link_create(ifname=quagga_config['bridge'], kind='bridge') |
| 209 | except NetlinkError as e: |
| 210 | err, _ = e.args |
| 211 | if err == errno.EEXIST: |
| 212 | pass |
| 213 | else: |
| 214 | raise NetlinkError(*e.args) |
| 215 | br = ip.link_lookup(ifname=quagga_config['bridge']) |
| 216 | br = br[0] |
| 217 | ip.link('set', index=br, state='up') |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 218 | ifname = '{0}-{1}'.format(self.name[:12], index) |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 219 | ifs = ip.link_lookup(ifname=ifname) |
| 220 | if len(ifs) > 0: |
| 221 | ip.link_remove(ifs[0]) |
| 222 | peer_ifname = '{0}-{1}'.format(pid, index) |
| 223 | ip.link_create(ifname=ifname, kind='veth', peer=peer_ifname) |
| 224 | host = ip.link_lookup(ifname=ifname)[0] |
| 225 | ip.link('set', index=host, master=br) |
| 226 | ip.link('set', index=host, state='up') |
| 227 | guest = ip.link_lookup(ifname=peer_ifname)[0] |
| 228 | ip.link('set', index=guest, net_ns_fd=pid) |
| 229 | with Namespace(pid, 'net'): |
| 230 | ip = IPRoute() |
| 231 | ip.link('set', index=guest, ifname='eth{}'.format(index+1)) |
| 232 | ip.addr('add', index=guest, address=quagga_config['ip'], mask=quagga_config['mask']) |
| 233 | ip.link('set', index=guest, state='up') |
| 234 | index += 1 |
| 235 | finally: |
| 236 | self.CONFIG_LOCK.release() |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 237 | |
Thangavelu K S | ef6f0a5 | 2016-12-14 19:57:05 +0000 | [diff] [blame] | 238 | def execute(self, cmd, tty = True, stream = False, shell = False, detach = True): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 239 | res = 0 |
| 240 | if type(cmd) == str: |
| 241 | cmds = (cmd,) |
| 242 | else: |
| 243 | cmds = cmd |
| 244 | if shell: |
| 245 | for c in cmds: |
| 246 | res += os.system('docker exec {0} {1}'.format(self.name, c)) |
| 247 | return res |
| 248 | for c in cmds: |
| 249 | i = self.dckr.exec_create(container=self.name, cmd=c, tty = tty, privileged = True) |
A R Karthick | d6dd9b2 | 2017-02-24 15:17:22 -0800 | [diff] [blame] | 250 | s = self.dckr.exec_start(i['Id'], stream = stream, detach=detach, socket=True) |
| 251 | try: |
| 252 | s.close() |
| 253 | except: pass |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 254 | result = self.dckr.exec_inspect(i['Id']) |
| 255 | res += 0 if result['ExitCode'] == None else result['ExitCode'] |
| 256 | return res |
| 257 | |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 258 | def restart(self, timeout =10): |
| 259 | return self.dckr.restart(self.name, timeout) |
| 260 | |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 261 | def get_mem(jvm_heap_size = None, instances = 1): |
A R Karthick | 1f90820 | 2016-11-16 17:32:20 -0800 | [diff] [blame] | 262 | if instances <= 0: |
| 263 | instances = 1 |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 264 | heap_size = jvm_heap_size |
| 265 | heap_size_i = 0 |
| 266 | #sanitize the heap size config |
| 267 | if heap_size is not None: |
| 268 | if not heap_size.isdigit(): |
| 269 | try: |
| 270 | heap_size_i = int(heap_size[:-1]) |
| 271 | suffix = heap_size[-1] |
| 272 | if suffix == 'M': |
| 273 | heap_size_i /= 1024 #convert to gigs |
A.R Karthick | 9904482 | 2017-02-09 14:04:20 -0800 | [diff] [blame] | 274 | #allow to specific minimum heap size |
| 275 | if heap_size_i == 0: |
| 276 | return heap_size |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 277 | except: |
| 278 | ##invalid suffix length probably. Fall back to default |
| 279 | heap_size = None |
| 280 | else: |
| 281 | heap_size_i = int(heap_size) |
| 282 | |
Chetan Gaonker | 462d9fa | 2016-05-03 16:39:10 -0700 | [diff] [blame] | 283 | with open('/proc/meminfo', 'r') as fd: |
| 284 | meminfo = fd.readlines() |
| 285 | mem = 0 |
| 286 | for m in meminfo: |
| 287 | if m.startswith('MemTotal:') or m.startswith('SwapTotal:'): |
| 288 | mem += int(m.split(':')[1].strip().split()[0]) |
| 289 | |
A R Karthick | 1f90820 | 2016-11-16 17:32:20 -0800 | [diff] [blame] | 290 | mem = max(mem/1024/1024/2/instances, 1) |
Chetan Gaonker | 6d0a7b0 | 2016-05-03 16:57:28 -0700 | [diff] [blame] | 291 | mem = min(mem, 16) |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 292 | |
| 293 | if heap_size_i: |
| 294 | #we take the minimum of the provided heap size and max allowed heap size |
| 295 | heap_size_i = min(heap_size_i, mem) |
| 296 | else: |
| 297 | heap_size_i = mem |
| 298 | |
| 299 | return '{}G'.format(heap_size_i) |
Chetan Gaonker | 462d9fa | 2016-05-03 16:39:10 -0700 | [diff] [blame] | 300 | |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 301 | class OnosCord(Container): |
| 302 | """Use this when running the cord tester agent on the onos compute node""" |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 303 | onos_config_dir_guest = '/root/onos/config' |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 304 | synchronizer_map = { 'vtn' : { 'install': |
| 305 | ('http://mavenrepo:8080/repository/org/opencord/cord-config/1.2-SNAPSHOT/cord-config-1.2-SNAPSHOT.oar', |
| 306 | 'http://mavenrepo:8080/repository/org/opencord/vtn/1.2-SNAPSHOT/vtn-1.2-SNAPSHOT.oar',), |
| 307 | 'activate': |
| 308 | ('org.onosproject.ovsdb-base', 'org.onosproject.drivers.ovsdb', |
| 309 | 'org.onosproject.dhcp', 'org.onosproject.optical-model', |
| 310 | 'org.onosproject.openflow-base', 'org.onosproject.proxyarp', |
| 311 | 'org.onosproject.hostprovider'), |
| 312 | }, |
| 313 | 'fabric' : { 'activate': |
| 314 | ('org.onosproject.hostprovider', 'org.onosproject.optical-model', |
| 315 | 'org.onosproject.openflow-base', 'org.onosproject.vrouter', |
| 316 | 'org.onosproject.netcfghostprovider', 'org.onosproject.netcfglinksprovider', |
| 317 | 'org.onosproject.segmentrouting', 'org.onosproject.proxyarp'), |
| 318 | } |
| 319 | } |
| 320 | tester_apps = ('http://mavenrepo:8080/repository/org/opencord/aaa/1.2-SNAPSHOT/aaa-1.2-SNAPSHOT.oar', |
| 321 | 'http://mavenrepo:8080/repository/org/opencord/igmp/1.2-SNAPSHOT/igmp-1.2-SNAPSHOT.oar',) |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 322 | |
A.R Karthick | ddf1277 | 2017-05-17 13:49:47 -0700 | [diff] [blame] | 323 | old_service_profile = '/opt/cord/orchestration/service-profile/cord-pod' |
A R Karthick | 49529c5 | 2017-05-19 09:43:01 -0700 | [diff] [blame] | 324 | cord_profile = '/opt/cord_profile' |
A.R Karthick | ddf1277 | 2017-05-17 13:49:47 -0700 | [diff] [blame] | 325 | |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 326 | def __init__(self, onos_ip, conf, service_profile, synchronizer, start = True, boot_delay = 5): |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 327 | if not os.access(conf, os.F_OK): |
| 328 | raise Exception('ONOS cord configuration location %s is invalid' %conf) |
A.R Karthick | ddf1277 | 2017-05-17 13:49:47 -0700 | [diff] [blame] | 329 | self.old_cord = False |
| 330 | if os.access(self.old_service_profile, os.F_OK): |
| 331 | self.old_cord = True |
A R Karthick | bd9b8a3 | 2016-07-21 09:56:45 -0700 | [diff] [blame] | 332 | self.onos_ip = onos_ip |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 333 | self.onos_cord_dir = conf |
A R Karthick | bd9b8a3 | 2016-07-21 09:56:45 -0700 | [diff] [blame] | 334 | self.boot_delay = boot_delay |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 335 | self.synchronizer = synchronizer |
| 336 | self.service_profile = service_profile |
| 337 | self.docker_yaml = os.path.join(conf, 'docker-compose.yml') |
| 338 | self.docker_yaml_saved = os.path.join(conf, 'docker-compose.yml.saved') |
| 339 | self.onos_config_dir = os.path.join(conf, 'config') |
| 340 | self.onos_cfg_save_loc = os.path.join(conf, 'network-cfg.json.saved') |
| 341 | instance_active = False |
| 342 | #if we have a wrapper onos instance already active, back out |
| 343 | if os.access(self.onos_config_dir, os.F_OK) or os.access(self.docker_yaml_saved, os.F_OK): |
| 344 | instance_active = True |
| 345 | else: |
| 346 | if start is True: |
| 347 | os.mkdir(self.onos_config_dir) |
| 348 | shutil.copy(self.docker_yaml, self.docker_yaml_saved) |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 349 | |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 350 | self.start_wrapper = instance_active is False and start is True |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 351 | ##update the docker yaml with the config volume |
| 352 | with open(self.docker_yaml, 'r') as f: |
| 353 | yaml_config = yaml.load(f) |
| 354 | image = yaml_config['services'].keys()[0] |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 355 | cord_conf_dir_basename = os.path.basename(self.onos_cord_dir.replace('-', '')) |
| 356 | xos_onos_name = '{}_{}_1'.format(cord_conf_dir_basename, image) |
A R Karthick | 5778a79 | 2017-01-31 13:47:16 -0800 | [diff] [blame] | 357 | if not yaml_config['services'][image].has_key('volumes'): |
| 358 | yaml_config['services'][image]['volumes'] = [] |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 359 | volumes = yaml_config['services'][image]['volumes'] |
| 360 | config_volumes = filter(lambda e: e.find(self.onos_config_dir_guest) >= 0, volumes) |
| 361 | if not config_volumes: |
| 362 | config_volume = '{}:{}'.format(self.onos_config_dir, self.onos_config_dir_guest) |
| 363 | volumes.append(config_volume) |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 364 | if self.start_wrapper: |
| 365 | docker_yaml_changed = '{}-changed'.format(self.docker_yaml) |
| 366 | with open(docker_yaml_changed, 'w') as wf: |
| 367 | yaml.dump(yaml_config, wf) |
| 368 | os.rename(docker_yaml_changed, self.docker_yaml) |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 369 | self.volumes = volumes |
| 370 | |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 371 | ##Create an container instance of xos onos |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 372 | super(OnosCord, self).__init__(xos_onos_name, image, tag = '', quagga_config = Onos.QUAGGA_CONFIG) |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 373 | self.last_cfg = None |
| 374 | if self.start_wrapper: |
| 375 | #fetch the current config of onos cord instance and save it |
| 376 | try: |
| 377 | self.last_cfg = OnosCtrl.get_config(controller = onos_ip) |
| 378 | json_data = json.dumps(self.last_cfg, indent=4) |
| 379 | with open(self.onos_cfg_save_loc, 'w') as f: |
| 380 | f.write(json_data) |
| 381 | except: |
| 382 | pass |
| 383 | #start the container back with the shared onos config volume |
| 384 | self.start() |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 385 | |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 386 | def cliEnter(self): |
| 387 | retries = 0 |
| 388 | while retries < 30: |
| 389 | cli = OnosCliDriver(controller = self.onos_ip, connect = True) |
| 390 | if cli.handle: |
| 391 | return cli |
| 392 | else: |
| 393 | retries += 1 |
A R Karthick | 72fcbc5 | 2017-03-06 12:35:17 -0800 | [diff] [blame] | 394 | time.sleep(3) |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 395 | |
| 396 | return None |
| 397 | |
| 398 | def cliExit(self, cli): |
| 399 | if cli: |
| 400 | cli.disconnect() |
| 401 | |
A.R Karthick | ddf1277 | 2017-05-17 13:49:47 -0700 | [diff] [blame] | 402 | def synchronize_fabric(self, cfg = None): |
| 403 | if self.old_cord is True: |
| 404 | cmds = [ 'cd {} && make {}'.format(self.old_service_profile, self.synchronizer), |
| 405 | 'sleep 30' |
| 406 | ] |
| 407 | for cmd in cmds: |
| 408 | try: |
| 409 | os.system(cmd) |
| 410 | except: |
| 411 | pass |
| 412 | |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 413 | def synchronize_vtn(self, cfg = None): |
A.R Karthick | ddf1277 | 2017-05-17 13:49:47 -0700 | [diff] [blame] | 414 | if self.old_cord is True: |
| 415 | cmds = [ 'cd {} && make {}'.format(self.old_service_profile, self.synchronizer), |
| 416 | 'sleep 30' |
| 417 | ] |
| 418 | for cmd in cmds: |
| 419 | try: |
| 420 | os.system(cmd) |
| 421 | except: |
| 422 | pass |
| 423 | return |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 424 | if cfg is None: |
| 425 | return |
| 426 | if not cfg.has_key('apps'): |
| 427 | return |
| 428 | if not cfg['apps'].has_key('org.opencord.vtn'): |
| 429 | return |
| 430 | vtn_neutron_cfg = cfg['apps']['org.opencord.vtn']['cordvtn']['openstack'] |
| 431 | password = vtn_neutron_cfg['password'] |
| 432 | endpoint = vtn_neutron_cfg['endpoint'] |
| 433 | user = vtn_neutron_cfg['user'] |
| 434 | tenant = vtn_neutron_cfg['tenant'] |
| 435 | vtn_host = cfg['apps']['org.opencord.vtn']['cordvtn']['nodes'][0]['hostname'] |
| 436 | cli = self.cliEnter() |
| 437 | if cli is None: |
| 438 | return |
| 439 | cli.cordVtnSyncNeutronStates(endpoint, password, tenant = tenant, user = user) |
| 440 | time.sleep(2) |
| 441 | cli.cordVtnNodeInit(vtn_host) |
| 442 | self.cliExit(cli) |
| 443 | |
| 444 | def synchronize(self, cfg_unlink = False): |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 445 | |
| 446 | if not self.synchronizer_map.has_key(self.synchronizer): |
| 447 | return |
| 448 | |
| 449 | install_list = () |
| 450 | if self.synchronizer_map[self.synchronizer].has_key('install'): |
| 451 | install_list = self.synchronizer_map[self.synchronizer]['install'] |
| 452 | |
| 453 | activate_list = () |
| 454 | if self.synchronizer_map[self.synchronizer].has_key('activate'): |
| 455 | activate_list = self.synchronizer_map[self.synchronizer]['activate'] |
| 456 | |
| 457 | for app_url in install_list: |
| 458 | print('Installing app from url: %s' %app_url) |
| 459 | OnosCtrl.install_app_from_url(None, None, app_url = app_url, onos_ip = self.onos_ip) |
| 460 | |
| 461 | for app in activate_list: |
| 462 | print('Activating app %s' %app) |
| 463 | OnosCtrl(app, controller = self.onos_ip).activate() |
| 464 | time.sleep(2) |
| 465 | |
| 466 | for app_url in self.tester_apps: |
| 467 | print('Installing tester app from url: %s' %app_url) |
| 468 | OnosCtrl.install_app_from_url(None, None, app_url = app_url, onos_ip = self.onos_ip) |
| 469 | |
A R Karthick | 72fcbc5 | 2017-03-06 12:35:17 -0800 | [diff] [blame] | 470 | cfg = None |
| 471 | #restore the saved config after applications are activated |
| 472 | if os.access(self.onos_cfg_save_loc, os.F_OK): |
| 473 | with open(self.onos_cfg_save_loc, 'r') as f: |
| 474 | cfg = json.load(f) |
| 475 | try: |
| 476 | OnosCtrl.config(cfg, controller = self.onos_ip) |
| 477 | if cfg_unlink is True: |
| 478 | os.unlink(self.onos_cfg_save_loc) |
| 479 | except: |
| 480 | pass |
| 481 | |
| 482 | if hasattr(self, 'synchronize_{}'.format(self.synchronizer)): |
| 483 | getattr(self, 'synchronize_{}'.format(self.synchronizer))(cfg = cfg) |
| 484 | |
| 485 | #now restart the xos synchronizer container |
A R Karthick | 49529c5 | 2017-05-19 09:43:01 -0700 | [diff] [blame] | 486 | cmd = None |
| 487 | if os.access('{}/onboarding-docker-compose/docker-compose.yml'.format(self.cord_profile), os.F_OK): |
| 488 | cmd = 'cd {}/onboarding-docker-compose && \ |
| 489 | docker-compose -p {} restart xos_synchronizer_{}'.format(self.cord_profile, |
| 490 | self.service_profile, |
| 491 | self.synchronizer) |
| 492 | else: |
| 493 | if os.access('{}/docker-compose.yml'.format(self.cord_profile), os.F_OK): |
| 494 | cmd = 'cd {} && \ |
| 495 | docker-compose -p {} restart {}-synchronizer'.format(self.cord_profile, |
| 496 | self.service_profile, |
| 497 | self.synchronizer) |
| 498 | if cmd is not None: |
| 499 | try: |
| 500 | print(cmd) |
| 501 | os.system(cmd) |
| 502 | except: |
| 503 | pass |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 504 | |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 505 | def start(self, restart = False, network_cfg = None): |
A R Karthick | 928ad62 | 2017-01-30 12:18:32 -0800 | [diff] [blame] | 506 | if network_cfg is not None: |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 507 | json_data = json.dumps(network_cfg, indent=4) |
| 508 | with open('{}/network-cfg.json'.format(self.onos_config_dir), 'w') as f: |
| 509 | f.write(json_data) |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 510 | |
| 511 | #we avoid using docker-compose restart for now. |
| 512 | #since we don't want to retain the metadata across restarts |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 513 | #stop and start and synchronize the services before installing tester cord apps |
| 514 | cmds = [ 'cd {} && docker-compose down'.format(self.onos_cord_dir), |
| 515 | 'cd {} && docker-compose up -d'.format(self.onos_cord_dir), |
A R Karthick | bc89437 | 2017-05-12 16:34:08 -0700 | [diff] [blame] | 516 | 'sleep 150', |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 517 | ] |
| 518 | for cmd in cmds: |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 519 | try: |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 520 | print(cmd) |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 521 | os.system(cmd) |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 522 | except:pass |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 523 | |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 524 | self.synchronize() |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 525 | ##we could also connect container to default docker network but disabled for now |
| 526 | #Container.connect_to_network(self.name, 'bridge') |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 527 | #connect container to the quagga bridge |
| 528 | self.connect_to_br(index = 0) |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 529 | print('Waiting %d seconds for ONOS instance to start' %self.boot_delay) |
A R Karthick | bd9b8a3 | 2016-07-21 09:56:45 -0700 | [diff] [blame] | 530 | time.sleep(self.boot_delay) |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 531 | |
| 532 | def build_image(self): |
| 533 | build_cmd = 'cd {} && docker-compose build'.format(self.onos_cord_dir) |
| 534 | os.system(build_cmd) |
| 535 | |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 536 | def restore(self, force = False): |
| 537 | restore = self.start_wrapper is True or force is True |
| 538 | if not restore: |
A.R Karthick | 263d3fc | 2017-01-27 12:52:53 -0800 | [diff] [blame] | 539 | return |
A R Karthick | 394976f | 2017-01-31 14:25:16 -0800 | [diff] [blame] | 540 | #nothing to restore |
| 541 | if not os.access(self.docker_yaml_saved, os.F_OK): |
| 542 | return |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 543 | |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 544 | #restore the config files back. The synchronizer restore should bring the last config back |
| 545 | cmds = ['cd {} && docker-compose down'.format(self.onos_cord_dir), |
| 546 | 'rm -rf {}'.format(self.onos_config_dir), |
| 547 | 'mv {} {}'.format(self.docker_yaml_saved, self.docker_yaml), |
| 548 | 'cd {} && docker-compose up -d'.format(self.onos_cord_dir), |
A R Karthick | bc89437 | 2017-05-12 16:34:08 -0700 | [diff] [blame] | 549 | 'sleep 150', |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 550 | ] |
| 551 | for cmd in cmds: |
A.R Karthick | b17e202 | 2017-01-27 11:29:26 -0800 | [diff] [blame] | 552 | try: |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 553 | print(cmd) |
| 554 | os.system(cmd) |
A.R Karthick | b17e202 | 2017-01-27 11:29:26 -0800 | [diff] [blame] | 555 | except: pass |
| 556 | |
A R Karthick | 03bd281 | 2017-03-03 17:49:17 -0800 | [diff] [blame] | 557 | self.synchronize(cfg_unlink = True) |
A.R Karthick | b17e202 | 2017-01-27 11:29:26 -0800 | [diff] [blame] | 558 | |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 559 | class OnosCordStopWrapper(Container): |
| 560 | onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord') |
| 561 | docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml') |
| 562 | |
| 563 | def __init__(self): |
| 564 | if os.access(self.docker_yaml, os.F_OK): |
| 565 | with open(self.docker_yaml, 'r') as f: |
| 566 | yaml_config = yaml.load(f) |
| 567 | image = yaml_config['services'].keys()[0] |
| 568 | name = 'cordtestercord_{}_1'.format(image) |
| 569 | super(OnosCordStopWrapper, self).__init__(name, image, tag = '') |
| 570 | if self.exists(): |
| 571 | print('Killing container %s' %self.name) |
| 572 | self.kill() |
| 573 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 574 | class Onos(Container): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 575 | QUAGGA_CONFIG = [ { 'bridge' : 'quagga-br', 'ip': '10.10.0.4', 'mask' : 16 }, ] |
A R Karthick | a2492c1 | 2016-12-16 10:31:51 -0800 | [diff] [blame] | 576 | MAX_INSTANCES = 3 |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 577 | JVM_HEAP_SIZE = None |
Chetan Gaonker | 462d9fa | 2016-05-03 16:39:10 -0700 | [diff] [blame] | 578 | SYSTEM_MEMORY = (get_mem(),) * 2 |
A R Karthick | a2492c1 | 2016-12-16 10:31:51 -0800 | [diff] [blame] | 579 | INSTANCE_MEMORY = (get_mem(instances=MAX_INSTANCES),) * 2 |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 580 | JAVA_OPTS_FORMAT = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode' |
| 581 | JAVA_OPTS_DEFAULT = JAVA_OPTS_FORMAT.format(*SYSTEM_MEMORY) #-XX:+PrintGCDetails -XX:+PrintGCTimeStamps' |
| 582 | JAVA_OPTS_CLUSTER_DEFAULT = JAVA_OPTS_FORMAT.format(*INSTANCE_MEMORY) |
| 583 | env = { 'ONOS_APPS' : 'drivers,openflow,proxyarp,vrouter', 'JAVA_OPTS' : JAVA_OPTS_DEFAULT } |
A R Karthick | b608d40 | 2017-06-02 11:48:41 -0700 | [diff] [blame] | 584 | onos_cord_apps = ( ['cord-config', '1.2-SNAPSHOT'], |
| 585 | ['aaa', '1.2-SNAPSHOT'], |
| 586 | ['igmp', '1.2-SNAPSHOT'], |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 587 | ) |
A R Karthick | b608d40 | 2017-06-02 11:48:41 -0700 | [diff] [blame] | 588 | cord_apps_version_updated = False |
A.R Karthick | dda2206 | 2017-02-09 14:39:20 -0800 | [diff] [blame] | 589 | ports = [] #[ 8181, 8101, 9876, 6653, 6633, 2000, 2620, 5005 ] |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 590 | setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup') |
| 591 | host_config_dir = os.path.join(setup_dir, 'onos-config') |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 592 | guest_config_dir = '/root/onos/config' |
A.R Karthick | dda2206 | 2017-02-09 14:39:20 -0800 | [diff] [blame] | 593 | guest_data_dir = '/root/onos/apache-karaf-3.0.8/data' |
| 594 | guest_log_file = '/root/onos/apache-karaf-3.0.8/data/log/karaf.log' |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 595 | onos_gen_partitions = os.path.join(setup_dir, 'onos-gen-partitions') |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 596 | onos_form_cluster = os.path.join(setup_dir, 'onos-form-cluster') |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 597 | cord_apps_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'apps') |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 598 | host_guest_map = ( (host_config_dir, guest_config_dir), ) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 599 | cluster_cfg = os.path.join(host_config_dir, 'cluster.json') |
| 600 | cluster_mode = False |
| 601 | cluster_instances = [] |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 602 | NAME = 'cord-onos' |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 603 | ##the ip of ONOS in default cluster.json in setup/onos-config |
| 604 | CLUSTER_CFG_IP = '172.17.0.2' |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 605 | IMAGE = 'onosproject/onos' |
| 606 | TAG = 'latest' |
| 607 | PREFIX = '' |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 608 | |
| 609 | @classmethod |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 610 | def generate_cluster_cfg(cls, ip): |
| 611 | if type(ip) in [ list, tuple ]: |
| 612 | ips = ' '.join(ip) |
| 613 | else: |
| 614 | ips = ip |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 615 | try: |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 616 | cmd = '{} {} {}'.format(cls.onos_gen_partitions, cls.cluster_cfg, ips) |
| 617 | os.system(cmd) |
| 618 | except: pass |
| 619 | |
| 620 | @classmethod |
| 621 | def form_cluster(cls, ips): |
| 622 | nodes = ' '.join(ips) |
| 623 | try: |
| 624 | cmd = '{} {}'.format(cls.onos_form_cluster, nodes) |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 625 | os.system(cmd) |
| 626 | except: pass |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 627 | |
A R Karthick | 9d48c65 | 2016-09-15 09:16:36 -0700 | [diff] [blame] | 628 | @classmethod |
| 629 | def cleanup_runtime(cls): |
| 630 | '''Cleanup ONOS runtime generated files''' |
| 631 | files = ( Onos.cluster_cfg, os.path.join(Onos.host_config_dir, 'network-cfg.json') ) |
| 632 | for f in files: |
| 633 | if os.access(f, os.F_OK): |
| 634 | try: |
| 635 | os.unlink(f) |
| 636 | except: pass |
| 637 | |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 638 | @classmethod |
| 639 | def get_data_map(cls, host_volume, guest_volume_dir): |
| 640 | host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume)) |
| 641 | if not os.path.exists(host_volume_dir): |
| 642 | os.mkdir(host_volume_dir) |
| 643 | return ( (host_volume_dir, guest_volume_dir), ) |
| 644 | |
| 645 | @classmethod |
| 646 | def remove_data_map(cls, host_volume, guest_volume_dir): |
| 647 | host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume)) |
| 648 | if os.path.exists(host_volume_dir): |
A.R Karthick | f184b34 | 2017-01-27 19:30:50 -0800 | [diff] [blame] | 649 | shutil.rmtree(host_volume_dir) |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 650 | |
A R Karthick | 973010f | 2017-02-06 16:41:51 -0800 | [diff] [blame] | 651 | @classmethod |
| 652 | def update_data_dir(cls, karaf): |
| 653 | Onos.guest_data_dir = '/root/onos/apache-karaf-{}/data'.format(karaf) |
| 654 | Onos.guest_log_file = '/root/onos/apache-karaf-{}/data/log/karaf.log'.format(karaf) |
| 655 | |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 656 | def remove_data_volume(self): |
| 657 | if self.data_map is not None: |
| 658 | self.remove_data_map(*self.data_map) |
| 659 | |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 660 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG, |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 661 | boot_delay = 20, restart = False, network_cfg = None, |
A R Karthick | 85eb186 | 2017-01-23 16:10:57 -0800 | [diff] [blame] | 662 | cluster = False, data_volume = None, async = False, quagga_config = None, |
| 663 | network = None): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 664 | if restart is True: |
| 665 | ##Find the right image to restart |
| 666 | running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers()) |
| 667 | if running_image: |
| 668 | image_name = running_image[0]['Image'] |
| 669 | try: |
| 670 | image = image_name.split(':')[0] |
| 671 | tag = image_name.split(':')[1] |
| 672 | except: pass |
| 673 | |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 674 | if quagga_config is None: |
| 675 | quagga_config = Onos.QUAGGA_CONFIG |
| 676 | super(Onos, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = quagga_config) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 677 | self.boot_delay = boot_delay |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 678 | self.data_map = None |
A R Karthick | c69d73e | 2017-01-20 11:44:34 -0800 | [diff] [blame] | 679 | instance_memory = (get_mem(jvm_heap_size = Onos.JVM_HEAP_SIZE, instances = Onos.MAX_INSTANCES),) * 2 |
| 680 | self.env['JAVA_OPTS'] = self.JAVA_OPTS_FORMAT.format(*instance_memory) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 681 | if cluster is True: |
| 682 | self.ports = [] |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 683 | if data_volume is not None: |
| 684 | self.data_map = self.get_data_map(data_volume, self.guest_data_dir) |
| 685 | self.host_guest_map = self.host_guest_map + self.data_map |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 686 | if os.access(self.cluster_cfg, os.F_OK): |
| 687 | try: |
| 688 | os.unlink(self.cluster_cfg) |
| 689 | except: pass |
| 690 | |
| 691 | self.host_config = self.create_host_config(port_list = self.ports, |
| 692 | host_guest_map = self.host_guest_map) |
| 693 | self.volumes = [] |
| 694 | for _,g in self.host_guest_map: |
| 695 | self.volumes.append(g) |
| 696 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 697 | if restart is True and self.exists(): |
| 698 | self.kill() |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 699 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 700 | if not self.exists(): |
| 701 | self.remove_container(name, force=True) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 702 | host_config = self.create_host_config(port_list = self.ports, |
| 703 | host_guest_map = self.host_guest_map) |
| 704 | volumes = [] |
| 705 | for _,g in self.host_guest_map: |
| 706 | volumes.append(g) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 707 | if network_cfg is not None: |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 708 | json_data = json.dumps(network_cfg, indent=4) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 709 | with open('{}/network-cfg.json'.format(self.host_config_dir), 'w') as f: |
| 710 | f.write(json_data) |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 711 | if cluster is False or async is False: |
| 712 | print('Starting ONOS container %s' %self.name) |
| 713 | self.start(ports = self.ports, environment = self.env, |
| 714 | host_config = self.host_config, volumes = self.volumes, tty = True) |
| 715 | if not restart: |
| 716 | ##wait a bit before fetching IP to regenerate cluster cfg |
| 717 | time.sleep(5) |
| 718 | ip = self.ip() |
| 719 | ##Just a quick hack/check to ensure we don't regenerate in the common case. |
| 720 | ##As ONOS is usually the first test container that is started |
| 721 | if cluster is False: |
| 722 | if ip != self.CLUSTER_CFG_IP or not os.access(self.cluster_cfg, os.F_OK): |
| 723 | print('Regenerating ONOS cluster cfg for ip %s' %ip) |
| 724 | self.generate_cluster_cfg(ip) |
| 725 | self.kill() |
| 726 | self.remove_container(self.name, force=True) |
| 727 | print('Restarting ONOS container %s' %self.name) |
| 728 | self.start(ports = self.ports, environment = self.env, |
| 729 | host_config = self.host_config, volumes = self.volumes, tty = True) |
| 730 | print('Waiting for ONOS to boot') |
| 731 | time.sleep(boot_delay) |
| 732 | self.wait_for_onos_start(self.ip()) |
| 733 | self.running = True |
| 734 | else: |
| 735 | self.running = False |
| 736 | else: |
| 737 | self.running = True |
| 738 | if self.running: |
| 739 | self.ipaddr = self.ip() |
| 740 | if cluster is False: |
| 741 | self.install_cord_apps(self.ipaddr) |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 742 | |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 743 | @classmethod |
| 744 | def get_quagga_config(cls, instance = 0): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 745 | quagga_config = copy.deepcopy(cls.QUAGGA_CONFIG) |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 746 | if instance == 0: |
| 747 | return quagga_config |
| 748 | ip = quagga_config[0]['ip'] |
| 749 | octets = ip.split('.') |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 750 | octets[3] = str((int(octets[3]) + instance) & 255) |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 751 | ip = '.'.join(octets) |
| 752 | quagga_config[0]['ip'] = ip |
| 753 | return quagga_config |
| 754 | |
| 755 | @classmethod |
| 756 | def start_cluster_async(cls, onos_instances): |
| 757 | instances = filter(lambda o: o.running == False, onos_instances) |
| 758 | if not instances: |
| 759 | return |
| 760 | tpool = ThreadPool(len(instances), queue_size = 1, wait_timeout = 1) |
| 761 | for onos in instances: |
| 762 | tpool.addTask(onos.start_async) |
| 763 | tpool.cleanUpThreads() |
| 764 | |
| 765 | def start_async(self): |
| 766 | print('Starting ONOS container %s' %self.name) |
| 767 | self.start(ports = self.ports, environment = self.env, |
| 768 | host_config = self.host_config, volumes = self.volumes, tty = True) |
| 769 | time.sleep(3) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 770 | self.ipaddr = self.ip() |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 771 | print('Waiting for ONOS container %s to start' %self.name) |
| 772 | self.wait_for_onos_start(self.ipaddr) |
| 773 | self.running = True |
| 774 | print('ONOS container %s started' %self.name) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 775 | |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 776 | @classmethod |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 777 | def wait_for_onos_start(cls, ip, tries = 30): |
A R Karthick | 973010f | 2017-02-06 16:41:51 -0800 | [diff] [blame] | 778 | onos_log = OnosLog(host = ip, log_file = Onos.guest_log_file) |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 779 | num_tries = 0 |
| 780 | started = None |
| 781 | while not started and num_tries < tries: |
| 782 | time.sleep(3) |
| 783 | started = onos_log.search_log_pattern('ApplicationManager .* Started') |
| 784 | num_tries += 1 |
| 785 | |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 786 | if not started: |
| 787 | print('ONOS did not start') |
| 788 | else: |
| 789 | print('ONOS started') |
| 790 | return started |
| 791 | |
| 792 | @classmethod |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 793 | def setup_cluster_deprecated(cls, onos_instances, image_name = None): |
| 794 | if not onos_instances or len(onos_instances) < 2: |
| 795 | return |
| 796 | ips = [] |
| 797 | if image_name is not None: |
| 798 | ips = Container.ips(image_name) |
| 799 | else: |
| 800 | for onos in onos_instances: |
| 801 | ips.append(onos.ipaddr) |
| 802 | Onos.cluster_instances = onos_instances |
| 803 | Onos.cluster_mode = True |
| 804 | ##regenerate the cluster json with the 3 instance ips before restarting them back |
| 805 | print('Generating cluster cfg for ONOS instances with ips %s' %ips) |
| 806 | Onos.generate_cluster_cfg(ips) |
| 807 | for onos in onos_instances: |
| 808 | onos.kill() |
| 809 | onos.remove_container(onos.name, force=True) |
| 810 | print('Restarting ONOS container %s for forming cluster' %onos.name) |
| 811 | onos.start(ports = onos.ports, environment = onos.env, |
| 812 | host_config = onos.host_config, volumes = onos.volumes, tty = True) |
| 813 | print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name)) |
| 814 | time.sleep(onos.boot_delay) |
| 815 | onos.ipaddr = onos.ip() |
| 816 | onos.install_cord_apps(onos.ipaddr) |
| 817 | |
| 818 | @classmethod |
| 819 | def setup_cluster(cls, onos_instances, image_name = None): |
| 820 | if not onos_instances or len(onos_instances) < 2: |
| 821 | return |
| 822 | ips = [] |
| 823 | if image_name is not None: |
| 824 | ips = Container.ips(image_name) |
| 825 | else: |
| 826 | for onos in onos_instances: |
| 827 | ips.append(onos.ipaddr) |
| 828 | Onos.cluster_instances = onos_instances |
| 829 | Onos.cluster_mode = True |
| 830 | ##regenerate the cluster json with the 3 instance ips before restarting them back |
| 831 | print('Forming cluster for ONOS instances with ips %s' %ips) |
| 832 | Onos.form_cluster(ips) |
| 833 | ##wait for the cluster to be formed |
| 834 | print('Waiting for the cluster to be formed') |
| 835 | time.sleep(60) |
| 836 | for onos in onos_instances: |
| 837 | onos.install_cord_apps(onos.ipaddr) |
| 838 | |
| 839 | @classmethod |
A R Karthick | e2c24bd | 2016-10-07 14:51:38 -0700 | [diff] [blame] | 840 | def add_cluster(cls, count = 1, network_cfg = None): |
| 841 | if not cls.cluster_instances or Onos.cluster_mode is False: |
| 842 | return |
| 843 | for i in range(count): |
| 844 | name = '{}-{}'.format(Onos.NAME, len(cls.cluster_instances)+1) |
| 845 | onos = cls(name = name, image = Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX, |
| 846 | cluster = True, network_cfg = network_cfg) |
| 847 | cls.cluster_instances.append(onos) |
| 848 | |
| 849 | cls.setup_cluster(cls.cluster_instances) |
| 850 | |
| 851 | @classmethod |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 852 | def restart_cluster(cls, network_cfg = None, timeout = 10, setup = False): |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 853 | if cls.cluster_mode is False: |
| 854 | return |
| 855 | if not cls.cluster_instances: |
| 856 | return |
| 857 | |
| 858 | if network_cfg is not None: |
| 859 | json_data = json.dumps(network_cfg, indent=4) |
| 860 | with open('{}/network-cfg.json'.format(cls.host_config_dir), 'w') as f: |
| 861 | f.write(json_data) |
| 862 | |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 863 | cls.cleanup_cluster() |
| 864 | if timeout > 0: |
| 865 | time.sleep(timeout) |
| 866 | |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 867 | #start the instances asynchronously |
| 868 | cls.start_cluster_async(cls.cluster_instances) |
| 869 | time.sleep(5) |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 870 | ##form the cluster as appropriate |
| 871 | if setup is True: |
| 872 | cls.setup_cluster(cls.cluster_instances) |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 873 | else: |
| 874 | for onos in cls.cluster_instances: |
| 875 | onos.install_cord_apps(onos.ipaddr) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 876 | |
| 877 | @classmethod |
| 878 | def cluster_ips(cls): |
| 879 | if cls.cluster_mode is False: |
| 880 | return [] |
| 881 | if not cls.cluster_instances: |
| 882 | return [] |
| 883 | ips = [ onos.ipaddr for onos in cls.cluster_instances ] |
| 884 | return ips |
| 885 | |
| 886 | @classmethod |
| 887 | def cleanup_cluster(cls): |
| 888 | if cls.cluster_mode is False: |
| 889 | return |
| 890 | if not cls.cluster_instances: |
| 891 | return |
| 892 | for onos in cls.cluster_instances: |
| 893 | if onos.exists(): |
| 894 | onos.kill() |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 895 | onos.running = False |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 896 | onos.remove_container(onos.name, force=True) |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 897 | |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 898 | @classmethod |
A R Karthick | de6b9dc | 2016-11-29 17:46:16 -0800 | [diff] [blame] | 899 | def restart_node(cls, node = None, network_cfg = None, timeout = 10): |
A R Karthick | 889d965 | 2016-10-03 14:13:45 -0700 | [diff] [blame] | 900 | if node is None: |
| 901 | cls(restart = True, network_cfg = network_cfg, image = cls.IMAGE, tag = cls.TAG) |
| 902 | else: |
| 903 | #Restarts a node in the cluster |
| 904 | valid_node = filter(lambda onos: node in [ onos.ipaddr, onos.name ], cls.cluster_instances) |
| 905 | if valid_node: |
| 906 | onos = valid_node.pop() |
| 907 | if onos.exists(): |
| 908 | onos.kill() |
| 909 | onos.remove_container(onos.name, force=True) |
A R Karthick | de6b9dc | 2016-11-29 17:46:16 -0800 | [diff] [blame] | 910 | if timeout > 0: |
| 911 | time.sleep(timeout) |
A R Karthick | 889d965 | 2016-10-03 14:13:45 -0700 | [diff] [blame] | 912 | print('Restarting ONOS container %s' %onos.name) |
| 913 | onos.start(ports = onos.ports, environment = onos.env, |
| 914 | host_config = onos.host_config, volumes = onos.volumes, tty = True) |
A R Karthick | 889d965 | 2016-10-03 14:13:45 -0700 | [diff] [blame] | 915 | onos.ipaddr = onos.ip() |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 916 | onos.wait_for_onos_start(onos.ipaddr) |
| 917 | onos.install_cord_apps(onos.ipaddr) |
A R Karthick | 889d965 | 2016-10-03 14:13:45 -0700 | [diff] [blame] | 918 | |
| 919 | @classmethod |
A R Karthick | b608d40 | 2017-06-02 11:48:41 -0700 | [diff] [blame] | 920 | def cliEnter(cls, onos_ip = None): |
| 921 | retries = 0 |
| 922 | while retries < 10: |
| 923 | cli = OnosCliDriver(controller = onos_ip, connect = True) |
| 924 | if cli.handle: |
| 925 | return cli |
| 926 | else: |
| 927 | retries += 1 |
| 928 | time.sleep(3) |
| 929 | |
| 930 | return None |
| 931 | |
| 932 | @classmethod |
| 933 | def cliExit(cls, cli): |
| 934 | if cli: |
| 935 | cli.disconnect() |
| 936 | |
| 937 | @classmethod |
| 938 | def getVersion(cls, onos_ip = None): |
| 939 | cli = cls.cliEnter(onos_ip = onos_ip) |
| 940 | try: |
| 941 | summary = json.loads(cli.summary(jsonFormat = True)) |
| 942 | except: |
| 943 | cls.cliExit(cli) |
| 944 | return '1.8.0' |
| 945 | cls.cliExit(cli) |
| 946 | return summary['version'] |
| 947 | |
| 948 | @classmethod |
| 949 | def update_cord_apps_version(cls, onos_ip = None): |
| 950 | if cls.cord_apps_version_updated == True: |
| 951 | return |
| 952 | version = cls.getVersion(onos_ip = onos_ip) |
| 953 | major = int(version.split('.')[0]) |
| 954 | minor = int(version.split('.')[1]) |
| 955 | app_version = '1.2-SNAPSHOT' |
| 956 | if major > 1: |
| 957 | app_version = '2.0-SNAPSHOT' |
| 958 | elif major == 1 and minor > 10: |
| 959 | app_version = '2.0-SNAPSHOT' |
| 960 | for apps in cls.onos_cord_apps: |
| 961 | apps[1] = app_version |
| 962 | cls.cord_apps_version_updated = True |
| 963 | |
| 964 | @classmethod |
A R Karthick | eaf1c4e | 2016-07-19 12:22:35 -0700 | [diff] [blame] | 965 | def install_cord_apps(cls, onos_ip = None): |
A R Karthick | b608d40 | 2017-06-02 11:48:41 -0700 | [diff] [blame] | 966 | cls.update_cord_apps_version(onos_ip = onos_ip) |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 967 | for app, version in cls.onos_cord_apps: |
| 968 | app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version) |
A R Karthick | eaf1c4e | 2016-07-19 12:22:35 -0700 | [diff] [blame] | 969 | ok, code = OnosCtrl.install_app(app_file, onos_ip = onos_ip) |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 970 | ##app already installed (conflicts) |
| 971 | if code in [ 409 ]: |
| 972 | ok = True |
| 973 | print('ONOS app %s, version %s %s' %(app, version, 'installed' if ok else 'failed to install')) |
| 974 | time.sleep(2) |
| 975 | |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 976 | class OnosStopWrapper(Container): |
| 977 | def __init__(self, name): |
| 978 | super(OnosStopWrapper, self).__init__(name, Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX) |
| 979 | if self.exists(): |
| 980 | self.kill() |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 981 | self.running = False |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 982 | else: |
| 983 | if Onos.cluster_mode is True: |
| 984 | valid_node = filter(lambda onos: name in [ onos.ipaddr, onos.name ], Onos.cluster_instances) |
| 985 | if valid_node: |
| 986 | onos = valid_node.pop() |
| 987 | if onos.exists(): |
| 988 | onos.kill() |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 989 | onos.running = False |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 990 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 991 | class Radius(Container): |
| 992 | ports = [ 1812, 1813 ] |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 993 | env = {'TIMEZONE':'America/Los_Angeles', |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 994 | 'DEBUG': 'true', 'cert_password':'whatever', 'primary_shared_secret':'radius_password' |
| 995 | } |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 996 | host_db_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/db') |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 997 | guest_db_dir = os.path.join(os.path.sep, 'opt', 'db') |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 998 | host_config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/radius-config/freeradius') |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 999 | guest_config_dir = os.path.join(os.path.sep, 'etc', 'freeradius') |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 1000 | start_command = os.path.join(guest_config_dir, 'start-radius.py') |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 1001 | host_guest_map = ( (host_db_dir, guest_db_dir), |
| 1002 | (host_config_dir, guest_config_dir) |
| 1003 | ) |
A R Karthick | f7a613b | 2017-02-24 09:36:44 -0800 | [diff] [blame] | 1004 | IMAGE = 'cordtest/radius' |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 1005 | NAME = 'cord-radius' |
| 1006 | |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 1007 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate', |
A R Karthick | 85eb186 | 2017-01-23 16:10:57 -0800 | [diff] [blame] | 1008 | boot_delay = 10, restart = False, update = False, network = None): |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 1009 | super(Radius, self).__init__(name, image, prefix = prefix, tag = tag, command = self.start_command) |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 1010 | if update is True or not self.img_exists(): |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 1011 | self.build_image(self.image_name) |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 1012 | if restart is True and self.exists(): |
| 1013 | self.kill() |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 1014 | if not self.exists(): |
| 1015 | self.remove_container(name, force=True) |
| 1016 | host_config = self.create_host_config(port_list = self.ports, |
| 1017 | host_guest_map = self.host_guest_map) |
| 1018 | volumes = [] |
| 1019 | for _,g in self.host_guest_map: |
| 1020 | volumes.append(g) |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 1021 | self.start(ports = self.ports, environment = self.env, |
| 1022 | volumes = volumes, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 1023 | host_config = host_config, tty = True) |
A R Karthick | 85eb186 | 2017-01-23 16:10:57 -0800 | [diff] [blame] | 1024 | if network is not None: |
| 1025 | Container.connect_to_network(self.name, network) |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 1026 | time.sleep(boot_delay) |
| 1027 | |
| 1028 | @classmethod |
| 1029 | def build_image(cls, image): |
| 1030 | print('Building Radius image %s' %image) |
| 1031 | dockerfile = ''' |
| 1032 | FROM hbouvier/docker-radius |
| 1033 | MAINTAINER chetan@ciena.com |
| 1034 | LABEL RUN docker pull hbouvier/docker-radius |
| 1035 | LABEL RUN docker run -it --name cord-radius hbouvier/docker-radius |
A R Karthick | c762df4 | 2016-05-25 10:09:21 -0700 | [diff] [blame] | 1036 | RUN apt-get update && \ |
| 1037 | apt-get -y install python python-pexpect strace |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 1038 | WORKDIR /root |
| 1039 | CMD ["/etc/freeradius/start-radius.py"] |
| 1040 | ''' |
| 1041 | super(Radius, cls).build_image(dockerfile, image) |
| 1042 | print('Done building image %s' %image) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 1043 | |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1044 | class Quagga(Container): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 1045 | QUAGGA_CONFIG = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 }, |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 1046 | { 'bridge' : 'quagga-br', 'ip': '192.168.10.3', 'mask': 16 }, |
| 1047 | ) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1048 | ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ] |
| 1049 | host_quagga_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/quagga-config') |
| 1050 | guest_quagga_config = '/root/config' |
| 1051 | quagga_config_file = os.path.join(guest_quagga_config, 'testrib.conf') |
| 1052 | host_guest_map = ( (host_quagga_config, guest_quagga_config), ) |
A R Karthick | f7a613b | 2017-02-24 09:36:44 -0800 | [diff] [blame] | 1053 | IMAGE = 'cordtest/quagga' |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 1054 | NAME = 'cord-quagga' |
| 1055 | |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 1056 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate', |
A R Karthick | 85eb186 | 2017-01-23 16:10:57 -0800 | [diff] [blame] | 1057 | boot_delay = 15, restart = False, config_file = quagga_config_file, update = False, |
| 1058 | network = None): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 1059 | super(Quagga, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.QUAGGA_CONFIG) |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 1060 | if update is True or not self.img_exists(): |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 1061 | self.build_image(self.image_name) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1062 | if restart is True and self.exists(): |
| 1063 | self.kill() |
| 1064 | if not self.exists(): |
| 1065 | self.remove_container(name, force=True) |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 1066 | host_config = self.create_host_config(port_list = self.ports, |
| 1067 | host_guest_map = self.host_guest_map, |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1068 | privileged = True) |
| 1069 | volumes = [] |
| 1070 | for _,g in self.host_guest_map: |
| 1071 | volumes.append(g) |
| 1072 | self.start(ports = self.ports, |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 1073 | host_config = host_config, |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1074 | volumes = volumes, tty = True) |
A R Karthick | 85eb186 | 2017-01-23 16:10:57 -0800 | [diff] [blame] | 1075 | if network is not None: |
| 1076 | Container.connect_to_network(self.name, network) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1077 | print('Starting Quagga on container %s' %self.name) |
| 1078 | self.execute('{0}/start.sh {1}'.format(self.guest_quagga_config, config_file)) |
| 1079 | time.sleep(boot_delay) |
| 1080 | |
| 1081 | @classmethod |
| 1082 | def build_image(cls, image): |
A R Karthick | aa54a1c | 2016-12-15 11:42:08 -0800 | [diff] [blame] | 1083 | onos_quagga_ip = Onos.QUAGGA_CONFIG[0]['ip'] |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1084 | print('Building Quagga image %s' %image) |
| 1085 | dockerfile = ''' |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 1086 | FROM ubuntu:14.04 |
| 1087 | MAINTAINER chetan@ciena.com |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1088 | WORKDIR /root |
| 1089 | RUN useradd -M quagga |
| 1090 | RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga |
| 1091 | RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga |
A R Karthick | 973ea69 | 2016-10-17 12:23:02 -0700 | [diff] [blame] | 1092 | RUN apt-get update && apt-get install -qy git autoconf libtool gawk make telnet libreadline6-dev pkg-config protobuf-c-compiler |
ChetanGaonker | b5b46c6 | 2016-08-16 12:02:53 -0700 | [diff] [blame] | 1093 | RUN git clone git://git.savannah.nongnu.org/quagga.git quagga && \ |
A R Karthick | 8f69c2c | 2016-10-21 11:43:26 -0700 | [diff] [blame] | 1094 | (cd quagga && git checkout quagga-1.0.20160315 && ./bootstrap.sh && \ |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 1095 | sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \ |
| 1096 | ./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install) |
| 1097 | RUN ldconfig |
| 1098 | '''.format(onos_quagga_ip) |
| 1099 | super(Quagga, cls).build_image(dockerfile, image) |
| 1100 | print('Done building image %s' %image) |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 1101 | |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 1102 | class QuaggaStopWrapper(Container): |
| 1103 | def __init__(self, name = Quagga.NAME, image = Quagga.IMAGE, tag = 'candidate'): |
| 1104 | super(QuaggaStopWrapper, self).__init__(name, image, prefix = Container.IMAGE_PREFIX, tag = tag) |
| 1105 | if self.exists(): |
| 1106 | self.kill() |
| 1107 | |
| 1108 | |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 1109 | def reinitContainerClients(): |
| 1110 | docker_netns.dckr = Client() |
| 1111 | Container.dckr = Client() |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1112 | |
| 1113 | class Xos(Container): |
| 1114 | setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup') |
| 1115 | TAG = 'latest' |
| 1116 | PREFIX = '' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1117 | host_guest_map = None |
| 1118 | env = None |
| 1119 | ports = None |
| 1120 | volumes = None |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1121 | |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1122 | @classmethod |
| 1123 | def get_cmd(cls, img_name): |
| 1124 | cmd = cls.dckr.inspect_image(img_name)['Config']['Cmd'] |
| 1125 | return ' '.join(cmd) |
| 1126 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1127 | def __init__(self, name, image, prefix = PREFIX, tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1128 | boot_delay = 20, restart = False, network_cfg = None, update = False): |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1129 | if restart is True: |
| 1130 | ##Find the right image to restart |
| 1131 | running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers()) |
| 1132 | if running_image: |
| 1133 | image_name = running_image[0]['Image'] |
| 1134 | try: |
| 1135 | image = image_name.split(':')[0] |
| 1136 | tag = image_name.split(':')[1] |
| 1137 | except: pass |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1138 | super(Xos, self).__init__(name, image, prefix = prefix, tag = tag) |
| 1139 | if update is True or not self.img_exists(): |
| 1140 | self.build_image(self.image_name) |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1141 | self.command = self.get_cmd(self.image_name).strip() or None |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1142 | if restart is True and self.exists(): |
| 1143 | self.kill() |
| 1144 | if not self.exists(): |
| 1145 | self.remove_container(name, force=True) |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1146 | host_config = self.create_host_config(port_list = self.ports, |
| 1147 | host_guest_map = self.host_guest_map, |
| 1148 | privileged = True) |
| 1149 | print('Starting XOS container %s' %self.name) |
| 1150 | self.start(ports = self.ports, environment = self.env, host_config = host_config, |
| 1151 | volumes = self.volumes, tty = True) |
| 1152 | print('Waiting %d seconds for XOS Base Container to boot' %(boot_delay)) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1153 | time.sleep(boot_delay) |
| 1154 | |
| 1155 | @classmethod |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1156 | def build_image(cls, image, dockerfile_path, image_target = 'build'): |
| 1157 | cmd = 'cd {} && make {}'.format(dockerfile_path, image_target) |
| 1158 | print('Building XOS %s' %image) |
| 1159 | res = os.system(cmd) |
| 1160 | print('Done building image %s. Image build %s' %(image, 'successful' if res == 0 else 'failed')) |
| 1161 | return res |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1162 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1163 | class XosServer(Xos): |
| 1164 | ports = [8000,9998,9999] |
| 1165 | NAME = 'xos-server' |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1166 | IMAGE = 'xosproject/xos' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1167 | BASE_IMAGE = 'xosproject/xos-base' |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1168 | TAG = 'latest' |
| 1169 | PREFIX = '' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1170 | dockerfile_path = os.path.join(Xos.setup_dir, 'xos') |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1171 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1172 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1173 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1174 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1175 | |
| 1176 | @classmethod |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1177 | def build_image(cls, image = IMAGE): |
| 1178 | ##build the base image and then build the server image |
| 1179 | Xos.build_image(cls.BASE_IMAGE, cls.dockerfile_path, image_target = 'base') |
| 1180 | Xos.build_image(image, cls.dockerfile_path) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1181 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1182 | class XosSynchronizerOpenstack(Xos): |
| 1183 | ports = [2375,] |
| 1184 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer') |
| 1185 | NAME = 'xos-synchronizer' |
| 1186 | IMAGE = 'xosproject/xos-synchronizer-openstack' |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1187 | TAG = 'latest' |
| 1188 | PREFIX = '' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1189 | host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1190 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1191 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1192 | tag = TAG, boot_delay = 20, restart = False, network_cfg = None, update = False): |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1193 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1194 | |
| 1195 | @classmethod |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1196 | def build_image(cls, image = IMAGE): |
| 1197 | XosServer.build_image() |
| 1198 | Xos.build_image(image, cls.dockerfile_path) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1199 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1200 | class XosSynchronizerOnboarding(Xos): |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1201 | NAME = 'xos-synchronizer-onboarding' |
| 1202 | IMAGE = 'xosproject/xos-synchronizer-onboarding' |
| 1203 | TAG = 'latest' |
| 1204 | PREFIX = '' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1205 | dockerfile_path = os.path.join(Xos.setup_dir, 'onboarding_synchronizer') |
| 1206 | host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1207 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1208 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1209 | tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False): |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1210 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1211 | |
| 1212 | @classmethod |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1213 | def build_image(cls, image = IMAGE): |
| 1214 | XosSynchronizerOpenstack.build_image() |
| 1215 | Xos.build_image(image, cls.dockerfile_path) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1216 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1217 | class XosSynchronizerOpenvpn(Xos): |
| 1218 | NAME = 'xos-synchronizer-openvpn' |
| 1219 | IMAGE = 'xosproject/xos-openvpn' |
| 1220 | TAG = 'latest' |
| 1221 | PREFIX = '' |
| 1222 | dockerfile_path = os.path.join(Xos.setup_dir, 'openvpn') |
| 1223 | host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1224 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1225 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1226 | tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False): |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1227 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1228 | |
| 1229 | @classmethod |
| 1230 | def build_image(cls, image = IMAGE): |
| 1231 | XosSynchronizerOpenstack.build_image() |
| 1232 | Xos.build_image(image, cls.dockerfile_path) |
| 1233 | |
| 1234 | class XosPostgresql(Xos): |
| 1235 | ports = [5432,] |
| 1236 | NAME = 'xos-db-postgres' |
| 1237 | IMAGE = 'xosproject/xos-postgres' |
| 1238 | TAG = 'latest' |
| 1239 | PREFIX = '' |
| 1240 | volumes = ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"] |
| 1241 | dockerfile_path = os.path.join(Xos.setup_dir, 'postgresql') |
| 1242 | |
| 1243 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1244 | tag = TAG, boot_delay = 10, restart = False, network_cfg = None, update = False): |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1245 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1246 | |
| 1247 | @classmethod |
| 1248 | def build_image(cls, image = IMAGE): |
| 1249 | Xos.build_image(image, cls.dockerfile_path) |
| 1250 | |
| 1251 | class XosSyndicateMs(Xos): |
| 1252 | ports = [8080,] |
| 1253 | env = None |
| 1254 | NAME = 'xos-syndicate-ms' |
| 1255 | IMAGE = 'xosproject/syndicate-ms' |
| 1256 | TAG = 'latest' |
| 1257 | PREFIX = '' |
| 1258 | dockerfile_path = os.path.join(Xos.setup_dir, 'syndicate-ms') |
| 1259 | |
| 1260 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1261 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 1262 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1263 | |
| 1264 | @classmethod |
| 1265 | def build_image(cls, image = IMAGE): |
| 1266 | Xos.build_image(image, cls.dockerfile_path) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 1267 | |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1268 | class XosSyncVtn(Xos): |
| 1269 | ports = [8080,] |
| 1270 | env = None |
| 1271 | NAME = 'xos-synchronizer-vtn' |
| 1272 | IMAGE = 'xosproject/xos-synchronizer-vtn' |
| 1273 | TAG = 'latest' |
| 1274 | PREFIX = '' |
| 1275 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtn') |
| 1276 | |
| 1277 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1278 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1279 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1280 | |
| 1281 | @classmethod |
| 1282 | def build_image(cls, image = IMAGE): |
| 1283 | Xos.build_image(image, cls.dockerfile_path) |
| 1284 | |
| 1285 | class XosSyncVtr(Xos): |
| 1286 | ports = [8080,] |
| 1287 | env = None |
| 1288 | NAME = 'xos-synchronizer-vtr' |
| 1289 | IMAGE = 'xosproject/xos-synchronizer-vtr' |
| 1290 | TAG = 'latest' |
| 1291 | PREFIX = '' |
| 1292 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtr') |
| 1293 | |
| 1294 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1295 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1296 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1297 | |
| 1298 | @classmethod |
| 1299 | def build_image(cls, image = IMAGE): |
| 1300 | Xos.build_image(image, cls.dockerfile_path) |
| 1301 | |
| 1302 | class XosSyncVsg(Xos): |
| 1303 | ports = [8080,] |
| 1304 | env = None |
| 1305 | NAME = 'xos-synchronizer-vsg' |
| 1306 | IMAGE = 'xosproject/xos-synchronizer-vsg' |
| 1307 | TAG = 'latest' |
| 1308 | PREFIX = '' |
| 1309 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vsg') |
| 1310 | |
| 1311 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1312 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1313 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1314 | |
| 1315 | @classmethod |
| 1316 | def build_image(cls, image = IMAGE): |
| 1317 | Xos.build_image(image, cls.dockerfile_path) |
| 1318 | |
| 1319 | |
| 1320 | class XosSyncOnos(Xos): |
| 1321 | ports = [8080,] |
| 1322 | env = None |
| 1323 | NAME = 'xos-synchronizer-onos' |
| 1324 | IMAGE = 'xosproject/xos-synchronizer-onos' |
| 1325 | TAG = 'latest' |
| 1326 | PREFIX = '' |
| 1327 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-onos') |
| 1328 | |
| 1329 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1330 | boot_delay = 30, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1331 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1332 | |
| 1333 | @classmethod |
| 1334 | def build_image(cls, image = IMAGE): |
| 1335 | Xos.build_image(image, cls.dockerfile_path) |
| 1336 | |
| 1337 | class XosSyncFabric(Xos): |
| 1338 | ports = [8080,] |
| 1339 | env = None |
| 1340 | NAME = 'xos-synchronizer-fabric' |
| 1341 | IMAGE = 'xosproject/xos-synchronizer-fabric' |
| 1342 | TAG = 'latest' |
| 1343 | PREFIX = '' |
| 1344 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-fabric') |
| 1345 | |
| 1346 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1347 | boot_delay = 30, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1348 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1349 | |
| 1350 | @classmethod |
| 1351 | def build_image(cls, image = IMAGE): |
| 1352 | Xos.build_image(image, cls.dockerfile_path) |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 1353 | |
| 1354 | if __name__ == '__main__': |
| 1355 | onos = Onos(boot_delay = 10, restart = True) |