Guest User

Untitled

a guest
Oct 29th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. class DialInClient(object):
  2. def __init__(self, host, port, timeout=100000000, user='root', password='lablab'):
  3. self._host = host
  4. self._port = port
  5. self._timeout = float(timeout)
  6. self._channel = None
  7. self._cisco_ems_stub = None
  8. self._connected = False
  9. self._metadata = [('username', user), ('password', password)]
  10.  
  11. def subscribe(self, sub_id):
  12. sub_args = CreateSubsArgs(ReqId=1, encode=3, subidstr=sub_id)
  13. stream = self._cisco_ems_stub.CreateSubs(sub_args, timeout=self._timeout, metadata=self._metadata)
  14. for segment in stream:
  15. yield segment
  16.  
  17. def connect(self):
  18. self._channel = grpc.insecure_channel(':'.join([self._host,self._port]))
  19. try:
  20. grpc.channel_ready_future(self._channel).result(timeout=10)
  21. self._connected = True
  22. except grpc.FutureTimeoutError as e:
  23. raise DeviceFailedToConnect from e
  24. else:
  25. self._cisco_ems_stub = gRPCConfigOperStub(self._channel)
Add Comment
Please, Sign In to add comment