当前位置: 首页>>代码示例>>Python>>正文


Python vrouter_api.ContrailVRouterApi类代码示例

本文整理汇总了Python中contrail_vrouter_api.vrouter_api.ContrailVRouterApi的典型用法代码示例。如果您正苦于以下问题:Python ContrailVRouterApi类的具体用法?Python ContrailVRouterApi怎么用?Python ContrailVRouterApi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ContrailVRouterApi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_unicode

 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)
开发者ID:Juniper,项目名称:contrail-dev-controller,代码行数:8,代码来源:test_vrouter_api_connection.py

示例2: interface_register

def interface_register(vm, vmi, iface_name, project=None):
    api = ContrailVRouterApi()
    mac = vmi.virtual_machine_interface_mac_addresses.mac_address[0]
    if project:
        proj_id = project.uuid
    else:
        proj_id = None
    api.add_port(vm.uuid, vmi.uuid, iface_name, mac, display_name=vm.name, vm_project_id=proj_id)
开发者ID:DreamLab,项目名称:opencontrail-netns,代码行数:8,代码来源:vrouter_control.py

示例3: teardown

def teardown(pod_namespace, pod_name, docker_id):
    client = ContrailClient()
    manager = LxcManager()
    short_id = docker_id[0:11]

    api = ContrailVRouterApi()

    _, podName = getDockerPod(docker_id)
    vmi = vrouter_interface_by_name(podName)
    if vmi is not None:
        api.delete_port(vmi)

    manager.clear_interfaces(short_id)
    Shell.run('ip netns delete %s' % short_id)
开发者ID:rombie,项目名称:contrail-kubernetes,代码行数:14,代码来源:plugin.py

示例4: __init__

 def __init__(self, conf):
     super(ContrailInterfaceDriver, self).__init__(conf)
     self._port_dict = {}
     self._client = self._connect_to_api_server()
     self._vrouter_client = ContrailVRouterApi()
     timer = loopingcall.FixedIntervalLoopingCall(self._keep_alive)
     timer.start(interval=2)
开发者ID:dattamiruke,项目名称:contrail-neutron-plugin,代码行数:7,代码来源:contrail_vif_driver.py

示例5: __init__

 def __init__(self, vm_uuid, nic_left, nic_right, other_nics=None,
              root_helper='sudo', cfg_file=None, update=False,
              pool_id=None, gw_ip=None, namespace_name=None):
     self.vm_uuid = vm_uuid
     if namespace_name is None:
         self.namespace = self.NETNS_PREFIX + self.vm_uuid
     else:
         self.namespace = namespace_name
     if pool_id:
         self.namespace = self.namespace + ":" + pool_id
     self.nic_left = nic_left
     self.nic_right = nic_right
     self.root_helper = root_helper
     self.nics = other_nics or []
     if self.nic_left:
         self.nic_left['name'] = (self.LEFT_DEV_PREFIX +
                              self.nic_left['uuid'])[:self.DEV_NAME_LEN]
         self.nics.append(self.nic_left)
     if self.nic_right:
         self.nic_right['name'] = (self.RIGH_DEV_PREFIX +
                                   self.nic_right['uuid'])[:self.DEV_NAME_LEN]
         self.nics.append(self.nic_right)
     self.ip_ns = ip_lib.IPWrapper(root_helper=self.root_helper,
                                   namespace=self.namespace)
     self.vrouter_client = ContrailVRouterApi()
     self.cfg_file = cfg_file
     self.update = update
     self.gw_ip = gw_ip
开发者ID:haripk,项目名称:contrail-controller,代码行数:28,代码来源:vrouter_netns.py

示例6: main

