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


Python Gateway.add_nat_rule方法代码示例

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


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

示例1: test_0010_add_nat_rule

# 需要导入模块: from pyvcloud.vcd.gateway import Gateway [as 别名]
# 或者: from pyvcloud.vcd.gateway.Gateway import add_nat_rule [as 别名]
    def test_0010_add_nat_rule(self):
        """Add Nat Rule in the gateway.

        Invokes the add_nat_rule of the gateway.
        """
        gateway = Environment. \
            get_test_gateway(TestNatRule._client)
        gateway_obj = Gateway(TestNatRule._client,
                              TestNatRule._name,
                              href=gateway.get('href'))
        # Create SNAT Rule
        gateway_obj.add_nat_rule(
            action=TestNatRule._snat_action,
            original_address=TestNatRule._snat_orig_addr,
            translated_address=TestNatRule._snat_trans_addr)
        # Create DNAT Rule for tcp/udp protocol
        gateway_obj.add_nat_rule(
            action=TestNatRule._dnat_action,
            original_address=TestNatRule._dnat1_orig_addr,
            translated_address=TestNatRule._dnat1_trans_addr,
            protocol=TestNatRule._dnat1_protocol,
            original_port=TestNatRule._dnat1_orig_port,
            translated_port=TestNatRule._dnat1_trans_port)
        # Create DNAT Rule for icmp protocol
        gateway_obj.add_nat_rule(
            action=TestNatRule._dnat_action,
            original_address=TestNatRule._dnat2_orig_addr,
            translated_address=TestNatRule._dnat2_trans_addr,
            description=TestNatRule._dnat2_protocol,
            protocol=TestNatRule._dnat2_protocol)
        nat_rule = gateway_obj.get_nat_rules()
        #Verify
        snat_found = False
        dnat_found = False
        for natRule in nat_rule.natRules.natRule:
            if natRule.action == 'snat' and \
                natRule.originalAddress == TestNatRule._snat_orig_addr :
                snat_found = True
            if natRule.action == 'dnat' and \
                natRule.originalAddress == TestNatRule._dnat1_orig_addr :
                dnat_found = True
        self.assertTrue(snat_found)
        self.assertTrue(dnat_found)
开发者ID:vmware,项目名称:pyvcloud,代码行数:45,代码来源:nat_rule_tests.py


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