class DaemonTopology(object):
    """
    Topology with two datacenters:

        dc1 <-- 50ms --> dc2
    """
    def __init__(self):
        self.running = True
        signal.signal(signal.SIGINT, self._stop_by_signal)
        signal.signal(signal.SIGTERM, self._stop_by_signal)
        # create and start topology
        self.create_topology()
        self.start_topology()
        self.daemonize()
        self.stop_topology()

    def create_topology(self):
        self.net = DCNetwork(monitor=False, enable_learning=True)
        self.dc1 = self.net.addDatacenter("dc1")
        self.dc2 = self.net.addDatacenter("dc2")
        self.net.addLink(self.dc1, self.dc2, cls=TCLink, delay="50ms")
        # add OpenStack-like APIs to the emulated DC
        self.api1 = OpenstackApiEndpoint("0.0.0.0", 6001)
        self.api1.connect_datacenter(self.dc1)
        self.api1.connect_dc_network(self.net)
        self.api2 = OpenstackApiEndpoint("0.0.0.0", 6002)
        self.api2.connect_datacenter(self.dc2)
        self.api2.connect_dc_network(self.net)
        # add the command line interface endpoint to the emulated DC (REST API)
        self.rapi1 = RestApiEndpoint("0.0.0.0", 5001)
        self.rapi1.connectDCNetwork(self.net)
        self.rapi1.connectDatacenter(self.dc1)
        self.rapi1.connectDatacenter(self.dc2)

    def start_topology(self):
        self.api1.start()
        self.api2.start()
        self.rapi1.start()
        self.net.start()

    def daemonize(self):
        print("Daemonizing vim-emu. Send SIGTERM or SIGKILL to stop.")
        while self.running:
            time.sleep(1)

    def _stop_by_signal(self, signum, frame):
        print("Received SIGNAL {}. Stopping.".format(signum))
        self.running = False

    def stop_topology(self):
        self.api1.stop()
        self.api2.stop()
        self.rapi1.stop()
        self.net.stop()
Beispiel #2
0
            other_end = time.time()
            zookeeper.start()
            zookeeper_started = time.time()
            kafka.start()
            kafka_started = time.time()
            mongo.start()
            mongo_started = time.time()
            nbi.start()
            nbi_started = time.time()
            ro_db.start()
            ro_db_started = time.time()
            ro.start()
            ro_started = time.time()
            lcm.start()
            lcm_started = time.time()

            writer.writerow({
                'other': other_end - start,
                'zookeeper': zookeeper_started - other_end,
                'kafka': kafka_started - zookeeper_started,
                'mongo': mongo_started - kafka_started,
                'nbi': nbi_started - mongo_started,
                'ro_db': ro_db_started - nbi_started,
                'ro': ro_started - ro_db_started,
                'lcm': lcm_started - ro_started,
            })
            csvfile.flush()
        finally:
            net.stop()
            api.stop()