Configure a docker network to connect to.
This currently attaches the test/quagga/radius containers to an existing docker network.
This is required if the test container needs to reside on the same network as the CiaB onos docker-network instances.
The manifest file option is: docker_network

Change-Id: I59615903580128c45c4a9001b602eb1c5e430c29
diff --git a/src/test/utils/CordContainer.py b/src/test/utils/CordContainer.py
index 2c57823..908ef1b 100644
--- a/src/test/utils/CordContainer.py
+++ b/src/test/utils/CordContainer.py
@@ -24,6 +24,7 @@
 from itertools import chain
 from nsenter import Namespace
 from docker import Client
+from docker import utils as dockerutils
 from shutil import rmtree
 from OnosCtrl import OnosCtrl
 from OnosLog import OnosLog
@@ -103,6 +104,22 @@
         return cls.dckr.create_host_config(binds = binds, port_bindings = port_bindings, privileged = privileged)
 
     @classmethod
+    def connect_to_network(cls, name, network):
+        try:
+            cls.dckr.connect_container_to_network(name, network)
+            return True
+        except:
+            return False
+
+    @classmethod
+    def create_network(cls, network, subnet = None, gateway = None):
+        ipam_config = None
+        if subnet is not None and gateway is not None:
+            ipam_pool = dockerutils.create_ipam_pool(subnet = subnet, gateway = gateway)
+            ipam_config = dockerutils.create_ipam_config(pool_configs = [ipam_pool])
+        cls.dckr.create_network(network, driver='bridge', ipam = ipam_config)
+
+    @classmethod
     def cleanup(cls, image):
         cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers(all=True))
         for cnt in cnt_list:
@@ -435,7 +452,8 @@
 
     def __init__(self, name = NAME, image = IMAGE, prefix = PREFIX, tag = TAG,
                  boot_delay = 20, restart = False, network_cfg = None,
-                 cluster = False, data_volume = None, async = False, quagga_config = None):
+                 cluster = False, data_volume = None, async = False, quagga_config = None,
+                 network = None):
         if restart is True:
             ##Find the right image to restart
             running_image = filter(lambda c: c['Names'][0] == '/{}'.format(name), self.dckr.containers())
@@ -734,7 +752,7 @@
     NAME = 'cord-radius'
 
     def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
-                 boot_delay = 10, restart = False, update = False):
+                 boot_delay = 10, restart = False, update = False, network = None):
         super(Radius, self).__init__(name, image, prefix = prefix, tag = tag, command = self.start_command)
         if update is True or not self.img_exists():
             self.build_image(self.image_name)
@@ -750,6 +768,8 @@
             self.start(ports = self.ports, environment = self.env,
                        volumes = volumes,
                        host_config = host_config, tty = True)
+            if network is not None:
+                Container.connect_to_network(self.name, network)
             time.sleep(boot_delay)
 
     @classmethod
@@ -781,7 +801,8 @@
     NAME = 'cord-quagga'
 
     def __init__(self, name = NAME, image = IMAGE, prefix = '', tag = 'candidate',
-                 boot_delay = 15, restart = False, config_file = quagga_config_file, update = False):
+                 boot_delay = 15, restart = False, config_file = quagga_config_file, update = False,
+                 network = None):
         super(Quagga, self).__init__(name, image, prefix = prefix, tag = tag, quagga_config = self.QUAGGA_CONFIG)
         if update is True or not self.img_exists():
             self.build_image(self.image_name)
@@ -798,6 +819,8 @@
             self.start(ports = self.ports,
                        host_config = host_config,
                        volumes = volumes, tty = True)
+            if network is not None:
+                Container.connect_to_network(self.name, network)
             print('Starting Quagga on container %s' %self.name)
             self.execute('{0}/start.sh {1}'.format(self.guest_quagga_config, config_file))
             time.sleep(boot_delay)
diff --git a/src/test/utils/TestManifest.py b/src/test/utils/TestManifest.py
index 78b01e1..74a95f6 100644
--- a/src/test/utils/TestManifest.py
+++ b/src/test/utils/TestManifest.py
@@ -35,6 +35,7 @@
             self.start_switch = args.start_switch
             self.image_prefix = args.prefix
             self.onos_image = args.onos
+            self.docker_network = None
             self.iterations = None
             self.server = '{}:{}'.format(CORD_TEST_HOST, CORD_TEST_PORT)
             self.jvm_heap_size = args.jvm_heap_size if args.jvm_heap_size else None
@@ -52,6 +53,7 @@
             self.start_switch = data.get('start_switch', self.olt)
             self.image_prefix = data.get('image_prefix', '')
             self.onos_image = data.get('onos_image', 'onosproject/onos:latest')
+            self.docker_network = data.get('docker_network', None)
             self.server = data.get('test_server', '{}:{}'.format(CORD_TEST_HOST, CORD_TEST_PORT))
             self.iterations = data.get('iterations', None)
             self.jvm_heap_size = data.get('jvm_heap_size', None)