示例#1
0
def remove_nodes(namelist):

    dbconn = DBConnManager.get_session()

    nodes = dbconn.query(Node).filter(Node.nodename.in_(namelist)).all()
    if not nodes:
        return None, None

    valid_node_names = [ node.nodename for node in nodes ]
    invalid_node_names = list(set(namelist) - set(valid_node_names))

    nidlist = [ node.nid for node in nodes ]
    nics = dbconn.query(Nic).filter(Nic.nid.in_(nidlist)).filter(Nic.nictype==NICTYPE_BOOT).all()

    macfiles = [ "01-%s" % nic.mac.replace(':', "-") for nic in nics ]
    rmcmd = "cd %s; rm -fr %s" % (PXEFILE_DIR, " ".join(macfiles))
    os.system(rmcmd) 
    
    #dbconn.query(Node).filter(Node.nodename.in_(namelist)).delete(synchronize_session='fetch')
    for node in nodes:
        dbconn.delete(node)

    dbconn.commit()
    dbconn.close()

    return valid_node_names, invalid_node_names
示例#2
0
def gennetbootpxe(mac):
    # necessary information
    dbconn = DBConnManager.get_session()
    installerip = get_installer_ip(dbconn)
   
    # gengerate file content
    pxetmpl = Template(file=NETBOOT_TMPL, searchList=[{'parentip': installerip}])
    content = str(pxetmpl)

    # generate pxe file
    macfilename = "01-%s" % (mac.replace(":", "-"))
    macfile = "%s/%s" % (PXEFILE_DIR, macfilename.lower())
    target = file(macfile, 'w')
    target.writelines(content)
    target.close()
    os.chmod(macfile, 0666)