def DeleteChunk(self, volumes): stub = self.getStub() arg = msg.DeleteChunk_Request() if not isinstance(volumes, list): volumes = [volumes] for volume in volumes: t = arg.guids.add() volguid = Guid.fromStr(volume.guid) Guid.assign(t, volguid) ret = stub.callMethod('DeleteChunk', arg)
def recvRpc(s): fd = s.makefile() parts = fd.readline().split() if len(parts) == 0: raise ServiceTerminated() guid = Guid.fromStr(parts[0]) token = int(parts[1]) name = parts[2] size = int(parts[3]) body = fd.read(size) fd.close() if len(body) != size: raise IOError('Invalid rpc message') return guid, token, name, body
def recvRpc(s): fd=s.makefile() parts=fd.readline().split() if len(parts)==0: raise ServiceTerminated() guid=Guid.fromStr(parts[0]) token=int(parts[1]) name=parts[2] size=int(parts[3]) body=fd.read(size) fd.close() if len(body)!=size: raise IOError('Invalid rpc message') return guid,token,name,body
def doHeartBeat(self, serviceport, stub): serviceip=stub.socket.getsockname()[0] while True: info=msg.ChunkServerInfo() info.ServiceAddress=serviceip info.ServicePort=serviceport self.lvm.reload_softsan_lvs() for lv in self.lvm.softsan_lvs: chk=info.chunks.add() name4guid = lv.name.split(self.prefix_vol)[1] Guid.assign(chk.guid, Guid.fromStr(name4guid)) chk.size = int(lv.get_sizes(lv.total_extents)[2]) stub.callMethod('ChunkServerInfo', info) print 'for test--------------------------------', random.randint(0,100) gevent.sleep(1)
def doHeartBeat(self, serviceport, stub): serviceip = stub.socket.getsockname()[0] while True: info = msg.ChunkServerInfo() info.ServiceAddress = serviceip info.ServicePort = serviceport self.lvm.reload_softsan_lvs() for lv in self.lvm.softsan_lvs: chk = info.chunks.add() name4guid = lv.name.split(self.prefix_vol)[1] Guid.assign(chk.guid, Guid.fromStr(name4guid)) chk.size = int(lv.get_sizes(lv.total_extents)[2]) stub.callMethod("ChunkServerInfo", info) print "for test--------------------------------", random.randint(0, 100) gevent.sleep(1)
def object2message(object, message): import guid as Guid, messages_pb2 as msg d = object if isinstance(object, dict) else object.__dict__ for key in d: if key.startswith('_'): continue value=d[key] if isinstance(value, list): mfield=getattr(message, key) appender = (lambda x : mfield.append(x)) if hasattr(mfield, 'append') \ else (lambda x : object2message(x, mfield.add())) for item in value: appender(item) else: try: if key == 'guid': value=Guid.fromStr(value) Guid.assign(message.guid, value) else: setattr(message, key, value) except: print 'exception occured' pass
def object2message(object, message): import guid as Guid, messages_pb2 as msg d = object if isinstance(object, dict) else object.__dict__ for key in d: if key.startswith('_'): continue value = d[key] if isinstance(value, list): mfield = getattr(message, key) appender = (lambda x : mfield.append(x)) if hasattr(mfield, 'append') \ else (lambda x : object2message(x, mfield.add())) for item in value: appender(item) else: try: if key == 'guid': value = Guid.fromStr(value) Guid.assign(message.guid, value) else: setattr(message, key, value) except: print 'exception occured' pass