-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Container Instance: Updating VNET workflow #7517
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 17 commits
d8aa50e
7ec3de5
398dc67
67e3275
ca92ef8
497d4e4
61e6796
36f9422
f67fddf
2635881
fce0681
a868528
cfa1d97
a4347bd
c79f519
5763980
1452848
b7db5b1
01be673
99e3b57
43b4a59
c558bad
487da41
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 |
|---|---|---|
|
|
@@ -91,6 +91,7 @@ def create_container(cmd, | |
| azure_file_volume_mount_path=None, | ||
| log_analytics_workspace=None, | ||
| log_analytics_workspace_key=None, | ||
| vnet=None, | ||
| vnet_name=None, | ||
| vnet_address_prefix='10.0.0.0/16', | ||
| subnet=None, | ||
|
|
@@ -183,8 +184,8 @@ def create_container(cmd, | |
| identity = _build_identities_info(assign_identity) | ||
|
|
||
| # Set up VNET, subnet and network profile if needed | ||
| if subnet and vnet_name and not network_profile: | ||
| network_profile = _get_vnet_network_profile(cmd, location, resource_group_name, vnet_name, vnet_address_prefix, subnet, subnet_address_prefix) | ||
| if subnet and not network_profile: | ||
| network_profile = _get_vnet_network_profile(cmd, location, resource_group_name, vnet, vnet_address_prefix, subnet, subnet_address_prefix) | ||
|
|
||
| cg_network_profile = None | ||
| if network_profile: | ||
|
|
@@ -245,51 +246,64 @@ def _get_resource(client, resource_group_name, *subresources): | |
| raise | ||
|
|
||
|
|
||
| def _get_vnet_network_profile(cmd, location, resource_group_name, vnet_name, vnet_address_prefix, subnet, subnet_address_prefix): | ||
| def _get_vnet_network_profile(cmd, location, resource_group_name, vnet, vnet_address_prefix, subnet, subnet_address_prefix): | ||
| from azure.cli.core.profiles import ResourceType | ||
| from msrestazure.tools import parse_resource_id, is_valid_resource_id | ||
|
|
||
| containerInstanceDelegationServiceName = "Microsoft.ContainerInstance/containerGroups" | ||
| Delegation = cmd.get_models('Delegation', resource_type=ResourceType.MGMT_NETWORK) | ||
| aci_delegation = Delegation( | ||
| name="Microsoft.ContainerInstance.containerGroups", | ||
| service_name="Microsoft.ContainerInstance/containerGroups" | ||
| name=containerInstanceDelegationServiceName, | ||
| service_name=containerInstanceDelegationServiceName | ||
|
samkreter marked this conversation as resolved.
Outdated
|
||
| ) | ||
|
|
||
| ncf = cf_network(cmd.cli_ctx) | ||
|
|
||
| vnet_name = vnet | ||
| subnet_name = subnet | ||
| if is_valid_resource_id(subnet): | ||
| parsed_subnet_id = parse_resource_id(subnet) | ||
| subnet_name = parsed_subnet_id['resource_name'] | ||
| vnet_name = parsed_subnet_id['name'] | ||
| resource_group_name = parsed_subnet_id['resource_group'] | ||
| elif is_valid_resource_id(vnet): | ||
| parsed_vnet_id = parse_resource_id(vnet) | ||
| vnet_name = parsed_vnet_id['resource_name'] | ||
| resource_group_name = parsed_vnet_id['resource_group'] | ||
| ncf.virtual_networks.get(resource_group_name, vnet_name) | ||
|
samkreter marked this conversation as resolved.
Outdated
|
||
|
|
||
| default_network_profile_name = "aci-network-profile-{}-{}".format(vnet_name, subnet_name) | ||
|
|
||
| subnet = _get_resource(ncf.subnets, resource_group_name, vnet_name, subnet_name) | ||
| # For an existing subnet, validate and add delegation if needed | ||
| if subnet: | ||
| for endpoint in (subnet.service_endpoints or []): | ||
| if endpoint.service != "Microsoft.ContainerInstance": | ||
| raise CLIError("Can not use subnet with existing service links other than 'Microsoft.ContainerInstance'.") | ||
| logger.info('Using existing subnet "%s" in resource group "%s"', subnet.name, resource_group_name) | ||
| for sal in (subnet.service_association_links or []): | ||
| if sal.linked_resource_type != containerInstanceDelegationServiceName: | ||
| raise CLIError("Can not use subnet with existing service association links other than {}.".format(containerInstanceDelegationServiceName)) | ||
|
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. Why doesn't the service provide this error message?
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. Currently, the error message doesn't propagate back correctly between our side and networking side. This is to make the error clear to customers for now. |
||
|
|
||
| if not subnet.delegations: | ||
| logger.info('Adding ACI delegation to the existing subnet.') | ||
| subnet.delegations = [aci_delegation] | ||
| subnet = ncf.subnets.create_or_update(resource_group_name, vnet_name, subnet_name, subnet).result() | ||
| else: | ||
| for delegation in subnet.delegations: | ||
| if delegation.service_name != containerInstanceDelegationServiceName: | ||
| raise CLIError("Can not use subnet with existing delegations other than {}".format(containerInstanceDelegationServiceName)) | ||
|
|
||
| network_profile = _get_resource(ncf.network_profiles, resource_group_name, default_network_profile_name) | ||
| if network_profile: | ||
| logger.info('Using existing network profile "%s"', default_network_profile_name) | ||
| return network_profile.id | ||
|
|
||
| # Create new subnet and Vnet if not exists | ||
| else: | ||
| Subnet, VirtualNetwork, AddressSpace = cmd.get_models('Subnet', 'VirtualNetwork', | ||
| 'AddressSpace', resource_type=ResourceType.MGMT_NETWORK) | ||
|
|
||
| vnet = _get_resource(ncf.virtual_networks, resource_group_name, vnet_name) | ||
| if not vnet: | ||
| logger.info('Creating new vnet "%s" in resource group "%s"', vnet_name, resource_group_name) | ||
| ncf.virtual_networks.create_or_update(resource_group_name, | ||
| vnet_name, | ||
| VirtualNetwork(name=vnet_name, | ||
|
|
@@ -301,13 +315,13 @@ def _get_vnet_network_profile(cmd, location, resource_group_name, vnet_name, vne | |
| address_prefix=subnet_address_prefix, | ||
| delegations=[aci_delegation]) | ||
|
|
||
| logger.info('Creating new subnet "%s" in resource group "%s"', subnet_name, resource_group_name) | ||
| subnet = ncf.subnets.create_or_update(resource_group_name, vnet_name, subnet_name, subnet).result() | ||
|
|
||
| NetworkProfile, ContainerNetworkInterfaceConfiguration, IPConfigurationProfile = cmd.get_models('NetworkProfile', | ||
| 'ContainerNetworkInterfaceConfiguration', | ||
| 'IPConfigurationProfile', | ||
| resource_type=ResourceType.MGMT_NETWORK) | ||
|
|
||
| # In all cases, create the network profile with aci NIC | ||
| network_profile = NetworkProfile( | ||
| name=default_network_profile_name, | ||
|
|
@@ -321,6 +335,7 @@ def _get_vnet_network_profile(cmd, location, resource_group_name, vnet_name, vne | |
| )] | ||
| ) | ||
|
|
||
| logger.info('Creating network profile "%s" in resource group "%s"', default_network_profile_name, resource_group_name) | ||
| network_profile = ncf.network_profiles.create_or_update(resource_group_name, default_network_profile_name, network_profile).result() | ||
|
|
||
| return network_profile.id | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.