Skip to content

Commit 721e29d

Browse files
authored
{Network} az network vnet-gateway packet-capture/vpn-client: Migrate to atomic commands (#25314)
1 parent 7739430 commit 721e29d

20 files changed

Lines changed: 2217 additions & 607 deletions

File tree

src/azure-cli/azure/cli/command_modules/network/_actions.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from knack.util import CLIError
1010
from azure.cli.core.azclierror import UnrecognizedArgumentError
1111
from ._validators import read_base_64_file
12-
from ._util import enum_check
1312

1413

1514
# pylint: disable=protected-access
@@ -135,41 +134,6 @@ def get_action(self, values, option_string): # pylint: disable=no-self-use
135134
return d
136135

137136

138-
class NatRuleCreate(argparse._AppendAction):
139-
def __call__(self, parser, namespace, values, option_string=None):
140-
action = self.get_action(values, option_string)
141-
super(NatRuleCreate, self).__call__(parser, namespace, action, option_string)
142-
143-
def get_action(self, values, option_string): # pylint: disable=no-self-use
144-
try:
145-
properties = defaultdict(list)
146-
for (k, v) in (x.split('=', 1) for x in values):
147-
properties[k].append(v)
148-
properties = dict(properties)
149-
except ValueError:
150-
raise UnrecognizedArgumentError('usage error: {} [KEY=VALUE ...]'.format(option_string))
151-
d = {}
152-
for k in properties:
153-
kl = k.lower()
154-
v = properties[k]
155-
if kl == 'type':
156-
d['type'] = enum_check(v[0], ['Static', 'Dynamic'])
157-
elif kl == 'name':
158-
d['name'] = v[0]
159-
elif kl == 'mode':
160-
d['mode'] = enum_check(v[0], ['EgressSnat', 'IngressSnat'])
161-
elif kl == 'internal-mappings':
162-
d['internal_mappings'] = _split(v[0])
163-
elif kl == 'external-mappings':
164-
d['external_mappings'] = _split(v[0])
165-
elif kl == 'ip-config-id':
166-
d['ip_config_id'] = v[0]
167-
else:
168-
raise UnrecognizedArgumentError('key error: key must be one of type, mode, internal-mappings,'
169-
'external-mappings, ip-config-id')
170-
return d
171-
172-
173137
class AddMappingRequest(argparse.Action):
174138
def __call__(self, parser, namespace, values, option_string=None):
175139
action = self.get_action(values, option_string)

src/azure-cli/azure/cli/command_modules/network/_params.py

Lines changed: 14 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from azure.cli.command_modules.network._validators import (
1919
dns_zone_name_type, validate_inbound_nat_rule_id_list,
2020
validate_address_pool_id_list, validate_inbound_nat_rule_name_or_id,
21-
validate_address_pool_name_or_id, load_cert_file, validate_metadata,
21+
validate_address_pool_name_or_id, validate_metadata,
2222
validate_dns_record_type, validate_private_ip_address,
2323
get_servers_validator, get_public_ip_validator, get_nsg_validator, get_subnet_validator,
2424
get_network_watcher_from_vm, get_network_watcher_for_pcap_creation, get_network_watcher_from_location, validate_capture_size_and_limit,
@@ -31,14 +31,13 @@
3131
validate_waf_policy,
3232
validate_user_assigned_identity, validate_virtul_network_gateway,
3333
NWConnectionMonitorEndpointFilterItemAction, NWConnectionMonitorTestConfigurationHTTPRequestHeaderAction,
34-
process_private_link_resource_id_argument, process_private_endpoint_connection_id_argument,
35-
validate_vpn_connection_name_or_id)
34+
process_private_link_resource_id_argument, process_private_endpoint_connection_id_argument)
3635
from azure.cli.command_modules.network._completers import (
3736
subnet_completion_list, get_lb_subresource_completion_list, get_ag_subresource_completion_list,
3837
ag_url_map_rule_completion_list, tm_endpoint_completion_list)
3938
from azure.cli.command_modules.network._actions import (
4039
TrustedClientCertificateCreate,
41-
SslProfilesCreate, NatRuleCreate, AddMappingRequest, WAFRulesCreate)
40+
SslProfilesCreate, AddMappingRequest, WAFRulesCreate)
4241
from azure.cli.core.util import get_json_object
4342
from azure.cli.core.profiles import ResourceType
4443