def main():
	parser = argparse.ArgumentParser()
	# "--mac-address", metadata.MacAddress,
	# 	"--vm", metadata.InstanceId, "--vmi", metadata.NicId,
	# 	"--interface", masterName, "add", c.DockerId)
	parser.add_argument('--mac-address')
	parser.add_argument('--vm')
	parser.add_argument('--vmi')
	parser.add_argument('--interface')
	parser.add_argument('command', choices=['add'])
	parser.add_argument('dockerId')
	args = parser.parse_args()
	if args.command == 'add':
		api = ContrailVRouterApi()
		api.add_port(args.vm, args.vmi, args.interface, args.mac_address, port_type='NovaVMPort', display_name=args.dockerId)
	else:
		print "No command specified"
开发者ID:pedro-r-marques,项目名称:packnet,代码行数:17,代码来源:vrouter_ctl.py

示例7: __init__

 def __init__(self, get_connection=None):
     if get_connection:
         super(VRouterVIFDriver, self).__init__(get_connection)
     else:
         # OpenStack Kilo compatibility
         super(VRouterVIFDriver, self).__init__()
     self._vrouter_semaphore = eventlet.semaphore.Semaphore()
     self._vrouter_client = ContrailVRouterApi(doconnect=True, semaphore=self._vrouter_semaphore)
     timer = loopingcall.FixedIntervalLoopingCall(self._keep_alive)
     timer.start(interval=2)
开发者ID:pupapaik,项目名称:contrail-nova-vif-driver,代码行数:10,代码来源:contrailvif.py

示例8: __init__

    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
开发者ID:Pojen-Huang,项目名称:contrail-controller,代码行数:13,代码来源:monitor.py

示例9: __init__

 def __init__(self, vm_uuid, nic_left, nic_right, root_helper='sudo'):
     self.vm_uuid = vm_uuid
     self.namespace = self.NETNS_PREFIX + self.vm_uuid
     self.nic_left = nic_left
     self.nic_right = nic_right
     self.root_helper = root_helper
     self.nic_left['name'] = (self.LEFT_DEV_PREFIX +
                              self.nic_left['uuid'])[:self.DEV_NAME_LEN]
     self.nic_right['name'] = (self.RIGH_DEV_PREFIX +
                               self.nic_right['uuid'])[:self.DEV_NAME_LEN]
     self.ip_ns = ip_lib.IPWrapper(root_helper=self.root_helper,
                                   namespace=self.namespace)
     self.vrouter_client = ContrailVRouterApi()
开发者ID:dazer-chen,项目名称:contrail-controller,代码行数:13,代码来源:vrouter_netns.py

示例10: NetnsMonitor

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()
开发者ID:Pojen-Huang,项目名称:contrail-controller,代码行数:36,代码来源:monitor.py

示例11: setUp

 def setUp(self):
     self._api = ContrailVRouterApi()
开发者ID:Juniper,项目名称:contrail-dev-controller,代码行数:2,代码来源:test_vrouter_api.py

示例12: VRouterApiTest

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)
开发者ID:Juniper,项目名称:contrail-dev-controller,代码行数:89,代码来源:test_vrouter_api.py

示例13: ContrailInterfaceDriver

