From c3b977eb522f497716171bae5b5d72d39fbd9905 Mon Sep 17 00:00:00 2001 From: peusterm Date: Tue, 12 Jan 2016 10:09:35 +0100 Subject: [PATCH] improved connection management --- emuvim/cli/__main__.py | 4 +++- emuvim/dcemulator/net.py | 15 +++++++++++++++ emuvim/dcemulator/node.py | 6 +++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/emuvim/cli/__main__.py b/emuvim/cli/__main__.py index dfb935e..1957082 100644 --- a/emuvim/cli/__main__.py +++ b/emuvim/cli/__main__.py @@ -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__': diff --git a/emuvim/dcemulator/net.py b/emuvim/dcemulator/net.py index 478c587..13df531 100644 --- a/emuvim/dcemulator/net.py +++ b/emuvim/dcemulator/net.py @@ -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(): diff --git a/emuvim/dcemulator/node.py b/emuvim/dcemulator/node.py index 6adf57c..67ce600 100644 --- a/emuvim/dcemulator/node.py +++ b/emuvim/dcemulator/node.py @@ -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] -- 2.25.1