Skip to content
Merged
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
9 changes: 9 additions & 0 deletions src/azure-cli/azure/cli/command_modules/network/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def load_arguments(self, _):
help='Space-separated list of availability zones into which to provision the resource.',
choices=['1', '2', '3']
)
edge_zone = CLIArgumentType(help='The name of edge zone.', is_preview=True, min_api='2020-08-01')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use this type for edge zone and add min_api version for your parameter

edge_zone_type = CLIArgumentType(options_list='--edge-zone', help='The name of edge zone.', is_preview=True)


# region NetworkRoot
with self.argument_context('network') as c:
Expand Down Expand Up @@ -857,6 +858,7 @@ def load_arguments(self, _):
c.argument('manual_request', help="Use manual request to establish the connection. Configure it as 'true' when you don't have access to the subscription of private link service.", arg_type=get_three_state_flag())
c.argument('connection_name', help='Name of the private link service connection.')
c.ignore('expand')
c.argument('edge_zone', edge_zone)

with self.argument_context('network private-endpoint dns-zone-group') as c:
c.argument('private_dns_zone', help='Name or ID of the private dns zone.', validator=validate_private_dns_zone)
Expand All @@ -877,6 +879,7 @@ def load_arguments(self, _):
c.argument('fqdns', nargs='+', help='Space-separated list of FQDNs.')
c.argument('location', get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group)
c.argument('enable_proxy_protocol', help='Enable proxy protocol for private link service.', arg_type=get_three_state_flag(), min_api='2019-09-01')
c.argument('edge_zone', edge_zone)

with self.argument_context('network private-link-service', arg_group='IP Configuration') as c:
c.argument('private_ip_address', private_ip_address_type)
Expand Down Expand Up @@ -941,6 +944,7 @@ def load_arguments(self, _):
c.argument('frontend_ip_zone', zone_type, min_api='2017-06-01', options_list=['--frontend-ip-zone'], help='used to create internal facing Load balancer')
c.argument('validate', help='Generate and validate the ARM template without creating any resources.', action='store_true')
c.argument('sku', min_api='2017-08-01', help='Load balancer SKU', arg_type=get_enum_type(LoadBalancerSkuName, default='basic'))
c.argument('edge_zone', edge_zone)

with self.argument_context('network lb create', arg_group='Public IP') as c:
public_ip_help = get_folded_parameter_help_string('public IP address', allow_none=True, allow_new=True)
Expand Down Expand Up @@ -1127,6 +1131,7 @@ def load_arguments(self, _):
with self.argument_context('network nic create') as c:
c.argument('private_ip_address_version', min_api='2016-09-01', help='The private IP address version to use.', default=IPVersion.I_PV4.value if IPVersion else '')
c.argument('network_interface_name', nic_type, options_list=['--name', '-n'], id_part=None)
c.argument('edge_zone', edge_zone)

public_ip_help = get_folded_parameter_help_string('public IP address', allow_none=True, default_none=True)
c.argument('public_ip_address', help=public_ip_help, completer=get_resource_name_completion_list('Microsoft.Network/publicIPAddresses'))
Expand Down Expand Up @@ -1687,6 +1692,7 @@ def load_arguments(self, _):
c.argument('sku', min_api='2017-08-01', help='Name of a public IP address SKU', arg_type=get_enum_type(PublicIPAddressSkuName))
c.argument('tier', min_api='2020-07-01', help='Tier of a public IP address SKU and Global tier is only supported for standard SKU public IP addresses', arg_type=get_enum_type(PublicIPAddressSkuTier))
c.ignore('dns_name_type')
c.argument('edge_zone', edge_zone)

for item in ['create', 'update']:
with self.argument_context('network public-ip {}'.format(item)) as c:
Expand All @@ -1707,6 +1713,7 @@ def load_arguments(self, _):
c.argument('zone', zone_compatible_type, min_api='2020-08-01')

with self.argument_context('network public-ip prefix create') as c:
c.argument('edge_zone', edge_zone)
c.argument('version', min_api='2019-08-01', help='IP address type.', arg_type=get_enum_type(IPVersion, 'ipv4'))
# endregion

Expand Down Expand Up @@ -1829,6 +1836,7 @@ def load_arguments(self, _):
c.argument('location', get_location_type(self.cli_ctx))
c.argument('vnet_name', virtual_network_name_type, options_list=['--name', '-n'], completer=None,
local_context_attribute=LocalContextAttribute(name='vnet_name', actions=[LocalContextAction.SET], scopes=[ALL]))
c.argument('edge_zone', edge_zone)

