示例#1
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):
                    s = socket.create_connection((hostname, port))
                    rpc_con = CtlSecSocket(s)
                    try:
                        rpc_con.handshake(machine["security"])
                    except SecSocketException:
                        logging.error("Failed authentication for machine %s" %\
                                      hostname)
                        continue

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

                    logging.debug("Calling cleanup on slave '%s'" % hostname)
                    rpc_con.send_msg(rpc_msg)
                    while True:
                        msg = rpc_con.recv_msg()
                        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")
示例#2
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):
                    s = socket.create_connection((hostname, port))
                    rpc_con = CtlSecSocket(s)
                    try:
                        rpc_con.handshake(machine["security"])
                    except SecSocketException:
                        logging.error("Failed authentication for machine %s" %\
                                      hostname)
                        continue

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

                    logging.debug("Calling cleanup on slave '%s'" % hostname)
                    rpc_con.send_msg(rpc_msg)
                    while True:
                        msg = rpc_con.recv_msg()
                        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")
示例#3
0
文件: Wizard.py 项目: wngjan/lnst
 def _get_suitable_interfaces(self, hostname, port):
     """
     Calls all functions, which are used by both interactive and
     noninteractive mode to get list of suitable interfaces. The list is
     saved to variable msg.
     """
     if not test_tcp_connection(hostname, port):
         sys.stderr.write("Host destination '%s:%s' unreachable.\n"
                           % (hostname, port))
         return False
     if not self._connect_and_configure_machine(hostname, port):
         return False
     msg =  self._get_device_ifcs(hostname, port)
     self._msg_dispatcher.disconnect_slave(1)
     return msg
示例#4
0
文件: SlavePool.py 项目: vicgc/lnst
    def add_file(self, filepath):
        if os.path.isfile(filepath) and re.search("\.xml$", filepath, re.I):
            dirname, basename = os.path.split(filepath)
            m_id = re.sub("\.[xX][mM][lL]$", "", basename)

            parser = SlaveMachineParser(filepath)
            xml_data = parser.parse()
            machine_spec = self._process_machine_xml_data(m_id, xml_data)

            # Check if there isn't any machine with the same
            # hostname or libvirt_domain already in the pool
            for pm_id, m in self._pool.iteritems():
                pm = m["params"]
                rm = machine_spec["params"]
                if pm["hostname"] == rm["hostname"]:
                    msg = "You have the same machine listed twice in " "your pool ('%s' and '%s')." % (m_id, pm_id)
                    raise SlaveMachineError(msg)

                if "libvirt_domain" in rm and "libvirt_domain" in pm and pm["libvirt_domain"] == rm["libvirt_domain"]:
                    msg = "You have the same libvirt_domain listed twice in " "your pool ('%s' and '%s')." % (
                        m_id,
                        pm_id,
                    )
                    raise SlaveMachineError(msg)

            if self._pool_checks:
                available = False

                hostname = machine_spec["params"]["hostname"]
                if "rpc_port" in machine_spec["params"]:
                    port = machine_spec["params"]["rpc_port"]
                else:
                    port = lnst_config.get_option("environment", "rpcport")

                logging.debug("Querying machine '%s': %s:%s" % (m_id, hostname, port))
                if test_tcp_connection(hostname, port):
                    available = True

                if "libvirt_domain" in machine_spec["params"] and not self._allow_virt:
                    logging.debug("libvirtd not running. Removing " "libvirt_domain from machine '%s'" % m_id)
                    del machine_spec["params"]["libvirt_domain"]

            if available:
                self._pool[m_id] = machine_spec
            return (m_id, available)
示例#5
0
文件: SlavePool.py 项目: pazdera/lnst
    def add_file(self, filepath):
        if os.path.isfile(filepath) and re.search("\.xml$", filepath, re.I):
            dom_init = XmlDomTreeInit()
            dom = dom_init.parse_file(filepath)

            dirname, basename = os.path.split(filepath)

            parser = SlaveMachineParse()
            parser.set_include_root(dirname)
            parser.disable_events()

            machine = {"params": {}, "interfaces": {}}
            m_id = re.sub("\.[xX][mM][lL]$", "", basename)
            parser.set_machine(m_id, machine)

            slavemachine = dom.getElementsByTagName("slavemachine")[0]

            parser.parse(slavemachine)

            if self._pool_checks:
                hostname = machine["params"]["hostname"]
                if "rpcport" in machine:
                    port = machine["params"]["rpcport"]
                else:
                    port = lnst_config.get_option('environment', 'rpcport')

                logging.info("Querying slave machine %s." % m_id)
                if not test_tcp_connection(hostname, port):
                    msg = "Machine '%s' not responding. Skipping." % m_id
                    logging.warning(msg)
                    return

                if 'libvirt_domain' in machine['params'] and \
                   not self._allow_virt:
                    msg = "libvird not running. Skipping machine '%s'." % m_id
                    logging.warning(msg)

            logging.info("Adding slave machine %s to slave pool." % m_id)
            self._pool[m_id] = machine
示例#6
0
文件: SlavePool.py 项目: pazdera/lnst
    def add_file(self, filepath):
        if os.path.isfile(filepath) and re.search("\.xml$", filepath, re.I):
            dom_init = XmlDomTreeInit()
            dom = dom_init.parse_file(filepath)

            dirname, basename = os.path.split(filepath)

            parser = SlaveMachineParse()
            parser.set_include_root(dirname)
            parser.disable_events()

            machine = {"params": {}, "interfaces": {}}
            m_id = re.sub("\.[xX][mM][lL]$", "", basename)
            parser.set_machine(m_id, machine)

            slavemachine = dom.getElementsByTagName("slavemachine")[0]

            parser.parse(slavemachine)

            if self._pool_checks:
                hostname = machine["params"]["hostname"]
                if "rpcport" in machine:
                    port = machine["params"]["rpcport"]
                else:
                    port = lnst_config.get_option("environment", "rpcport")

                logging.info("Querying slave machine %s." % m_id)
                if not test_tcp_connection(hostname, port):
                    msg = "Machine '%s' not responding. Skipping." % m_id
                    logging.warning(msg)
                    return

                if "libvirt_domain" in machine["params"] and not self._allow_virt:
                    msg = "libvird not running. Skipping machine '%s'." % m_id
                    logging.warning(msg)

            logging.info("Adding slave machine %s to slave pool." % m_id)
            self._pool[m_id] = machine