def __init__(
            self,
            network_backend_bootstrapper,
            node_id,
            # network
            interfaces=None,
            management_switch=False):
        super(EmulationNodeNetworkBackend,
              self).__init__(network_backend_bootstrapper)

        self.node_id = node_id

        self.nlog = get_node_logger(self.node_id)

        if interfaces is None:
            self.interfaces = Interfaces.Interfaces.factory([Interface.Mesh])
        else:
            self.interfaces = interfaces

        if management_switch:
            self.interfaces.append(
                Interfaces.Interfaces.factory([Interface.Management])[0])

        # let the management interface be the last one
        self.interfaces.sort()
    def __init__(self, id, emulation_node):
        StartableSimulationStateObject.__init__(self)

        self.emulation_node = emulation_node

        # create extra node logger
        self.nlog = get_node_logger(id)

        self.id = id
Exemplo n.º 3
0
    def run_shell_async(self,
                        node_name,
                        cmd,
                        prefixes=None,
                        take_process_ownership=True,
                        supervise_process=True):
        """

        Parameters
        ----------
        node_name
        cmd
        prefixes
        take_process_ownership : bool, optional (default is True)
            Take care of stopping the process for the simulation reset.

        Returns
        -------

        """

        with self.lock:
            if not self.log_writer:
                self.log_writer = LogWriter()
                self.log_writer.start()

        if prefixes is None:
            prefixes = ["N/A"]

        prefix_str = '>>> '.join(map(str, [node_name] + prefixes))
        nlog = get_node_logger(node_name)
        # TODO: #2 : catch/reraise exception if command malformed!
        if supervise_process:
            stdout = subprocess.PIPE
            stderr = subprocess.PIPE
        else:
            stdout, stderr = ["devnull"] * 2
        p, cmd = run_sub_process_popen(cmd, stdout=stdout, stderr=stderr)
        nlog.info('%s: %s', '>>> '.join(prefixes), cmd)

        if supervise_process:
            # important: otherwise subprocess blocks!
            self.log_writer.register_object(p.stdout, prefix_str)
            self.log_writer.register_object(p.stderr, prefix_str)

        if take_process_ownership and self.garbage_collect:
            with self.lock:
                self.subprocesses.append(p)

        return p
Exemplo n.º 4
0
    def __init__(self, qemu):

        self.qemu = qemu

        # create extra node logger
        self.id = self.qemu.id
        self.nlog = get_node_logger(self.id)

        ################################
        # REPLable
        ################################

        REPLable.__init__(self)

        # unix domain socket paths
        self.path_uds_socket = self.get_qemu_sock_path(self.id)
Exemplo n.º 5
0
    def __init__(self, id, interface):
        """
        Parameters
        ----------
        id : int
        interface : Interface
        colorful : bool
            If the interface shall be colored on the switch.
        """
        StartableObject.StartableSimulationStateObject.__init__(self)

        self.interface = interface
        self.id = self.get_interface_class_dependent_id(id, interface.node_class, interface.nr_host_interface)

        # create extra node logger
        self.nlog = get_node_logger(id)
Exemplo n.º 6
0
    def run_shell(self, node_id, cmd, prefixes=None):
        if prefixes is None:
            prefixes = ["N/A"]

        # if prefixes are supplied as tuple
        prefixes = list(prefixes)

        prefix_str = '>>> '.join(map(str, [node_id] + prefixes))
        nlog = get_node_logger(node_id)
        cmd = fmt_cmd_template(cmd)

        # TODO: #2: ABSTRACTION!
        nlog.info('%s: %s', '>>> '.join(prefixes), cmd)

        try:
            output = run_shell(cmd)
            with open(FOREGROUND_SHELL_LOG_PATH, "a") as f:
                f.write("%s '%s'\n:%s\n" % (prefix_str, cmd, output))

            return output
        # TODO:
        except subprocess.CalledProcessError as e:
            log.exception(e)
            raise