Update Cluster Driver

Change-Id: I8a3a57e19637ff210548e57d41178e6f194cf694
diff --git a/TestON/tests/CHOTestMonkey/CHOTestMonkey.py b/TestON/tests/CHOTestMonkey/CHOTestMonkey.py
index e484e3a..0de4a84 100644
--- a/TestON/tests/CHOTestMonkey/CHOTestMonkey.py
+++ b/TestON/tests/CHOTestMonkey/CHOTestMonkey.py
@@ -71,8 +71,6 @@
             main.enableIPv6 = main.params[ 'TEST' ][ 'IPv6' ]
             main.enableIPv6 = True if main.enableIPv6 == "on" else False
             main.caseSleep = int( main.params[ 'TEST' ][ 'caseSleep' ] )
-            main.numCtrls = int( main.params[ 'TEST' ][ 'numCtrl' ] )
-            main.maxNodes = main.numCtrls
             main.controllers = []
 
             main.devices = []
@@ -99,19 +97,18 @@
 
         main.testSetUp.evnSetupConclusion( stepResult )
 
-
-        for i in range( 1, main.numCtrls + 1 ):
-            newController = Controller( i )
-            newController.setCLI( main.CLIs[i - 1] )
-            main.controllers.append( newController )
-
         if not main.onoscell :
             main.log.error("Please provide onoscell option at TestON CLI to run CHO tests")
             main.log.error("Example: ~/TestON/bin/cli.py run CHOTestMonkey onoscell <cellName>")
             main.cleanup()
             main.exit()
 
-        setupResult = main.testSetUp.ONOSSetUp( Mininet=main.Mininet1, newCell=False, cellName=main.onoscell )
+        setupResult = main.testSetUp.ONOSSetUp( main.Mininet1, main.Cluster,
+                                                newCell=False, cellName=main.onoscell )
+        for i in range( 1, main.Cluster.numCtrls + 1 ):
+            newController = Controller( i )
+            newController.setCLI( main.Cluster.active( i - 1 ).CLI )
+            main.controllers.append( newController )
 
         main.step( "Set IPv6 cfg parameters for Neighbor Discovery" )
         setIPv6CfgSleep = int( main.params[ 'TEST' ][ 'setIPv6CfgSleep' ] )
@@ -196,10 +193,11 @@
         main.step( "Assign switches to controllers" )
         switchMastership = main.TRUE
         for switchName in main.mininetSwitches.keys():
-            main.Mininet1.assignSwController( sw=switchName, ip=main.ONOSip )
+            ips = main.Cluster.getIps()
+            main.Mininet1.assignSwController( sw=switchName, ip=ips )
             response = main.Mininet1.getSwController( switchName )
             print( "Response is " + str( response ) )
-            if re.search( "tcp:" + main.ONOSip[ 0 ], response ):
+            if re.search( "tcp:" + main.Cluster.active( 0 ).ipAddress, response ):
                 switchMastership = switchMastership and main.TRUE
             else:
                 switchMastership = main.FALSE
@@ -212,7 +210,7 @@
         time.sleep( sleep )
 
         main.step( "Balance devices across controllers" )
-        balanceResult = main.ONOScli1.balanceMasters()
+        balanceResult = main.Cluster.active( 0 ).CLI.balanceMasters()
         # giving some breathing time for ONOS to complete re-balance
         time.sleep( sleep )
 
@@ -233,8 +231,8 @@
         main.log.report( "____________________________________________________________________" )
         main.case( "Collect and Store Topology Details from ONOS" )
         topoResult = main.TRUE
-        topologyOutput = main.ONOScli1.topology()
-        topologyResult = main.ONOScli1.getTopology( topologyOutput )
+        topologyOutput = main.Cluster.active( 0 ).CLI.topology()
+        topologyResult = main.Cluster.active( 0 ).CLI.getTopology( topologyOutput )
         ONOSDeviceNum = int( topologyResult[ 'devices' ] )
         ONOSLinkNum = int( topologyResult[ 'links' ] )
         mininetSwitchNum = len( main.mininetSwitches )
@@ -245,7 +243,7 @@
             dpidToName = {}
             for key, value in main.mininetSwitches.items():
                 dpidToName[ 'of:' + str( value[ 'dpid' ] ) ] = key
-            devicesRaw = main.ONOScli1.devices()
+            devicesRaw = main.Cluster.active( 0 ).CLI.devices()
             devices = json.loads( devicesRaw )
             deviceInitIndex = 0
             for device in devices:
@@ -261,7 +259,7 @@
 
             main.step( "Collect and store link data" )
             stepResult = main.TRUE
-            linksRaw = main.ONOScli1.links()
+            linksRaw = main.Cluster.active( 0 ).CLI.links()
             links = json.loads( linksRaw )
             linkInitIndex = 0
             for link in links:
diff --git a/TestON/tests/CHOTestMonkey/CHOTestMonkey.topo b/TestON/tests/CHOTestMonkey/CHOTestMonkey.topo
index 23ebde5..9930443 100644
--- a/TestON/tests/CHOTestMonkey/CHOTestMonkey.topo
+++ b/TestON/tests/CHOTestMonkey/CHOTestMonkey.topo
@@ -1,58 +1,32 @@
 <TOPOLOGY>
     <COMPONENT>
 
-        <ONOSbench>
-            <host>localhost</host>
+        <ONOScell>
+            <host>localhost</host>  # ONOS "bench" machine
             <user>admin</user>
             <password></password>
-            <type>OnosDriver</type>
+            <type>OnosClusterDriver</type>
             <connect_order>1</connect_order>
             <COMPONENTS>
