def _keep_alive(self): try: if self._agent_alive == False: self._protocol = self._agent_conn_open() if self._protocol == None: return #from instance_service import InstanceService service = InstanceService.Client(self._protocol) aa_latest = service.KeepAliveCheck() if self._agent_alive == False and aa_latest == True: port_l = [v for k, v in self._port_dict.iteritems()] LOG.debug(_('Agent sending port list %d, %s'), len(port_l), self) if len(port_l): for i in range(len(port_l)): LOG.debug(_('Port %s %s'), port_l[i].tap_name, port_l[i].ip_address) service.AddPort(port_l) self._agent_alive = True return if self._agent_alive == True and aa_latest == False: LOG.debug(_('Agent not available, %s'), self) self._agent_alive = False return except: self._agent_alive = False LOG.debug(_('Agent keep alive exception: %s'), self)
def _agent_inform(self, port, id, add): # First add to the port list if add == True: self._port_dict[id] = port else: if id in self._port_dict: del self._port_dict[id] if not self._agent_alive: return #from instance_service import InstanceService LOG.debug(_('agent_inform %s, %s, %s, %s'), port.ip_address, port.tap_name, add, self) import socket try: service = InstanceService.Client(self._protocol) if add == True: service.AddPort([port]) else: service.DeletePort(port.port_id) except: self._agent_alive = False
def _agent_connect(self, protocol): # Agent connect for first time if protocol != None: #from instance_service import InstanceService service = InstanceService.Client(protocol) return service.Connect() else: return False
def _rpc_client_instance(self): """ Return an RPC client connection """ import thrift.transport.TSocket as TSocket socket = TSocket.TSocket('127.0.0.1', 9090) try: transport = TTransport.TFramedTransport(socket) transport.open() except thrift.transport.TTransport.TTransportException: logging.error('Connection failure') return None protocol = TBinaryProtocol.TBinaryProtocol(transport) client = InstanceService.Client(protocol) return client
def _rpc_client_instance(self): """ Return an RPC client connection """ import thrift.transport.TSocket as TSocket socket = TSocket.TSocket('localhost', self._server_port) try: transport = TTransport.TFramedTransport(socket) transport.open() except TTransport.TTransportException: logging.error('Unable to connect to contrail-vrouter-agent ' 'localhost:%d' % self._server_port) return None protocol = TBinaryProtocol.TBinaryProtocol(transport) client = InstanceService.Client(protocol) return client