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
26 changes: 10 additions & 16 deletions src/azure-cli-core/azure/cli/core/commands/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,18 @@ def arguments_loader():
def handler(args): # pylint: disable=too-many-branches,too-many-statements
from msrestazure.azure_operation import AzureOperationPoller

ordered_arguments = args.pop('ordered_arguments') if 'ordered_arguments' in args else []
ordered_arguments = args.pop('ordered_arguments', [])
for item in ['properties_to_add', 'properties_to_set', 'properties_to_remove']:
if args[item]:
raise CLIError("Unexpected '{}' was not empty.".format(item))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we just say '{}' was not expected'. I don't know much about generic update though, but in case it helps
Also why we want to error out here? I assume we will apply their values on sending out the update payload?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an Action somewhere that removes the entries in these lists and puts them into the "ordered_args" argument. So if anything was left in these, I want to raise an error so I know there's a bug in the generic update logic before I delete them.

del args[item]

try:
client = factory() if factory else None
except TypeError:
client = factory(None) if factory else None

getterargs = {key: val for key, val in args.items()
if key in get_arguments_loader()}
getterargs = {key: val for key, val in args.items() if key in get_arguments_loader()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the cost of get_arguments_loader()? Can we call it once and save the result?

Copy link
Member Author

@tjprescott tjprescott Mar 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are only calling it once in the handler. This method doesn't get the "argument_loader" in the sense that "get_foo" would get the foo. It returns the CLI Arguments for the "get" side of the update. There's a corresponding "set_arguments_loader" that returns the CLI Arguments for the "set" side of the update. That's also only called once in the handler.

getter = get_op_handler(getter_op)
if child_collection_prop_name:
parent = getter(client, **getterargs) if client else getter(**getterargs)
Expand All @@ -278,13 +281,7 @@ def handler(args): # pylint: disable=too-many-branches,too-many-statements
instance = custom_function(instance, **custom_func_args)

# apply generic updates after custom updates
setterargs = set_arguments_loader()
for k in args.copy().keys():
if k in get_arguments_loader() or k in setterargs \
or k in ('properties_to_add', 'properties_to_remove', 'properties_to_set'):
args.pop(k)
for key, val in args.items():
ordered_arguments.append((key, val))
setterargs = {key: val for key, val in args.items() if key in set_arguments_loader()}

for arg in ordered_arguments:
arg_type, arg_values = arg
Expand All @@ -306,15 +303,12 @@ def handler(args): # pylint: disable=too-many-branches,too-many-statements
raise CLIError('invalid syntax: {}'.format(remove_usage))

# Done... update the instance!
getterargs[setter_arg_name] = parent if child_collection_prop_name else instance
setterargs[setter_arg_name] = parent if child_collection_prop_name else instance
setter = get_op_handler(setter_op)
no_wait = no_wait_param and setterargs.get(no_wait_param, None)
if no_wait:
getterargs[no_wait_param] = True

opres = setter(client, **getterargs) if client else setter(**getterargs)
opres = setter(client, **setterargs) if client else setter(**setterargs)

if no_wait:
if setterargs.get(no_wait_param, None):
return None

result = opres.result() if isinstance(opres, AzureOperationPoller) else opres
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,20 @@ def _make_singular(value):
cli_command(__name__, 'network express-route peering create', custom_path.format('create_express_route_peering'), cf_express_route_circuit_peerings)

# ExpressRouteCircuitsOperations
cli_command(__name__, 'network express-route delete', 'azure.mgmt.network.operations.express_route_circuits_operations#ExpressRouteCircuitsOperations.delete', cf_express_route_circuits)
cli_command(__name__, 'network express-route delete', 'azure.mgmt.network.operations.express_route_circuits_operations#ExpressRouteCircuitsOperations.delete', cf_express_route_circuits, no_wait_param='raw')
cli_command(__name__, 'network express-route show', 'azure.mgmt.network.operations.express_route_circuits_operations#ExpressRouteCircuitsOperations.get', cf_express_route_circuits, exception_handler=empty_on_404)
cli_command(__name__, 'network express-route get-stats', 'azure.mgmt.network.operations.express_route_circuits_operations#ExpressRouteCircuitsOperations.get_stats', cf_express_route_circuits)
cli_command(__name__, 'network express-route list-arp-tables', 'azure.mgmt.network.operations.express_route_circuits_operations#ExpressRouteCircuitsOperations.list_arp_table', cf_express_route_circuits)
cli_command(__name__, 'network express-route list-route-tables', 'azure.mgmt.network.operations.express_route_circuits_operations#ExpressRouteCircuitsOperations.list_routes_table', cf_express_route_circuits)
cli_command(__name__, 'network express-route create', custom_path.format('create_express_route'))
cli_command(__name__, 'network express-route create', custom_path.format('create_express_route'), no_wait_param='no_wait')
cli_command(__name__, 'network express-route list', custom_path.format('list_express_route_circuits'))
cli_generic_update_command(__name__, 'network express-route update',
'azure.mgmt.network.operations.express_route_circuits_operations#ExpressRouteCircuitsOperations.get',
'azure.mgmt.network.operations.express_route_circuits_operations#ExpressRouteCircuitsOperations.create_or_update',
cf_express_route_circuits,
custom_function_op=custom_path.format('update_express_route'))
custom_function_op=custom_path.format('update_express_route'),
no_wait_param='raw')
cli_generic_wait_command(__name__, 'network express-route wait', 'azure.mgmt.network.operations.express_route_circuits_operations#ExpressRouteCircuitsOperations.get', cf_express_route_circuits)

