Skip to content

Commit

Permalink
vm create: support configure Public-IP sku (Azure#5917)
Browse files Browse the repository at this point in the history
  • Loading branch information
yugangw-msft authored Mar 27, 2018
1 parent 04a7089 commit 40741cd
Show file tree
Hide file tree
Showing 7 changed files with 981 additions and 242 deletions.
3 changes: 3 additions & 0 deletions src/command_modules/azure-cli-vm/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Release History
===============
2.0.30
++++++
* `vm create`: support configure Public-IP sku

2.0.29
++++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,11 @@ def load_arguments(self, _):
c.argument('nics', nargs='+', help='Names or IDs of existing NICs to attach to the VM. The first NIC will be designated as primary. If omitted, a new NIC will be created. If an existing NIC is specified, do not specify subnet, VNet, public IP or NSG.')
c.argument('private_ip_address', help='Static private IP address (e.g. 10.0.0.5).')
c.argument('public_ip_address', help='Name of the public IP address when creating one (default) or referencing an existing one. Can also reference an existing public IP by ID or specify "" for None.')
c.argument('public_ip_address_allocation', help=None, arg_type=get_enum_type(['dynamic', 'static']))
c.argument('public_ip_address_allocation', help=None, default=None, arg_type=get_enum_type(['dynamic', 'static']))
c.argument('public_ip_address_dns_name', help='Globally unique DNS name for a newly created public IP.')
if self.supported_api_version(min_api='2017-08-01', resource_type=ResourceType.MGMT_NETWORK):
PublicIPAddressSkuName = self.get_models('PublicIPAddressSkuName', resource_type=ResourceType.MGMT_NETWORK)
c.argument('public_ip_sku', help='Sku', default=None, arg_type=get_enum_type(PublicIPAddressSkuName))

with self.argument_context(scope, arg_group='Marketplace Image Plan') as c:
c.argument('plan_name', help='plan name')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def _validate_vmss_create_nsg(cmd, namespace):
'networkSecurityGroups', 'Microsoft.Network')


def _validate_vm_create_public_ip(cmd, namespace):
def _validate_vm_vmss_create_public_ip(cmd, namespace):
if namespace.public_ip_address:
if check_existence(cmd.cli_ctx, namespace.public_ip_address, namespace.resource_group_name,
'Microsoft.Network', 'publicIPAddresses'):
Expand All @@ -633,14 +633,23 @@ def _validate_vm_create_public_ip(cmd, namespace):
namespace.public_ip_type = 'new'
logger.debug('new public IP address will be created')

# Public-IP SKU is only exposed for VM. VMSS has no such needs so far
if getattr(namespace, 'public_ip_sku', None):
from azure.cli.core.profiles import ResourceType
PublicIPAddressSkuName, IPAllocationMethod = cmd.get_models('PublicIPAddressSkuName', 'IPAllocationMethod',
resource_type=ResourceType.MGMT_NETWORK)
if namespace.public_ip_sku == PublicIPAddressSkuName.standard.value:
if not namespace.public_ip_address_allocation:
namespace.public_ip_address_allocation = IPAllocationMethod.static.value


def _validate_vmss_create_public_ip(cmd, namespace):
if namespace.load_balancer_type is None and namespace.app_gateway_type is None:
if namespace.public_ip_address:
raise CLIError('--public-ip-address can only be used when creating a new load '
'balancer or application gateway frontend.')
namespace.public_ip_address = ''
_validate_vm_create_public_ip(cmd, namespace)
_validate_vm_vmss_create_public_ip(cmd, namespace)


def _validate_vm_create_nics(cmd, namespace):
Expand Down Expand Up @@ -863,7 +872,7 @@ def process_vm_create_namespace(cmd, namespace):
_validate_vm_create_availability_set(cmd, namespace)
_validate_vm_vmss_create_vnet(cmd, namespace)
_validate_vm_create_nsg(cmd, namespace)
_validate_vm_create_public_ip(cmd, namespace)
_validate_vm_vmss_create_public_ip(cmd, namespace)
_validate_vm_create_nics(cmd, namespace)
_validate_vm_vmss_create_auth(namespace)
if namespace.secrets:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,8 @@ def create_vm(cmd, vm_name, resource_group_name, image=None, size='Standard_DS1_
admin_username=getpass.getuser(), ssh_dest_key_path=None, ssh_key_value=None,
generate_ssh_keys=False, availability_set=None, nics=None, nsg=None, nsg_rule=None,
private_ip_address=None, public_ip_address=None, public_ip_address_allocation='dynamic',
public_ip_address_dns_name=None, os_disk_name=None, os_type=None, storage_account=None,
os_caching=None, data_caching=None, storage_container_name=None, storage_sku=None,
public_ip_address_dns_name=None, public_ip_sku=None, os_disk_name=None, os_type=None,
storage_account=None, os_caching=None, data_caching=None, storage_container_name=None, storage_sku=None,
use_unmanaged_disk=False, attach_os_disk=None, os_disk_size_gb=None,
attach_data_disks=None, data_disk_sizes_gb=None, image_data_disks=None,
vnet_name=None, vnet_address_prefix='10.0.0.0/16', subnet=None, subnet_address_prefix='10.0.0.0/24',
Expand Down Expand Up @@ -569,7 +569,7 @@ def create_vm(cmd, vm_name, resource_group_name, image=None, size='Standard_DS1_
master_template.add_resource(build_public_ip_resource(cmd, public_ip_address, location, tags,
public_ip_address_allocation,
public_ip_address_dns_name,
None, zone))
public_ip_sku, zone))

subnet_id = subnet if is_valid_resource_id(subnet) else \
'{}/virtualNetworks/{}/subnets/{}'.format(network_id_template, vnet_name, subnet)
Expand Down
Loading

0 comments on commit 40741cd

Please sign in to comment.