with self.argument_context('network vnet create', arg_group='Subnet') as c:
c.argument('subnet_name', help='Name of a new subnet to create within the VNet.',
Expand Down Expand Up @@ -1925,6 +1933,7 @@ def load_arguments(self, _):
vnet_help = "Name or ID of an existing virtual network which has a subnet named 'GatewaySubnet'."
c.argument('virtual_network', options_list='--vnet', help=vnet_help)
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.')
c.ignore('edge_zone') # wait for service ready
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to expose this parameter as service not ready?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'az network vnet-gateway create' need new swagger : https://github.com/Azure/azure-rest-api-specs/pull/13864/files
(RE: virtualNetworkGateway missing extendedLocation in swagger)

Copy link
Member Author

@msyyc msyyc Apr 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is ignored. So customers could not use it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is ignored. So customers could not use it.

I think customer can see it in command help message. Why not expose it when service is ready?


with self.argument_context('network vnet-gateway update') as c:
c.argument('enable_bgp', help='Enable BGP (Border Gateway Protocol)', arg_group='BGP Peering', arg_type=get_enum_type(['true', 'false']))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ def _ag_subresource_id(_type, name):

def build_load_balancer_resource(cmd, name, location, tags, backend_pool_name, frontend_ip_name, public_ip_id,
subnet_id, private_ip_address, private_ip_allocation,
sku, frontend_ip_zone, private_ip_address_version, tier=None):
sku, frontend_ip_zone, private_ip_address_version, tier=None,
edge_zone=None, edge_zone_type=None):
frontend_ip_config = _build_frontend_ip_config(cmd, frontend_ip_name, public_ip_id, subnet_id, private_ip_address,
private_ip_allocation, frontend_ip_zone, private_ip_address_version)

