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