Пример #1
0
def get_state(proc_name):
    exec_cmd_msg = exec_cmd_pb2.Exec_Cmd()
    exec_cmd_msg.command = exec_cmd_pb2.Exec_Cmd.STATE
    exec_cmd_msg.name = proc_name
    msg = exec_cmd_msg.SerializeToString()
    unixIPC.send("exec_cmd_pb2",msg)
    flush()
    msgs = unixIPC.waitForRecv();
    if len(msgs) == 0:
        print "ERROR: IPC timeout to mod_exec during get_state()";
    else:
        # Bad idea ahead. Works for mod_exec b/c it only sends solicited exec_resp messages
        if len(msgs) > 1:
            print "Note: Uh-oh, I ate extra messages: ",msgs[1:len(msgs)]
        (type, msg, client) = msgs[0];
        exec_resp_msg = exec_resp_pb2.Exec_Resp()
        exec_resp_msg.ParseFromString(msg);
        if exec_resp_msg.type == exec_resp_pb2.Exec_Resp.STATE:
            if exec_resp_msg.processes[0].name == proc_name:
                if exec_resp_msg.processes[0].state == exec_resp_pb2.Exec_Resp.RUNNING:
                    return RUNNING;
                elif exec_resp_msg.processes[0].state == exec_resp_pb2.Exec_Resp.STOPPED:
                    return STOPPED;
                elif exec_resp_msg.processes[0].state == exec_resp_pb2.Exec_Resp.RESTARTING:
                    return RESTARTING;
            else:
                print "ERROR: mod_exec response to a read did not return the same process name!"
        else:
            print "ERROR: Expected STATE response but got",exec_resp_msg.type
Пример #2
0
def proc_end():
    msgs = unixIPC.waitForRecv();
    if ( len(msgs) > 0 ):
        (typ,msg,client) = msgs[-1]
        if ( typ == 'xbee_relay_resp_pb2'):
            resp = xbee_relay_resp_pb2.XBee_Relay_Resp()
            resp.ParseFromString(msg)
            if ( resp.code == xbee_relay_resp_pb2.XBee_Relay_Resp.SUCCESS ):
                return SUCCESS
            elif ( resp.code == xbee_relay_resp_pb2.XBee_Relay_Resp.ADDRESS_NOT_FOUND ):
                return ADDRESS_NOT_FOUND
            elif ( resp.code == xbee_relay_resp_pb2.XBee_Relay_Resp.NETWORK_TIMEOUT ):
                return NETWORK_TIMEOUT
            
    return NETWORK_TIMEOUT
Пример #3
0
def list():
    exec_cmd_msg = exec_cmd_pb2.Exec_Cmd()
    exec_cmd_msg.command = exec_cmd_pb2.Exec_Cmd.LIST
    msg = exec_cmd_msg.SerializeToString()
    unixIPC.send("exec_cmd_pb2",msg)
    flush()
    msgs = unixIPC.waitForRecv();
    if len(msgs) == 0:
        print "ERROR: IPC timeout to mod_exec during list()";
    else:
        # Bad idea ahead. Works for mod_exec b/c it only sends solicited exec_resp messages
        if len(msgs) > 1:
            print "Note: Uh-oh, I ate extra messages: ",msgs[1:len(msgs)]
        (type, msg, client) = msgs[0];
        exec_resp_msg = exec_resp_pb2.Exec_Resp()
        
        try:
            exec_resp_msg.ParseFromString(msg);
        except google.protobuf.message.DecodeError:
            print "Error parsing exec_resp_msg"  
            
        if exec_resp_msg.type == exec_resp_pb2.Exec_Resp.STATE:
            retval = [];
            for proc in exec_resp_msg.processes:
                p = Process()
                p.name = proc.name;
                if proc.state == exec_resp_pb2.Exec_Resp.RUNNING:
                    p.state =  RUNNING;
                elif proc.state == exec_resp_pb2.Exec_Resp.STOPPED:
                    p.state = STOPPED;
                elif proc.state == exec_resp_pb2.Exec_Resp.RESTARTING:
                    p.state = RESTARTING;
                retval.append(p);
            return retval;
        else:
            print "ERROR: Expected STATE response but got",exec_resp_msg.type