本文整理汇总了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)