-                <prompt></prompt>
-            </COMPONENTS>
-        </ONOSbench>
-
-        <ONOScli1>
-            <host>localhost</host>
-            <user>admin</user>
-            <password></password>
-            <type>OnosCliDriver</type>
-            <connect_order>2</connect_order>
-            <COMPONENTS>
+                <cluster_name></cluster_name>  # Used as a prefix for cluster components. Defaults to 'ONOS'
+                <diff_clihost></diff_clihost> # if it has different host other than localhost for CLI. True or empty. OC# will be used if True.
                 <karaf_username></karaf_username>
                 <karaf_password></karaf_password>
-                <prompt></prompt>
+                <web_user></web_user>
+                <web_pass></web_pass>
+                <rest_port></rest_port>
+                <prompt></prompt>  # TODO: we technically need a few of these, one per component
+                <onos_home></onos_home>  # defines where onos home is
+                <nodes> 3 </nodes>  # number of nodes in the cluster
             </COMPONENTS>
-        </ONOScli1>
-
-        <ONOScli2>
-            <host>localhost</host>
-            <user>admin</user>
-            <password></password>
-            <type>OnosCliDriver</type>
-            <connect_order>3</connect_order>
-            <COMPONENTS>
-                <prompt></prompt>
-            </COMPONENTS>
-        </ONOScli2>
-
-        <ONOScli3>
-            <host>localhost</host>
-            <user>admin</user>
-            <password></password>
-            <type>OnosCliDriver</type>
-            <connect_order>4</connect_order>
-            <COMPONENTS>
-                <prompt></prompt>
-            </COMPONENTS>
-        </ONOScli3>
+        </ONOScell>
 
         <Mininet1>
             <host>OCN</host>
             <user>admin</user>
             <password></password>
             <type>MininetCliDriver</type>
-            <connect_order>10</connect_order>
+            <connect_order>2</connect_order>
             <COMPONENTS>
                 <prompt></prompt>
             </COMPONENTS>
diff --git a/TestON/tests/CHOTestMonkey/dependencies/elements/ONOSElement.py b/TestON/tests/CHOTestMonkey/dependencies/elements/ONOSElement.py
index 7cb300a..e18e0b3 100644
--- a/TestON/tests/CHOTestMonkey/dependencies/elements/ONOSElement.py
+++ b/TestON/tests/CHOTestMonkey/dependencies/elements/ONOSElement.py
@@ -31,7 +31,7 @@
     def __init__( self, index ):
         self.default = ''
         self.index = index
-        self.ip = main.ONOSip[ index - 1 ]
+        self.ip = main.Cluster.getIps()[ index - 1 ]
         self.CLI = None
         self.CLILock = Lock()
         self.status = 'up'
diff --git a/TestON/tests/CHOTestMonkey/dependencies/events/AppEvent.py b/TestON/tests/CHOTestMonkey/dependencies/events/AppEvent.py
index d0f154d..45df912 100644
--- a/TestON/tests/CHOTestMonkey/dependencies/events/AppEvent.py
+++ b/TestON/tests/CHOTestMonkey/dependencies/events/AppEvent.py
@@ -130,7 +130,7 @@
                             main.log.warn( "Host %s does not exist: " % ( args[ 1 ] ) )
                             return EventStates().ABORT
                     index = int( args[ 2 ] )
-                    if index < 1 or index > int( main.numCtrls ):
+                    if index < 1 or index > int( main.Cluster.numCtrls ):
                         main.log.warn( "%s - invalid argument: %s" % ( self.typeString, index ) )
                         return EventStates().ABORT
                     if not main.controllers[ index - 1 ].isUp():
@@ -279,7 +279,7 @@
                             main.log.warn( "Device %s does not exist: " % ( args[ 1 ] ) )
                             return EventStates().ABORT
                     index = int( args[ 2 ] )
-                    if index < 1 or index > int( main.numCtrls ):
+                    if index < 1 or index > int( main.Cluster.numCtrls ):
                         main.log.warn( "%s - invalid argument: %s" % ( self.typeString, index ) )
                         return EventStates().ABORT
                     if not main.controllers[ index - 1 ].isUp():
diff --git a/TestON/tests/CHOTestMonkey/dependencies/events/NetworkEvent.py b/TestON/tests/CHOTestMonkey/dependencies/events/NetworkEvent.py
index 82e60ed..4d676cd 100644
--- a/TestON/tests/CHOTestMonkey/dependencies/events/NetworkEvent.py
+++ b/TestON/tests/CHOTestMonkey/dependencies/events/NetworkEvent.py
@@ -306,7 +306,8 @@
                             intent.setInstalled()
         # Re-assign mastership for the device
         with main.mininetLock:
-            main.Mininet1.assignSwController( sw=self.device.name, ip=main.ONOSip )
+            ips = main.Cluster.getIps()
+            main.Mininet1.assignSwController( sw=self.device.name, ip=ips )
         # Re-discover hosts
         for host in self.device.hosts:
             correspondent = None
diff --git a/TestON/tests/CHOTestMonkey/dependencies/events/ONOSEvent.py b/TestON/tests/CHOTestMonkey/dependencies/events/ONOSEvent.py
index 0df5253..e8b7281 100644
--- a/TestON/tests/CHOTestMonkey/dependencies/events/ONOSEvent.py
+++ b/TestON/tests/CHOTestMonkey/dependencies/events/ONOSEvent.py
@@ -45,7 +45,7 @@
                     result = EventStates().ABORT
                 else:
                     index = int( args[ 0 ] )
-                    if index < 1 or index > int( main.numCtrls ):
+                    if index < 1 or index > int( main.Cluster.numCtrls ):
                         main.log.warn( "%s - invalid argument: %s" % ( self.typeString, index ) )
                         result = EventStates().ABORT
                     else: