Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,7 @@ def cf_virtual_appliance_sites(cli_ctx, _):

def cf_custom_ip_prefixes(cli_ctx, _):
return network_client_factory(cli_ctx).custom_ip_prefixes


def cf_inbound_nat_rules(cli_ctx, _):
return network_client_factory(cli_ctx).inbound_nat_rules
17 changes: 15 additions & 2 deletions src/azure-cli/azure/cli/command_modules/network/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
cf_virtual_router, cf_virtual_router_peering, cf_service_aliases, cf_bastion_hosts, cf_flow_logs,
cf_private_dns_zone_groups, cf_security_partner_providers, cf_load_balancer_backend_pools,
cf_network_virtual_appliances, cf_virtual_appliance_skus, cf_virtual_appliance_sites, cf_virtual_hub,
cf_virtual_hub_bgp_connection, cf_virtual_hub_bgp_connections, cf_custom_ip_prefixes)
cf_virtual_hub_bgp_connection, cf_virtual_hub_bgp_connections, cf_custom_ip_prefixes, cf_inbound_nat_rules)
from azure.cli.command_modules.network._util import (
list_network_resource_property, get_network_resource_property_entry, delete_network_resource_property_entry,
delete_lb_resource_property_entry)
Expand Down Expand Up @@ -450,6 +450,11 @@ def load_command_table(self, _):
min_api='2020-06-01'
)

network_inbound_nat_rule = CliCommandType(
operations_tmpl='azure.mgmt.network.operations#.InboundNatRulesOperations.{}',
client_factory=cf_inbound_nat_rules
)

network_custom = CliCommandType(operations_tmpl='azure.cli.command_modules.network.custom#{}')

network_load_balancers_custom = CliCommandType(
Expand Down Expand Up @@ -931,14 +936,22 @@ def _make_singular(value):
custom_func_name='set_lb_frontend_ip_configuration',
validator=process_lb_frontend_ip_namespace)

with self.command_group('network lb inbound-nat-rule', network_lb_sdk) as g:
with self.command_group('network lb inbound-nat-rule', network_lb_sdk, max_api='2021-02-01') as g:
g.custom_command('create', 'create_lb_inbound_nat_rule')
g.generic_update_command('update', child_collection_prop_name='inbound_nat_rules',
getter_name='lb_get',
getter_type=network_load_balancers_custom,
setter_name='begin_create_or_update',
custom_func_name='set_lb_inbound_nat_rule')

with self.command_group('network lb inbound-nat-rule', network_inbound_nat_rule, min_api='2021-05-01') as g:
g.custom_command('create', 'create_lb_inbound_nat_rule_v2')
g.generic_update_command('update', child_collection_prop_name='inbound_nat_rules',
getter_name='lb_get',
getter_type=network_load_balancers_custom,
setter_name='begin_create_or_update',
custom_func_name='set_lb_inbound_nat_rule')

with self.command_group('network lb inbound-nat-pool', network_lb_sdk) as g:
g.custom_command('create', 'create_lb_inbound_nat_pool')
g.generic_update_command('update', child_collection_prop_name='inbound_nat_pools',
Expand Down
25 changes: 25 additions & 0 deletions src/azure-cli/azure/cli/command_modules/network/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3649,6 +3649,31 @@ def create_lb_inbound_nat_rule(
return get_property(poller.result().inbound_nat_rules, item_name)


def create_lb_inbound_nat_rule_v2(
cmd, resource_group_name, load_balancer_name, item_name, protocol, backend_port, frontend_port=None,
frontend_ip_name=None, floating_ip=None, idle_timeout=None, enable_tcp_reset=None,
frontend_port_range_start=None, frontend_port_range_end=None, backend_address_pool_name=None):
InboundNatRule = cmd.get_models('InboundNatRule')
ncf = network_client_factory(cmd.cli_ctx)
lb = lb_get(ncf.load_balancers, resource_group_name, load_balancer_name)
if not frontend_ip_name:
frontend_ip_name = _get_default_name(lb, 'frontend_ip_configurations', '--frontend-ip-name')
frontend_ip = get_property(lb.frontend_ip_configurations, frontend_ip_name) # pylint: disable=no-member
new_rule = InboundNatRule(
name=item_name, protocol=protocol,
frontend_port=frontend_port, backend_port=backend_port,
frontend_ip_configuration=frontend_ip,
enable_floating_ip=floating_ip,
idle_timeout_in_minutes=idle_timeout,
enable_tcp_reset=enable_tcp_reset,
frontend_port_range_start=frontend_port_range_start,
frontend_port_range_end=frontend_port_range_end,
)
if backend_address_pool_name:
new_rule.backend_address_pool = get_property(lb.backend_address_pools, backend_address_pool_name) # pylint: disable=no-member
return ncf.inbound_nat_rules.begin_create_or_update(resource_group_name, load_balancer_name, item_name, new_rule)


# workaround for : https://github.com/Azure/azure-cli/issues/17071
def lb_get(client, resource_group_name, load_balancer_name):
lb = client.get(resource_group_name, load_balancer_name)
Expand Down
Loading