From: peusterm Date: Wed, 13 Jan 2016 16:05:28 +0000 (+0100) Subject: Refactored design: DCNetwork now inherits from Dockernet. This is much nicer and... X-Git-Tag: v3.1~185^2~15 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=293cbc3515b371d2029fdfd624ae6ae38ced77a9;p=osm%2Fvim-emu.git Refactored design: DCNetwork now inherits from Dockernet. This is much nicer and more consistent. --- diff --git a/README.md b/README.md index 92c3655..22a94b1 100644 --- a/README.md +++ b/README.md @@ -30,17 +30,13 @@ ### TODO * DCemulator * ... -* Cloud-like reference API with CLI for demonstrations - * Write CLI client - * Start compute - * Stop compute -* Re-factor endpoint API so that API objects can be more or less statless (ask DCEmulator for available DCs instead of maintaining a own list) +* Write unit tests * Create an Ansible-based automatic installation routine * Add resource constraints to datacenters * Check if we can use the Mininet GUI to visualize our DCs? -### Features +### Features / Done * Define a topology (Python script) * Add data centers * Add switches and links between the, @@ -52,3 +48,7 @@ * remove and disconnect compute resources at runtime * do IP management for new containers * list active compute resources +* Cloud-like reference API with CLI for demonstrations + * Write CLI client + * Start compute + * Stop compute diff --git a/emuvim/dcemulator/net.py b/emuvim/dcemulator/net.py index 83ac619..0725ac1 100644 --- a/emuvim/dcemulator/net.py +++ b/emuvim/dcemulator/net.py @@ -13,23 +13,22 @@ from mininet.link import TCLink, Link from node import Datacenter, EmulatorCompute -class DCNetwork(object): +class DCNetwork(Dockernet): """ - Wraps the original Mininet class and provides + Wraps the original Mininet/Dockernet class and provides methods to add data centers, switches, etc. This class is used by topology definition scripts. """ - def __init__(self): + def __init__(self, **kwargs): self.dcs = {} - self.switches = {} - self.links = [] - # create a Mininet/Dockernet network setLogLevel('info') # set Mininet loglevel - self.mnet = Dockernet(controller=Controller, switch=OVSKernelSwitch) - self.mnet.addController('c0') + # call original Docker.__init__ and setup default controller + Dockernet.__init__( + self, controller=Controller, switch=OVSKernelSwitch, **kwargs) + self.addController('c0') def addDatacenter(self, name): """ @@ -44,15 +43,6 @@ class DCNetwork(object): logging.info("added data center: %s" % name) return dc - def addSwitch(self, name): - """ - We can also add additional SDN switches between data centers. - """ - s = self.mnet.addSwitch(name) - self.switches[name] = s - logging.info("added switch: %s" % name) - return s - def addLink(self, node1, node2, **params): """ Able to handle Datacenter objects as link @@ -65,16 +55,12 @@ class DCNetwork(object): if isinstance( node1, basestring ): if node1 in self.dcs: node1 = self.dcs[node1].switch - elif node1 in self.switches: - node1 = self.switches[node1] if isinstance( node1, Datacenter ): node1 = node1.switch # ensure type of node2 if isinstance( node2, basestring ): if node2 in self.dcs: node2 = self.dcs[node2].switch - elif node2 in self.switches: - node2 = self.switches[node2] if isinstance( node2, Datacenter ): node2 = node2.switch # try to give containers a default IP @@ -89,30 +75,13 @@ class DCNetwork(object): 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): - """ - Removes a link. Can either be specified by link object, - or the nodes the link connects. Wraps Dockernet method. - """ - logging.debug("removeLink: n1=%s n2=%s" % (str(node1), str(node2))) - return self.mnet.removeLink(link=link, node1=node1, node2=node2) + return Dockernet.addLink(self, node1, node2, **params) # TODO we need TCLinks with user defined performance here def addDocker( self, name, **params ): """ - Wrapper for addDocker method provided by Dockernet. - """ - return self.mnet.addDocker( name, cls=EmulatorCompute, **params) - - def removeDocker( self, name, **params): + Wrapper for addDocker method to use custom container class. """ - Wrapper for removeHost. Just to be complete. - """ - return self.mnet.removeDocker(name, **params) - - def getNextIp(self): - return self.mnet.getNextIp() + return Dockernet.addDocker(self, name, cls=EmulatorCompute, **params) def getAllContainers(self): """ @@ -127,10 +96,10 @@ class DCNetwork(object): # start for dc in self.dcs.itervalues(): dc.start() - self.mnet.start() + Dockernet.start(self) def stop(self): - self.mnet.stop() + Dockernet.stop(self) def CLI(self): - CLI(self.mnet) + CLI(self) diff --git a/emuvim/dcemulator/node.py b/emuvim/dcemulator/node.py index de64d69..551ebaf 100644 --- a/emuvim/dcemulator/node.py +++ b/emuvim/dcemulator/node.py @@ -83,7 +83,7 @@ class Datacenter(object): TODO: This will be changed in the future to support multiple networks per data center """ - self.switch = self.net.mnet.addSwitch( + self.switch = self.net.addSwitch( "%s.s1" % self.name, dpid=hex(self._get_next_dc_dpid())[2:]) logging.debug("created data center switch: %s" % str(self.switch))