class ContrailInterfaceDriver(interface.LinuxInterfaceDriver):
    """ Opencontrail VIF driver for neutron."""

    @classmethod
    def _parse_class_args(cls, cfg_parser):
        cfg_parser.read(CONTRAIL_CFG_FILE)
        cls._api_server_ip = _read_cfg(cfg_parser, 'APISERVER',
                                       'api_server_ip', '127.0.0.1')
        cls._api_server_port = _read_cfg(cfg_parser, 'APISERVER',
                                         'api_server_port', '8082')
        cls._api_server_use_ssl  = _read_cfg(cfg_parser, 'APISERVER',
                                         'use_ssl', False)

    def __init__(self, conf):
        super(ContrailInterfaceDriver, self).__init__(conf)
        self._port_dict = {}
        self._client = self._connect_to_api_server()
        self._vrouter_client = ContrailVRouterApi()
        timer = loopingcall.FixedIntervalLoopingCall(self._keep_alive)
        timer.start(interval=2)

    def _connect_to_api_server(self):
        cfg_parser = ConfigParser.ConfigParser()
        ContrailInterfaceDriver._parse_class_args(cfg_parser)
        try:
            client = VncApi(api_server_host=self._api_server_ip,
                            api_server_port=self._api_server_port,
                            api_server_use_ssl=self._api_server_use_ssl)
            return client
        except:
            pass

    def _keep_alive(self):
        self._vrouter_client.periodic_connection_check()

    def _delete_port(self, port_id):
        self._vrouter_client.delete_port(port_id)

    def _instance_locate(self, port_obj):
        """ lookup the instance associated with the port object.
        Create the vm instance if port object is not associated
        with a vm instance
        """
        if port_obj.get_virtual_machine_refs() is not None:
            try:
                vm_uuid = port_obj.get_virtual_machine_refs()[0]['uuid']
                instance_obj = self._client.virtual_machine_read(id=vm_uuid)
                return instance_obj
            except NoIdError:
                pass

        vm_uuid = str(uuid.uuid4())
        instance_obj = VirtualMachine(vm_uuid)
        instance_obj.uuid = vm_uuid
        self._client.virtual_machine_create(instance_obj)
        port_obj.set_virtual_machine(instance_obj)
        self._client.virtual_machine_interface_update(port_obj)
        return instance_obj

    def _add_port_to_agent(self, port_id, net_id, iface_name, mac_address):
        port_obj = self._client.virtual_machine_interface_read(id=port_id)
        if port_obj is None:
            LOG.debug(_("Invalid port_id : %s"), port_id)
            return

        ips = port_obj.get_instance_ip_back_refs()
        ip_addr = '0.0.0.0'
        # get the ip address of the port if associated
        if ips and len(ips):
            ip_uuid = ips[0]['uuid']
            ip = self._client.instance_ip_read(id=ip_uuid)
            ip_addr = ip.get_instance_ip_address()

        net_obj = self._client.virtual_network_read(id=net_id)
        if net_obj is None:
            LOG.debug(_("Invalid net_id : %s"), net_id)
            return

        # get the instance object the port is attached to
        instance_obj = self._instance_locate(port_obj)

        if instance_obj is None:
            return

        kwargs = {}
        kwargs['ip_address'] = ip_addr
        kwargs['network_uuid'] = net_id
        kwargs['vm_project_uuid'] = net_obj.parent_uuid
        self._vrouter_client.add_port(instance_obj.uuid, port_id, iface_name,
                                      mac_address, **kwargs)

    def plug(self, network_id, port_id, device_name, mac_address,
             bridge=None, namespace=None, prefix=None):
        if not ip_lib.device_exists(device_name, self.root_helper, namespace):
            ip = ip_lib.IPWrapper(self.root_helper)
            tap_name = device_name.replace(prefix or 'veth', 'veth')

            # Create ns_dev in a namespace if one is configured.
            root_dev, ns_dev = ip.add_veth(tap_name,
                                           device_name,
#.........这里部分代码省略.........
开发者ID:dattamiruke,项目名称:contrail-neutron-plugin,代码行数:101,代码来源:contrail_vif_driver.py

示例14: VRouterApiTest

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())
        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()
        self.assertTrue(mock_client.AddPort.called)

    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_uuid = uuid.uuid1()
        self._api.add_port(str(uuid.uuid1()), str(vif_uuid), 'tapX',
                           'aa:bb:cc:ee:ff:00',
                           network_uuid=str(network_uuid),
                           vm_project_uuid=str(project_uuid))
        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_to_hex(project_uuid),
                         port.vm_project_uuid)
开发者ID:Doude,项目名称:contrail-controller,代码行数:61,代码来源:test_vrouter_api.py

示例15: interface_unregister

def interface_unregister(vmi_uuid):
    api = ContrailVRouterApi()
    api.delete_port(vmi_uuid)
开发者ID:FooBarQuaxx,项目名称:opencontrail-netns,代码行数:3,代码来源:vrouter_control.py


注:本文中的contrail_vrouter_api.vrouter_api.ContrailVRouterApi类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。