-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Compute] BREAKING CHANGE: Fix #10728: az vm create: create subnet automatically if vnet is specified and subnet not exists
#12115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a2e20e4
f30efac
1fd5ce3
dae7dff
f413924
e1db954
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -660,11 +660,37 @@ def create_vm(cmd, vm_name, resource_group_name, image=None, size='Standard_DS1_ | |
|
|
||
| nic_dependencies = [] | ||
| if vnet_type == 'new': | ||
| vnet_name = vnet_name or '{}VNET'.format(vm_name) | ||
| subnet = subnet or '{}Subnet'.format(vm_name) | ||
| nic_dependencies.append('Microsoft.Network/virtualNetworks/{}'.format(vnet_name)) | ||
| master_template.add_resource(build_vnet_resource( | ||
| cmd, vnet_name, location, tags, vnet_address_prefix, subnet, subnet_address_prefix)) | ||
| vnet_exists = False | ||
| if vnet_name: | ||
| from azure.cli.command_modules.vm._vm_utils import check_existence | ||
| vnet_exists = \ | ||
| check_existence(cmd.cli_ctx, vnet_name, resource_group_name, 'Microsoft.Network', 'virtualNetworks') | ||
| if vnet_exists: | ||
| from azure.cli.core.commands import cached_get, cached_put, upsert_to_collection | ||
| from azure.cli.command_modules.vm._validators import get_network_client | ||
| client = get_network_client(cmd.cli_ctx).virtual_networks | ||
| vnet = cached_get(cmd, client.get, resource_group_name, vnet_name) | ||
|
|
||
| Subnet = cmd.get_models('Subnet', resource_type=ResourceType.MGMT_NETWORK) | ||
| subnet_obj = Subnet( | ||
| name=subnet, | ||
| address_prefixes=[subnet_address_prefix], | ||
| address_prefix=subnet_address_prefix | ||
| ) | ||
|
||
| upsert_to_collection(vnet, 'subnets', subnet_obj, 'name') | ||
| try: | ||
| cached_put(cmd, client.create_or_update, vnet, resource_group_name, vnet_name).result() | ||
| except Exception: | ||
| raise CLIError('Subnet({}) does not exist, but failed to create a new subnet with address ' | ||
| 'prefix {}. It may be caused by name or address prefix conflict. Please specify ' | ||
| 'an appropriate subnet name with --subnet or a valid address prefix value with ' | ||
| '--subnet-address-prefix.'.format(subnet, subnet_address_prefix)) | ||
| if not vnet_exists: | ||
| vnet_name = vnet_name or '{}VNET'.format(vm_name) | ||
| nic_dependencies.append('Microsoft.Network/virtualNetworks/{}'.format(vnet_name)) | ||
| master_template.add_resource(build_vnet_resource( | ||
| cmd, vnet_name, location, tags, vnet_address_prefix, subnet, subnet_address_prefix)) | ||
|
|
||
| if nsg_type == 'new': | ||
| nsg_rule_type = 'rdp' if os_type.lower() == 'windows' else 'ssh' | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default value: subnet_address_prefix='10.0.0.0/24'
It may be incompatible with vnet. You can deduce a valid value from vnet.
I request a change here.