예제 #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']
예제 #2
0
파일: rpcclient.py 프로젝트: tx626/dpmtest
 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']
예제 #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)
예제 #4
0
파일: package.py 프로젝트: tx626/dpm
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)
예제 #5
0
파일: proc.py 프로젝트: virtdev/virtdev
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)
예제 #6
0
파일: package.py 프로젝트: tx626/dpm
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)
예제 #7
0
파일: proc.py 프로젝트: virtdev/virtdev
 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
예제 #8
0
파일: rpcclient.py 프로젝트: tx626/dpm
 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']