diff --git a/src/vnsw/contrail-vrouter-api/MANIFEST.in b/src/vnsw/contrail-vrouter-api/MANIFEST.in deleted file mode 100644 index e610d65f9d1..00000000000 --- a/src/vnsw/contrail-vrouter-api/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -include *.txt -prune contrail_vrouter_api/tests \ No newline at end of file diff --git a/src/vnsw/contrail-vrouter-api/SConscript b/src/vnsw/contrail-vrouter-api/SConscript index 90d81293585..ba6107304b6 100644 --- a/src/vnsw/contrail-vrouter-api/SConscript +++ b/src/vnsw/contrail-vrouter-api/SConscript @@ -8,22 +8,11 @@ Import('BuildEnv') env = BuildEnv.Clone() sources = [ - 'MANIFEST.in', - 'requirements.txt', 'setup.py', - 'test-requirements.txt', 'contrail_vrouter_api/__init__.py', 'contrail_vrouter_api/vrouter_api.py', - 'contrail_vrouter_api/tests/__init__.py', - 'contrail_vrouter_api/tests/instance_server.py', - 'contrail_vrouter_api/tests/test_vrouter_api.py', - 'contrail_vrouter_api/tests/test_vrouter_api_connection.py', ] -sources += env.ThriftGenPy( - '#controller/src/vnsw/agent/openstack/instance_service.thrift', - 'contrail_vrouter_api') - cd_cmd = 'cd ' + Dir('.').path + ' && ' sdist_gen = env.Command('dist/contrail-vrouter-api-1.0.tar.gz', sources, @@ -31,41 +20,6 @@ sdist_gen = env.Command('dist/contrail-vrouter-api-1.0.tar.gz', env.Alias('controller/src/vnsw/contrail_vrouter_api:sdist', sdist_gen) -test_sources = sources -packages = [ -] - -def BuildPyTestSetup(env, target, source): - file = open(target[0].abspath, 'w') - file.write("[easy_install]\nfind_links =") - for pkg in source: - dependency = env.File(pkg) - file.write(" %s" % os.path.dirname(dependency.abspath)) - file.write("\n") - file.close() - return - -def GeneratePyTestSetup(env, targets, source): - """ - Generate a setup.cfg file that contains a list of directories - where dependent packages can be found. The fact that package directory - list is being given as a source automatically adds them as dependencies. - """ - target = env.File('setup.cfg') - return env.Command(target=target, source=source, action=BuildPyTestSetup); - -env.Append(BUILDERS = {'PythonTestSetup': GeneratePyTestSetup}) -test_sources += env.PythonTestSetup(source=packages) - -test = env.Command(None, test_sources, - cd_cmd + 'python setup.py test') - - -env.Alias('controller/src/vnsw/contrail_vrouter_api:test', test) - -# This add'l alias is to allow retry of UT in CI -env.Alias('controller/src/vnsw/contrail-vrouter-api/contrail_vrouter_api:test', test) - if 'install' in BUILD_TARGETS: install_cmd = env.Command(None, sources, cd_cmd + 'python setup.py install %s' % diff --git a/src/vnsw/contrail-vrouter-api/contrail_vrouter_api/tests/__init__.py b/src/vnsw/contrail-vrouter-api/contrail_vrouter_api/tests/__init__.py deleted file mode 100644 index 8b137891791..00000000000 --- a/src/vnsw/contrail-vrouter-api/contrail_vrouter_api/tests/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/vnsw/contrail-vrouter-api/contrail_vrouter_api/tests/instance_server.py b/src/vnsw/contrail-vrouter-api/contrail_vrouter_api/tests/instance_server.py deleted file mode 100644 index b078882ab57..00000000000 --- a/src/vnsw/contrail-vrouter-api/contrail_vrouter_api/tests/instance_server.py +++ /dev/null @@ -1,93 +0,0 @@ -# Copyright (c) 2014 Juniper Networks, Inc - -import argparse -import os -import signal -import sys -import uuid - -def import_path_setup(): - """ Test environment managed by easy_install """ - sys.path.append(os.curdir) - for lsentry in os.listdir(os.curdir): - if not os.path.isdir(lsentry): - continue - if lsentry.endswith('.egg'): - sys.path.append(lsentry) - -if __name__ == '__main__': - import_path_setup() - -from thrift.protocol import TBinaryProtocol -from thrift.transport import TTransport -import thrift.transport.TSocket as TSocket -from thrift.server import TServer - -from contrail_vrouter_api.gen_py.instance_service import InstanceService - -class VRouterApiServer(object): - def __init__(self): - self._dict = {} - - def _uuid_from_bytes(self, byte_array): - return uuid.UUID(bytes=''.join([chr(x) for x in byte_array])) - - def _store(self, port): - item = {} - item['uuid'] = str(self._uuid_from_bytes(port.port_id)) - item['instance'] = str(self._uuid_from_bytes(port.instance_id)) - item['network'] = str(self._uuid_from_bytes(port.vn_id)) - item['display_name'] = port.display_name - return item - - def AddPort(self, port_list): - for port in port_list: - uid = self._uuid_from_bytes(port.port_id) - self._dict[str(uid)] = self._store(port) - return True - - def KeepAliveCheck(self): - return True - - def Connect(self): - return True - - def DeletePort(self, port_id): - return True - - def dump(self): - import json - print json.dumps(self._dict) - -def create_server(handler, port): - processor = InstanceService.Processor(handler) - transport = TSocket.TServerSocket(port=port) - tfactory = TTransport.TFramedTransportFactory() - pfactory = TBinaryProtocol.TBinaryProtocolFactory() - server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) - return server - -def interrupt_handler(signal, frame): - global handler - handler.dump() - sys.exit(0) - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument("-p", "--server-port", type=int, help="Server Port") - arguments = parser.parse_args(sys.argv[1:]) - - global handler - handler = VRouterApiServer() - signal.signal(signal.SIGTERM, interrupt_handler) - server = create_server(handler, arguments.server_port) - try: - server.serve() - except IOError as ex: - import errno - if ex.errno != errno.EINTR: - raise - -if __name__ == '__main__': - main() - diff --git a/src/vnsw/contrail-vrouter-api/contrail_vrouter_api/tests/test_vrouter_api.py b/src/vnsw/contrail-vrouter-api/contrail_vrouter_api/tests/test_vrouter_api.py deleted file mode 100644 index 7f72471e863..00000000000 --- a/src/vnsw/contrail-vrouter-api/contrail_vrouter_api/tests/test_vrouter_api.py +++ /dev/null @@ -1,100 +0,0 @@ -# Copyright (c) 2014 Juniper Networks, Inc - -import mock -import unittest -import uuid - -from contrail_vrouter_api.vrouter_api import ContrailVRouterApi -from contrail_vrouter_api.gen_py.instance_service import InstanceService -from contrail_vrouter_api.gen_py.instance_service import ttypes - - -class VRouterApiTest(unittest.TestCase): - def setUp(self): - self._api = ContrailVRouterApi() - - def test_create_port(self): - mock_client = mock.Mock() - self._api._rpc_client_instance = mock.MagicMock( - name='rpc_client_instance') - self._api._rpc_client_instance.return_value = mock_client - self._api.add_port(str(uuid.uuid1()), str(uuid.uuid1()), 'tapX', - 'aa:bb:cc:ee:ff:00') - self.assertTrue(mock_client.AddPort.called) - - def test_delete_port(self): - mock_client = mock.Mock() - self._api._rpc_client_instance = mock.MagicMock( - name='rpc_client_instance') - self._api._rpc_client_instance.return_value = mock_client - - vm_uuid = uuid.uuid1() - vif_uuid = uuid.uuid1() - self._api.add_port(str(vm_uuid), str(vif_uuid), 'tapX', - 'aa:bb:cc:ee:ff:00') - self.assertTrue(mock_client.AddPort.called) - self.assertTrue(self._api._ports[vif_uuid]) - - self._api.delete_port(str(vif_uuid)) - self.assertTrue(mock_client.DeletePort.called) - - def test_resynchronize(self): - self._api._rpc_client_instance = mock.MagicMock( - name='rpc_client_instance') - self._api._rpc_client_instance.return_value = None - - vm_uuid = str(uuid.uuid1()) - vif_uuid = str(uuid.uuid1()) - port1 = ttypes.Port(self._api._uuid_string_to_hex(vif_uuid), - self._api._uuid_string_to_hex(vm_uuid), - 'tapX', '0.0.0.0', [0] * 16, 'aa:bb:cc:ee:ff:00') - self._api.add_port(vm_uuid, vif_uuid, 'tapX', 'aa:bb:cc:ee:ff:00') - - mock_client = mock.Mock() - self._api._rpc_client_instance.return_value = mock_client - self._api.periodic_connection_check() - mock_client.AddPort.assert_called_with([port1]) - - def test_resynchronize_multi_ports(self): - self._api._rpc_client_instance = mock.MagicMock( - name='rpc_client_instance') - self._api._rpc_client_instance.return_value = None - - vm_uuid = str(uuid.uuid1()) - vif_uuid = str(uuid.uuid1()) - port1 = ttypes.Port(self._api._uuid_string_to_hex(vif_uuid), - self._api._uuid_string_to_hex(vm_uuid), - 'tapX', '0.0.0.0', [0] * 16, 'aa:bb:cc:ee:ff:00') - self._api.add_port(vm_uuid, vif_uuid, 'tapX', 'aa:bb:cc:ee:ff:00') - - vm_uuid = str(uuid.uuid1()) - vif_uuid = str(uuid.uuid1()) - port2 = ttypes.Port(self._api._uuid_string_to_hex(vif_uuid), - self._api._uuid_string_to_hex(vm_uuid), - 'tapY', '0.0.0.0', [0] * 16, '11:22:33:44:55:66') - self._api.add_port(vm_uuid, vif_uuid, 'tapY', '11:22:33:44:55:66') - - mock_client = mock.Mock() - self._api._rpc_client_instance.return_value = mock_client - self._api.connect() - self._api._resynchronize() - mock_client.AddPort.assert_called_with([port1, port2]) - - def test_additional_arguments(self): - mock_client = mock.Mock() - self._api._rpc_client_instance = mock.MagicMock( - name='rpc_client_instance') - self._api._rpc_client_instance.return_value = mock_client - vif_uuid = uuid.uuid1() - network_uuid = uuid.uuid1() - project_id = uuid.uuid1().hex - self._api.add_port(str(uuid.uuid1()), str(vif_uuid), 'tapX', - 'aa:bb:cc:ee:ff:00', - vn_id=str(network_uuid), - vm_project_id=project_id) - self.assertTrue(mock_client.AddPort.called) - port = self._api._ports[vif_uuid] - self.assertEqual(self._api._uuid_to_hex(network_uuid), - port.vn_id) - self.assertEqual(self._api._uuid_string_to_hex(project_id), - port.vm_project_id) diff --git a/src/vnsw/contrail-vrouter-api/contrail_vrouter_api/tests/test_vrouter_api_connection.py b/src/vnsw/contrail-vrouter-api/contrail_vrouter_api/tests/test_vrouter_api_connection.py deleted file mode 100644 index e11a8c29c0f..00000000000 --- a/src/vnsw/contrail-vrouter-api/contrail_vrouter_api/tests/test_vrouter_api_connection.py +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright (c) 2014 Juniper Networks, Inc -import subprocess -import time -import unittest -import uuid - -from contrail_vrouter_api.vrouter_api import ContrailVRouterApi - -def PickUnusedPort(): - import socket - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.bind(('localhost', 0)) - addr, port = s.getsockname() - s.close() - return port - -class VRouterApiTestConnection(unittest.TestCase): - - def setUp(self): - self._port = PickUnusedPort() - self._server = None - - def tearDown(self): - if self._server is not None: - self._server.terminate() - - def _start_server(self): - cmd = ['python', 'contrail_vrouter_api/tests/instance_server.py', - '-p', str(self._port)] - self._server = subprocess.Popen(cmd) - - def _try_connect(self, client): - attempts = 3 - while attempts > 0: - if client.connect(): - return - attempts -= 1 - time.sleep(1) - self.fail('Unable to connect to server') - - def test_connection_failure(self): - api = ContrailVRouterApi(server_port=self._port) - self.assertIsNone(api._client) - - def test_unicode(self): - self._start_server() - api = ContrailVRouterApi(server_port=self._port) - self._try_connect(api) - response = api.add_port(str(uuid.uuid1()), str(uuid.uuid1()), 'tapX', - 'aa:bb:cc:ee:ff:00', - display_name=u'p\u227do') - self.assertTrue(response) - diff --git a/src/vnsw/contrail-vrouter-api/contrail_vrouter_api/vrouter_api.py b/src/vnsw/contrail-vrouter-api/contrail_vrouter_api/vrouter_api.py index f5c891a4d62..86810b538fa 100644 --- a/src/vnsw/contrail-vrouter-api/contrail_vrouter_api/vrouter_api.py +++ b/src/vnsw/contrail-vrouter-api/contrail_vrouter_api/vrouter_api.py @@ -1,142 +1,96 @@ -# Copyright (c) 2014 Juniper Networks, Inc - -import logging -import uuid -from thrift.protocol import TBinaryProtocol -from thrift.transport import TTransport -from gen_py.instance_service import InstanceService, ttypes +# Copyright (c) 2016 Juniper Networks, Inc +import subprocess class ContrailVRouterApi(object): def __init__(self, server_port=9090, doconnect=False, semaphore=None): """ + Arguments server_port and doconnect are not used. Retained only + for backward compatibility. + local variables: - _client: current transport connection - _ports: dictionary of active ports keyed by vif uuid. + _ports: dictionary of ports keyed by vif uuid. """ - self._server_port = server_port - self._client = None self._ports = {} - self._connect = doconnect self._semaphore = semaphore - 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) - if client and self._connect: - client.Connect() - return client - def _resynchronize(self): - """ Add all the active ports to the agent """ - self._client.AddPort([port for port in self._ports.itervalues()]) - - def _uuid_from_string(self, idstr): - """ Convert an uuid string into an uuid object """ - if not idstr: - return None - return uuid.UUID(idstr) - - def _uuid_to_hex(self, id): - """ Convert an uuid into an array of integers """ - hexstr = id.hex - return [int(hexstr[i:i + 2], 16) for i in range(32) if i % 2 == 0] - - def _uuid_string_to_hex(self, idstr): - return self._uuid_to_hex(self._uuid_from_string(idstr)) - - def connect(self): - if self._client is None: - self._client = self._rpc_client_instance() - if self._client is None: - return False - if self._connect: - return True - - return self._client.Connect() + """ Add all ports which we failed to add earlier """ + if (len(self._ports) == 0): + return + for key in self._ports.keys(): + ret_code = subprocess.call(self._ports[key]) + """ If port is added successfully, remove it from our list """ + if (ret_code == 0): + self._ports.pop(key, None) def add_port(self, vm_uuid_str, vif_uuid_str, interface_name, mac_address, **kwargs): """ - Add a port to the agent. The information is stored in the _ports - dictionary since the vrouter agent may not be running at the - moment or the RPC may fail. + Add a port to the agent. Ports which we failed to add are stored in + _ports dictionary since the vrouter agent may not be running at the + moment or the REST API call may fail. """ try: if self._semaphore: self._semaphore.acquire() - vif_uuid = self._uuid_from_string(vif_uuid_str) - # ip_address and network_uuid are optional to this API but must - # be present in the message. For instance, when running in - # CloudStack/XenServer/XAPI these arguments are not known. + if 'ip_address' in kwargs: ip_address = kwargs['ip_address'] else: ip_address = '0.0.0.0' + network_uuid = '' if 'vn_id' in kwargs: - network_uuid = self._uuid_string_to_hex(kwargs['vn_id']) - else: - network_uuid = [0] * 16 - - # create port with mandatory arguments - data = ttypes.Port( - self._uuid_to_hex(vif_uuid), - self._uuid_string_to_hex(vm_uuid_str), - interface_name, - ip_address, - network_uuid, - mac_address) - + network_uuid = kwargs['vn_id'] + + display_name='' if 'display_name' in kwargs: - data.display_name = kwargs['display_name'] - if 'hostname' in kwargs: - data.hostname = kwargs['hostname'] + display_name = kwargs['display_name'] + vm_project_id='' + if 'vm_project_id' in kwargs: - data.vm_project_id = self._uuid_string_to_hex( - kwargs['vm_project_id']) + vm_project_id = kwargs['vm_project_id'] if ('port_type' in kwargs and - kwargs['port_type'] in ttypes.PortTypes._NAMES_TO_VALUES.keys()): - data.port_type = \ - ttypes.PortTypes._NAMES_TO_VALUES[kwargs['port_type']] + kwargs['port_type'] in [0,1]): + if (kwargs['port_type'] == 0): + port_type = "NovaVMPort" + elif (kwargs['port_type'] == 1): + port_type = "NameSpacePort" + elif (kwargs['port_type'] == 'NameSpacePort'): + port_type = "NameSpacePort" + else: + port_type = "NovaVMPort" else: - data.port_type = ttypes.PortTypes.NameSpacePort + port_type = "NameSpacePort" + + ip6_address='' if 'ip6_address' in kwargs: - data.ip6_address = kwargs['ip6_address'] + ip6_address = kwargs['ip6_address'] + tx_vlan_id = -1 if 'vlan' in kwargs: - data.vlan_id = kwargs['vlan'] - - data.validate() - - if self._client is None: - self._client = self._rpc_client_instance() - - if self._client is None: - self._ports[vif_uuid] = data - return False + tx_vlan_id = kwargs['vlan'] + + cmd_args = ("vrouter-port-control --oper=\"add\" --uuid=\"%s\" " + "--instance_uuid=\"%s\" --vn_uuid=\"%s\" " + "--vm_project_uuid=\"%s\" --ip_address=\"%s\" " + "--ipv6_address=\"%s\" --vm_name=\"%s\" --mac=\"%s\" " + "--tap_name=\"%s\" --port_type=\"%s\" " + "--vif_type=\"Vrouter\" --tx_vlan_id=\"%d\" " + "--rx_vlan_id=\"%d\"" %(vif_uuid_str, vm_uuid_str, + network_uuid, vm_project_id, ip_address, ip6_address, + display_name, mac_address, interface_name, port_type, + tx_vlan_id, -1)) + + cmd = cmd_args.split() + ret_code = subprocess.call(cmd) + if (ret_code != 0): + self._ports[vif_uuid_str] = cmd self._resynchronize() - self._ports[vif_uuid] = data - - try: - result = self._client.AddPort([data]) - except: - self._client = None - raise - return result finally: if self._semaphore: self._semaphore.release() @@ -149,44 +103,31 @@ def delete_port(self, vif_uuid_str): try: if self._semaphore: self._semaphore.acquire() - vif_uuid = self._uuid_from_string(vif_uuid_str) - self._ports.pop(vif_uuid, None) - - if self._client is None: - self._client = self._rpc_client_instance() - if self._client is None: - return - self._resynchronize() - - try: - self._client.DeletePort(self._uuid_to_hex(vif_uuid)) - except: - self._client = None + if (vif_uuid_str in self._ports.keys()): + self._ports.pop(vif_uuid_str, None) + return + + cmd_args = ("vrouter-port-control --oper=delete --uuid=%s" % vif_uuid_str) + cmd = cmd_args.split() + ret_code = subprocess.call(cmd) + + self._resynchronize() + finally: if self._semaphore: self._semaphore.release() def periodic_connection_check(self): """ - Periodicly check if the connection to the agent is valid. + Periodicly add ports to agent which we failed to add earlier. It is the API client's resposibility to periodically invoke this method. """ try: if self._semaphore: self._semaphore.acquire() - if self._client is None: - self._client = self._rpc_client_instance() - if self._client is None: - return - self._resynchronize() - - try: - if self._client: - self._client.KeepAliveCheck() - except Exception as ex: - self._client = None - logging.exception(ex) + self._resynchronize() + finally: if self._semaphore: self._semaphore.release() diff --git a/src/vnsw/contrail-vrouter-api/requirements.txt b/src/vnsw/contrail-vrouter-api/requirements.txt deleted file mode 100644 index 175a0afe2bc..00000000000 --- a/src/vnsw/contrail-vrouter-api/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -thrift >= 0.8.0 diff --git a/src/vnsw/contrail-vrouter-api/setup.py b/src/vnsw/contrail-vrouter-api/setup.py index f28e33952c8..b29c8da2329 100644 --- a/src/vnsw/contrail-vrouter-api/setup.py +++ b/src/vnsw/contrail-vrouter-api/setup.py @@ -1,15 +1,9 @@ # -# Copyright (c) 2014 Juniper Networks, Inc. +# Copyright (c) 2016 Juniper Networks, Inc. # import setuptools - -def requirements(filename): - with open(filename) as f: - lines = f.read().splitlines() - return lines - setuptools.setup( name='contrail-vrouter-api', version='1.0', @@ -20,9 +14,4 @@ def requirements(filename): author_email="dev@lists.opencontrail.org", license="Apache Software License", url="http://www.opencontrail.org/", - - install_requires=requirements('requirements.txt'), - - test_suite='contrail_vrouter_api.tests', - tests_require=requirements('test-requirements.txt'), ) diff --git a/src/vnsw/contrail-vrouter-api/test-requirements.txt b/src/vnsw/contrail-vrouter-api/test-requirements.txt deleted file mode 100644 index 987f5d7801e..00000000000 --- a/src/vnsw/contrail-vrouter-api/test-requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -gevent==1.1a2 -mock diff --git a/src/vnsw/opencontrail-vrouter-netns/SConscript b/src/vnsw/opencontrail-vrouter-netns/SConscript index 2bdbf43a1aa..3eb0931ac5e 100644 --- a/src/vnsw/opencontrail-vrouter-netns/SConscript +++ b/src/vnsw/opencontrail-vrouter-netns/SConscript @@ -27,7 +27,6 @@ sources = [ 'opencontrail_vrouter_netns/lxc_manager.py', 'opencontrail_vrouter_netns/network_manage.py', 'opencontrail_vrouter_netns/vrouter_control.py', - 'opencontrail_vrouter_netns/monitor.py', 'opencontrail_vrouter_netns/lxc_docker.py', 'opencontrail_vrouter_netns/linux/__init__.py', 'opencontrail_vrouter_netns/linux/ip_lib.py', diff --git a/src/vnsw/opencontrail-vrouter-netns/opencontrail_vrouter_netns/daemon_start.py b/src/vnsw/opencontrail-vrouter-netns/opencontrail_vrouter_netns/daemon_start.py index 5ce40519dc8..0a787e6dcbd 100644 --- a/src/vnsw/opencontrail-vrouter-netns/opencontrail_vrouter_netns/daemon_start.py +++ b/src/vnsw/opencontrail-vrouter-netns/opencontrail_vrouter_netns/daemon_start.py @@ -10,7 +10,6 @@ from instance_provisioner import Provisioner from lxc_manager import LxcManager from vrouter_control import interface_register -from monitor import NetnsMonitor def build_network_name(project_name, network_name): @@ -50,6 +49,11 @@ def daemon_start(): parser.add_argument("--project", help="OpenStack project name") parser.add_argument("-n", "--network", help="Primary network") parser.add_argument("-o", "--outbound", help="Outbound traffic network") + ''' + --monitor is maintained only for backward compatibility. Replug of vif's + across vrouter-agent is not required anymore as vif info is persisted in + files which are read upon vrouter-agent start. + ''' parser.add_argument("-M", "--monitor", action='store_true', help="Monitor the vrouter agent connection to replug the vif's.") parser.add_argument("daemon", help="Deamon Name") @@ -96,10 +100,6 @@ def daemon_start(): if vmi_out: manager.interface_config(arguments.daemon, 'veth1') - if arguments.monitor: - netns_monitor = NetnsMonitor(project, vm, vmi, ifname, - **vmi_out_kwargs) - netns_monitor.monitor() # end daemon_start diff --git a/src/vnsw/opencontrail-vrouter-netns/opencontrail_vrouter_netns/monitor.py b/src/vnsw/opencontrail-vrouter-netns/opencontrail_vrouter_netns/monitor.py deleted file mode 100644 index f9bd83055fe..00000000000 --- a/src/vnsw/opencontrail-vrouter-netns/opencontrail_vrouter_netns/monitor.py +++ /dev/null @@ -1,56 +0,0 @@ -""" -Monitors the namespace created by daemon_start. -""" - -import sys -import socket -import argparse - -import gevent -import gevent.lock -import gevent.monkey - -gevent.monkey.patch_all() - -from vrouter_control import interface_register -from contrail_vrouter_api.vrouter_api import ContrailVRouterApi - - -INTERVAL = 10 - -class NetnsMonitor(object): - def __init__(self, project, vm_obj, vmi_obj, ifname, **kwargs): - self.project = project - self.vm = vm_obj - self.vmi = vmi_obj - self.ifname = ifname - self.vmi_out = kwargs.get('vmi_out', None) - self.ifname_out = kwargs.get('ifname_out', None) - - vrouter_semaphore = gevent.lock.Semaphore() - self.vrouter_client = ContrailVRouterApi(doconnect=True, - semaphore=vrouter_semaphore) - self.vrouter_client.connect() - self.vrouter_agent_connection = self.vrouter_client._client - - def keepalive(self): - self.vrouter_client.periodic_connection_check() - current_agent_connection = self.vrouter_client._client - if not current_agent_connection: - # vrouter agent is down, Try checking... - return - if self.vrouter_agent_connection != current_agent_connection: - # Initial connection object to vrouter agent is different from - # the current object, vrouter agent is restarted, plug the netns - # vif's again. - interface_register(self.vm, self.vmi, self.ifname, - project=self.project) - if self.vmi_out: - interface_register(self.vm, self.vmi_out, self.ifname_out, - project=self.project) - self.vrouter_agent_connection = current_agent_connection - - def monitor(self): - while True: - gevent.sleep(INTERVAL) - self.keepalive()