コード例 #1
0
def waitForSignal(session):
    # Wait up to 10 seconds for signal
    event = cqmf2.ConsoleEvent()
    while session._impl.nextEvent(event, cqpid.Duration(10000)):
        if event.getType() == cqmf2.CONSOLE_EVENT and event.getAgent(
        ).getAttributes()['_product'] == 'DBusBridge':
            return event
    return None
コード例 #2
0
 def update(self, timeout=5):
     dur = cqpid.Duration(cqpid.Duration.SECOND.getMilliseconds() * timeout)
     agent = self._impl.getAgent()
     query = cqmf2.Query(self._impl.getAddr())
     result = agent.query(query, dur)
     if result.getType() != cqmf2.CONSOLE_QUERY_RESPONSE:
         raise "Update query failed"
     if result.getDataCount == 0:
         raise "Object no longer exists on agent"
     self._impl = cqmf2.Data(result.getData(0))
コード例 #3
0
 def query(self, q, timeout=30):
     """
 """
     if q.__class__ == Query:
         q_arg = q._impl
     else:
         q_arg = q
     dur = cqpid.Duration(cqpid.Duration.SECOND.getMilliseconds() * timeout)
     result = self._impl.query(q_arg, dur)
     if result.getType() == cqmf2.CONSOLE_EXCEPTION:
         raise Exception(Data(result.getData(0)))
     if result.getType() != cqmf2.CONSOLE_QUERY_RESPONSE:
         raise Exception(
             "Protocol error, expected CONSOLE_QUERY_RESPONSE, got %d" %
             result.getType())
     dataList = []
     count = result.getDataCount()
     for i in range(count):
         dataList.append(Data(result.getData(i)))
     return dataList
コード例 #4
0
    def _invoke(self, name, args, kwargs):
        ##
        ## Get local copies of the agent and the address of the data object
        ##
        agent = self._impl.getAgent()
        addr = self._impl.getAddr()

        ##
        ## Set up the timeout duration for the method call.  Set the default and override
        ## it if the _timeout keyword arg was supplied.
        ##
        timeout = 30
        if '_timeout' in kwargs:
            timeout = kwargs['_timeout']
        dur = cqpid.Duration(cqpid.Duration.SECOND.getMilliseconds() * timeout)

        ##
        ## Get the list of arguments from the schema, isolate those that are IN or IN_OUT,
        ## validate that we have the right number of arguments supplied, and marshall them
        ## into a map for transmission.
        ##
        arglist = []
        methods = self._schema.getMethods()
        for m in methods:
            if m.getName() == name:
                arglist = m.getArguments()
                break
        argmap = {}
        count = 0
        for a in arglist:
            if a.getDirection() == DIR_IN or a.getDirection() == DIR_IN_OUT:
                count += 1
        if count != len(args):
            raise Exception("Wrong number of arguments: expected %d, got %d" %
                            (count, len(args)))
        i = 0
        for a in arglist:
            if a.getDirection() == DIR_IN or a.getDirection() == DIR_IN_OUT:
                argmap[a.getName()] = args[i]
                i += 1

        ##
        ## Invoke the method through the agent proxy.
        ##
        result = agent.callMethod(name, argmap, addr, dur)

        ##
        ## If the agent sent an exception, raise it in a QmfAgentException.
        ##
        if result.getType() == cqmf2.CONSOLE_EXCEPTION:
            exdata = result.getData(0)
            raise QmfAgentException(exdata)

        ##
        ## If a successful method response was received, collect the output arguments into a map
        ## and return them to the caller.
        ##
        if result.getType() != cqmf2.CONSOLE_METHOD_RESPONSE:
            raise Exception(
                "Protocol error: Unexpected event type in method-response: %d"
                % result.getType())
        return result.getArguments()
コード例 #5
0
 def getSchema(self, schemaId, timeout=30):
     """
 """
     dur = cqpid.Duration(cqpid.Duration.SECOND.getMilliseconds() * timeout)
     return Schema(self._impl.getSchema(schemaId._impl, dur))
コード例 #6
0
 def loadSchemaInfo(self, timeout=30):
     """
 """
     dur = cqpid.Duration(cqpid.Duration.SECOND.getMilliseconds() * timeout)
     self._impl.querySchema(dur)