# ExpressRouteServiceProvidersOperations
cli_command(__name__, 'network express-route list-service-providers', 'azure.mgmt.network.operations.express_route_service_providers_operations#ExpressRouteServiceProvidersOperations.list', cf_express_route_service_providers)
Expand Down Expand Up @@ -181,15 +183,16 @@ def _make_singular(value):
custom_function_op=custom_path.format('set_lb_probe'))

# LocalNetworkGatewaysOperations
cli_command(__name__, 'network local-gateway delete', 'azure.mgmt.network.operations.local_network_gateways_operations#LocalNetworkGatewaysOperations.delete', cf_local_network_gateways)
cli_command(__name__, 'network local-gateway delete', 'azure.mgmt.network.operations.local_network_gateways_operations#LocalNetworkGatewaysOperations.delete', cf_local_network_gateways, no_wait_param='raw')
cli_command(__name__, 'network local-gateway show', 'azure.mgmt.network.operations.local_network_gateways_operations#LocalNetworkGatewaysOperations.get', cf_local_network_gateways, exception_handler=empty_on_404)
cli_command(__name__, 'network local-gateway list', 'azure.mgmt.network.operations.local_network_gateways_operations#LocalNetworkGatewaysOperations.list', cf_local_network_gateways, table_transformer=transform_local_gateway_table_output)
cli_command(__name__, 'network local-gateway create', custom_path.format('create_local_gateway'))
cli_command(__name__, 'network local-gateway create', custom_path.format('create_local_gateway'), no_wait_param='no_wait')
cli_generic_update_command(__name__, 'network local-gateway update',
'azure.mgmt.network.operations.local_network_gateways_operations#LocalNetworkGatewaysOperations.get',
'azure.mgmt.network.operations.local_network_gateways_operations#LocalNetworkGatewaysOperations.create_or_update',
cf_local_network_gateways,
custom_function_op=custom_path.format('update_local_gateway'))
custom_function_op=custom_path.format('update_local_gateway'), no_wait_param='raw')
cli_generic_wait_command(__name__, 'network local-gateway wait', 'azure.mgmt.network.operations.local_network_gateways_operations#LocalNetworkGatewaysOperations.get', cf_local_network_gateways)

# NetworkInterfacesOperations
cli_command(__name__, 'network nic create', custom_path.format('create_nic'), transform=transform_nic_create_output)
Expand Down Expand Up @@ -312,7 +315,7 @@ def _make_singular(value):
cf_virtual_network_gateway_connections)

