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