From e609269ddf271d7d86d13656bacfb2019ffe5810 Mon Sep 17 00:00:00 2001 From: peusterm Date: Mon, 11 Jan 2016 16:32:58 +0100 Subject: [PATCH] first basic in-datacenter link management --- emuvim/cli/__main__.py | 4 ++-- emuvim/dcemulator/net.py | 13 ++++--------- emuvim/dcemulator/node.py | 3 ++- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/emuvim/cli/__main__.py b/emuvim/cli/__main__.py index 4c55916..dfb935e 100644 --- a/emuvim/cli/__main__.py +++ b/emuvim/cli/__main__.py @@ -18,11 +18,11 @@ def main(): c.connect("tcp://127.0.0.1:4242") # do some API tests - print c.compute_action_start("dc2", "my_new_container1") + print c.compute_action_start("dc2", "d1") time.sleep(10) - print c.compute_action_stop("dc2", "my_new_container1") + print c.compute_action_stop("dc2", "d1") if __name__ == '__main__': diff --git a/emuvim/dcemulator/net.py b/emuvim/dcemulator/net.py index 0efcafa..600eca3 100644 --- a/emuvim/dcemulator/net.py +++ b/emuvim/dcemulator/net.py @@ -5,7 +5,7 @@ Distributed Cloud Emulator (dcemulator) import logging from mininet.net import Mininet -from mininet.node import Controller, OVSKernelSwitch, Switch +from mininet.node import Controller, OVSKernelSwitch, Switch, Docker, Host from mininet.cli import CLI from mininet.log import setLogLevel, info from mininet.link import TCLink, Link @@ -53,13 +53,14 @@ class DCNetwork(object): logging.info("added switch: %s" % name) return s - def addLink(self, node1, node2): + def addLink(self, node1, node2, **params): """ Able to handle Datacenter objects as link end points. """ assert node1 is not None assert node2 is not None + logging.debug("addLink: n1=%s n2=%s" % (str(node1), str(node2))) # ensure type of node1 if isinstance( node1, basestring ): if node1 in self.dcs: @@ -76,13 +77,7 @@ class DCNetwork(object): node2 = self.switches[node2] if isinstance( node2, Datacenter ): node2 = node2.switch - # create link if everything is correct - if (node1 is not None and isinstance(node1, OVSKernelSwitch) - and node2 is not None and isinstance(node2, OVSKernelSwitch)): - self.mnet.addLink(node1, node2) # TODO we need TCLinks with user defined performance here - else: - raise Exception( - "one of the given nodes is not a Mininet switch or None") + self.mnet.addLink(node1, node2, **params) # TODO we need TCLinks with user defined performance here def addDocker( self, name, **params ): """ diff --git a/emuvim/dcemulator/node.py b/emuvim/dcemulator/node.py index 6d1c6de..71267ff 100644 --- a/emuvim/dcemulator/node.py +++ b/emuvim/dcemulator/node.py @@ -47,7 +47,8 @@ class Datacenter(object): data center. """ #TODO connect container to DC's swtich - self.net.addDocker("%s.%s" % (self.name, name), dimage="ubuntu") + d1 = self.net.addDocker("%s.%s" % (self.name, name), dimage="ubuntu") + l1 = self.net.addLink(d1, self.switch) def removeCompute(self, name): #TODO disconnect container to DC's swtich -- 2.25.1