# VirtualNetworkGatewaysOperations
cli_command(__name__, 'network vnet-gateway delete', 'azure.mgmt.network.operations.virtual_network_gateways_operations#VirtualNetworkGatewaysOperations.delete', cf_virtual_network_gateways)
cli_command(__name__, 'network vnet-gateway delete', 'azure.mgmt.network.operations.virtual_network_gateways_operations#VirtualNetworkGatewaysOperations.delete', cf_virtual_network_gateways, no_wait_param='raw')
cli_command(__name__, 'network vnet-gateway show', 'azure.mgmt.network.operations.virtual_network_gateways_operations#VirtualNetworkGatewaysOperations.get', cf_virtual_network_gateways, exception_handler=empty_on_404)
cli_command(__name__, 'network vnet-gateway list', 'azure.mgmt.network.operations.virtual_network_gateways_operations#VirtualNetworkGatewaysOperations.list', cf_virtual_network_gateways)
cli_command(__name__, 'network vnet-gateway reset', 'azure.mgmt.network.operations.virtual_network_gateways_operations#VirtualNetworkGatewaysOperations.reset', cf_virtual_network_gateways)
Expand All @@ -323,14 +326,13 @@ def _make_singular(value):
cf_virtual_network_gateways,
custom_function_op=custom_path.format('update_vnet_gateway'),
no_wait_param='raw')
cli_generic_wait_command(__name__, 'network vnet-gateway wait', 'azure.mgmt.network.operations.virtual_network_gateways_operations#VirtualNetworkGatewaysOperations.get', cf_virtual_network_gateways)

cli_command(__name__, 'network vnet-gateway root-cert create', custom_path.format('create_vnet_gateway_root_cert'))
cli_command(__name__, 'network vnet-gateway root-cert delete', custom_path.format('delete_vnet_gateway_root_cert'))
cli_command(__name__, 'network vnet-gateway revoked-cert create', custom_path.format('create_vnet_gateway_revoked_cert'))
cli_command(__name__, 'network vnet-gateway revoked-cert delete', custom_path.format('delete_vnet_gateway_revoked_cert'))


cli_generic_wait_command(__name__, 'network vnet-gateway wait', 'azure.mgmt.network.operations.virtual_network_gateways_operations#VirtualNetworkGatewaysOperations.get', cf_virtual_network_gateways)

# VirtualNetworksOperations
cli_command(__name__, 'network vnet delete', 'azure.mgmt.network.operations.virtual_networks_operations#VirtualNetworksOperations.delete', cf_virtual_networks)
cli_command(__name__, 'network vnet show', 'azure.mgmt.network.operations.virtual_networks_operations#VirtualNetworksOperations.get', cf_virtual_networks, exception_handler=empty_on_404)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ def update_vnet_gateway(instance, address_prefixes=None, sku=None, vpn_type=None
# region Express Route commands

def create_express_route(circuit_name, resource_group_name, bandwidth_in_mbps, peering_location,
service_provider_name, location=None, tags=None,
service_provider_name, location=None, tags=None, no_wait=False,
sku_family=ExpressRouteCircuitSkuFamily.metered_data.value,
sku_tier=ExpressRouteCircuitSkuTier.standard.value):
from azure.mgmt.network.models import \
Expand All @@ -1261,7 +1261,7 @@ def create_express_route(circuit_name, resource_group_name, bandwidth_in_mbps, p
service_provider_name, peering_location, bandwidth_in_mbps),
sku=ExpressRouteCircuitSku(sku_name, sku_tier, sku_family)
)
return client.create_or_update(resource_group_name, circuit_name, circuit)
return client.create_or_update(resource_group_name, circuit_name, circuit, raw=no_wait)

def update_express_route(instance, bandwidth_in_mbps=None, peering_location=None,
service_provider_name=None, sku_family=None, sku_tier=None, tags=None):
Expand Down Expand Up @@ -1409,15 +1409,16 @@ def update_route(instance, address_prefix=None, next_hop_type=None, next_hop_ip_

def create_local_gateway(resource_group_name, local_network_gateway_name, gateway_ip_address,
location=None, tags=None, local_address_prefix=None, asn=None,
bgp_peering_address=None, peer_weight=None):
bgp_peering_address=None, peer_weight=None, no_wait=False):
from azure.mgmt.network.models import LocalNetworkGateway, BgpSettings
client = _network_client_factory().local_network_gateways
local_gateway = LocalNetworkGateway(
local_address_prefix or [], location=location, tags=tags,
gateway_ip_address=gateway_ip_address)
if bgp_peering_address or asn or peer_weight:
local_gateway.bgp_settings = BgpSettings(asn, bgp_peering_address, peer_weight)
return client.create_or_update(resource_group_name, local_network_gateway_name, local_gateway)
return client.create_or_update(
resource_group_name, local_network_gateway_name, local_gateway, raw=no_wait)

def update_local_gateway(instance, gateway_ip_address=None, local_address_prefix=None, asn=None,
bgp_peering_address=None, peer_weight=None, tags=None):
Expand Down
Loading