Expand All @@ -370,10 +371,13 @@ def build_load_balancer_resource(cmd, name, location, tags, backend_pool_name, f
lb['sku'] = {'name': sku}
if tier and cmd.supported_api_version(min_api='2020-07-01'):
lb['sku'].update({'tier': tier})
if edge_zone and edge_zone_type:
lb['extendedLocation'] = {'name': edge_zone, 'type': edge_zone_type}
return lb


def build_public_ip_resource(cmd, name, location, tags, address_allocation, dns_name, sku, zone, tier=None):
def build_public_ip_resource(cmd, name, location, tags, address_allocation, dns_name, sku, zone, tier=None,
edge_zone=None, edge_zone_type=None):
public_ip_properties = {'publicIPAllocationMethod': address_allocation}

if dns_name:
Expand All @@ -396,6 +400,8 @@ def build_public_ip_resource(cmd, name, location, tags, address_allocation, dns_
public_ip['sku'].update({'tier': tier})
if zone and cmd.supported_api_version(min_api='2017-06-01'):
public_ip['zones'] = zone
if edge_zone and edge_zone_type:
public_ip['extendedLocation'] = {'name': edge_zone, 'type': edge_zone_type}
return public_ip


Expand Down
46 changes: 36 additions & 10 deletions src/azure-cli/azure/cli/command_modules/network/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3003,7 +3003,7 @@ def update_express_route_port_link(cmd, instance, express_route_port_name, link_
def create_private_endpoint(cmd, resource_group_name, private_endpoint_name, subnet,
private_connection_resource_id, connection_name, group_ids=None,
virtual_network_name=None, tags=None, location=None,
request_message=None, manual_request=None):
request_message=None, manual_request=None, edge_zone=None):
client = network_client_factory(cmd.cli_ctx).private_endpoints
PrivateEndpoint, Subnet, PrivateLinkServiceConnection = cmd.get_models('PrivateEndpoint',
'Subnet',
Expand All @@ -3023,6 +3023,8 @@ def create_private_endpoint(cmd, resource_group_name, private_endpoint_name, sub
else:
private_endpoint.private_link_service_connections = [pls_connection]

if edge_zone:
private_endpoint.extended_location = _edge_zone_model(cmd, edge_zone)
return client.begin_create_or_update(resource_group_name, private_endpoint_name, private_endpoint)


Expand Down Expand Up @@ -3099,7 +3101,7 @@ def create_private_link_service(cmd, resource_group_name, service_name, subnet,
virtual_network_name=None, public_ip_address=None,
location=None, tags=None, load_balancer_name=None,
visibility=None, auto_approval=None, fqdns=None,
enable_proxy_protocol=None):
enable_proxy_protocol=None, edge_zone=None):
client = network_client_factory(cmd.cli_ctx).private_link_services
FrontendIPConfiguration, PrivateLinkService, PrivateLinkServiceIpConfiguration, PublicIPAddress, Subnet = \
cmd.get_models('FrontendIPConfiguration', 'PrivateLinkService', 'PrivateLinkServiceIpConfiguration',
Expand All @@ -3124,6 +3126,8 @@ def create_private_link_service(cmd, resource_group_name, service_name, subnet,
tags=tags,
enable_proxy_protocol=enable_proxy_protocol
)
if edge_zone:
link_service.extended_location = _edge_zone_model(cmd, edge_zone)
return client.begin_create_or_update(resource_group_name, service_name, link_service)


Expand Down Expand Up @@ -3208,6 +3212,11 @@ def remove_private_link_services_ipconfig(cmd, resource_group_name, service_name
# endregion


def _edge_zone_model(cmd, edge_zone):
ExtendedLocation, ExtendedLocationTypes = cmd.get_models('ExtendedLocation', 'ExtendedLocationTypes')
return ExtendedLocation(name=edge_zone, type=ExtendedLocationTypes.EDGE_ZONE)


# region LoadBalancers
def create_load_balancer(cmd, load_balancer_name, resource_group_name, location=None, tags=None,
backend_pool_name=None, frontend_ip_name='LoadBalancerFrontEnd',
Expand All @@ -3217,7 +3226,7 @@ def create_load_balancer(cmd, load_balancer_name, resource_group_name, location=
virtual_network_name=None, vnet_address_prefix='10.0.0.0/16',
public_ip_address_type=None, subnet_type=None, validate=False,
no_wait=False, sku=None, frontend_ip_zone=None, public_ip_zone=None,
private_ip_address_version=None):
private_ip_address_version=None, edge_zone=None):
from azure.cli.core.util import random_string
from azure.cli.core.commands.arm import ArmTemplateBuilder
from azure.cli.command_modules.network._template_builder import (
Expand Down Expand Up @@ -3246,6 +3255,11 @@ def create_load_balancer(cmd, load_balancer_name, resource_group_name, location=
subscription=get_subscription_id(cmd.cli_ctx), resource_group=resource_group_name,
namespace='Microsoft.Network')

if edge_zone and cmd.supported_api_version(min_api='2020-08-01'):
edge_zone_type = 'EdgeZone'
else:
edge_zone_type = None

if subnet_type == 'new':
lb_dependencies.append('Microsoft.Network/virtualNetworks/{}'.format(virtual_network_name))
vnet = build_vnet_resource(
Expand All @@ -3261,14 +3275,14 @@ def create_load_balancer(cmd, load_balancer_name, resource_group_name, location=
tags,
public_ip_address_allocation,
public_ip_dns_name,
sku, public_ip_zone))
sku, public_ip_zone, None, edge_zone, edge_zone_type))
public_ip_id = '{}/publicIPAddresses/{}'.format(network_id_template,
public_ip_address)

load_balancer_resource = build_load_balancer_resource(
cmd, load_balancer_name, location, tags, backend_pool_name, frontend_ip_name,
public_ip_id, subnet_id, private_ip_address, private_ip_allocation, sku,
frontend_ip_zone, private_ip_address_version)
frontend_ip_zone, private_ip_address_version, None, edge_zone, edge_zone_type)
load_balancer_resource['dependsOn'] = lb_dependencies
master_template.add_resource(load_balancer_resource)
master_template.add_output('loadBalancer', load_balancer_name, output_type='object')
Expand Down Expand Up @@ -4055,7 +4069,7 @@ def create_nic(cmd, resource_group_name, network_interface_name, subnet, locatio
private_ip_address=None, private_ip_address_version=None,
public_ip_address=None, virtual_network_name=None, enable_accelerated_networking=None,
application_security_groups=None, no_wait=False,
app_gateway_backend_address_pools=None):
app_gateway_backend_address_pools=None, edge_zone=None):
client = network_client_factory(cmd.cli_ctx).network_interfaces
(NetworkInterface, NetworkInterfaceDnsSettings, NetworkInterfaceIPConfiguration, NetworkSecurityGroup,
PublicIPAddress, Subnet, SubResource) = cmd.get_models(
Expand Down Expand Up @@ -4093,6 +4107,9 @@ def create_nic(cmd, resource_group_name, network_interface_name, subnet, locatio
if public_ip_address:
ip_config.public_ip_address = PublicIPAddress(id=public_ip_address)
nic.ip_configurations = [ip_config]

if edge_zone:
nic.extended_location = _edge_zone_model(cmd, edge_zone)
return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name, network_interface_name, nic)


Expand Down Expand Up @@ -5661,7 +5678,7 @@ def run_network_configuration_diagnostic(cmd, client, watcher_rg, watcher_name,
def create_public_ip(cmd, resource_group_name, public_ip_address_name, location=None, tags=None,
allocation_method=None, dns_name=None,
idle_timeout=4, reverse_fqdn=None, version=None, sku=None, tier=None, zone=None, ip_tags=None,
public_ip_prefix=None):
public_ip_prefix=None, edge_zone=None):
IPAllocationMethod, PublicIPAddress, PublicIPAddressDnsSettings, SubResource = cmd.get_models(
'IPAllocationMethod', 'PublicIPAddress', 'PublicIPAddressDnsSettings', 'SubResource')
client = network_client_factory(cmd.cli_ctx).public_ip_addresses
Expand Down Expand Up @@ -5698,6 +5715,9 @@ def create_public_ip(cmd, resource_group_name, public_ip_address_name, location=
public_ip.dns_settings = PublicIPAddressDnsSettings(
domain_name_label=dns_name,
reverse_fqdn=reverse_fqdn)

if edge_zone:
public_ip.extended_location = _edge_zone_model(cmd, edge_zone)
return client.begin_create_or_update(resource_group_name, public_ip_address_name, public_ip)


Expand Down Expand Up @@ -5733,7 +5753,7 @@ def update_public_ip(cmd, instance, dns_name=None, allocation_method=None, versi


def create_public_ip_prefix(cmd, client, resource_group_name, public_ip_prefix_name, prefix_length,
version=None, location=None, tags=None, zone=None):
version=None, location=None, tags=None, zone=None, edge_zone=None):
PublicIPPrefix, PublicIPPrefixSku = cmd.get_models('PublicIPPrefix', 'PublicIPPrefixSku')
prefix = PublicIPPrefix(
location=location,
Expand All @@ -5746,6 +5766,8 @@ def create_public_ip_prefix(cmd, client, resource_group_name, public_ip_prefix_n
if cmd.supported_api_version(min_api='2019-08-01'):
prefix.public_ip_address_version = version if version is not None else 'ipv4'

if edge_zone:
prefix.extended_location = _edge_zone_model(cmd, edge_zone)
return client.begin_create_or_update(resource_group_name, public_ip_prefix_name, prefix)


Expand Down Expand Up @@ -6018,7 +6040,7 @@ def list_traffic_manager_endpoints(cmd, resource_group_name, profile_name, endpo
def create_vnet(cmd, resource_group_name, vnet_name, vnet_prefixes='10.0.0.0/16',
subnet_name=None, subnet_prefix=None, dns_servers=None,
location=None, tags=None, vm_protection=None, ddos_protection=None,
ddos_protection_plan=None, network_security_group=None):
ddos_protection_plan=None, network_security_group=None, edge_zone=None):
AddressSpace, DhcpOptions, Subnet, VirtualNetwork, SubResource, NetworkSecurityGroup = \
cmd.get_models('AddressSpace', 'DhcpOptions', 'Subnet', 'VirtualNetwork',
'SubResource', 'NetworkSecurityGroup')
Expand All @@ -6043,6 +6065,8 @@ def create_vnet(cmd, resource_group_name, vnet_name, vnet_prefixes='10.0.0.0/16'
vnet.enable_vm_protection = vm_protection
if cmd.supported_api_version(min_api='2018-02-01'):
vnet.ddos_protection_plan = SubResource(id=ddos_protection_plan) if ddos_protection_plan else None
if edge_zone:
vnet.extended_location = _edge_zone_model(cmd, edge_zone)
return cached_put(cmd, client.begin_create_or_update, vnet, resource_group_name, vnet_name)


Expand Down Expand Up @@ -6337,7 +6361,7 @@ def create_vnet_gateway(cmd, resource_group_name, virtual_network_gateway_name,
asn=None, bgp_peering_address=None, peer_weight=None,
address_prefixes=None, radius_server=None, radius_secret=None, client_protocol=None,
gateway_default_site=None, custom_routes=None, aad_tenant=None, aad_audience=None,
aad_issuer=None, root_cert_data=None, root_cert_name=None, vpn_auth_type=None):
aad_issuer=None, root_cert_data=None, root_cert_name=None, vpn_auth_type=None, edge_zone=None):
(VirtualNetworkGateway, BgpSettings, SubResource, VirtualNetworkGatewayIPConfiguration, VirtualNetworkGatewaySku,
VpnClientConfiguration, AddressSpace, VpnClientRootCertificate) = cmd.get_models(
'VirtualNetworkGateway', 'BgpSettings', 'SubResource', 'VirtualNetworkGatewayIPConfiguration',
Expand Down Expand Up @@ -6386,6 +6410,8 @@ def create_vnet_gateway(cmd, resource_group_name, virtual_network_gateway_name,
vnet_gateway.custom_routes = AddressSpace()
vnet_gateway.custom_routes.address_prefixes = custom_routes

if edge_zone:
vnet_gateway.virtual_network_extended_location = _edge_zone_model(cmd, edge_zone)
return sdk_no_wait(no_wait, client.begin_create_or_update,
resource_group_name, virtual_network_gateway_name, vnet_gateway)

Expand Down
Loading