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
5 changes: 4 additions & 1 deletion src/azure-cli/azure/cli/command_modules/vm/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,11 @@ def _check_subnet(s):
if (subnet_is_id and vnet) or (not subnet_is_id and not vnet):
raise CLIError("incorrect usage: --subnet ID | --subnet NAME --vnet-name NAME")

from azure.cli.command_modules.network.aaz.latest.network.vnet import Show as VirtualNetworkShow
api_version = VirtualNetworkShow._aaz_info['version']
subnet_exists = \
check_existence(cmd.cli_ctx, subnet, rg, 'Microsoft.Network', 'subnets', vnet, 'virtualNetworks')
check_existence(cmd.cli_ctx, subnet, rg, 'Microsoft.Network', 'subnets',
vnet, 'virtualNetworks', api_version=api_version)

if subnet_is_id and not subnet_exists:
raise CLIError("Subnet '{}' does not exist.".format(subnet))
Expand Down
6 changes: 4 additions & 2 deletions src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def log_pprint_template(template):


def check_existence(cli_ctx, value, resource_group, provider_namespace, resource_type,
parent_name=None, parent_type=None):
parent_name=None, parent_type=None, api_version=None):
# check for name or ID and set the type flags
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.core.exceptions import HttpResponseError
Expand All @@ -93,7 +93,9 @@ def check_existence(cli_ctx, value, resource_group, provider_namespace, resource
parent_path = ''
resource_name = id_parts['name']
resource_type = id_parts.get('type', resource_type)
api_version = _resolve_api_version(cli_ctx, provider_namespace, resource_type, parent_path)

if not api_version:
api_version = _resolve_api_version(cli_ctx, provider_namespace, resource_type, parent_path)

try:
resource_client.get(rg, ns, parent_path, resource_type, resource_name, api_version)
Expand Down
Loading