@@ -47,25 +46,23 @@
4746
def load_arguments(self, _):
4847

4948
(ApplicationGatewayProtocol,
50-
ApplicationGatewayRequestRoutingRuleType, ApplicationGatewaySkuName, ApplicationGatewaySslProtocol, AuthenticationMethod,
51-
Direction, VpnAuthenticationType,
49+
ApplicationGatewayRequestRoutingRuleType, ApplicationGatewaySkuName, ApplicationGatewaySslProtocol,
50+
Direction,
5251
FlowLogFormatType, HTTPMethod, IPAllocationMethod,
53-
IPVersion, ProbeProtocol, ProcessorArchitecture, Protocol, PublicIPAddressSkuName, PublicIPAddressSkuTier,
52+
IPVersion, ProbeProtocol, Protocol, PublicIPAddressSkuName, PublicIPAddressSkuTier,
5453
SecurityRuleAccess, SecurityRuleProtocol, SecurityRuleDirection, TransportProtocol,
55-
VirtualNetworkGatewaySkuName, VirtualNetworkGatewayType, VpnClientProtocol, VpnType,
5654
ConnectionMonitorEndpointFilterType, ConnectionMonitorTestConfigurationProtocol,
5755
PreferredIPVersion, HTTPConfigurationMethod, OutputType, DestinationPortBehavior, CoverageLevel, EndpointType,
58-
VpnNatRuleType, VpnNatRuleMode, PacketCaptureTargetType) = self.get_models(
56+
PacketCaptureTargetType) = self.get_models(
5957
'ApplicationGatewayProtocol',
60-
'ApplicationGatewayRequestRoutingRuleType', 'ApplicationGatewaySkuName', 'ApplicationGatewaySslProtocol', 'AuthenticationMethod',
61-
'Direction', 'VpnAuthenticationType',
58+
'ApplicationGatewayRequestRoutingRuleType', 'ApplicationGatewaySkuName', 'ApplicationGatewaySslProtocol',
59+
'Direction',
6260
'FlowLogFormatType', 'HTTPMethod', 'IPAllocationMethod',
63-
'IPVersion', 'ProbeProtocol', 'ProcessorArchitecture', 'Protocol', 'PublicIPAddressSkuName', 'PublicIPAddressSkuTier',
61+
'IPVersion', 'ProbeProtocol', 'Protocol', 'PublicIPAddressSkuName', 'PublicIPAddressSkuTier',
6462
'SecurityRuleAccess', 'SecurityRuleProtocol', 'SecurityRuleDirection', 'TransportProtocol',
65-
'VirtualNetworkGatewaySkuName', 'VirtualNetworkGatewayType', 'VpnClientProtocol', 'VpnType',
6663
'ConnectionMonitorEndpointFilterType', 'ConnectionMonitorTestConfigurationProtocol',
6764
'PreferredIPVersion', 'HTTPConfigurationMethod', 'OutputType', 'DestinationPortBehavior', 'CoverageLevel', 'EndpointType',
68-
'VpnNatRuleType', 'VpnNatRuleMode', 'PacketCaptureTargetType')
65+
'PacketCaptureTargetType')
6966

7067
ZoneType = self.get_models('ZoneType', resource_type=ResourceType.MGMT_NETWORK_DNS)
7168

@@ -675,13 +672,6 @@ def load_arguments(self, _):
675672
c.argument('threshold', help='The number of consecutive probe failures before an instance is deemed unhealthy.')
676673
# endregion
677674

