Skip to content

Commit c240fe6

Browse files
authored
vmss create: support public ip per vm, custom domain name, custom dns servers (Azure#3961)
1 parent a2ef00c commit c240fe6

21 files changed

+4031
-2553
lines changed

src/command_modules/azure-cli-network/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
]
3131

3232
DEPENDENCIES = [
33-
'azure-mgmt-network==1.1.0',
33+
'azure-mgmt-network==1.2.0',
3434
'azure-mgmt-trafficmanager==0.30.0',
3535
'azure-mgmt-dns==1.0.1',
3636
'azure-mgmt-resource==1.1.0',

src/command_modules/azure-cli-vm/HISTORY.rst

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ unreleased
1212
to password without needing `--authentication-type password` explicitly.
1313
* `vm/vmss create`: added information statements that can be shown using --debug
1414
* `vm/vmss create`: added client-side validation where certain parameters were previously just ignored.
15+
* `vmss create`: support public ip per instance, instance custom domain name, custom dns servers
1516

1617

1718
2.0.9 (2017-06-21)

src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_client_factory.py

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ def cf_ni(_):
2121
return ni
2222

2323

24+
def cf_public_ip_addresses(_):
25+
from azure.cli.core.profiles import ResourceType
26+
from azure.cli.core.commands.client_factory import get_mgmt_service_client
27+
public_ip_ops = get_mgmt_service_client(ResourceType.MGMT_NETWORK).public_ip_addresses
28+
return public_ip_ops
29+
30+
2431
def cf_avail_set(_):
2532
return _compute_client_factory().availability_sets
2633

src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_help.py

+8
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
- name: Create a Linux VM scale set from a custom image using an existing ssh public key of ~/.ssh/id_rsa.pub.
124124
text: >
125125
az vmss create -n MyVmss -g MyResourceGroup --image MyImage
126+
- name: Create a Linux VM scale set, a load balancer, each VM has a public-ip address, a custom domain name, own dns servers
127+
text: >
128+
az vmss create -n MyVmss -g MyResourceGroup --image centos --public-ip-per-vm --vm-domain-name myvmss --dns-servers 10.0.0.6 10.0.0.5
126129
- name: Create a Linux VM scale set with a cloud-init script (https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-using-cloud-init).
127130
text: >
128131
az vmss create -g MyResourceGroup -n MyVmss --image debian --custom_data MyCloudInitScript.yml
@@ -748,6 +751,11 @@
748751
short-summary: Get the IP address and port number used to connect to individual instances.
749752
"""
750753

754+
helps['vmss list-instance-public-ips'] = """
755+
type: command
756+
short-summary: List public IP addresses of VM instances
757+
"""
758+
751759
helps['vmss extension'] = """
752760
type: group
753761
short-summary: Extend the functionality of your VM scale set with extensions.

src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_params.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
UpgradeMode)
1111
from azure.mgmt.storage.models import SkuName
1212

13-
from azure.cli.core.commands import register_cli_argument, CliArgumentType
13+
from azure.cli.core.commands import register_cli_argument, CliArgumentType, VersionConstraint
14+
from azure.cli.core.profiles import ResourceType
1415
from azure.cli.core.commands.validators import \
1516
(get_default_location_from_resource_group, validate_file_or_dict)
1617
from azure.cli.core.commands.parameters import \
@@ -260,6 +261,11 @@ def get_vm_size_completion_list(prefix, action, parsed_args, **kwargs): # pylin
260261
register_cli_argument('vmss create', 'upgrade_policy_mode', help=None, **enum_choice_list(UpgradeMode))
261262
register_cli_argument('vmss create', 'vm_sku', help='Size of VMs in the scale set. See https://azure.microsoft.com/en-us/pricing/details/virtual-machines/ for size info.')
262263

264+
with VersionConstraint(ResourceType.MGMT_COMPUTE, min_api='2017-03-30') as c:
265+
c.register_cli_argument('vmss create', 'public_ip_per_vm', action='store_true', help="Each VM instance will have a public ip", arg_group='Network')
266+
c.register_cli_argument('vmss create', 'vm_domain_name', help="domain name of VM instances, once configured, the FQDN is 'vm<vm-index>.<vm-domain-name>.<..rest..>'", arg_group='Network')
267+
c.register_cli_argument('vmss create', 'dns_servers', nargs='+', help="space separated IP addresses of DNS servers, e.g. 10.0.0.5 10.0.0.6", arg_group='Network')
268+
263269
register_cli_argument('vm encryption', 'volume_type', help='Type of volume that the encryption operation is performed on', **enum_choice_list(['DATA', 'OS', 'ALL']))
264270
register_cli_argument('vm encryption', 'force', action='store_true', help='continue with encryption operations regardless of the warnings')
265271
register_cli_argument('vm encryption', 'disk_encryption_keyvault', validator=process_disk_encryption_namespace)

src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_template_builder.py

