Use explicit RequestsLibrary.Create_Session reference
[integration/test.git] / csit / libraries / DynamicMininet.py
index 6e274c6da6d6e65ea36e747ae9d1bf136bce6c69..639fe0c6abac7ddf26108ebeb12bfe41513c2c7a 100644 (file)
@@ -3,6 +3,7 @@ New CLI for mininet which should dynamically add and delete switches from networ
 """
 
 import cmd
+
 # import json
 # import logging
 
@@ -35,7 +36,7 @@ class DynamicMininet(cmd.Cmd):
     Note: Do not mix scanarios
     """
 
-    prompt = 'mininet> '
+    prompt = "mininet> "
 
     def __init__(self):
         cmd.Cmd.__init__(self)
@@ -53,25 +54,31 @@ class DynamicMininet(cmd.Cmd):
             :param num: initial number of switches in the topology
         """
         if self._running:
-            print 'Mininet topology is already active'
+            print("Mininet topology is already active")
             return
         cntl, numsw = line.split()
         self._topo = mininet.topo.Topo()
         for _ in range(int(numsw)):
             self._lid += 1
-            self._topo.addSwitch('s{0}'.format(self._lid))
-        controller = mininet.util.customConstructor({'remote': RemoteController}, 'remote,ip={0}'.format(cntl))
-        switch = mininet.util.customConstructor({'ovsk': OVSKernelSwitch}, 'ovsk,protocols=OpenFlow13')
-        self._net = mininet.net.Mininet(topo=self._topo, switch=switch, controller=controller)
+            self._topo.addSwitch("s{0}".format(self._lid))
+        controller = mininet.util.customConstructor(
+            {"remote": RemoteController}, "remote,ip={0}".format(cntl)
+        )
+        switch = mininet.util.customConstructor(
+            {"ovsk": OVSKernelSwitch}, "ovsk,protocols=OpenFlow13"
+        )
+        self._net = mininet.net.Mininet(
+            topo=self._topo, switch=switch, controller=controller
+        )
         self._net.start()
         self._running = True
 
     def help_start(self):
         """Provide help message for start command"""
-        print 'Starts mininet'
-        print 'Usage: start <controller_ip> <num>'
-        print '\tcontroller_ip - controllers ip or host name'
-        print '\tnum           - number of switches at start'
+        print("Starts mininet")
+        print("Usage: start <controller_ip> <num>")
+        print("\tcontroller_ip - controllers ip or host name")
+        print("\tnum           - number of switches at start")
 
     def do_start_with_cluster(self, line):
         """Starts mininet network with initial number of switches
@@ -81,19 +88,23 @@ class DynamicMininet(cmd.Cmd):
                                    e.g.  1.1.1.1,2.2.2.2,3.3.3.3 (no spaces)
         """
         if self._running:
-            print 'Mininet topology is already active'
+            print("Mininet topology is already active")
             return
-        cntls = line.split(',')
+        cntls = line.split(",")
 
         self._topo = mininet.topo.SingleSwitchTopo()
-        switch = mininet.util.customConstructor({'ovsk': OVSKernelSwitch}, 'ovsk,protocols=OpenFlow13')
+        switch = mininet.util.customConstructor(
+            {"ovsk": OVSKernelSwitch}, "ovsk,protocols=OpenFlow13"
+        )
         self._net = mininet.net.Mininet(switch=switch)
 
         controllers = []
         for i, cntl_ip in enumerate(cntls):
-            cnt = self._net.addController('c{0}'.format(i), controller=RemoteController, ip=cntl_ip, port=6633)
+            cnt = self._net.addController(
+                "c{0}".format(i), controller=RemoteController, ip=cntl_ip, port=6633
+            )
             controllers.append(cnt)
-            print "contrller {0} created".format(cnt)
+            print("contrller {0} created".format(cnt))
 
         self._net.buildFromTopo(topo=self._topo)
         self._net.start()
@@ -101,9 +112,9 @@ class DynamicMininet(cmd.Cmd):
 
     def help_start_with_cluster(self):
         """Provide help message for start_with_cluster command"""
-        print 'Starts mininet with one switch'
-        print 'Usage: start <controller_ips>'
-        print '\tcontroller_ips - comma separated list of controllers ip or host names'
+        print("Starts mininet with one switch")
+        print("Usage: start <controller_ips>")
+        print("\tcontroller_ips - comma separated list of controllers ip or host names")
 
     def do_start_switches_with_cluster(self, line):
         """Starts mininet network with initial number of switches