678-
# region VnetGateway
679-
for item in ['vnet-gateway']:
680-
with self.argument_context('network {}'.format(item)) as c:
681-
c.argument('asn', type=int, arg_group='BGP Peering', help='Autonomous System Number to use for the BGP settings.')
682-
c.argument('peer_weight', arg_group='BGP Peering', help='Weight (0-100) added to routes learned through BGP peering.')
683-
# endregion
684-
685675
# region NetworkInterfaces (NIC)
686676
with self.argument_context('network nic') as c:
687677
c.argument('enable_accelerated_networking', min_api='2016-09-01', options_list=['--accelerated-networking'], help='Enable accelerated networking.', arg_type=get_three_state_flag())
@@ -1387,95 +1377,16 @@ def load_arguments(self, _):
13871377
# endregion
13881378

13891379
# region VirtualNetworkGateways
1390-
vnet_gateway_type = CLIArgumentType(help='The gateway type.', arg_type=get_enum_type(VirtualNetworkGatewayType), default=VirtualNetworkGatewayType.vpn.value)
1391-
vnet_gateway_sku_type = CLIArgumentType(help='VNet gateway SKU.', arg_type=get_enum_type(VirtualNetworkGatewaySkuName), default=VirtualNetworkGatewaySkuName.basic.value)
1392-
vnet_gateway_routing_type = CLIArgumentType(help='VPN routing type.', arg_type=get_enum_type(VpnType), default=VpnType.route_based.value)
1393-
edge_zone_vnet_id = CLIArgumentType(help='The Extended vnet resource id of the local gateway', min_api='2021-02-01')
13941380
with self.argument_context('network vnet-gateway') as c:
13951381
c.argument('virtual_network_gateway_name', options_list=['--name', '-n'], help='Name of the VNet gateway.', completer=get_resource_name_completion_list('Microsoft.Network/virtualNetworkGateways'), id_part='name')
1396-
c.argument('cert_name', help='Root certificate name', options_list=['--name', '-n'])
1397-
c.argument('gateway_name', help='Virtual network gateway name')
1398-
c.argument('gateway_type', vnet_gateway_type)
1399-
c.argument('gateway_default_site', help='Name or ID of a local network gateway representing a local network site with default routes.')
1400-
c.argument('sku', vnet_gateway_sku_type)
1401-
c.argument('vpn_type', vnet_gateway_routing_type)
1402-
c.argument('bgp_peering_address', arg_group='BGP Peering', help='IP address to use for BGP peering.')
1403-
c.argument('public_ip_address', options_list=['--public-ip-addresses'], nargs='+', help='Specify a single public IP (name or ID) for an active-standby gateway. Specify two space-separated public IPs for an active-active gateway.', completer=get_resource_name_completion_list('Microsoft.Network/publicIPAddresses'))
1404-
c.argument('address_prefixes', help='Space-separated list of CIDR prefixes representing the address space for the P2S Vpnclient.', nargs='+', arg_group='VPN Client')
1405-
c.argument('radius_server', min_api='2017-06-01', help='Radius server address to connect to.', arg_group='VPN Client')
1406-
c.argument('radius_secret', min_api='2017-06-01', help='Radius secret to use for authentication.', arg_group='VPN Client')
1407-
c.argument('client_protocol', min_api='2017-06-01', help='Protocols to use for connecting', nargs='+', arg_group='VPN Client', arg_type=get_enum_type(VpnClientProtocol))
1408-
c.argument('custom_routes', min_api='2019-02-01', help='Space-separated list of CIDR prefixes representing the custom routes address space specified by the customer for VpnClient.', nargs='+', arg_group='VPN Client')
1409-
c.argument('vpn_auth_type', min_api='2020-11-01', nargs='+', help='VPN authentication types enabled for the virtual network gateway.', arg_type=get_enum_type(VpnAuthenticationType))
1410-
1411-
with self.argument_context('network vnet-gateway', arg_group='AAD Authentication', min_api='2020-11-01') as c:
1412-
c.argument('aad_tenant', help='The AAD Tenant URI of the VirtualNetworkGateway.')
1413-
c.argument('aad_audience', help='The AADAudience ID of the VirtualNetworkGateway.')
1414-
c.argument('aad_issuer', help='The AAD Issuer URI of the VirtualNetworkGateway.')
1415-
1416-
with self.argument_context('network vnet-gateway', arg_group='Root Cert Authentication', min_api='2020-11-01') as c:
1417-
c.argument('root_cert_data', help='Base64 contents of the root certificate file or file path.', type=file_type, completer=FilesCompleter())
1418-
c.argument('root_cert_name', help='Root certificate name')
1419-
1420-
with self.argument_context('network vnet-gateway', arg_group='Nat Rule', min_api='2021-02-01') as c:
1421-
c.argument('nat_rule', nargs='+', action=NatRuleCreate)
1422-
1423-
with self.argument_context('network vnet-gateway update') as c:
1424-
c.argument('gateway_type', vnet_gateway_type, default=None)
1425-
c.argument('sku', vnet_gateway_sku_type, default=None)
1426-
c.argument('vpn_type', vnet_gateway_routing_type, default=None)
1427-
1428-
with self.argument_context('network vnet-gateway create') as c:
1429-
vnet_help = "Name or ID of an existing virtual network which has a subnet named 'GatewaySubnet'."
1430-
c.argument('virtual_network', options_list='--vnet', help=vnet_help)
1431-
c.argument('vpn_gateway_generation', arg_type=get_enum_type(['Generation1', 'Generation2']), min_api='2019-07-01', help='The generation for the virtual network gateway. vpn_gateway_generation should not be provided if gateway_type is not Vpn.')
1432-
c.argument('edge_zone', edge_zone, min_api='2021-02-01')
1433-
c.argument('edge_zone_vnet_id', edge_zone_vnet_id)
1434-
1435-
with self.argument_context('network vnet-gateway update') as c:
1436-
c.argument('enable_bgp', help='Enable BGP (Border Gateway Protocol)', arg_group='BGP Peering', arg_type=get_enum_type(['true', 'false']))
1437-
c.argument('virtual_network', virtual_network_name_type, options_list='--vnet', help="Name or ID of a virtual network that contains a subnet named 'GatewaySubnet'.")
1438-
c.extra('address_prefixes', options_list='--address-prefixes', help='List of address prefixes for the VPN gateway. Prerequisite for uploading certificates.', nargs='+')
1439-
1440-
with self.argument_context('network vnet-gateway aad assign', min_api='2019-04-01') as c:
1441-
c.argument('aad_tenant', options_list='--tenant', help='The AADTenant URI of the VirtualNetworkGateway.')
1442-
c.argument('aad_audience', options_list='--audience', help='The AADAudience ID of the VirtualNetworkGateway.')
1443-
c.argument('aad_issuer', options_list='--issuer', help='The AADIssuer URI of the VirtualNetworkGateway.')
1444-
1445-
with self.argument_context('network vnet-gateway root-cert create') as c:
1446-
c.argument('public_cert_data', help='Base64 contents of the root certificate file or file path.', type=file_type, completer=FilesCompleter(), validator=load_cert_file('public_cert_data'))
1447-
c.argument('cert_name', help='Root certificate name', options_list=['--name', '-n'])
14481382
c.argument('gateway_name', help='Virtual network gateway name')
14491383

