From 5877ea26273aed77b51263efb19fc13b70087c25 Mon Sep 17 00:00:00 2001 From: peusterm Date: Wed, 11 May 2016 13:44:59 +0200 Subject: [PATCH] First part of Containernet re-integration --- README.md | 11 ++++---- ansible/install.yml | 6 +++++ setup.py | 5 ++-- src/emuvim/dcemulator/net.py | 26 +++++++++---------- src/emuvim/dcemulator/node.py | 4 +-- src/emuvim/test/base.py | 8 +++--- src/emuvim/test/test_emulator.py | 20 +++++++------- src/emuvim/test/test_resourcemodel.py | 6 ++--- .../test/test_sonata_dummy_gatekeeper.py | 2 +- utils/docker/Dockerfile | 10 ++----- utils/docker/entrypoint.sh | 6 ++--- 11 files changed, 53 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index f37712f..6d54ca5 100755 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ The following lead developers are responsible for this repository and have admin * flask_restful (BSD) * requests (Apache 2.0) * docker-py (Apache 2.0) +* paramiko (LGPL) ### 3rd-party code used * (none) @@ -37,7 +38,7 @@ The following lead developers are responsible for this repository and have admin * **src/emuvim/** all emulator code * **api/** Data center API endpoint implementations (zerorpc, OpenStack REST, ...) * **cli/** CLI client to interact with a running emulator - * **dcemulator/** Dockernet wrapper that introduces the notion of data centers and API endpoints + * **dcemulator/** Containernet wrapper that introduces the notion of data centers and API endpoints * **examples/** Example topology scripts * **test/** Unit tests * **ansible/** Ansible install scripts @@ -51,10 +52,10 @@ Automatic installation is provide through Ansible playbooks. * `sudo vim /etc/ansible/hosts` * Add: `localhost ansible_connection=local` -#### 1. Dockernet +#### 1. Containernet * `cd` -* `git clone -b dockernet-sonata https://github.com/mpeuster/dockernet.git` -* `cd ~/dockernet/ansible` +* `git clone https://github.com/mpeuster/containernet.git` +* `cd ~/containernet/ansible` * `sudo ansible-playbook install.yml` * Wait (and have a coffee) ... @@ -82,7 +83,7 @@ In the `~/son-emu` directory: * `son-emu-cli compute start -d datacenter1 -n vnf2` * `son-emu-cli compute list` * First terminal: - * `dockernet> vnf1 ping -c 2 vnf2` + * `containernet> vnf1 ping -c 2 vnf2` * Second terminal: * `son-emu-cli monitor get_rate -vnf vnf1` diff --git a/ansible/install.yml b/ansible/install.yml index b31615e..0aa0ab6 100755 --- a/ansible/install.yml +++ b/ansible/install.yml @@ -12,6 +12,9 @@ - name: install libzmq-dev apt: pkg=libzmq-dev state=installed + - name: install libffi-dev + apt: pkg=libffi-dev state=installed + - name: install pip apt: pkg=python-pip state=installed @@ -57,5 +60,8 @@ - name: install prometheus_client pip: name=prometheus_client state=latest + - name: install paramiko + pip: name=paramiko state=latest + diff --git a/setup.py b/setup.py index 367c4fb..8e4b16e 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup(name='emuvim', version='0.0.1', - license='TODO', + license='Apache 2.0', description='emuvim is a VIM for the SONATA platform', url='http://github.com/sonata-emu', author_email='sonata-dev@sonata-nfv.eu', @@ -23,7 +23,8 @@ setup(name='emuvim', 'flask_restful', 'docker-py', 'requests', - 'prometheus_client' + 'prometheus_client', + 'paramiko' ], zip_safe=False, entry_points={ diff --git a/src/emuvim/dcemulator/net.py b/src/emuvim/dcemulator/net.py index 248dc34..7f31a46 100755 --- a/src/emuvim/dcemulator/net.py +++ b/src/emuvim/dcemulator/net.py @@ -12,7 +12,7 @@ import re import urllib2 from functools import partial -from mininet.net import Dockernet +from mininet.net import Containernet from mininet.node import Controller, DefaultController, OVSSwitch, OVSKernelSwitch, Docker, RemoteController from mininet.cli import CLI from mininet.link import TCLink @@ -21,9 +21,9 @@ from emuvim.dcemulator.monitoring import DCNetworkMonitor from emuvim.dcemulator.node import Datacenter, EmulatorCompute from emuvim.dcemulator.resourcemodel import ResourceModelRegistrar -class DCNetwork(Dockernet): +class DCNetwork(Containernet): """ - Wraps the original Mininet/Dockernet class and provides + Wraps the original Mininet/Containernet class and provides methods to add data centers, switches, etc. This class is used by topology definition scripts. @@ -34,7 +34,7 @@ class DCNetwork(Dockernet): dc_emulation_max_mem=512, # emulation max mem in MB **kwargs): """ - Create an extended version of a Dockernet network + Create an extended version of a Containernet network :param dc_emulation_max_cpu: max. CPU time used by containers in data centers :param kwargs: path through for Mininet parameters :return: @@ -42,7 +42,7 @@ class DCNetwork(Dockernet): self.dcs = {} # call original Docker.__init__ and setup default controller - Dockernet.__init__( + Containernet.__init__( self, switch=OVSKernelSwitch, **kwargs) # Ryu management @@ -121,11 +121,11 @@ class DCNetwork(Dockernet): params["params2"]["ip"] = self.getNextIp() # ensure that we allow TCLinks between data centers # TODO this is not optimal, we use cls=Link for containers and TCLink for data centers - # see Dockernet issue: https://github.com/mpeuster/dockernet/issues/3 + # see Containernet issue: https://github.com/mpeuster/containernet/issues/3 if "cls" not in params: params["cls"] = TCLink - link = Dockernet.addLink(self, node1, node2, **params) + link = Containernet.addLink(self, node1, node2, **params) # try to give container interfaces a default id node1_port_id = node1.ports[link.intf1] @@ -143,7 +143,7 @@ class DCNetwork(Dockernet): # add edge and assigned port number to graph in both directions between node1 and node2 # port_id: id given in descriptor (if available, otherwise same as port) - # port: portnumber assigned by Dockernet + # port: portnumber assigned by Containernet attr_dict = {} # possible weight metrics allowed by TClink class: @@ -180,14 +180,14 @@ class DCNetwork(Dockernet): Wrapper for addDocker method to use custom container class. """ self.DCNetwork_graph.add_node(label) - return Dockernet.addDocker(self, label, cls=EmulatorCompute, **params) + return Containernet.addDocker(self, label, cls=EmulatorCompute, **params) def removeDocker( self, label, **params ): """ Wrapper for removeDocker method to update graph. """ self.DCNetwork_graph.remove_node(label) - return Dockernet.removeDocker(self, label, **params) + return Containernet.removeDocker(self, label, **params) def addSwitch( self, name, add_to_graph=True, **params ): """ @@ -195,7 +195,7 @@ class DCNetwork(Dockernet): """ if add_to_graph: self.DCNetwork_graph.add_node(name) - return Dockernet.addSwitch(self, name, protocols='OpenFlow10,OpenFlow12,OpenFlow13', **params) + return Containernet.addSwitch(self, name, protocols='OpenFlow10,OpenFlow12,OpenFlow13', **params) def getAllContainers(self): """ @@ -210,7 +210,7 @@ class DCNetwork(Dockernet): # start for dc in self.dcs.itervalues(): dc.start() - Dockernet.start(self) + Containernet.start(self) def stop(self): @@ -219,7 +219,7 @@ class DCNetwork(Dockernet): self.monitor_agent.stop() # stop emulator net - Dockernet.stop(self) + Containernet.stop(self) # stop Ryu controller self.stopRyu() diff --git a/src/emuvim/dcemulator/node.py b/src/emuvim/dcemulator/node.py index 3258a9f..f9328e3 100755 --- a/src/emuvim/dcemulator/node.py +++ b/src/emuvim/dcemulator/node.py @@ -19,7 +19,7 @@ DCDPID_BASE = 1000 # start of switch dpid's used for data center switches class EmulatorCompute(Docker): """ Emulator specific compute node class. - Inherits from Dockernet's Docker host class. + Inherits from Containernet's Docker host class. Represents a single container connected to a (logical) data center. We can add emulator specific helper functions to it. @@ -168,7 +168,7 @@ class Datacenter(object): # if no --net option is given, network = [{}], so 1 empty dict in the list # this results in 1 default interface with a default ip address for nw in network: - # TODO we cannot use TCLink here (see: https://github.com/mpeuster/dockernet/issues/3) + # TODO we cannot use TCLink here (see: https://github.com/mpeuster/containernet/issues/3) self.net.addLink(d, self.switch, params1=nw, cls=Link, intfName1=nw.get('id')) # do bookkeeping self.containers[name] = d diff --git a/src/emuvim/test/base.py b/src/emuvim/test/base.py index 4bad515..5a83547 100644 --- a/src/emuvim/test/base.py +++ b/src/emuvim/test/base.py @@ -74,11 +74,11 @@ class SimpleTestTopology(unittest.TestCase): base_url='unix://var/run/docker.sock') return self.docker_cli - def getDockernetContainers(self): + def getContainernetContainers(self): """ - List the containers managed by dockernet + List the containers managed by containernet """ - return self.getDockerCli().containers(filters={"label": "com.dockernet"}) + return self.getDockerCli().containers(filters={"label": "com.containernet"}) @staticmethod def setUp(): @@ -90,7 +90,7 @@ class SimpleTestTopology(unittest.TestCase): # make sure that all pending docker containers are killed with open(os.devnull, 'w') as devnull: subprocess.call( - "sudo docker rm -f $(sudo docker ps --filter 'label=com.dockernet' -a -q)", + "sudo docker rm -f $(sudo docker ps --filter 'label=com.containernet' -a -q)", stdout=devnull, stderr=devnull, shell=True) \ No newline at end of file diff --git a/src/emuvim/test/test_emulator.py b/src/emuvim/test/test_emulator.py index 2038116..243f050 100755 --- a/src/emuvim/test/test_emulator.py +++ b/src/emuvim/test/test_emulator.py @@ -32,7 +32,7 @@ class testEmulatorTopology( SimpleTestTopology ): # start Mininet network self.startNet() # check number of running nodes - self.assertTrue(len(self.getDockernetContainers()) == 0) + self.assertTrue(len(self.getContainernetContainers()) == 0) self.assertTrue(len(self.net.hosts) == 2) self.assertTrue(len(self.net.switches) == 1) # check connectivity by using ping @@ -54,7 +54,7 @@ class testEmulatorTopology( SimpleTestTopology ): # start Mininet network self.startNet() # check number of running nodes - self.assertTrue(len(self.getDockernetContainers()) == 0) + self.assertTrue(len(self.getContainernetContainers()) == 0) self.assertTrue(len(self.net.hosts) == 2) self.assertTrue(len(self.net.switches) == 2) # check connectivity by using ping @@ -79,7 +79,7 @@ class testEmulatorTopology( SimpleTestTopology ): # start Mininet network self.startNet() # check number of running nodes - self.assertTrue(len(self.getDockernetContainers()) == 0) + self.assertTrue(len(self.getContainernetContainers()) == 0) self.assertTrue(len(self.net.hosts) == 2) self.assertTrue(len(self.net.switches) == 5) # check connectivity by using ping @@ -110,7 +110,7 @@ class testEmulatorCompute( SimpleTestTopology ): # add compute resources vnf1 = self.dc[0].startCompute("vnf1") # check number of running nodes - self.assertTrue(len(self.getDockernetContainers()) == 1) + self.assertTrue(len(self.getContainernetContainers()) == 1) self.assertTrue(len(self.net.hosts) == 2) self.assertTrue(len(self.net.switches) == 1) # check compute list result @@ -136,7 +136,7 @@ class testEmulatorCompute( SimpleTestTopology ): # add compute resources vnf1 = self.dc[0].startCompute("vnf1") # check number of running nodes - self.assertTrue(len(self.getDockernetContainers()) == 1) + self.assertTrue(len(self.getContainernetContainers()) == 1) self.assertTrue(len(self.net.hosts) == 2) self.assertTrue(len(self.net.switches) == 1) # check compute list result @@ -146,7 +146,7 @@ class testEmulatorCompute( SimpleTestTopology ): # remove compute resources self.dc[0].stopCompute("vnf1") # check number of running nodes - self.assertTrue(len(self.getDockernetContainers()) == 0) + self.assertTrue(len(self.getContainernetContainers()) == 0) self.assertTrue(len(self.net.hosts) == 1) self.assertTrue(len(self.net.switches) == 1) # check compute list result @@ -168,7 +168,7 @@ class testEmulatorCompute( SimpleTestTopology ): # add compute resources vnf1 = self.dc[0].startCompute("vnf1") # check number of running nodes - self.assertTrue(len(self.getDockernetContainers()) == 1) + self.assertTrue(len(self.getContainernetContainers()) == 1) self.assertTrue(len(self.net.hosts) == 2) self.assertTrue(len(self.net.switches) == 1) # check compute list result @@ -202,7 +202,7 @@ class testEmulatorCompute( SimpleTestTopology ): vnf1 = self.dc[0].startCompute("vnf1") vnf2 = self.dc[1].startCompute("vnf2") # check number of running nodes - self.assertTrue(len(self.getDockernetContainers()) == 2) + self.assertTrue(len(self.getContainernetContainers()) == 2) self.assertTrue(len(self.net.hosts) == 2) self.assertTrue(len(self.net.switches) == 5) # check compute list result @@ -231,7 +231,7 @@ class testEmulatorCompute( SimpleTestTopology ): vnf1 = self.dc[0].startCompute("vnf1") vnf2 = self.dc[1].startCompute("vnf2") # check number of running nodes - self.assertTrue(len(self.getDockernetContainers()) == 2) + self.assertTrue(len(self.getContainernetContainers()) == 2) self.assertTrue(len(self.net.hosts) == 2) self.assertTrue(len(self.net.switches) == 5) # check compute list result @@ -242,7 +242,7 @@ class testEmulatorCompute( SimpleTestTopology ): # remove compute resources self.dc[0].stopCompute("vnf1") # check number of running nodes - self.assertTrue(len(self.getDockernetContainers()) == 1) + self.assertTrue(len(self.getContainernetContainers()) == 1) self.assertTrue(len(self.net.hosts) == 1) self.assertTrue(len(self.net.switches) == 5) # check compute list result diff --git a/src/emuvim/test/test_resourcemodel.py b/src/emuvim/test/test_resourcemodel.py index 1817a25..a1d273c 100644 --- a/src/emuvim/test/test_resourcemodel.py +++ b/src/emuvim/test/test_resourcemodel.py @@ -41,7 +41,7 @@ class testResourceModel(SimpleTestTopology): # start Mininet network self.startNet() # check number of running nodes - self.assertTrue(len(self.getDockernetContainers()) == 0) + self.assertTrue(len(self.getContainernetContainers()) == 0) self.assertTrue(len(self.net.hosts) == 2) self.assertTrue(len(self.net.switches) == 1) # check resource model and resource model registrar @@ -213,7 +213,7 @@ class testUpbSimpleCloudDcRM(SimpleTestTopology): def testInRealTopo(self): """ - Start a real container and check if limitations are really passed down to Dockernet. + Start a real container and check if limitations are really passed down to Conteinernet. :return: """ # ATTENTION: This test should only be executed if emu runs not inside a Docker container, @@ -231,7 +231,7 @@ class testUpbSimpleCloudDcRM(SimpleTestTopology): # start Mininet network self.startNet() # check number of running nodes - self.assertTrue(len(self.getDockernetContainers()) == 0) + self.assertTrue(len(self.getContainernetContainers()) == 0) self.assertTrue(len(self.net.hosts) == 2) self.assertTrue(len(self.net.switches) == 1) # check resource model and resource model registrar diff --git a/src/emuvim/test/test_sonata_dummy_gatekeeper.py b/src/emuvim/test/test_sonata_dummy_gatekeeper.py index db3fd92..33a1d57 100644 --- a/src/emuvim/test/test_sonata_dummy_gatekeeper.py +++ b/src/emuvim/test/test_sonata_dummy_gatekeeper.py @@ -60,7 +60,7 @@ class testSonataDummyGatekeeper(SimpleTestTopology): self.assertEqual(len(r4.json().get("service_instance_list")), 1) # check number of running nodes - self.assertTrue(len(self.getDockernetContainers()) == 3) + self.assertTrue(len(self.getContainernetContainers()) == 3) self.assertTrue(len(self.net.hosts) == 5) self.assertTrue(len(self.net.switches) == 2) # check compute list result diff --git a/utils/docker/Dockerfile b/utils/docker/Dockerfile index 2c1bda6..ebd3607 100644 --- a/utils/docker/Dockerfile +++ b/utils/docker/Dockerfile @@ -1,14 +1,8 @@ -FROM cgeoffroy/dockernet +FROM mpeuster/containernet +MAINTAINER manuel@peuster.de ENV SON_EMU_IN_DOCKER 1 -# ensure that we have the latest dockernet code base! -WORKDIR / -RUN rm -rf dockernet -RUN git clone -b dockernet-sonata https://github.com/mpeuster/dockernet.git -WORKDIR /dockernet -RUN python setup.py develop - WORKDIR /son-emu COPY . /son-emu/ diff --git a/utils/docker/entrypoint.sh b/utils/docker/entrypoint.sh index 580762f..7e72914 100755 --- a/utils/docker/entrypoint.sh +++ b/utils/docker/entrypoint.sh @@ -1,7 +1,7 @@ #! /bin/bash -e set -x -#cp /dockernet/util/docker/entrypoint.sh /tmp/x.sh -#cat /tmp/x.sh | awk 'NR==1{print; print "set -x"} NR!=1' > /dockernet/util/docker/entrypoint.sh +#cp /containernet/util/docker/entrypoint.sh /tmp/x.sh +#cat /tmp/x.sh | awk 'NR==1{print; print "set -x"} NR!=1' > /conteinernet/util/docker/entrypoint.sh -exec /dockernet/util/docker/entrypoint.sh $* +exec /containernet/util/docker/entrypoint.sh $* -- 2.25.1