cleanup ryu and leftover containers at startup
diff --git a/src/emuvim/dcemulator/monitoring.py b/src/emuvim/dcemulator/monitoring.py
index 78d6ebb..80b139c 100755
--- a/src/emuvim/dcemulator/monitoring.py
+++ b/src/emuvim/dcemulator/monitoring.py
@@ -60,8 +60,6 @@
self.pushgateway = 'localhost:9091'
# when sdk is started with docker-compose, we could use
# self.pushgateway = 'pushgateway:9091'
- # Start up the server to expose the metrics to Prometheus
- #start_http_server(8000)
# supported Prometheus metrics
self.registry = CollectorRegistry()
@@ -104,10 +102,8 @@
self.monitor_flow_thread.start()
# helper tools
- # Prometheus pushgateway and DB are started as external contianer, outside of son-emu
- #self.pushgateway_process = self.start_PushGateway()
- #self.prometheus_process = self.start_Prometheus()
- #self.cadvisor_process = self.start_cadvisor()
+ # cAdvisor, Prometheus pushgateway and DB are started as external container, outside of son-emu
+
# first set some parameters, before measurement can start
def setup_flow(self, vnf_name, vnf_interface=None, metric='tx_packets', cookie=0):
diff --git a/src/emuvim/dcemulator/net.py b/src/emuvim/dcemulator/net.py
index 0e3882c..2c5ce14 100755
--- a/src/emuvim/dcemulator/net.py
+++ b/src/emuvim/dcemulator/net.py
@@ -65,6 +65,11 @@
"""
self.dcs = {}
+ # make sure any remaining Ryu processes are killed
+ self.killRyu()
+ # make sure no containers are left over from a previous emulator run.
+ self.removeLeftoverContainers()
+
# call original Docker.__init__ and setup default controller
Containernet.__init__(
self, switch=OVSKernelSwitch, controller=controller, **kwargs)
@@ -500,6 +505,16 @@
if self.ryu_process is not None:
self.ryu_process.terminate()
self.ryu_process.kill()
+ self.killRyu()
+
+ @staticmethod
+ def removeLeftoverContainers():
+ # TODO can be more python-based using eg. docker-py?
+ Popen('docker ps -a -q --filter="name=mn.*" | xargs -r docker rm -f', shell=True)
+
+ @staticmethod
+ def killRyu():
+ Popen(['pkill', '-f', 'ryu-manager'])
def ryu_REST(self, prefix, dpid=None, data=None):
try: