improved connection management
authorpeusterm <manuel.peuster@uni-paderborn.de>
Tue, 12 Jan 2016 09:09:35 +0000 (10:09 +0100)
committerpeusterm <manuel.peuster@uni-paderborn.de>
Tue, 12 Jan 2016 09:09:35 +0000 (10:09 +0100)
emuvim/cli/__main__.py
emuvim/dcemulator/net.py
emuvim/dcemulator/node.py

index dfb935e..1957082 100644 (file)
@@ -19,10 +19,12 @@ def main():
 
     # do some API tests
     print c.compute_action_start("dc2", "d1")
+    print c.compute_action_start("dc2", "d2")
 
-    time.sleep(10)
+    time.sleep(20)
 
     print c.compute_action_stop("dc2", "d1")
+    print c.compute_action_stop("dc2", "d2")
 
 
 if __name__ == '__main__':
index 478c587..13df531 100644 (file)
@@ -77,6 +77,18 @@ class DCNetwork(object):
                 node2 = self.switches[node2]
         if isinstance( node2, Datacenter ):
             node2 = node2.switch
+        # try to give containers a default IP
+        if isinstance( node1, Docker ):
+            if not "params1" in params:
+                params["params1"] = {}
+            if not "ip" in params["params1"]:
+                params["params1"]["ip"] = self.getNextIp()
+        if isinstance( node2, Docker ):
+            if not "params2" in params:
+                params["params2"] = {}
+            if not "ip" in params["params2"]:
+                params["params2"]["ip"] = self.getNextIp()
+
         return self.mnet.addLink(node1, node2, **params)  # TODO we need TCLinks with user defined performance here
 
     def removeLink(self, link=None, node1=None, node2=None):
@@ -99,6 +111,9 @@ class DCNetwork(object):
         """
         return self.mnet.removeDocker(name, **params)
 
+    def getNextIp(self):
+        return self.mnet.getNextIp()
+
     def start(self):
         # start
         for dc in self.dcs.itervalues():
index 6adf57c..67ce600 100644 (file)
@@ -48,8 +48,8 @@ class Datacenter(object):
         data center.
         """
         # TODO ip management
-        d = self.net.addDocker("%s.%s" % (self.name, name), dimage="ubuntu")
-        self.net.addLink(d, self.switch, params1={"ip": "10.0.0.254/8"})
+        d = self.net.addDocker("%s" % (name), dimage="ubuntu")
+        self.net.addLink(d, self.switch) #params1={"ip": "10.0.0.254/8"}
         self.containers[name] = d
 
     def removeCompute(self, name):
@@ -59,5 +59,5 @@ class Datacenter(object):
         assert name in self.containers
         self.net.removeLink(
             link=None, node1=self.containers[name], node2=self.switch)
-        self.net.removeDocker("%s.%s" % (self.name, name))
+        self.net.removeDocker("%s" % (name))
         del self.containers[name]