Beispiel #1
0
def Save_SysInfo(sysInfo, sysInfo_lock, 
                 filename=sysCfg.SYSTEM_INFO):
    sysInfo_lock.acquire()
    try:
        sysInfo_d = node_enum_to_str(sysInfo.getDict(), sysNode=True)
        with open(filename, 'w') as file_h:
            json.dump(sysInfo_d, file_h)
        logging.debug('Successfully saved the following ' \
                      'System (Node) Information to %s \n%s' % \
                      (filename, str(sysInfo)))
    finally:
        sysInfo_lock.release()
Beispiel #2
0
def Save_NodeStore(node_store, node_store_lock, 
                   filename=sysCfg.NODE_STORE):
    node_store_lock.acquire()
    try:
        node_dict = {}
        # key = nodeId 
        # value = dict(object of type Node())
        for nId, n in node_store.iteritems():
            node_dict[nId] = node_enum_to_str(n.getDict())
        with open(filename, 'w') as file_h:
            json.dump(node_dict, file_h)
        logging.debug('Saved %d Node(s) to %s' % \
                     (len(node_dict), filename))
    finally:
        node_store_lock.release()
Beispiel #3
0
def Load_SysInfo(filename=sysCfg.SYSTEM_INFO):

    # if the persistence file does not exist,
    # then create one from the user config
    if not os.path.exists(filename): 
        logging.debug('%s does not exist; creating one ' \
                      'based on user config' % filename)
        usrConfig = usrCfg.SYSTEM_DEFAULT_SETTINGS[sysCfg.OADR_NODE.VEN]
        sysNode_d = node_enum_to_str(usrConfig, sysNode=True)
        with open(filename, 'w') as file_h:
            json.dump(sysNode_d, file_h)

    # if the persistence file already exist, 
    # then read from that!
    with open(filename, 'r') as file_h:
        usrConfig = json.load(file_h)
    sysNode_d = node_str_to_enum(usrConfig, sysNode=True)
    sysInfo = Node(sysNode=True, **sysNode_d)
    logging.debug('Loaded System Information Successfully ' \
                  'from %s' % filename)
    logging.info(str(sysInfo))
    return sysInfo