@@ -114,20 +125,24 @@ class DynamicMininet(cmd.Cmd):
                                    e.g.  1.1.1.1,2.2.2.2,3.3.3.3 (no spaces)
         """
         if self._running:
-            print 'Mininet topology is already active'
+            print("Mininet topology is already active")
             return
         num, contls = line.split()
-        cntls = contls.split(',')
+        cntls = contls.split(",")
 
         self._topo = mininet.topo.LinearTopo(int(num))
-        switch = mininet.util.customConstructor({'ovsk': OVSKernelSwitch}, 'ovsk,protocols=OpenFlow13')
+        switch = mininet.util.customConstructor(
+            {"ovsk": OVSKernelSwitch}, "ovsk,protocols=OpenFlow13"
+        )
         self._net = mininet.net.Mininet(switch=switch)
 
         controllers = []
         for i, cntl_ip in enumerate(cntls):
-            cnt = self._net.addController('c{0}'.format(i), controller=RemoteController, ip=cntl_ip, port=6633)
+            cnt = self._net.addController(
+                "c{0}".format(i), controller=RemoteController, ip=cntl_ip, port=6633
+            )
             controllers.append(cnt)
-            print "contrller {0} created".format(cnt)
+            print("contrller {0} created".format(cnt))
 
         self._net.buildFromTopo(topo=self._topo)
         self._net.start()
@@ -135,10 +150,10 @@ class DynamicMininet(cmd.Cmd):
 
     def help_start_switches_with_cluster(self):
         """Provide help message for start_with_cluster command"""
-        print 'Starts mininet with one switch'
-        print 'Usage: start <swnr> <controller_ips>'
-        print '\tswnt - number of switches in topology'
-        print '\tcontroller_ips - comma separated list of controllers ip or host names'
+        print("Starts mininet with one switch")
+        print("Usage: start <swnr> <controller_ips>")
+        print("\tswnt - number of switches in topology")
+        print("\tcontroller_ips - comma separated list of controllers ip or host names")
 
     def do_add_switch(self, line):
         """Adds one switch to the network
@@ -148,17 +163,17 @@ class DynamicMininet(cmd.Cmd):
         if not self._running:
             raise RuntimeError('Network not running, use command "start" first')
         self._lid += 1
-        sname = 's{0}'.format(self._lid)
+        sname = "s{0}".format(self._lid)
         self._topo.addSwitch(sname)
         self._net.addSwitch(sname, **self._topo.nodeInfo(sname))
         s = self._net.get(sname)
-        c = self._net.get('c0')
+        c = self._net.get("c0")
         s.start([c])
 
     def help_add_switch(self):
         """Provide help message for add_switch command"""
-        print 'Adds one sinle switch to the running topology'
-        print 'Usage: add_switch'
+        print("Adds one sinle switch to the running topology")
+        print("Usage: add_switch")
 
     def do_add_switches(self, line):
         """Adds switches to the network
@@ -170,9 +185,9 @@ class DynamicMininet(cmd.Cmd):
 
     def help_add_switches(self):
         """Provide help message for add_switch command"""
-        print 'Adds one sinle switch to the running topology'
-        print 'Usage: add_switches <num>'
-        print '\tnum - number of switches tp be added'
+        print("Adds one sinle switch to the running topology")
+        print("Usage: add_switches <num>")
+        print("\tnum - number of switches tp be added")
 
     def do_exit(self, line):
         """Stops mininet"""
@@ -183,8 +198,8 @@ class DynamicMininet(cmd.Cmd):
 
     def help_exit(self):
         """Provide help message for exit command"""
-        print 'Exit mininet cli'
-        print 'Usage: exit'
+        print("Exit mininet cli")
+        print("Usage: exit")
 
     def do_sh(self, line):
         """Run an external shell command
@@ -195,14 +210,14 @@ class DynamicMininet(cmd.Cmd):
 
     def help_sh(self, line):
         """Provide help message for sh command"""
-        print 'Executes given commandAdds one sinle switch to the running topology'
-        print 'Usage: sh <line>'
-        print '\tline - command to be executed(e.g. ps -e'
+        print("Executes given commandAdds one sinle switch to the running topology")
+        print("Usage: sh <line>")
+        print("\tline - command to be executed(e.g. ps -e")
 
     def emptyline(self):
         pass
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     dynamic_mininet_cli = DynamicMininet()
     dynamic_mininet_cli.cmdloop()