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