本文整理汇总了Python中contrail_vrouter_api.vrouter_api.ContrailVRouterApi.connect方法的典型用法代码示例。如果您正苦于以下问题:Python ContrailVRouterApi.connect方法的具体用法?Python ContrailVRouterApi.connect怎么用?Python ContrailVRouterApi.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类contrail_vrouter_api.vrouter_api.ContrailVRouterApi
的用法示例。
在下文中一共展示了ContrailVRouterApi.connect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NetnsMonitor
# 需要导入模块: from contrail_vrouter_api.vrouter_api import ContrailVRouterApi [as 别名]
# 或者: from contrail_vrouter_api.vrouter_api.ContrailVRouterApi import connect [as 别名]
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()
示例2: VRouterApiTest
# 需要导入模块: from contrail_vrouter_api.vrouter_api import ContrailVRouterApi [as 别名]
# 或者: from contrail_vrouter_api.vrouter_api.ContrailVRouterApi import connect [as 别名]
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',
network_uuid=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)