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


Python VirtualMachineInterface.get_fq_name方法代码示例

本文整理汇总了Python中vnc_api.vnc_api.VirtualMachineInterface.get_fq_name方法的典型用法代码示例。如果您正苦于以下问题:Python VirtualMachineInterface.get_fq_name方法的具体用法?Python VirtualMachineInterface.get_fq_name怎么用?Python VirtualMachineInterface.get_fq_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vnc_api.vnc_api.VirtualMachineInterface的用法示例。


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

示例1: test_public_snat_routes

# 需要导入模块: from vnc_api.vnc_api import VirtualMachineInterface [as 别名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import get_fq_name [as 别名]
    def test_public_snat_routes(self):

        #create private vn
        vn_private_name = self.id() + 'vn1'
        vn_private = self.create_virtual_network(vn_private_name, "1.0.0.0/24")

        # create virtual machine interface
        vmi_name = self.id() + 'vmi1'
        vmi = VirtualMachineInterface(vmi_name, parent_type='project',
                        fq_name=['default-domain', 'default-project', vmi_name])
        vmi.add_virtual_network(vn_private)
        self._vnc_lib.virtual_machine_interface_create(vmi)

        #create public vn
        vn_public_name = 'vn-public'
        vn_public = VirtualNetwork(vn_public_name)
        vn_public.set_router_external(True)
        ipam_obj = NetworkIpam('ipam')
        self._vnc_lib.network_ipam_create(ipam_obj)
        vn_public.add_network_ipam(ipam_obj, VnSubnetsType(
            [IpamSubnetType(SubnetType("192.168.7.0", 24))]))
        self._vnc_lib.virtual_network_create(vn_public)

        #create logical router, set route targets,
        #add private network and extend lr to public network
        lr_name = self.id() + 'lr1'
        lr = LogicalRouter(lr_name)
        rtgt_list = RouteTargetList(route_target=['target:1:1'])
        lr.set_configured_route_target_list(rtgt_list)
        lr.add_virtual_machine_interface(vmi)
        lr.add_virtual_network(vn_public)
        self._vnc_lib.logical_router_create(lr)

        @retries(5)
        def _match_route_table(rtgt_list, ri_name):
            lri = self._vnc_lib.routing_instance_read(
                fq_name_str=ri_name)
            sr = lri.get_static_route_entries()
            if sr is None:
                raise Exception("sr is None")
            route = sr.route[0]
            self.assertEqual(route.prefix, "0.0.0.0/0")
            self.assertEqual(route.next_hop, "100.64.0.4")
            for rtgt in rtgt_list:
                self.assertIn(rtgt, route.route_target)

        @retries(5)
        def _wait_to_get_si():
            si_list = self._vnc_lib.service_instances_list()
            si = si_list.get("service-instances")[0]
            si = self._vnc_lib.service_instance_read(id=si.get("uuid"))
            return si

        @retries(5)
        def _wait_to_delete_si():
            si_list = self._vnc_lib.service_instances_list()
            try:
                si = si_list.get("service-instances")[0]
                si = self._vnc_lib.service_instance_read(id=si.get("uuid"))
                raise
            except:
                pass

        @retries(5)
        def _wait_to_delete_ip(vn_fq_name):
            vn = self._vnc_lib.virtual_network_read(fq_name=vn_fq_name)
            ip_refs = vn.get_instance_ip_back_refs()
            if ip_refs:
                raise
            return
        # end

        si = _wait_to_get_si()
        si_props = si.get_service_instance_properties().get_interface_list()[1]
        ri_name = si_props.virtual_network + ":" + si_props.virtual_network.split(':')[-1]
        lr_rtgt = self._vnc_lib.logical_router_read(id=lr.uuid).route_target_refs[0]['to'][0]
        _match_route_table(['target:1:1', lr_rtgt], ri_name)

        rtgt_list = RouteTargetList(route_target=['target:2:2'])
        lr.set_configured_route_target_list(rtgt_list)
        self._vnc_lib.logical_router_update(lr)
        _match_route_table(['target:2:2', lr_rtgt], ri_name)

        lr.del_virtual_network(vn_public)
        self._vnc_lib.logical_router_update(lr)
        _wait_to_delete_si()

        #cleanup
        self._vnc_lib.logical_router_delete(fq_name=lr.get_fq_name())
        self._vnc_lib.virtual_machine_interface_delete(fq_name=vmi.get_fq_name())
        _wait_to_delete_ip(vn_private.get_fq_name())
        self._vnc_lib.virtual_network_delete(fq_name=vn_private.get_fq_name())
        _wait_to_delete_ip(vn_public.get_fq_name())
        self._vnc_lib.virtual_network_delete(fq_name=vn_public.get_fq_name())
开发者ID:Juniper,项目名称:contrail-controller,代码行数:96,代码来源:test_route_table.py


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