Exemple #1
0
    def wait_interface_init(self):
        while len(self._tmp_mapping) > 0:
            rl, wl, xl = select.select([self._nl_socket], [], [], 1)

            if len(rl) == 0:
                continue

            msgs = recv_data(self._nl_socket)["data"]
            self.handle_netlink_msgs(msgs)
Exemple #2
0
    def wait_interface_init(self):
        while len(self._tmp_mapping) > 0:
            rl, wl, xl = select.select([self._nl_socket], [], [], 1)

            if len(rl) == 0:
                continue

            msgs = recv_data(self._nl_socket)["data"]
            self.handle_netlink_msgs(msgs)
Exemple #3
0
    def remove_saved_machine_config(cls):
        #removes previously saved configuration
        cfg = None
        try:
            with open("/tmp/.lnst_machine_conf", "rb") as f:
                cfg = cPickle.load(f)
        except:
            logging.info("No previous configuration found.")
            return

        if cfg:
            logging.info("Cleaning up leftover configuration from previous "\
                         "config_only run.")
            for hostname, machine in cfg["machines"].iteritems():
                port = lnst_config.get_option("environment", "rpcport")
                if test_tcp_connection(hostname, port):
                    rpc_con = socket.create_connection((hostname, port))

                    rpc_msg = {
                        "type": "command",
                        "method_name": "machine_cleanup",
                        "args": []
                    }

                    logging.debug("Calling cleanup on slave '%s'" % hostname)
                    send_data(rpc_con, rpc_msg)
                    while True:
                        msg = recv_data(rpc_con)
                        if msg['type'] == 'result':
                            break
                    rpc_con.close()

                if "libvirt_dom" in machine:
                    libvirt_dom = machine["libvirt_dom"]
                    domain_ctl = VirtDomainCtl(libvirt_dom)
                    logging.info("Detaching dynamically created interfaces.")
                    for i in machine["interfaces"]:
                        try:
                            domain_ctl.detach_interface(i)
                        except:
                            pass

            logging.info("Removing dynamically created bridges.")
            for br in cfg["bridges"]:
                try:
                    net_ctl = VirtNetCtl(br)
                    net_ctl.cleanup()
                except:
                    pass

            os.remove("/tmp/.lnst_machine_conf")
Exemple #4
0
    def _get_machine_interfaces(self, sock):
        """ Gets machine interfaces via RPC call
        @param sock Socket used for connecting to machine
        @return Dictionary with machine interfaces or None if RPC call fails
        """
        msg = {"type": "command", "method_name": "get_devices", "args": {}}
        if not send_data(sock, msg):
            sys.stderr.write("Could not send request to slave machine\n")
            return None

        while True:
            data = recv_data(sock)
            if data["type"] == "result":
                return data["result"]
Exemple #5
0
    def _get_machine_interfaces(self, sock):
        """ Gets machine interfaces via RPC call
        @param sock Socket used for connecting to machine
        @return Dictionary with machine interfaces or None if RPC call fails
        """
        msg = {"type": "command", "method_name": "get_devices", "args": {}}
        if not send_data(sock, msg):
            sys.stderr.write("Could not send request to slave machine\n")
            return None

        while True:
            data = recv_data(sock)
            if data["type"] == "result":
                return data["result"]
Exemple #6
0
    def remove_saved_machine_config(cls):
        #removes previously saved configuration
        cfg = None
        try:
            with open("/tmp/.lnst_machine_conf", "rb") as f:
                cfg = cPickle.load(f)
        except:
            logging.info("No previous configuration found.")
            return

        if cfg:
            logging.info("Cleaning up leftover configuration from previous "\
                         "config_only run.")
            for hostname, machine in cfg["machines"].iteritems():
                port = lnst_config.get_option("environment", "rpcport")
                if test_tcp_connection(hostname, port):
                    rpc_con = socket.create_connection((hostname, port))

                    rpc_msg= {"type": "command",
                              "method_name": "machine_cleanup",
                              "args": []}

                    logging.debug("Calling cleanup on slave '%s'" % hostname)
                    send_data(rpc_con, rpc_msg)
                    while True:
                        msg = recv_data(rpc_con)
                        if msg['type'] == 'result':
                            break
                    rpc_con.close()

                if "libvirt_dom" in machine:
                    libvirt_dom = machine["libvirt_dom"]
                    domain_ctl = VirtDomainCtl(libvirt_dom)
                    logging.info("Detaching dynamically created interfaces.")
                    for i in machine["interfaces"]:
                        try:
                            domain_ctl.detach_interface(i)
                        except:
                            pass

            logging.info("Removing dynamically created bridges.")
            for br in cfg["bridges"]:
                try:
                    net_ctl = VirtNetCtl(br)
                    net_ctl.cleanup()
                except:
                    pass

            os.remove("/tmp/.lnst_machine_conf")