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 |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 21 | from pyroute2 import IPRoute |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 22 | from pyroute2.netlink import NetlinkError |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 23 | from itertools import chain |
| 24 | from nsenter import Namespace |
| 25 | from docker import Client |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 26 | from shutil import rmtree |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 27 | from OnosCtrl import OnosCtrl |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 28 | from OnosLog import OnosLog |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 29 | from threadPool import ThreadPool |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 30 | |
| 31 | class docker_netns(object): |
| 32 | |
| 33 | dckr = Client() |
| 34 | def __init__(self, name): |
| 35 | pid = int(self.dckr.inspect_container(name)['State']['Pid']) |
| 36 | if pid == 0: |
| 37 | raise Exception('no container named {0}'.format(name)) |
| 38 | self.pid = pid |
| 39 | |
| 40 | def __enter__(self): |
| 41 | pid = self.pid |
| 42 | if not os.path.exists('/var/run/netns'): |
| 43 | os.mkdir('/var/run/netns') |
| 44 | os.symlink('/proc/{0}/ns/net'.format(pid), '/var/run/netns/{0}'.format(pid)) |
| 45 | return str(pid) |
| 46 | |
| 47 | def __exit__(self, type, value, traceback): |
| 48 | pid = self.pid |
| 49 | os.unlink('/var/run/netns/{0}'.format(pid)) |
| 50 | |
| 51 | flatten = lambda l: chain.from_iterable(l) |
| 52 | |
| 53 | class Container(object): |
| 54 | dckr = Client() |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 55 | IMAGE_PREFIX = '' ##for saving global prefix for all test classes |
| 56 | |
| 57 | 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] | 58 | self.name = name |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 59 | self.prefix = prefix |
| 60 | if prefix: |
| 61 | self.prefix += '/' |
| 62 | image = '{}{}'.format(self.prefix, image) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 63 | self.image = image |
| 64 | self.tag = tag |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 65 | if tag: |
| 66 | self.image_name = image + ':' + tag |
| 67 | else: |
| 68 | self.image_name = image |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 69 | self.id = None |
| 70 | self.command = command |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 71 | self.quagga_config = quagga_config |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 72 | |
| 73 | @classmethod |
| 74 | def build_image(cls, dockerfile, tag, force=True, nocache=False): |
| 75 | f = io.BytesIO(dockerfile.encode('utf-8')) |
| 76 | if force or not cls.image_exists(tag): |
| 77 | print('Build {0}...'.format(tag)) |
| 78 | for line in cls.dckr.build(fileobj=f, rm=True, tag=tag, decode=True, nocache=nocache): |
| 79 | if 'stream' in line: |
| 80 | print(line['stream'].strip()) |
| 81 | |
| 82 | @classmethod |
| 83 | def image_exists(cls, name): |
| 84 | return name in [ctn['RepoTags'][0] for ctn in cls.dckr.images()] |
| 85 | |
| 86 | @classmethod |
| 87 | def create_host_config(cls, port_list = None, host_guest_map = None, privileged = False): |
| 88 | port_bindings = None |
| 89 | binds = None |
| 90 | if port_list: |
| 91 | port_bindings = {} |
| 92 | for p in port_list: |
| 93 | port_bindings[str(p)] = str(p) |
| 94 | |
| 95 | if host_guest_map: |
| 96 | binds = [] |
| 97 | for h, g in host_guest_map: |
| 98 | binds.append('{0}:{1}'.format(h, g)) |
| 99 | |
| 100 | return cls.dckr.create_host_config(binds = binds, port_bindings = port_bindings, privileged = privileged) |
| 101 | |
| 102 | @classmethod |
| 103 | def cleanup(cls, image): |
A R Karthick | 09b1f4e | 2016-05-12 14:31:50 -0700 | [diff] [blame] | 104 | 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] | 105 | for cnt in cnt_list: |
| 106 | print('Cleaning container %s' %cnt['Id']) |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 107 | if cnt.has_key('State') and cnt['State'] == 'running': |
A R Karthick | 09b1f4e | 2016-05-12 14:31:50 -0700 | [diff] [blame] | 108 | cls.dckr.kill(cnt['Id']) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 109 | cls.dckr.remove_container(cnt['Id'], force=True) |
| 110 | |
| 111 | @classmethod |
| 112 | def remove_container(cls, name, force=True): |
| 113 | try: |
| 114 | cls.dckr.remove_container(name, force = force) |
| 115 | except: pass |
| 116 | |
| 117 | def exists(self): |
| 118 | return '/{0}'.format(self.name) in list(flatten(n['Names'] for n in self.dckr.containers())) |
| 119 | |
| 120 | def img_exists(self): |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 121 | return self.image_name in [ctn['RepoTags'][0] if ctn['RepoTags'] else '' for ctn in self.dckr.images()] |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 122 | |
| 123 | def ip(self): |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 124 | cnt_list = filter(lambda c: c['Names'][0] == '/{}'.format(self.name), self.dckr.containers()) |
| 125 | #if not cnt_list: |
| 126 | # 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] | 127 | cnt_settings = cnt_list.pop() |
| 128 | return cnt_settings['NetworkSettings']['Networks']['bridge']['IPAddress'] |
| 129 | |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 130 | @classmethod |
| 131 | def ips(cls, image_name): |
| 132 | cnt_list = filter(lambda c: c['Image'] == image_name, cls.dckr.containers()) |
| 133 | ips = [ cnt['NetworkSettings']['Networks']['bridge']['IPAddress'] for cnt in cnt_list ] |
| 134 | return ips |
| 135 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 136 | def kill(self, remove = True): |
| 137 | self.dckr.kill(self.name) |
| 138 | self.dckr.remove_container(self.name, force=True) |
| 139 | |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 140 | def start(self, rm = True, ports = None, volumes = None, host_config = None, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 141 | environment = None, tty = False, stdin_open = True): |
| 142 | |
| 143 | if rm and self.exists(): |
| 144 | print('Removing container:', self.name) |
| 145 | self.dckr.remove_container(self.name, force=True) |
| 146 | |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 147 | 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] | 148 | detach=True, name=self.name, |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 149 | environment = environment, |
| 150 | volumes = volumes, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 151 | host_config = host_config, stdin_open=stdin_open, tty = tty) |
| 152 | self.dckr.start(container=self.name) |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 153 | if self.quagga_config: |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 154 | self.connect_to_br() |
| 155 | self.id = ctn['Id'] |
| 156 | return ctn |
| 157 | |
Thangavelu K S | ef6f0a5 | 2016-12-14 19:57:05 +0000 | [diff] [blame] | 158 | @classmethod |
| 159 | def pause_container(cls, image, delay): |
| 160 | cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True)) |
| 161 | for cnt in cnt_list: |
| 162 | print('Pause the container %s' %cnt['Id']) |
| 163 | if cnt.has_key('State') and cnt['State'] == 'running': |
| 164 | cls.dckr.pause(cnt['Id']) |
| 165 | if delay != 0: |
| 166 | time.sleep(delay) |
| 167 | for cnt in cnt_list: |
| 168 | print('Unpause the container %s' %cnt['Id']) |
| 169 | cls.dckr.unpause(cnt['Id']) |
| 170 | else: |
| 171 | print('Infinity time pause the container %s' %cnt['Id']) |
| 172 | return 'success' |
| 173 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 174 | def connect_to_br(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 175 | index = 0 |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 176 | with docker_netns(self.name) as pid: |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 177 | for quagga_config in self.quagga_config: |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 178 | ip = IPRoute() |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 179 | br = ip.link_lookup(ifname=quagga_config['bridge']) |
| 180 | if len(br) == 0: |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 181 | try: |
| 182 | ip.link_create(ifname=quagga_config['bridge'], kind='bridge') |
| 183 | except NetlinkError as e: |
| 184 | err, _ = e.args |
| 185 | if err == errno.EEXIST: |
| 186 | pass |
| 187 | else: |
| 188 | raise NetlinkError(*e.args) |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 189 | br = ip.link_lookup(ifname=quagga_config['bridge']) |
| 190 | br = br[0] |
| 191 | ip.link('set', index=br, state='up') |
| 192 | ifname = '{0}-{1}'.format(self.name, index) |
| 193 | ifs = ip.link_lookup(ifname=ifname) |
| 194 | if len(ifs) > 0: |
| 195 | ip.link_remove(ifs[0]) |
| 196 | peer_ifname = '{0}-{1}'.format(pid, index) |
Chetan Gaonker | 5a0fda3 | 2016-05-10 14:09:07 -0700 | [diff] [blame] | 197 | ip.link_create(ifname=ifname, kind='veth', peer=peer_ifname) |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 198 | host = ip.link_lookup(ifname=ifname)[0] |
| 199 | ip.link('set', index=host, master=br) |
| 200 | ip.link('set', index=host, state='up') |
| 201 | guest = ip.link_lookup(ifname=peer_ifname)[0] |
| 202 | ip.link('set', index=guest, net_ns_fd=pid) |
| 203 | with Namespace(pid, 'net'): |
| 204 | ip = IPRoute() |
| 205 | ip.link('set', index=guest, ifname='eth{}'.format(index+1)) |
| 206 | ip.addr('add', index=guest, address=quagga_config['ip'], mask=quagga_config['mask']) |
| 207 | ip.link('set', index=guest, state='up') |
| 208 | index += 1 |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 209 | |
Thangavelu K S | ef6f0a5 | 2016-12-14 19:57:05 +0000 | [diff] [blame] | 210 | def execute(self, cmd, tty = True, stream = False, shell = False, detach = True): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 211 | res = 0 |
| 212 | if type(cmd) == str: |
| 213 | cmds = (cmd,) |
| 214 | else: |
| 215 | cmds = cmd |
| 216 | if shell: |
| 217 | for c in cmds: |
| 218 | res += os.system('docker exec {0} {1}'.format(self.name, c)) |
| 219 | return res |
| 220 | for c in cmds: |
| 221 | i = self.dckr.exec_create(container=self.name, cmd=c, tty = tty, privileged = True) |
Thangavelu K S | ef6f0a5 | 2016-12-14 19:57:05 +0000 | [diff] [blame] | 222 | self.dckr.exec_start(i['Id'], stream = stream, detach=detach) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 223 | result = self.dckr.exec_inspect(i['Id']) |
| 224 | res += 0 if result['ExitCode'] == None else result['ExitCode'] |
| 225 | return res |
| 226 | |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 227 | def restart(self, timeout =10): |
| 228 | return self.dckr.restart(self.name, timeout) |
| 229 | |
A R Karthick | 1f90820 | 2016-11-16 17:32:20 -0800 | [diff] [blame] | 230 | def get_mem(instances = 1): |
| 231 | if instances <= 0: |
| 232 | instances = 1 |
Chetan Gaonker | 462d9fa | 2016-05-03 16:39:10 -0700 | [diff] [blame] | 233 | with open('/proc/meminfo', 'r') as fd: |
| 234 | meminfo = fd.readlines() |
| 235 | mem = 0 |
| 236 | for m in meminfo: |
| 237 | if m.startswith('MemTotal:') or m.startswith('SwapTotal:'): |
| 238 | mem += int(m.split(':')[1].strip().split()[0]) |
| 239 | |
A R Karthick | 1f90820 | 2016-11-16 17:32:20 -0800 | [diff] [blame] | 240 | mem = max(mem/1024/1024/2/instances, 1) |
Chetan Gaonker | 6d0a7b0 | 2016-05-03 16:57:28 -0700 | [diff] [blame] | 241 | mem = min(mem, 16) |
Chetan Gaonker | 462d9fa | 2016-05-03 16:39:10 -0700 | [diff] [blame] | 242 | return str(mem) + 'G' |
| 243 | |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 244 | class OnosCord(Container): |
| 245 | """Use this when running the cord tester agent on the onos compute node""" |
| 246 | onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord') |
| 247 | onos_config_dir_guest = '/root/onos/config' |
| 248 | onos_config_dir = os.path.join(onos_cord_dir, 'config') |
| 249 | docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml') |
| 250 | |
A R Karthick | bd9b8a3 | 2016-07-21 09:56:45 -0700 | [diff] [blame] | 251 | def __init__(self, onos_ip, conf, boot_delay = 60): |
| 252 | self.onos_ip = onos_ip |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 253 | self.cord_conf_dir = conf |
A R Karthick | bd9b8a3 | 2016-07-21 09:56:45 -0700 | [diff] [blame] | 254 | self.boot_delay = boot_delay |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 255 | if os.access(self.cord_conf_dir, os.F_OK) and not os.access(self.onos_cord_dir, os.F_OK): |
| 256 | os.mkdir(self.onos_cord_dir) |
| 257 | os.mkdir(self.onos_config_dir) |
| 258 | ##copy the config file from cord-tester-config |
| 259 | cmd = 'cp {}/* {}'.format(self.cord_conf_dir, self.onos_cord_dir) |
| 260 | os.system(cmd) |
| 261 | |
| 262 | ##update the docker yaml with the config volume |
| 263 | with open(self.docker_yaml, 'r') as f: |
| 264 | yaml_config = yaml.load(f) |
| 265 | image = yaml_config['services'].keys()[0] |
| 266 | name = 'cordtestercord_{}_1'.format(image) |
| 267 | volumes = yaml_config['services'][image]['volumes'] |
| 268 | config_volumes = filter(lambda e: e.find(self.onos_config_dir_guest) >= 0, volumes) |
| 269 | if not config_volumes: |
| 270 | config_volume = '{}:{}'.format(self.onos_config_dir, self.onos_config_dir_guest) |
| 271 | volumes.append(config_volume) |
| 272 | docker_yaml_changed = '{}-changed'.format(self.docker_yaml) |
| 273 | with open(docker_yaml_changed, 'w') as wf: |
| 274 | yaml.dump(yaml_config, wf) |
| 275 | |
| 276 | os.rename(docker_yaml_changed, self.docker_yaml) |
| 277 | self.volumes = volumes |
| 278 | |
| 279 | super(OnosCord, self).__init__(name, image, tag = '') |
| 280 | cord_conf_dir_basename = os.path.basename(self.cord_conf_dir.replace('-', '')) |
| 281 | self.xos_onos_name = '{}_{}_1'.format(cord_conf_dir_basename, image) |
| 282 | ##Create an container instance of xos onos |
| 283 | self.xos_onos = Container(self.xos_onos_name, image, tag = '') |
| 284 | |
| 285 | def start(self, restart = False, network_cfg = None): |
| 286 | if restart is True: |
| 287 | if self.exists(): |
| 288 | ##Kill the existing instance |
| 289 | print('Killing container %s' %self.name) |
| 290 | self.kill() |
| 291 | if self.xos_onos.exists(): |
| 292 | print('Killing container %s' %self.xos_onos.name) |
| 293 | self.xos_onos.kill() |
| 294 | |
| 295 | if network_cfg is not None: |
| 296 | json_data = json.dumps(network_cfg, indent=4) |
| 297 | with open('{}/network-cfg.json'.format(self.onos_config_dir), 'w') as f: |
| 298 | f.write(json_data) |
| 299 | |
| 300 | #start the container using docker-compose |
| 301 | cmd = 'cd {} && docker-compose up -d'.format(self.onos_cord_dir) |
| 302 | os.system(cmd) |
A R Karthick | bd9b8a3 | 2016-07-21 09:56:45 -0700 | [diff] [blame] | 303 | #Delay to make sure ONOS fully boots |
| 304 | time.sleep(self.boot_delay) |
| 305 | Onos.install_cord_apps(onos_ip = self.onos_ip) |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 306 | |
| 307 | def build_image(self): |
| 308 | build_cmd = 'cd {} && docker-compose build'.format(self.onos_cord_dir) |
| 309 | os.system(build_cmd) |
| 310 | |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 311 | class OnosCordStopWrapper(Container): |
| 312 | onos_cord_dir = os.path.join(os.getenv('HOME'), 'cord-tester-cord') |
| 313 | docker_yaml = os.path.join(onos_cord_dir, 'docker-compose.yml') |
| 314 | |
| 315 | def __init__(self): |
| 316 | if os.access(self.docker_yaml, os.F_OK): |
| 317 | with open(self.docker_yaml, 'r') as f: |
| 318 | yaml_config = yaml.load(f) |
| 319 | image = yaml_config['services'].keys()[0] |
| 320 | name = 'cordtestercord_{}_1'.format(image) |
| 321 | super(OnosCordStopWrapper, self).__init__(name, image, tag = '') |
| 322 | if self.exists(): |
| 323 | print('Killing container %s' %self.name) |
| 324 | self.kill() |
| 325 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 326 | class Onos(Container): |
| 327 | |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 328 | quagga_config = [ { 'bridge' : 'quagga-br', 'ip': '10.10.0.4', 'mask' : 16 }, ] |
Chetan Gaonker | 462d9fa | 2016-05-03 16:39:10 -0700 | [diff] [blame] | 329 | SYSTEM_MEMORY = (get_mem(),) * 2 |
A R Karthick | 1f90820 | 2016-11-16 17:32:20 -0800 | [diff] [blame] | 330 | INSTANCE_MEMORY = (get_mem(instances=3),) * 2 |
Chetan Gaonker | 462d9fa | 2016-05-03 16:39:10 -0700 | [diff] [blame] | 331 | JAVA_OPTS = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode'.format(*SYSTEM_MEMORY)#-XX:+PrintGCDetails -XX:+PrintGCTimeStamps' |
A R Karthick | 1f90820 | 2016-11-16 17:32:20 -0800 | [diff] [blame] | 332 | JAVA_OPTS_CLUSTER = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode'.format(*INSTANCE_MEMORY) |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 333 | env = { 'ONOS_APPS' : 'drivers,openflow,proxyarp,vrouter', 'JAVA_OPTS' : JAVA_OPTS } |
A.R Karthick | dfeadb0 | 2016-11-30 17:55:51 -0800 | [diff] [blame] | 334 | onos_cord_apps = ( ('cord-config', '1.1-SNAPSHOT'), |
| 335 | ('aaa', '1.1-SNAPSHOT'), |
| 336 | ('igmp', '1.1-SNAPSHOT'), |
| 337 | #('vtn', '1.1-SNAPSHOT'), |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 338 | ) |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 339 | ports = [] #[ 8181, 8101, 9876, 6653, 6633, 2000, 2620 ] |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 340 | setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup') |
| 341 | host_config_dir = os.path.join(setup_dir, 'onos-config') |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 342 | guest_config_dir = '/root/onos/config' |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 343 | guest_data_dir = '/root/onos/apache-karaf-3.0.5/data' |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 344 | onos_gen_partitions = os.path.join(setup_dir, 'onos-gen-partitions') |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 345 | onos_form_cluster = os.path.join(setup_dir, 'onos-form-cluster') |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 346 | 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] | 347 | host_guest_map = ( (host_config_dir, guest_config_dir), ) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 348 | cluster_cfg = os.path.join(host_config_dir, 'cluster.json') |
| 349 | cluster_mode = False |
| 350 | cluster_instances = [] |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 351 | NAME = 'cord-onos' |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 352 | ##the ip of ONOS in default cluster.json in setup/onos-config |
| 353 | CLUSTER_CFG_IP = '172.17.0.2' |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 354 | IMAGE = 'onosproject/onos' |
| 355 | TAG = 'latest' |
| 356 | PREFIX = '' |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 357 | |
| 358 | @classmethod |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 359 | def generate_cluster_cfg(cls, ip): |
| 360 | if type(ip) in [ list, tuple ]: |
| 361 | ips = ' '.join(ip) |
| 362 | else: |
| 363 | ips = ip |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 364 | try: |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 365 | cmd = '{} {} {}'.format(cls.onos_gen_partitions, cls.cluster_cfg, ips) |
| 366 | os.system(cmd) |
| 367 | except: pass |
| 368 | |
| 369 | @classmethod |
| 370 | def form_cluster(cls, ips): |
| 371 | nodes = ' '.join(ips) |
| 372 | try: |
| 373 | cmd = '{} {}'.format(cls.onos_form_cluster, nodes) |
A R Karthick | f2f4ca6 | 2016-08-17 10:34:08 -0700 | [diff] [blame] | 374 | os.system(cmd) |
| 375 | except: pass |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 376 | |
A R Karthick | 9d48c65 | 2016-09-15 09:16:36 -0700 | [diff] [blame] | 377 | @classmethod |
| 378 | def cleanup_runtime(cls): |
| 379 | '''Cleanup ONOS runtime generated files''' |
| 380 | files = ( Onos.cluster_cfg, os.path.join(Onos.host_config_dir, 'network-cfg.json') ) |
| 381 | for f in files: |
| 382 | if os.access(f, os.F_OK): |
| 383 | try: |
| 384 | os.unlink(f) |
| 385 | except: pass |
| 386 | |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 387 | @classmethod |
| 388 | def get_data_map(cls, host_volume, guest_volume_dir): |
| 389 | host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume)) |
| 390 | if not os.path.exists(host_volume_dir): |
| 391 | os.mkdir(host_volume_dir) |
| 392 | return ( (host_volume_dir, guest_volume_dir), ) |
| 393 | |
| 394 | @classmethod |
| 395 | def remove_data_map(cls, host_volume, guest_volume_dir): |
| 396 | host_volume_dir = os.path.join(cls.setup_dir, os.path.basename(host_volume)) |
| 397 | if os.path.exists(host_volume_dir): |
| 398 | rmtree(host_volume_dir) |
| 399 | |
| 400 | def remove_data_volume(self): |
| 401 | if self.data_map is not None: |
| 402 | self.remove_data_map(*self.data_map) |
| 403 | |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 404 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG, |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 405 | boot_delay = 20, restart = False, network_cfg = None, |
A R Karthick | 3b81115 | 2016-12-15 10:24:24 -0800 | [diff] [blame^] | 406 | cluster = False, data_volume = None, async = False, quagga_config = None, max_instances=1): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 407 | if restart is True: |
| 408 | ##Find the right image to restart |
| 409 | running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers()) |
| 410 | if running_image: |
| 411 | image_name = running_image[0]['Image'] |
| 412 | try: |
| 413 | image = image_name.split(':')[0] |
| 414 | tag = image_name.split(':')[1] |
| 415 | except: pass |
| 416 | |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 417 | if quagga_config is not None: |
| 418 | self.quagga_config = quagga_config |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 419 | super(Onos, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.quagga_config) |
A R Karthick | 3b81115 | 2016-12-15 10:24:24 -0800 | [diff] [blame^] | 420 | self.max_instances = max_instances |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 421 | self.boot_delay = boot_delay |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 422 | self.data_map = None |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 423 | if cluster is True: |
| 424 | self.ports = [] |
A R Karthick | 3b81115 | 2016-12-15 10:24:24 -0800 | [diff] [blame^] | 425 | if self.max_instances <= 3: |
| 426 | java_opts = self.JAVA_OPTS_CLUSTER |
| 427 | else: |
| 428 | instance_memory = (get_mem(instances=self.max_instances),) * 2 |
| 429 | java_opts = '-Xms{} -Xmx{} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode'.format(*instance_memory) |
| 430 | |
| 431 | self.env['JAVA_OPTS'] = java_opts |
A R Karthick | ec2db32 | 2016-11-17 15:06:01 -0800 | [diff] [blame] | 432 | if data_volume is not None: |
| 433 | self.data_map = self.get_data_map(data_volume, self.guest_data_dir) |
| 434 | self.host_guest_map = self.host_guest_map + self.data_map |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 435 | if os.access(self.cluster_cfg, os.F_OK): |
| 436 | try: |
| 437 | os.unlink(self.cluster_cfg) |
| 438 | except: pass |
| 439 | |
| 440 | self.host_config = self.create_host_config(port_list = self.ports, |
| 441 | host_guest_map = self.host_guest_map) |
| 442 | self.volumes = [] |
| 443 | for _,g in self.host_guest_map: |
| 444 | self.volumes.append(g) |
| 445 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 446 | if restart is True and self.exists(): |
| 447 | self.kill() |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 448 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 449 | if not self.exists(): |
| 450 | self.remove_container(name, force=True) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 451 | host_config = self.create_host_config(port_list = self.ports, |
| 452 | host_guest_map = self.host_guest_map) |
| 453 | volumes = [] |
| 454 | for _,g in self.host_guest_map: |
| 455 | volumes.append(g) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 456 | if network_cfg is not None: |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 457 | json_data = json.dumps(network_cfg, indent=4) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 458 | with open('{}/network-cfg.json'.format(self.host_config_dir), 'w') as f: |
| 459 | f.write(json_data) |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 460 | if cluster is False or async is False: |
| 461 | print('Starting ONOS container %s' %self.name) |
| 462 | self.start(ports = self.ports, environment = self.env, |
| 463 | host_config = self.host_config, volumes = self.volumes, tty = True) |
| 464 | if not restart: |
| 465 | ##wait a bit before fetching IP to regenerate cluster cfg |
| 466 | time.sleep(5) |
| 467 | ip = self.ip() |
| 468 | ##Just a quick hack/check to ensure we don't regenerate in the common case. |
| 469 | ##As ONOS is usually the first test container that is started |
| 470 | if cluster is False: |
| 471 | if ip != self.CLUSTER_CFG_IP or not os.access(self.cluster_cfg, os.F_OK): |
| 472 | print('Regenerating ONOS cluster cfg for ip %s' %ip) |
| 473 | self.generate_cluster_cfg(ip) |
| 474 | self.kill() |
| 475 | self.remove_container(self.name, force=True) |
| 476 | print('Restarting ONOS container %s' %self.name) |
| 477 | self.start(ports = self.ports, environment = self.env, |
| 478 | host_config = self.host_config, volumes = self.volumes, tty = True) |
| 479 | print('Waiting for ONOS to boot') |
| 480 | time.sleep(boot_delay) |
| 481 | self.wait_for_onos_start(self.ip()) |
| 482 | self.running = True |
| 483 | else: |
| 484 | self.running = False |
| 485 | else: |
| 486 | self.running = True |
| 487 | if self.running: |
| 488 | self.ipaddr = self.ip() |
| 489 | if cluster is False: |
| 490 | self.install_cord_apps(self.ipaddr) |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 491 | |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 492 | @classmethod |
| 493 | def get_quagga_config(cls, instance = 0): |
| 494 | quagga_config = cls.quagga_config[:] |
| 495 | if instance == 0: |
| 496 | return quagga_config |
| 497 | ip = quagga_config[0]['ip'] |
| 498 | octets = ip.split('.') |
| 499 | octets[3] = str((int(octets[3]) + 1) & 255) |
| 500 | ip = '.'.join(octets) |
| 501 | quagga_config[0]['ip'] = ip |
| 502 | return quagga_config |
| 503 | |
| 504 | @classmethod |
| 505 | def start_cluster_async(cls, onos_instances): |
| 506 | instances = filter(lambda o: o.running == False, onos_instances) |
| 507 | if not instances: |
| 508 | return |
| 509 | tpool = ThreadPool(len(instances), queue_size = 1, wait_timeout = 1) |
| 510 | for onos in instances: |
| 511 | tpool.addTask(onos.start_async) |
| 512 | tpool.cleanUpThreads() |
| 513 | |
| 514 | def start_async(self): |
| 515 | print('Starting ONOS container %s' %self.name) |
| 516 | self.start(ports = self.ports, environment = self.env, |
| 517 | host_config = self.host_config, volumes = self.volumes, tty = True) |
| 518 | time.sleep(3) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 519 | self.ipaddr = self.ip() |
A.R Karthick | c4e474d | 2016-12-12 15:24:57 -0800 | [diff] [blame] | 520 | print('Waiting for ONOS container %s to start' %self.name) |
| 521 | self.wait_for_onos_start(self.ipaddr) |
| 522 | self.running = True |
| 523 | print('ONOS container %s started' %self.name) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 524 | |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 525 | @classmethod |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 526 | def wait_for_onos_start(cls, ip, tries = 30): |
| 527 | onos_log = OnosLog(host = ip) |
| 528 | num_tries = 0 |
| 529 | started = None |
| 530 | while not started and num_tries < tries: |
| 531 | time.sleep(3) |
| 532 | started = onos_log.search_log_pattern('ApplicationManager .* Started') |
| 533 | num_tries += 1 |
| 534 | |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 535 | if not started: |
| 536 | print('ONOS did not start') |
| 537 | else: |
| 538 | print('ONOS started') |
| 539 | return started |
| 540 | |
| 541 | @classmethod |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 542 | def setup_cluster_deprecated(cls, onos_instances, image_name = None): |
| 543 | if not onos_instances or len(onos_instances) < 2: |
| 544 | return |
| 545 | ips = [] |
| 546 | if image_name is not None: |
| 547 | ips = Container.ips(image_name) |
| 548 | else: |
| 549 | for onos in onos_instances: |
| 550 | ips.append(onos.ipaddr) |
| 551 | Onos.cluster_instances = onos_instances |
| 552 | Onos.cluster_mode = True |
| 553 | ##regenerate the cluster json with the 3 instance ips before restarting them back |
| 554 | print('Generating cluster cfg for ONOS instances with ips %s' %ips) |
| 555 | Onos.generate_cluster_cfg(ips) |
| 556 | for onos in onos_instances: |
| 557 | onos.kill() |
| 558 | onos.remove_container(onos.name, force=True) |
| 559 | print('Restarting ONOS container %s for forming cluster' %onos.name) |
| 560 | onos.start(ports = onos.ports, environment = onos.env, |
| 561 | host_config = onos.host_config, volumes = onos.volumes, tty = True) |
| 562 | print('Waiting %d seconds for ONOS %s to boot' %(onos.boot_delay, onos.name)) |
| 563 | time.sleep(onos.boot_delay) |
| 564 | onos.ipaddr = onos.ip() |
| 565 | onos.install_cord_apps(onos.ipaddr) |
| 566 | |
| 567 | @classmethod |
| 568 | def setup_cluster(cls, onos_instances, image_name = None): |
| 569 | if not onos_instances or len(onos_instances) < 2: |
| 570 | return |
| 571 | ips = [] |
| 572 | if image_name is not None: |
| 573 | ips = Container.ips(image_name) |
| 574 | else: |
| 575 | for onos in onos_instances: |
| 576 | ips.append(onos.ipaddr) |
| 577 | Onos.cluster_instances = onos_instances |
| 578 | Onos.cluster_mode = True |
| 579 | ##regenerate the cluster json with the 3 instance ips before restarting them back |
| 580 | print('Forming cluster for ONOS instances with ips %s' %ips) |
| 581 | Onos.form_cluster(ips) |
| 582 | ##wait for the cluster to be formed |
| 583 | print('Waiting for the cluster to be formed') |
| 584 | time.sleep(60) |
| 585 | for onos in onos_instances: |
| 586 | onos.install_cord_apps(onos.ipaddr) |
| 587 | |
| 588 | @classmethod |
A R Karthick | e2c24bd | 2016-10-07 14:51:38 -0700 | [diff] [blame] | 589 | def add_cluster(cls, count = 1, network_cfg = None): |
| 590 | if not cls.cluster_instances or Onos.cluster_mode is False: |
| 591 | return |
| 592 | for i in range(count): |
| 593 | name = '{}-{}'.format(Onos.NAME, len(cls.cluster_instances)+1) |
| 594 | onos = cls(name = name, image = Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX, |
| 595 | cluster = True, network_cfg = network_cfg) |
| 596 | cls.cluster_instances.append(onos) |
| 597 | |
| 598 | cls.setup_cluster(cls.cluster_instances) |
| 599 | |
| 600 | @classmethod |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 601 | def restart_cluster(cls, network_cfg = None, timeout = 10, setup = False): |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 602 | if cls.cluster_mode is False: |
| 603 | return |
| 604 | if not cls.cluster_instances: |
| 605 | return |
| 606 | |
| 607 | if network_cfg is not None: |
| 608 | json_data = json.dumps(network_cfg, indent=4) |
| 609 | with open('{}/network-cfg.json'.format(cls.host_config_dir), 'w') as f: |
| 610 | f.write(json_data) |
| 611 | |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 612 | cls.cleanup_cluster() |
| 613 | if timeout > 0: |
| 614 | time.sleep(timeout) |
| 615 | |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 616 | for onos in cls.cluster_instances: |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 617 | print('Restarting ONOS container %s' %onos.name) |
| 618 | onos.start(ports = onos.ports, environment = onos.env, |
| 619 | host_config = onos.host_config, volumes = onos.volumes, tty = True) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 620 | onos.ipaddr = onos.ip() |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 621 | onos.wait_for_onos_start(onos.ipaddr) |
| 622 | onos.install_cord_apps(onos.ipaddr) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 623 | |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 624 | ##form the cluster as appropriate |
| 625 | if setup is True: |
| 626 | cls.setup_cluster(cls.cluster_instances) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 627 | |
| 628 | @classmethod |
| 629 | def cluster_ips(cls): |
| 630 | if cls.cluster_mode is False: |
| 631 | return [] |
| 632 | if not cls.cluster_instances: |
| 633 | return [] |
| 634 | ips = [ onos.ipaddr for onos in cls.cluster_instances ] |
| 635 | return ips |
| 636 | |
| 637 | @classmethod |
| 638 | def cleanup_cluster(cls): |
| 639 | if cls.cluster_mode is False: |
| 640 | return |
| 641 | if not cls.cluster_instances: |
| 642 | return |
| 643 | for onos in cls.cluster_instances: |
| 644 | if onos.exists(): |
| 645 | onos.kill() |
| 646 | onos.remove_container(onos.name, force=True) |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 647 | |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 648 | @classmethod |
A R Karthick | de6b9dc | 2016-11-29 17:46:16 -0800 | [diff] [blame] | 649 | def restart_node(cls, node = None, network_cfg = None, timeout = 10): |
A R Karthick | 889d965 | 2016-10-03 14:13:45 -0700 | [diff] [blame] | 650 | if node is None: |
| 651 | cls(restart = True, network_cfg = network_cfg, image = cls.IMAGE, tag = cls.TAG) |
| 652 | else: |
| 653 | #Restarts a node in the cluster |
| 654 | valid_node = filter(lambda onos: node in [ onos.ipaddr, onos.name ], cls.cluster_instances) |
| 655 | if valid_node: |
| 656 | onos = valid_node.pop() |
| 657 | if onos.exists(): |
| 658 | onos.kill() |
| 659 | onos.remove_container(onos.name, force=True) |
A R Karthick | de6b9dc | 2016-11-29 17:46:16 -0800 | [diff] [blame] | 660 | if timeout > 0: |
| 661 | time.sleep(timeout) |
A R Karthick | 889d965 | 2016-10-03 14:13:45 -0700 | [diff] [blame] | 662 | print('Restarting ONOS container %s' %onos.name) |
| 663 | onos.start(ports = onos.ports, environment = onos.env, |
| 664 | host_config = onos.host_config, volumes = onos.volumes, tty = True) |
A R Karthick | 889d965 | 2016-10-03 14:13:45 -0700 | [diff] [blame] | 665 | onos.ipaddr = onos.ip() |
A.R Karthick | 2560f04 | 2016-11-30 14:38:52 -0800 | [diff] [blame] | 666 | onos.wait_for_onos_start(onos.ipaddr) |
| 667 | onos.install_cord_apps(onos.ipaddr) |
A R Karthick | 889d965 | 2016-10-03 14:13:45 -0700 | [diff] [blame] | 668 | |
| 669 | @classmethod |
A R Karthick | eaf1c4e | 2016-07-19 12:22:35 -0700 | [diff] [blame] | 670 | def install_cord_apps(cls, onos_ip = None): |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 671 | for app, version in cls.onos_cord_apps: |
| 672 | app_file = '{}/{}-{}.oar'.format(cls.cord_apps_dir, app, version) |
A R Karthick | eaf1c4e | 2016-07-19 12:22:35 -0700 | [diff] [blame] | 673 | ok, code = OnosCtrl.install_app(app_file, onos_ip = onos_ip) |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 674 | ##app already installed (conflicts) |
| 675 | if code in [ 409 ]: |
| 676 | ok = True |
| 677 | print('ONOS app %s, version %s %s' %(app, version, 'installed' if ok else 'failed to install')) |
| 678 | time.sleep(2) |
| 679 | |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 680 | class OnosStopWrapper(Container): |
| 681 | def __init__(self, name): |
| 682 | super(OnosStopWrapper, self).__init__(name, Onos.IMAGE, tag = Onos.TAG, prefix = Container.IMAGE_PREFIX) |
| 683 | if self.exists(): |
| 684 | self.kill() |
| 685 | else: |
| 686 | if Onos.cluster_mode is True: |
| 687 | valid_node = filter(lambda onos: name in [ onos.ipaddr, onos.name ], Onos.cluster_instances) |
| 688 | if valid_node: |
| 689 | onos = valid_node.pop() |
| 690 | if onos.exists(): |
| 691 | onos.kill() |
| 692 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 693 | class Radius(Container): |
| 694 | ports = [ 1812, 1813 ] |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 695 | env = {'TIMEZONE':'America/Los_Angeles', |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 696 | 'DEBUG': 'true', 'cert_password':'whatever', 'primary_shared_secret':'radius_password' |
| 697 | } |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 698 | 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] | 699 | guest_db_dir = os.path.join(os.path.sep, 'opt', 'db') |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 700 | 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] | 701 | guest_config_dir = os.path.join(os.path.sep, 'etc', 'freeradius') |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 702 | start_command = os.path.join(guest_config_dir, 'start-radius.py') |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 703 | host_guest_map = ( (host_db_dir, guest_db_dir), |
| 704 | (host_config_dir, guest_config_dir) |
| 705 | ) |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 706 | IMAGE = 'cord-test/radius' |
| 707 | NAME = 'cord-radius' |
| 708 | |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 709 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate', |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 710 | boot_delay = 10, restart = False, update = False): |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 711 | 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] | 712 | if update is True or not self.img_exists(): |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 713 | self.build_image(self.image_name) |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 714 | if restart is True and self.exists(): |
| 715 | self.kill() |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 716 | if not self.exists(): |
| 717 | self.remove_container(name, force=True) |
| 718 | host_config = self.create_host_config(port_list = self.ports, |
| 719 | host_guest_map = self.host_guest_map) |
| 720 | volumes = [] |
| 721 | for _,g in self.host_guest_map: |
| 722 | volumes.append(g) |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 723 | self.start(ports = self.ports, environment = self.env, |
| 724 | volumes = volumes, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 725 | host_config = host_config, tty = True) |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 726 | time.sleep(boot_delay) |
| 727 | |
| 728 | @classmethod |
| 729 | def build_image(cls, image): |
| 730 | print('Building Radius image %s' %image) |
| 731 | dockerfile = ''' |
| 732 | FROM hbouvier/docker-radius |
| 733 | MAINTAINER chetan@ciena.com |
| 734 | LABEL RUN docker pull hbouvier/docker-radius |
| 735 | LABEL RUN docker run -it --name cord-radius hbouvier/docker-radius |
A R Karthick | c762df4 | 2016-05-25 10:09:21 -0700 | [diff] [blame] | 736 | RUN apt-get update && \ |
| 737 | apt-get -y install python python-pexpect strace |
Chetan Gaonker | 7f4bf74 | 2016-05-04 15:56:08 -0700 | [diff] [blame] | 738 | WORKDIR /root |
| 739 | CMD ["/etc/freeradius/start-radius.py"] |
| 740 | ''' |
| 741 | super(Radius, cls).build_image(dockerfile, image) |
| 742 | print('Done building image %s' %image) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 743 | |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 744 | class Quagga(Container): |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 745 | quagga_config = ( { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 }, |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 746 | { 'bridge' : 'quagga-br', 'ip': '192.168.10.3', 'mask': 16 }, |
| 747 | ) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 748 | ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ] |
| 749 | host_quagga_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup/quagga-config') |
| 750 | guest_quagga_config = '/root/config' |
| 751 | quagga_config_file = os.path.join(guest_quagga_config, 'testrib.conf') |
| 752 | host_guest_map = ( (host_quagga_config, guest_quagga_config), ) |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 753 | IMAGE = 'cord-test/quagga' |
| 754 | NAME = 'cord-quagga' |
| 755 | |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 756 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate', |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 757 | boot_delay = 15, restart = False, config_file = quagga_config_file, update = False): |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 758 | 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] | 759 | if update is True or not self.img_exists(): |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 760 | self.build_image(self.image_name) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 761 | if restart is True and self.exists(): |
| 762 | self.kill() |
| 763 | if not self.exists(): |
| 764 | self.remove_container(name, force=True) |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 765 | host_config = self.create_host_config(port_list = self.ports, |
| 766 | host_guest_map = self.host_guest_map, |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 767 | privileged = True) |
| 768 | volumes = [] |
| 769 | for _,g in self.host_guest_map: |
| 770 | volumes.append(g) |
| 771 | self.start(ports = self.ports, |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 772 | host_config = host_config, |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 773 | volumes = volumes, tty = True) |
| 774 | print('Starting Quagga on container %s' %self.name) |
| 775 | self.execute('{0}/start.sh {1}'.format(self.guest_quagga_config, config_file)) |
| 776 | time.sleep(boot_delay) |
| 777 | |
| 778 | @classmethod |
| 779 | def build_image(cls, image): |
Chetan Gaonker | 2a6601b | 2016-05-02 17:28:26 -0700 | [diff] [blame] | 780 | onos_quagga_ip = Onos.quagga_config[0]['ip'] |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 781 | print('Building Quagga image %s' %image) |
| 782 | dockerfile = ''' |
A R Karthick | 41adfce | 2016-06-10 09:51:25 -0700 | [diff] [blame] | 783 | FROM ubuntu:14.04 |
| 784 | MAINTAINER chetan@ciena.com |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 785 | WORKDIR /root |
| 786 | RUN useradd -M quagga |
| 787 | RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga |
| 788 | RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga |
A R Karthick | 973ea69 | 2016-10-17 12:23:02 -0700 | [diff] [blame] | 789 | 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] | 790 | RUN git clone git://git.savannah.nongnu.org/quagga.git quagga && \ |
A R Karthick | 8f69c2c | 2016-10-21 11:43:26 -0700 | [diff] [blame] | 791 | (cd quagga && git checkout quagga-1.0.20160315 && ./bootstrap.sh && \ |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 792 | sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \ |
| 793 | ./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install) |
| 794 | RUN ldconfig |
| 795 | '''.format(onos_quagga_ip) |
| 796 | super(Quagga, cls).build_image(dockerfile, image) |
| 797 | print('Done building image %s' %image) |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 798 | |
A.R Karthick | 1700e0e | 2016-10-06 18:16:57 -0700 | [diff] [blame] | 799 | class QuaggaStopWrapper(Container): |
| 800 | def __init__(self, name = Quagga.NAME, image = Quagga.IMAGE, tag = 'candidate'): |
| 801 | super(QuaggaStopWrapper, self).__init__(name, image, prefix = Container.IMAGE_PREFIX, tag = tag) |
| 802 | if self.exists(): |
| 803 | self.kill() |
| 804 | |
| 805 | |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 806 | def reinitContainerClients(): |
| 807 | docker_netns.dckr = Client() |
| 808 | Container.dckr = Client() |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 809 | |
| 810 | class Xos(Container): |
| 811 | setup_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup') |
| 812 | TAG = 'latest' |
| 813 | PREFIX = '' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 814 | host_guest_map = None |
| 815 | env = None |
| 816 | ports = None |
| 817 | volumes = None |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 818 | |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 819 | @classmethod |
| 820 | def get_cmd(cls, img_name): |
| 821 | cmd = cls.dckr.inspect_image(img_name)['Config']['Cmd'] |
| 822 | return ' '.join(cmd) |
| 823 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 824 | def __init__(self, name, image, prefix = PREFIX, tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 825 | boot_delay = 20, restart = False, network_cfg = None, update = False): |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 826 | if restart is True: |
| 827 | ##Find the right image to restart |
| 828 | running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers()) |
| 829 | if running_image: |
| 830 | image_name = running_image[0]['Image'] |
| 831 | try: |
| 832 | image = image_name.split(':')[0] |
| 833 | tag = image_name.split(':')[1] |
| 834 | except: pass |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 835 | super(Xos, self).__init__(name, image, prefix = prefix, tag = tag) |
| 836 | if update is True or not self.img_exists(): |
| 837 | self.build_image(self.image_name) |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 838 | self.command = self.get_cmd(self.image_name).strip() or None |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 839 | if restart is True and self.exists(): |
| 840 | self.kill() |
| 841 | if not self.exists(): |
| 842 | self.remove_container(name, force=True) |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 843 | host_config = self.create_host_config(port_list = self.ports, |
| 844 | host_guest_map = self.host_guest_map, |
| 845 | privileged = True) |
| 846 | print('Starting XOS container %s' %self.name) |
| 847 | self.start(ports = self.ports, environment = self.env, host_config = host_config, |
| 848 | volumes = self.volumes, tty = True) |
| 849 | print('Waiting %d seconds for XOS Base Container to boot' %(boot_delay)) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 850 | time.sleep(boot_delay) |
| 851 | |
| 852 | @classmethod |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 853 | def build_image(cls, image, dockerfile_path, image_target = 'build'): |
| 854 | cmd = 'cd {} && make {}'.format(dockerfile_path, image_target) |
| 855 | print('Building XOS %s' %image) |
| 856 | res = os.system(cmd) |
| 857 | print('Done building image %s. Image build %s' %(image, 'successful' if res == 0 else 'failed')) |
| 858 | return res |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 859 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 860 | class XosServer(Xos): |
| 861 | ports = [8000,9998,9999] |
| 862 | NAME = 'xos-server' |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 863 | IMAGE = 'xosproject/xos' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 864 | BASE_IMAGE = 'xosproject/xos-base' |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 865 | TAG = 'latest' |
| 866 | PREFIX = '' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 867 | dockerfile_path = os.path.join(Xos.setup_dir, 'xos') |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 868 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 869 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 870 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 871 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 872 | |
| 873 | @classmethod |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 874 | def build_image(cls, image = IMAGE): |
| 875 | ##build the base image and then build the server image |
| 876 | Xos.build_image(cls.BASE_IMAGE, cls.dockerfile_path, image_target = 'base') |
| 877 | Xos.build_image(image, cls.dockerfile_path) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 878 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 879 | class XosSynchronizerOpenstack(Xos): |
| 880 | ports = [2375,] |
| 881 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer') |
| 882 | NAME = 'xos-synchronizer' |
| 883 | IMAGE = 'xosproject/xos-synchronizer-openstack' |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 884 | TAG = 'latest' |
| 885 | PREFIX = '' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 886 | host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 887 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 888 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 889 | 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] | 890 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 891 | |
| 892 | @classmethod |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 893 | def build_image(cls, image = IMAGE): |
| 894 | XosServer.build_image() |
| 895 | Xos.build_image(image, cls.dockerfile_path) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 896 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 897 | class XosSynchronizerOnboarding(Xos): |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 898 | NAME = 'xos-synchronizer-onboarding' |
| 899 | IMAGE = 'xosproject/xos-synchronizer-onboarding' |
| 900 | TAG = 'latest' |
| 901 | PREFIX = '' |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 902 | dockerfile_path = os.path.join(Xos.setup_dir, 'onboarding_synchronizer') |
| 903 | host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 904 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 905 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 906 | 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] | 907 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 908 | |
| 909 | @classmethod |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 910 | def build_image(cls, image = IMAGE): |
| 911 | XosSynchronizerOpenstack.build_image() |
| 912 | Xos.build_image(image, cls.dockerfile_path) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 913 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 914 | class XosSynchronizerOpenvpn(Xos): |
| 915 | NAME = 'xos-synchronizer-openvpn' |
| 916 | IMAGE = 'xosproject/xos-openvpn' |
| 917 | TAG = 'latest' |
| 918 | PREFIX = '' |
| 919 | dockerfile_path = os.path.join(Xos.setup_dir, 'openvpn') |
| 920 | host_guest_map = ( ('/usr/local/share/ca-certificates', '/usr/local/share/ca-certificates'),) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 921 | |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 922 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 923 | 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] | 924 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 925 | |
| 926 | @classmethod |
| 927 | def build_image(cls, image = IMAGE): |
| 928 | XosSynchronizerOpenstack.build_image() |
| 929 | Xos.build_image(image, cls.dockerfile_path) |
| 930 | |
| 931 | class XosPostgresql(Xos): |
| 932 | ports = [5432,] |
| 933 | NAME = 'xos-db-postgres' |
| 934 | IMAGE = 'xosproject/xos-postgres' |
| 935 | TAG = 'latest' |
| 936 | PREFIX = '' |
| 937 | volumes = ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"] |
| 938 | dockerfile_path = os.path.join(Xos.setup_dir, 'postgresql') |
| 939 | |
| 940 | def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 941 | 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] | 942 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 943 | |
| 944 | @classmethod |
| 945 | def build_image(cls, image = IMAGE): |
| 946 | Xos.build_image(image, cls.dockerfile_path) |
| 947 | |
| 948 | class XosSyndicateMs(Xos): |
| 949 | ports = [8080,] |
| 950 | env = None |
| 951 | NAME = 'xos-syndicate-ms' |
| 952 | IMAGE = 'xosproject/syndicate-ms' |
| 953 | TAG = 'latest' |
| 954 | PREFIX = '' |
| 955 | dockerfile_path = os.path.join(Xos.setup_dir, 'syndicate-ms') |
| 956 | |
| 957 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 958 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
A R Karthick | e3bde96 | 2016-09-27 15:06:35 -0700 | [diff] [blame] | 959 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 960 | |
| 961 | @classmethod |
| 962 | def build_image(cls, image = IMAGE): |
| 963 | Xos.build_image(image, cls.dockerfile_path) |
ChetanGaonker | 2c0e9bb | 2016-09-21 13:38:37 -0700 | [diff] [blame] | 964 | |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 965 | class XosSyncVtn(Xos): |
| 966 | ports = [8080,] |
| 967 | env = None |
| 968 | NAME = 'xos-synchronizer-vtn' |
| 969 | IMAGE = 'xosproject/xos-synchronizer-vtn' |
| 970 | TAG = 'latest' |
| 971 | PREFIX = '' |
| 972 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtn') |
| 973 | |
| 974 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 975 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 976 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 977 | |
| 978 | @classmethod |
| 979 | def build_image(cls, image = IMAGE): |
| 980 | Xos.build_image(image, cls.dockerfile_path) |
| 981 | |
| 982 | class XosSyncVtr(Xos): |
| 983 | ports = [8080,] |
| 984 | env = None |
| 985 | NAME = 'xos-synchronizer-vtr' |
| 986 | IMAGE = 'xosproject/xos-synchronizer-vtr' |
| 987 | TAG = 'latest' |
| 988 | PREFIX = '' |
| 989 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vtr') |
| 990 | |
| 991 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 992 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 993 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 994 | |
| 995 | @classmethod |
| 996 | def build_image(cls, image = IMAGE): |
| 997 | Xos.build_image(image, cls.dockerfile_path) |
| 998 | |
| 999 | class XosSyncVsg(Xos): |
| 1000 | ports = [8080,] |
| 1001 | env = None |
| 1002 | NAME = 'xos-synchronizer-vsg' |
| 1003 | IMAGE = 'xosproject/xos-synchronizer-vsg' |
| 1004 | TAG = 'latest' |
| 1005 | PREFIX = '' |
| 1006 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-vsg') |
| 1007 | |
| 1008 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1009 | boot_delay = 10, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1010 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1011 | |
| 1012 | @classmethod |
| 1013 | def build_image(cls, image = IMAGE): |
| 1014 | Xos.build_image(image, cls.dockerfile_path) |
| 1015 | |
| 1016 | |
| 1017 | class XosSyncOnos(Xos): |
| 1018 | ports = [8080,] |
| 1019 | env = None |
| 1020 | NAME = 'xos-synchronizer-onos' |
| 1021 | IMAGE = 'xosproject/xos-synchronizer-onos' |
| 1022 | TAG = 'latest' |
| 1023 | PREFIX = '' |
| 1024 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-onos') |
| 1025 | |
| 1026 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1027 | boot_delay = 30, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1028 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1029 | |
| 1030 | @classmethod |
| 1031 | def build_image(cls, image = IMAGE): |
| 1032 | Xos.build_image(image, cls.dockerfile_path) |
| 1033 | |
| 1034 | class XosSyncFabric(Xos): |
| 1035 | ports = [8080,] |
| 1036 | env = None |
| 1037 | NAME = 'xos-synchronizer-fabric' |
| 1038 | IMAGE = 'xosproject/xos-synchronizer-fabric' |
| 1039 | TAG = 'latest' |
| 1040 | PREFIX = '' |
| 1041 | dockerfile_path = os.path.join(Xos.setup_dir, 'synchronizer-fabric') |
| 1042 | |
| 1043 | def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = TAG, |
A R Karthick | 6e80afd | 2016-10-10 16:03:12 -0700 | [diff] [blame] | 1044 | boot_delay = 30, restart = False, network_cfg = None, update = False): |
ChetanGaonker | c220e0d | 2016-10-05 05:06:25 -0700 | [diff] [blame] | 1045 | Xos.__init__(self, name, image, prefix, tag, boot_delay, restart, network_cfg, update) |
| 1046 | |
| 1047 | @classmethod |
| 1048 | def build_image(cls, image = IMAGE): |
| 1049 | Xos.build_image(image, cls.dockerfile_path) |
A R Karthick | 19aaf5c | 2016-11-09 17:47:57 -0800 | [diff] [blame] | 1050 | |
| 1051 | if __name__ == '__main__': |
| 1052 | onos = Onos(boot_delay = 10, restart = True) |