1450-
with self.argument_context('network vnet-gateway revoked-cert create') as c:
1451-
c.argument('thumbprint', help='Certificate thumbprint.')
1452-
1453-
with self.argument_context('network vnet-gateway packet-capture start') as c:
1454-
c.argument('filter_data', options_list=['--filter'], help='Data filter.')
1455-
1456-
with self.argument_context('network vnet-gateway packet-capture stop') as c:
1457-
c.argument('sas_url', options_list=['--sas-url'],
1458-
help='The SAS url to be used for packet capture.')
1459-
14601384
with self.argument_context('network vnet-gateway vpn-client') as c:
1461-
c.argument('processor_architecture', help='Processor architecture of the target system.', arg_type=get_enum_type(ProcessorArchitecture))
1462-
c.argument('authentication_method', help='Method used to authenticate with the generated client.', arg_type=get_enum_type(AuthenticationMethod))
1385+
c.argument('processor_architecture', help='Processor architecture of the target system.', arg_type=get_enum_type(['Amd64', 'X86']))
1386+
c.argument('authentication_method', help='Method used to authenticate with the generated client.', arg_type=get_enum_type(['EAPMSCHAPv2', 'EAPTLS']))
14631387
c.argument('radius_server_auth_certificate', help='Public certificate data for the Radius server auth certificate in Base-64 format. Required only if external Radius auth has been configured with EAPTLS auth.')
14641388
c.argument('client_root_certificates', nargs='+', help='Space-separated list of client root certificate public certificate data in Base-64 format. Optional for external Radius-based auth with EAPTLS')
14651389
c.argument('use_legacy', min_api='2017-06-01', help='Generate VPN client package using legacy implementation.', arg_type=get_three_state_flag())
1466-
1467-
with self.argument_context('network vnet-gateway disconnect-vpn-connections') as c:
1468-
c.argument('vpn_connection_ids', options_list=['--vpn-connections'], nargs='+',
1469-
help='List of Name or ID of VPN connections.',
1470-
validator=validate_vpn_connection_name_or_id)
1471-
1472-
with self.argument_context('network vnet-gateway nat-rule', min_api='2021-02-01') as c:
1473-
c.argument('name', help='The name of the resource that is unique within a resource group. This name can be used to access the resource.')
1474-
c.argument('rule_type', options_list='--type', help='The type of NAT rule for VPN NAT.', arg_type=get_enum_type(VpnNatRuleType))
1475-
c.argument('mode', help='The Source NAT direction of a VPN NAT.', arg_type=get_enum_type(VpnNatRuleMode))
1476-
c.argument('internal_mappings', nargs='+', help='The private IP address internal mapping for NAT.')
1477-
c.argument('external_mappings', nargs='+', help='The private IP address external mapping for NAT.')
1478-
c.argument('ip_config_id', help='The IP Configuration ID this NAT rule applies to.')
14791390
# endregion
14801391

