示例#1
0
    def test_docker_network(self):
        env = Environment({})

        ack = env.create_docker_network()

        assert ack is True

        nack = env.remove_docker_network()

        assert nack is True
示例#2
0
    def start(self, scenario):
        self.clear()
        self.exp_topo = Environment(scenario)
        ok, info = self.exp_topo.start()
        logger.info("hosts info %s", info)

        msg = {
            "info": info,
            "error": None,
        }

        ack = {
            'ok': str(ok),
            'msg': msg,
        }
        return ack
示例#3
0
 def clear(self):
     exp = Environment({})
     exp.mn_cleanup()
     logger.info("Experiments cleanup OK")
示例#4
0
class Playground:
    def __init__(self, in_queue, out_queue):
        self.exp_topo = None
        self.in_queue = in_queue
        self.out_queue = out_queue
        self.init()

    def init(self):
        self.loop(self.in_queue, self.out_queue)

    def loop(self, in_queue, out_queue):
        logger.info("Playground loop started")
        while True:
            try:
                msg = in_queue.get()
            except Exception as e:
                logger.debug(f"Exception in the loop: {e}")
            else:
                cmd = msg.get("cmd")
                scenario = msg.get("scenario")

                logger.info("Playground command %s", cmd)

                if cmd == "start":
                    reply = self.start(scenario)
                elif cmd == "stop":
                    reply = self.stop()
                else:
                    reply = {}

                out_queue.put(reply)

                if cmd == "stop":
                    break

    def start(self, scenario):
        self.clear()
        self.exp_topo = Environment(scenario)
        ok, info = self.exp_topo.start()
        logger.info("hosts info %s", info)

        msg = {
            "info": info,
            "error": None,
        }

        ack = {
            'ok': str(ok),
            'msg': msg,
        }
        return ack

    def stop(self):
        logger.info("Stopping topo %s", self.exp_topo)
        ack = self.exp_topo.stop()
        self.exp_topo = None

        msg = {
            "info": "",
            "error": "",
        }

        ack = {
            'ok': str(ack),
            'msg': msg,
        }
        return ack

    def clear(self):
        exp = Environment({})
        exp.mn_cleanup()
        logger.info("Experiments cleanup OK")
示例#5
0
class Playground:
    def __init__(self, in_queue, out_queue):
        self.exp_topo = None

    def start(self, scenario):
        self.clear()
        self.exp_topo = Environment(scenario)
        ok, info = self.exp_topo.start()
        logger.info("hosts info %s", info)

        msg = {
            "info": info,
            "error": "",
        }

        ack = {
            "ok": str(ok),
            "msg": msg,
        }
        return ack

    def stop(self):
        logger.info("Stopping topo %s", self.exp_topo)

        ack = True
        if self.exp_topo:
            ack = self.exp_topo.stop()

        self.exp_topo = None

        msg = {
            "info": {},
            "error": "",
        }

        ack = {
            "ok": str(ack),
            "msg": msg,
        }
        return ack

    def stats(self):
        ok, info = "True", {}
        if self.exp_topo:
            ok, info = self.exp_topo.stats()

        ack = {
            "ok": str(ok),
            "msg": {
                "info": info,
                "error": "",
            },
        }

        return ack

    def update(self, scenario):
        ok, info = "True", {}
        if self.exp_topo:
            ok, info = self.exp_topo.update(scenario)

        ack = {
            "ok": str(ok),
            "msg": {
                "info": info,
                "error": "",
            },
        }

        return ack

    def clear(self):
        exp = Environment({})
        exp.mn_cleanup()
        logger.info("Experiments cleanup OK")
示例#6
0
class Playground:
    def __init__(self, in_queue, out_queue):
        self.exp_topo = None
        self.in_queue = in_queue
        self.out_queue = out_queue
        self.init()

    def init(self):
        self.loop(self.in_queue, self.out_queue)
        
    def loop(self, in_queue, out_queue):
        logger.info("Playground loop started")
        while True:
            try:
                msg = in_queue.get()
            except Exception as e:
                logger.debug(f"Exception in the loop: {e}")
            else:
                cmd = msg.get("cmd")
                scenario = msg.get("scenario")
                
                logger.info("Playground command %s", cmd)

                if cmd == "start":
                    reply = self.start(scenario)
                elif cmd == "stop":
                    reply = self.stop()
                elif cmd == "environment_event":
                    target_node = scenario.get('target_node', None)
                    action = scenario.get('action', None)
                    action_args = scenario.get('action_args', None)

                    if action == "kill_container":
                        reply = self.kill_container(target_node)
                    elif action == "update_cpu_limit":
                        reply= self.update_cpu_limit(target_node, action_args)
                    elif action == "update_memory_limit":
                        reply= self.update_memory_limit(target_node, action_args)
                    elif action == "update_link":
                        reply= self.update_link(action_args)
                    else:
                        reply = {}
                elif cmd == "current_topology":
                    reply = self.get_current_topology()
                else:
                    reply = {}

                out_queue.put(reply)

                if cmd == "stop":
                    break

    def start(self, scenario):
        self.clear()
        self.exp_topo = Environment(scenario)
        ok, info = self.exp_topo.start()
        logger.info("hosts info %s", info)

        msg = {
            "info": info,
            "error": None,
        }

        ack = {
            'ok': str(ok),
            'msg': msg, 
        }
        return ack

    def stop(self):
        logger.info("Stopping topo %s", self.exp_topo)
        ack = self.exp_topo.stop()
        self.exp_topo = None

        msg = {
            "info": "",
            "error": "",
        }

        ack = {
            'ok': str(ack),
            'msg': msg, 
        }
        return ack

    def get_current_topology(self):
        ok, info = "True", {}
        if self.exp_topo:
            ok, info = self.exp_topo.get_current_topology()

        ack = {
            'ok': str(ok),
            'msg': {
                'info': info,
                'error': "",
            }
        }

        return ack

    def kill_container(self, target_node):
        ok, err_msg = self.exp_topo.kill_container(target_node)
        logger.info("Terminating container name: %s", target_node)

        ack = {
            'ok': str(ok),
            'msg': {
                'info': {},
                'error': err_msg,
            }
        }

        return ack

    def update_cpu_limit(self, target_node, params):
        cpu_quota = params.get('cpu_quota', -1)
        cpu_period = params.get('cpu_period', -1)
        cpu_shares = params.get('cpu_shares', -1)
        cores = params.get('cores', None)

        ok, err_msg = self.exp_topo.update_cpu_limit(target_node,
            cpu_quota, cpu_period,cpu_shares, cores)
        logger.info("Updating cpu limit of %s with %s", target_node, params)

        ack = {
            'ok': str(ok),
            'msg': {
                'info': {},
                'error': err_msg,
            }
        }

        return ack

    def update_memory_limit(self, target_node, params):
        mem_limit = params.get('mem_limit', -1)
        memswap_limit = params.get('memswap_limit', -1)

        ok, err_msg = self.exp_topo.update_memory_limit(target_node,
            mem_limit, memswap_limit)
        logger.info("Updating mem limit of %s with %s", target_node, params)

        ack = {
            'ok': str(ok),
            'msg': {
                'info': {},
                'error': err_msg
            }
        }

        return ack

    def update_link(self, params):

        events = params.get('events', [])
        ok, err_msg = self.exp_topo.update(events)
        logger.info("Updating link with events=%s", events)

        ack = {
            'ok': str(ok),
            'msg': {
                'info': {},
                'error': err_msg
            }
        }

        return ack

    def clear(self):
        exp = Environment({})
        exp.mn_cleanup()
        logger.info("Experiments cleanup OK")