Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/azure/cli/commands/template_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
def register_folded_cli_argument(scope, base_name, resource_type, parent_name=None, # pylint: disable=too-many-arguments
parent_type=None, type_field=None,
existing_id_flag_value='existingId', new_flag_value='new',
none_flag_value='none', default_value_flag='new', allow_none=True,
none_flag_value='none', default_value_flag='new',
**kwargs):
type_field_name = type_field or base_name + '_type'

Expand All @@ -29,7 +29,6 @@ def register_folded_cli_argument(scope, base_name, resource_type, parent_name=No
existing_id_flag_value,
new_flag_value,
none_flag_value,
allow_none,
parent_name,
parent_type)
custom_validator = kwargs.pop('validator', None)
Expand All @@ -42,7 +41,7 @@ def wrapped(namespace):
validator = fold_validator

quotes = '""' if platform.system() == 'Windows' else "''"
quote_text = ' Use {} for none.'.format(quotes) if allow_none else ''
quote_text = ' Use {} for none.'.format(quotes) if none_flag_value else ''
flag_texts = {
new_flag_value: ' Creates new by default.{}'.format(quote_text),
existing_id_flag_value: ' Uses existing resource.{}'
Expand All @@ -55,7 +54,7 @@ def wrapped(namespace):
register_cli_argument(scope, type_field_name, help=argparse.SUPPRESS, default=None)

def _name_id_fold(base_name, resource_type, type_field, #pylint: disable=too-many-arguments
existing_id_flag_value, new_flag_value, none_flag_value, allow_none=True,
existing_id_flag_value, new_flag_value, none_flag_value,
parent_name=None, parent_type=None):
def handle_folding(namespace):
base_name_val = getattr(namespace, base_name)
Expand All @@ -70,7 +69,7 @@ def handle_folding(namespace):
# An empty name specified - that means that we are neither referencing an existing
# field, or the name is set to an empty string. We check for all types of quotes
# so scripts can run cross-platform.
if not allow_none:
if not none_flag_value:
raise CLIError('Field {} cannot be none.'.format(make_camel_case(base_name)))
setattr(namespace, type_field, none_flag_value)
setattr(namespace, base_name, None)
Expand Down Expand Up @@ -103,6 +102,9 @@ def handle_folding(namespace):
raise CLIError('ID {} does not exist. Please specify '
'a name to create a new resource.'.format(
resource_id(**resource_id_parts)))
elif not new_flag_value:
raise CLIError('Referenced resource {} does not exist. Please create the required '
'resource and try again.'.format(resource_id(**resource_id_parts)))
else:
setattr(namespace, type_field, new_flag_value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def completer(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-a
register_cli_argument('network application-gateway', 'sku_tier', completer=get_enum_type_completion_list(ApplicationGatewayTier))
register_cli_argument('network application-gateway', 'routing_rule_type', completer=get_enum_type_completion_list(ApplicationGatewayRequestRoutingRuleType))
register_cli_argument('network application-gateway', 'virtual_network_name', virtual_network_name_type)
register_folded_cli_argument('network application-gateway', 'subnet', 'subnets', parent_name='virtual_network_name', parent_type='Microsoft.Network/virtualNetworks', validator=validate_address_prefixes, completer=get_subnet_completion_list())
register_folded_cli_argument('network application-gateway', 'subnet', 'subnets', parent_name='virtual_network_name', parent_type='Microsoft.Network/virtualNetworks', none_flag_value=None, validator=validate_address_prefixes, completer=get_subnet_completion_list())
register_folded_cli_argument('network application-gateway', 'public_ip', 'Microsoft.Network/publicIPAddresses', completer=get_resource_name_completion_list('Microsoft.Network/publicIPAddresses'))
register_cli_argument('network application-gateway', 'virtual_network_type', help=argparse.SUPPRESS)
register_cli_argument('network application-gateway', 'private_ip_address_allocation', help=argparse.SUPPRESS)
Expand Down Expand Up @@ -230,9 +230,9 @@ def completer(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-a
register_cli_argument('network nic create', 'network_interface_name', name_arg_type, validator=process_nic_create_namespace)
register_cli_argument('network nic create', 'enable_ip_forwarding', options_list=('--ip-forwarding',), action='store_true')
register_cli_argument('network nic create', 'use_dns_settings', help=argparse.SUPPRESS)
register_folded_cli_argument('network nic create', 'public_ip_address', 'Microsoft.Network/publicIPAddresses', completer=get_resource_name_completion_list('Microsoft.Network/publicIPAddresses'))
register_folded_cli_argument('network nic create', 'subnet', 'subnets', parent_name='virtual_network_name', parent_type='Microsoft.Network/virtualNetworks', completer=get_subnet_completion_list())
register_folded_cli_argument('network nic create', 'network_security_group', 'Microsoft.Network/networkSecurityGroups', completer=get_resource_name_completion_list('Microsoft.Network/networkSecurityGroups'))
register_folded_cli_argument('network nic create', 'public_ip_address', 'Microsoft.Network/publicIPAddresses', new_flag_value=None, default_value_flag='none', completer=get_resource_name_completion_list('Microsoft.Network/publicIPAddresses'))
register_folded_cli_argument('network nic create', 'subnet', 'subnets', none_flag_value=None, new_flag_value=None, default_value_flag='existingId', parent_name='virtual_network_name', parent_type='Microsoft.Network/virtualNetworks', completer=get_subnet_completion_list())
register_folded_cli_argument('network nic create', 'network_security_group', 'Microsoft.Network/networkSecurityGroups', new_flag_value=None, default_value_flag='none', completer=get_resource_name_completion_list('Microsoft.Network/networkSecurityGroups'))

register_cli_argument('network nic update', 'enable_ip_forwarding', options_list=('--ip-forwarding',), choices=['true', 'false'])
register_cli_argument('network nic update', 'network_security_group', validator=validate_nsg_name_or_id, completer=get_resource_name_completion_list('Microsoft.Network/networkSecurityGroups'))
Expand Down Expand Up @@ -353,7 +353,7 @@ def completer(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-a
register_cli_argument('network vpn-gateway create', 'gateway_type', choices=get_enum_choices(gatewayType))
register_cli_argument('network vpn-gateway create', 'sku', choices=get_enum_choices(sku))
register_cli_argument('network vpn-gateway create', 'vpn_type', choices=get_enum_choices(vpnType))
register_folded_cli_argument('network vpn-gateway create', 'public_ip_address', 'Microsoft.Network/publicIPAddresses', default_value_flag='existingId', allow_none=False, required=True)
register_folded_cli_argument('network vpn-gateway create', 'public_ip_address', 'Microsoft.Network/publicIPAddresses', default_value_flag='existingId', none_flag_value=None, new_flag_value=None, required=True)
register_cli_argument('network vpn-gateway', 'cert_name', help='Root certificate name', options_list=('--name', '-n'))
register_cli_argument('network vpn-gateway', 'gateway_name', help='Virtual network gateway name')
register_cli_argument('network vpn-gateway root-cert create', 'public_cert_data', help='Base64 contents of the root certificate file or file path.', validator=load_cert_file('public_cert_data'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ def get_vm_size_completion_list(prefix, action, parsed_args, **kwargs):#pylint:
register_cli_argument(scope, 'ssh_dest_key_path', completer=FilesCompleter())
register_cli_argument(scope, 'dns_name_for_public_ip', action=VMDNSNameAction, options_list=('--public-ip-address-dns-name',), help='Globally unique DNS Name for the Public IP.')
register_cli_argument(scope, 'authentication_type', authentication_type)
register_folded_cli_argument(scope, 'availability_set', 'Microsoft.Compute/availabilitySets', default_value_flag='none')
register_folded_cli_argument(scope, 'availability_set', 'Microsoft.Compute/availabilitySets', new_flag_value=None, default_value_flag='none')
register_cli_argument(scope, 'private_ip_address_allocation', help=argparse.SUPPRESS)
register_cli_argument(scope, 'virtual_network_ip_address_prefix', options_list=('--vnet-ip-address-prefix',))
register_cli_argument(scope, 'subnet_ip_address_prefix', options_list=('--subnet-ip-address-prefix',))
register_cli_argument(scope, 'private_ip_address', help='Static private IP address (e.g. 10.0.0.5).', options_list=('--private-ip-address',), action=PrivateIpAction)
register_cli_argument(scope, 'public_ip_address_allocation', choices=['dynamic', 'static'], help='', default='dynamic', type=str.lower)
register_folded_cli_argument(scope, 'public_ip_address', 'Microsoft.Network/publicIPAddresses')
register_folded_cli_argument(scope, 'storage_account', 'Microsoft.Storage/storageAccounts', validator=_find_default_storage_account, allow_none=False, default_value_flag='existingId')
register_folded_cli_argument(scope, 'virtual_network', 'Microsoft.Network/virtualNetworks', options_list=('--vnet',), validator=_find_default_vnet, allow_none=False, default_value_flag='existingId')
register_folded_cli_argument(scope, 'storage_account', 'Microsoft.Storage/storageAccounts', validator=_find_default_storage_account, none_flag_value=None, default_value_flag='existingId')
register_folded_cli_argument(scope, 'virtual_network', 'Microsoft.Network/virtualNetworks', options_list=('--vnet',), validator=_find_default_vnet, none_flag_value=None, default_value_flag='existingId')
register_folded_cli_argument(scope, 'network_security_group', 'Microsoft.Network/networkSecurityGroups', options_list=('--nsg',))
register_folded_cli_argument(scope, 'load_balancer', 'Microsoft.Network/loadBalancers')
register_cli_argument(scope, 'network_security_group_rule', nsg_rule_type, options_list=('--nsg-rule',))
Expand Down