14811392
# region VirtualNetworkGatewayConnections
@@ -1547,7 +1458,7 @@ def load_arguments(self, _):
15471458
with self.argument_context('network routeserver create') as c:
15481459
c.argument('virtual_hub_name', id_part=None)
15491460

1550-
for scope in ['vpn-connection', 'vnet-gateway', 'vnet-gateway vpn-client']:
1461+
for scope in ['vpn-connection']:
15511462
with self.argument_context('network {} ipsec-policy'.format(scope), arg_group='Security Association') as c:
15521463
c.argument('sa_data_size_kilobytes', options_list=['--sa-max-size'], type=int, help='The payload size in KB for P2S client.')
15531464
c.argument('sa_life_time_seconds', options_list=['--sa-lifetime'], type=int, help='The lifetime in seconds for P2S client.')

src/azure-cli/azure/cli/command_modules/network/_validators.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,6 @@ def _validate_vpn_gateway_generation(namespace):
105105
raise CLIError('vpn_gateway_generation should not be provided if gateway_type is not Vpn.')
106106

107107

108-
def validate_vpn_connection_name_or_id(cmd, namespace):
109-
if namespace.vpn_connection_ids:
110-
from msrestazure.tools import is_valid_resource_id, resource_id
111-
for index, vpn_connection_id in enumerate(namespace.vpn_connection_ids):
112-
if not is_valid_resource_id(vpn_connection_id):
113-
namespace.vpn_connection_ids[index] = resource_id(
114-
subscription=get_subscription_id(cmd.cli_ctx),
115-
resource_group=namespace.resource_group_name,
116-
namespace='Microsoft.Network',
117-
type='connections',
118-
name=vpn_connection_id
119-
)
120-
121-
122108
def validate_ddos_name_or_id(cmd, namespace):
123109
if namespace.ddos_protection_plan:
124110
from msrestazure.tools import is_valid_resource_id, resource_id
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command_group(
15+
"network vnet-gateway packet-capture",
16+
)
17+
class __CMDGroup(AAZCommandGroup):
18+
"""Manage packet capture on a virtual network gateway.
19+
"""
20+
pass
21+
22+
23+
__all__ = ["__CMDGroup"]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from .__cmd_group import *
12+
from ._start import *
13+
from ._stop import *

0 commit comments

Comments
 (0)