-
Notifications
You must be signed in to change notification settings - Fork 9
/
locations.py
38 lines (28 loc) · 1.03 KB
/
locations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import logging
import socket
import grpc
from grpc_support import CannotConnectException
from grpc_support import grpc_url
from utils import setup_logging
from proto.location_service_pb2 import ClientInfo
from proto.location_service_pb2 import LocationServiceStub
logger = logging.getLogger(__name__)
class Locations(object):
def __init__(self, hostname):
url = grpc_url(hostname)
try:
channel = grpc.insecure_channel(url)
self._stub = LocationServiceStub(channel)
self._client_info = ClientInfo(info="{0} client".format(socket.gethostname()))
self._server_info = self._stub.registerClient(self._client_info)
except grpc._channel._Rendezvous:
raise CannotConnectException(url)
def values(self):
return self._stub.getLocations(self._client_info)
def main():
setup_logging()
for val in Locations("localhost").values():
logger.info("Read value:\n{0}".format(val))
logger.info("Exiting...")
if __name__ == "__main__":
main()