-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[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 | ||
| ) | ||
|
Comment on lines
676
to
680
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a subnet is not as simple as adding a new resource. We need to take the vnet's address space and subnet's prefix into consideration. It is very hard to deduce the new subnet's prefix based on the existing vnet's address space and existing subnet's prefix. This PR will always try to add subnet
My suggestion: If cc @myronfanqiu
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we discussed the cases you mentioned above before. Previously, there are some problems with the vnet/subnet prefix. However, for this PR, we don't want to change these behaviors, just keep them as before. What we changed in this PR this that, when vnet is specified and exists, no matter subnet is specified or not, if the subnet not exists, create it without removing other existing subnets. As the cases above, if the user not specify subnet prefix, it will use a default value (10.0.0.0/24) which may be wrong, however this is not the problem we want to solve in this PR.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to share some context, not related with this PR. There's default vnet/subnet azure CLI created when creating VM. This is convenient scenario CLI providing: minimum effort to get started on a VM.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
1, retry 25, 26..., or 23, 22... I agree it's complex and tricky. Users might be astonished when a strange subnet is created. |
||
| 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.