コード例 #1
0
ファイル: remote.py プロジェクト: mastbaum/dirt
def node_recon(nodelist, interactive=True):
    """grab system information from a list of hosts and create or update
    nodes' db entries.
    """
    import execnet
    from dirt.tasks import system_info
    from dirt.core.db import db

    nodes = db.get_nodes()
    for node in nodelist:
        log.write("Connecting to host %s" % node)
        try:
            gw = execnet.makegateway("ssh=%s" % node)
        except execnet.HostNotFound:
            log.write("Host not found: %s" % node)
            continue
        log.write("Connected to host %s" % node)

        ch = gw.remote_exec(system_info)
        sys_info = ch.receive()

        # update the db
        if sys_info["fqdn"] in nodes:
            d = nodes[sys_info["fqdn"]]
            d["sys_info"] = sys_info
            d["enabled"] = True
        else:
            d = {"type": "node", "fqdn": sys_info["fqdn"], "sys_info": sys_info}
            log.write("Adding new node %(fqdn)s to database" % d)
            d["enabled"] = settings.node_enable_default
        db.save(d)
コード例 #2
0
ファイル: server.py プロジェクト: mastbaum/dirt
def signal_handler(signal, frame):
    '''handle SIGINTs gracefully, clearing running tasks from the db'''
    log.write('Caught SIGINT (Ctrl-C), Exiting.')

    # clear any currently-running tasks from db
    log.write('Clearing running tasks from database')
    nodes = db.get_nodes()
    for node in nodes:
        if 'alloc' in nodes[node]:
            for i in range(len(nodes[node]['alloc'])):
                # only clear tasks from this master
                alloc = nodes[node]['alloc'][i]
                if alloc['master'] == socket.getfqdn():
                    doc = db[alloc['task']]
                    if 'started' in doc:
                        del doc['started']
                    if 'node' in doc:
                        del doc['node']
                    db.save(doc)
                    node_doc = db[nodes[node]['_id']]
                    node_doc['alloc'].pop(i)
                    db.save(node_doc)
    sys.exit(0)