Exemple #1
0
 def request(self, op, *args, **kwargs):
     log_debug('RPCClient', 'start to request, op=%s' % str(op))
     buf = pack(op, args, kwargs)
     res = self.dpmclient.request(self.addr, self.port, buf)
     if res:
         ret = loads(res)
         return ret['res']
Exemple #2
0
 def request(self, op, *args, **kwargs):
     log_debug('RPCClient', 'start to request, op=%s' % str(op))
     buf = pack(op, args, kwargs)
     res = self.dpmclient.request(self.addr, self.port, buf)
     if res:
         ret = loads(res)
         return ret['res']
Exemple #3
0
 def _request(self, addr, **args):
     sock = io.connect(addr, WORKER_PORT)
     try:
         buf = bson.dumps(args)
         io.send_pkt(sock, buf)
         res = io.recv_pkt(sock)
         return unicode2str(bson.loads(res)['result'])
     finally:
         io.close(sock)
Exemple #4
0
def unpack(buf):
    tmp = loads(buf)
    if type(tmp) != dict or not tmp.has_key('op') or not tmp.has_key('args') or not tmp.has_key('kwargs'):
        log_err('package', 'failed to unpack, invalid type')
        return
    op = tmp['op']
    args = tmp['args']
    kwargs = tmp['kwargs']
    if type(op) != str or type(args) != list or type(kwargs) != dict:
        log_err('package', 'failed to unpack, invalid arguments')
        return
    return (op, args, kwargs)
Exemple #5
0
def put(addr, port, code, args):
    if not code or type(args) != dict:
        raise Exception('Error: cannot process')

    sock = io.connect(addr, port)
    try:
        buf = bson.dumps({'code':code, 'args':args})
        io.send_pkt(sock, buf)
        res = io.recv_pkt(sock)
        return unicode2str(bson.loads(res)[''])
    finally:
        io.close(sock)
Exemple #6
0
def unpack(buf):
    tmp = loads(buf)
    if type(tmp) != dict or not tmp.has_key('op') or not tmp.has_key(
            'args') or not tmp.has_key('kwargs'):
        log_err('package', 'failed to unpack, invalid type')
        return
    op = tmp['op']
    args = tmp['args']
    kwargs = tmp['kwargs']
    if type(op) != str or type(args) != list or type(kwargs) != dict:
        log_err('package', 'failed to unpack, invalid arguments')
        return
    return (op, args, kwargs)
Exemple #7
0
 def handle(self):
     try:
         res = ''
         buf = io.recv_pkt(self.request)
         if buf:
             req = unicode2str(bson.loads(buf))
             if type(req) == dict:
                 device = _manager.compute_unit
                 ret = _exec(device, req['code'], **req['args'])
                 if ret:
                     res = ret
         io.send_pkt(self.request, bson.dumps({'':res}))
     except:
         pass
Exemple #8
0
 def request(self, op, *args, **kwargs):
     buf = pack(op, args, kwargs)
     res = self.dpmclient.request(self.addr, self.port, buf)
     if res:
         ret = loads(res)
         return ret['res']