+24-7
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ def build_vmss_storage_account_pool_resource(loop_name, location, tags, storage_
618618
# pylint: disable=too-many-locals
619619
def build_vmss_resource(name, naming_prefix, location, tags, overprovision, upgrade_policy_mode,
620620
vm_sku, instance_count, ip_config_name, nic_name, subnet_id,
621+
public_ip_per_vm, vm_domain_name, dns_servers,
621622
admin_username, authentication_type,
622623
storage_profile, os_disk_name,
623624
os_caching, data_caching, storage_sku, data_disk_sizes_gb,
@@ -635,6 +636,18 @@ def build_vmss_resource(name, naming_prefix, location, tags, overprovision, upgr
635636
}
636637
}
637638

639+
if public_ip_per_vm:
640+
ip_configuration['properties']['publicipaddressconfiguration'] = {
641+
'name': 'instancepublicip',
642+
'properties': {
643+
'idleTimeoutInMinutes': 10,
644+
}
645+
}
646+
if vm_domain_name:
647+
ip_configuration['properties']['publicipaddressconfiguration']['properties']['dnsSettings'] = {
648+
'domainNameLabel': vm_domain_name
649+
}
650+
638651
if backend_address_pool_id:
639652
key = 'loadBalancerBackendAddressPools' if 'loadBalancers' in backend_address_pool_id \
640653
else 'ApplicationGatewayBackendAddressPools'
@@ -717,6 +730,16 @@ def build_vmss_resource(name, naming_prefix, location, tags, overprovision, upgr
717730
if single_placement_group is None: # this should never happen, but just in case
718731
raise ValueError('single_placement_group was not set by validators')
719732
# Build VMSS
733+
nic_config = {
734+
'name': nic_name,
735+
'properties': {
736+
'primary': 'true',
737+
'ipConfigurations': [ip_configuration]
738+
}
739+
}
740+
if dns_servers:
741+
nic_config['dnsServers'] = dns_servers
742+
720743
vmss_properties = {
721744
'overprovision': overprovision,
722745
'upgradePolicy': {
@@ -726,13 +749,7 @@ def build_vmss_resource(name, naming_prefix, location, tags, overprovision, upgr
726749
'storageProfile': storage_properties,
727750
'osProfile': os_profile,
728751
'networkProfile': {
729-
'networkInterfaceConfigurations': [{
730-
'name': nic_name,
731-
'properties': {
732-
'primary': 'true',
733-
'ipConfigurations': [ip_configuration]
734-
}
735-
}]
752+
'networkInterfaceConfigurations': [nic_config]
736753
}
737754
}
738755
}

src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_validators.py

+4
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,10 @@ def process_vmss_create_namespace(namespace):
830830
_validate_vmss_create_public_ip(namespace)
831831
_validate_vm_vmss_create_auth(namespace)
832832

833+
if not namespace.public_ip_per_vm and namespace.vm_domain_name:
834+
raise CLIError('Usage error: --vm-domain-name can only be used when --public-ip-per-vm is enabled')
835+
836+
833837
# endregion
834838

835839
# region disk, snapshot, image validators

src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/commands.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
cf_vm_ext_image, cf_vm_image, cf_usage,
1111
cf_vmss, cf_vmss_vm,
1212
cf_vm_sizes, cf_disks, cf_snapshots,
13-
cf_images)
13+
cf_images, cf_public_ip_addresses)
1414
from azure.cli.core.commands import DeploymentOutputLongRunningOperation, cli_command
1515
from azure.cli.core.commands.arm import \
1616
(cli_generic_update_command, cli_generic_wait_command, handle_long_running_operation_exception,
@@ -242,11 +242,12 @@ def transform_vm_list(vm_list):
242242
cli_command(__name__, 'vmss reimage', custom_path.format('reimage_vmss'), no_wait_param='no_wait')
243243
cli_command(__name__, 'vmss scale', custom_path.format('scale_vmss'), no_wait_param='no_wait')
244244
cli_command(__name__, 'vmss list-instance-connection-info', custom_path.format('list_vmss_instance_connection_info'))
245+
if supported_api_version(ResourceType.MGMT_COMPUTE, min_api='2017-03-30'):
246+
cli_command(__name__, 'vmss list-instance-public-ips', 'azure.mgmt.network.operations.public_ip_addresses_operations#PublicIPAddressesOperations.list_virtual_machine_scale_set_public_ip_addresses', cf_public_ip_addresses)
245247

246248
# VM Size
247249
cli_command(__name__, 'vm list-sizes', mgmt_path.format('virtual_machine_sizes_operations', 'VirtualMachineSizesOperations', 'list'), cf_vm_sizes)
248250

249-
250251
if supported_api_version(ResourceType.MGMT_COMPUTE, min_api='2016-04-30-preview'):
251252
# VM Disk
252253
op_var = 'disks_operations'

src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/custom.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,7 @@ def create_vmss(vmss_name, resource_group_name, image,
17001700
backend_pool_name=None, nat_pool_name=None, backend_port=None,
17011701
public_ip_address=None, public_ip_address_allocation='dynamic',
17021702
public_ip_address_dns_name=None,
1703+
public_ip_per_vm=False, vm_domain_name=None, dns_servers=None,
17031704
os_caching=DefaultStr(CachingTypes.read_write.value), data_caching=None,
17041705
storage_container_name=DefaultStr('vhds'), storage_sku=None,
17051706
os_type=None, os_disk_name=None,
@@ -1882,8 +1883,9 @@ def create_vmss(vmss_name, resource_group_name, image,
18821883
vmss_resource = build_vmss_resource(vmss_name, naming_prefix, location, tags,
18831884
not disable_overprovision, upgrade_policy_mode,
18841885
vm_sku, instance_count,
1885-
ip_config_name, nic_name, subnet_id, admin_username,
1886-
authentication_type, storage_profile,
1886+
ip_config_name, nic_name, subnet_id,
1887+
public_ip_per_vm, vm_domain_name, dns_servers,
1888+
admin_username, authentication_type, storage_profile,
18871889
os_disk_name, os_caching, data_caching,
18881890
storage_sku, data_disk_sizes_gb, image_data_disks,
18891891
os_type, image, admin_password,

0 commit comments

Comments
 (0)