Change simple_output_query to be table_transformer (#771)

This commit is contained in:
Derek Bekoe 2016-08-26 16:06:29 -07:00 коммит произвёл GitHub
Родитель df80c14cb9
Коммит 154c701c95
13 изменённых файлов: 104 добавлений и 127 удалений

Просмотреть файл

@ -34,12 +34,12 @@ from azure.cli.commands import cli_command
The signature of this method is
```Python
def cli_command(name, operation, client_factory=None, transform=None, simple_output_query=None):
def cli_command(name, operation, client_factory=None, transform=None, table_transformer=None):
```
You will generally only specify `name`, `operation` and possibly `simple_output_query`.
You will generally only specify `name`, `operation` and possibly `table_transformer`.
- `name` - String uniquely naming your command and placing it within the command hierachy. It will be the string that you would type at the command line, omitting `az` (ex: access your command at `az mypackage mycommand` using a name of `mypackage mycommand`).
- `operation` - Your function's name.
- `simple_output_query` (optional) - Supply a JMESPath projection string to enable the table output type for your command. This is most applicable to list-type commands. See www.jmespath.org for guidance on creating JMESPath queries. Alternatively, you can supply a callable that takes, transforms and returns a result. This is appropriate when the structure of the server response makes JMESPath querying difficult.
- `table_transformer` (optional) - Supply a callable that takes, transforms and returns a result for table output.
At this point, you should be able to access your command using `az [name]` and access the built-in help with `az [name] -h/--help`. Your command will automatically be 'wired up' with the global parameters.

Просмотреть файл

@ -57,9 +57,8 @@ def format_text(obj):
def format_table(obj):
result = obj.result
try:
if obj.simple_output_query and not obj.is_query_active:
if callable(obj.simple_output_query):
result = obj.simple_output_query(result)
if obj.table_transformer and not obj.is_query_active:
result = obj.table_transformer(result)
result_list = result if isinstance(result, list) else [result]
return TableOutput.dump(result_list)
except:
@ -81,9 +80,9 @@ def format_tsv(obj):
class CommandResultItem(object): #pylint: disable=too-few-public-methods
def __init__(self, result, simple_output_query=None, is_query_active=False):
def __init__(self, result, table_transformer=None, is_query_active=False):
self.result = result
self.simple_output_query = simple_output_query
self.table_transformer = table_transformer
self.is_query_active = is_query_active
class OutputProducer(object): #pylint: disable=too-few-public-methods

Просмотреть файл

@ -126,8 +126,8 @@ class Application(object):
self.raise_event(self.TRANSFORM_RESULT, event_data=event_data)
self.raise_event(self.FILTER_RESULT, event_data=event_data)
return CommandResultItem(event_data['result'],
simple_output_query=
command_table[args.command].simple_output_query,
table_transformer=
command_table[args.command].table_transformer,
is_query_active=self.session['query_active'])
def raise_event(self, name, **kwargs):

Просмотреть файл

@ -133,13 +133,13 @@ class CommandTable(dict):
class CliCommand(object):
def __init__(self, name, handler, description=None, simple_output_query=None):
def __init__(self, name, handler, description=None, table_transformer=None):
self.name = name
self.handler = handler
self.description = description
self.help = None
self.arguments = {}
self.simple_output_query = simple_output_query
self.table_transformer = table_transformer
def add_argument(self, param_name, *option_strings, **kwargs):
argument = CliCommandArgument(
@ -201,12 +201,12 @@ def register_extra_cli_argument(command, dest, **kwargs):
'''
_cli_extra_argument_registry[command][dest] = CliCommandArgument(dest, **kwargs)
def cli_command(name, operation, client_factory=None, transform=None, simple_output_query=None):
def cli_command(name, operation, client_factory=None, transform=None, table_transformer=None):
""" Registers a default Azure CLI command. These commands require no special parameters. """
command_table[name] = create_command(name, operation, transform, simple_output_query,
command_table[name] = create_command(name, operation, transform, table_transformer,
client_factory)
def create_command(name, operation, transform_result, simple_output_query, client_factory):
def create_command(name, operation, transform_result, table_transformer, client_factory):
def _execute_command(kwargs):
client = client_factory(kwargs) if client_factory else None
@ -228,7 +228,7 @@ def create_command(name, operation, transform_result, simple_output_query, clien
raise CLIError(message)
name = ' '.join(name.split())
cmd = CliCommand(name, _execute_command, simple_output_query=simple_output_query)
cmd = CliCommand(name, _execute_command, table_transformer=table_transformer)
cmd.description = extract_full_summary_from_signature(operation)
cmd.arguments.update(extract_args_from_signature(operation))
return cmd

Просмотреть файл

@ -170,7 +170,7 @@ def _get_child(parent, collection_name, item_name, collection_key):
return result
def cli_generic_update_command(name, getter, setter, factory=None, setter_arg_name='parameters', # pylint: disable=too-many-arguments
simple_output_query=None, child_collection_prop_name=None,
table_transformer=None, child_collection_prop_name=None,
child_collection_key='name', child_arg_name='item_name',
custom_function=None):
@ -261,7 +261,7 @@ def cli_generic_update_command(name, getter, setter, factory=None, setter_arg_na
setattr(namespace, 'ordered_arguments', [])
namespace.ordered_arguments.append((option_string, values))
cmd = CliCommand(name, handler, simple_output_query=simple_output_query)
cmd = CliCommand(name, handler, table_transformer=table_transformer)
cmd.arguments.update(set_arguments)
cmd.arguments.update(get_arguments)
if function_arguments:

Просмотреть файл

@ -12,8 +12,7 @@ from .custom import (list_components, install, update, update_all, update_self,
# HELPER METHODS
cli_command('component list', list_components,
simple_output_query="[*].{Name:name, Version:version} | sort_by(@, &Name)")
cli_command('component list', list_components)
cli_command('component install', install)
cli_command('component update', update)
cli_command('component update-all', update_all)

Просмотреть файл

@ -18,20 +18,13 @@ def _keyvault_client_factory(**_):
factory = lambda args: _keyvault_client_factory(**args).vaults
keyvault_show_query = "{Name:name, ResourceGroup:resourceGroup, Location:location, "\
"SkuFamily:properties.sku.family, SkuName:properties.sku.name, "\
"VaultUri:properties.vaultUri}"
cli_command('keyvault create', create_keyvault, factory, simple_output_query=keyvault_show_query)
cli_command('keyvault list', list_keyvault, factory,
simple_output_query="[*].{Name:name, ResourceGroup:resourceGroup, Location:location} |"\
" sort_by(@, &Name)")
cli_command('keyvault show', VaultsOperations.get, factory, simple_output_query=keyvault_show_query)
cli_command('keyvault create', create_keyvault, factory)
cli_command('keyvault list', list_keyvault, factory)
cli_command('keyvault show', VaultsOperations.get, factory)
cli_command('keyvault delete', VaultsOperations.delete, factory)
cli_command('keyvault set-policy', set_policy, factory, simple_output_query=keyvault_show_query)
cli_command('keyvault delete-policy', delete_policy, factory,
simple_output_query=keyvault_show_query)
cli_command('keyvault set-policy', set_policy, factory)
cli_command('keyvault delete-policy', delete_policy, factory)
def keyvault_update_setter(client, resource_group_name, vault_name, parameters):
from azure.mgmt.keyvault.models import VaultCreateOrUpdateParameters
@ -44,5 +37,4 @@ def keyvault_update_setter(client, resource_group_name, vault_name, parameters):
cli_generic_update_command('keyvault update',
VaultsOperations.get,
keyvault_update_setter,
lambda: _keyvault_client_factory().vaults,
simple_output_query=keyvault_show_query)
lambda: _keyvault_client_factory().vaults)

Просмотреть файл

@ -123,7 +123,7 @@ from ._factory import _network_client_factory
factory = lambda _: _network_client_factory().application_gateways
cli_command('network application-gateway delete', ApplicationGatewaysOperations.delete, factory)
cli_command('network application-gateway show', ApplicationGatewaysOperations.get, factory)
cli_command('network application-gateway list', list_application_gateways, simple_output_query="[*].{Name:name, ResourceGroup:resourceGroup, Location:location, State:provisioningState} | sort_by(@, &Name)")
cli_command('network application-gateway list', list_application_gateways)
cli_command('network application-gateway start', ApplicationGatewaysOperations.start, factory)
cli_command('network application-gateway stop', ApplicationGatewaysOperations.stop, factory)
cli_generic_update_command('network application-gateway update', ApplicationGatewaysOperations.get, ApplicationGatewaysOperations.create_or_update, factory)
@ -143,7 +143,7 @@ property_map = {
'url_path_maps': 'url-path-map'
}
for subresource, alias in property_map.items():
cli_command('network application-gateway {} list'.format(alias), list_network_resource_property('application_gateways', subresource), simple_output_query="[*].{Name:name} | sort_by(@, &Name)")
cli_command('network application-gateway {} list'.format(alias), list_network_resource_property('application_gateways', subresource))
cli_command('network application-gateway {} show'.format(alias), get_network_resource_property_entry('application_gateways', subresource))
cli_command('network application-gateway {} delete'.format(alias), delete_network_resource_property_entry('application_gateways', subresource))
@ -282,7 +282,7 @@ cli_command('network nsg create', NsgOperations.create_or_update, factory, trans
factory = lambda _: _network_client_factory().public_ip_addresses
cli_command('network public-ip delete', PublicIPAddressesOperations.delete, factory)
cli_command('network public-ip show', PublicIPAddressesOperations.get, factory)
cli_command('network public-ip list', list_public_ips, simple_output_query="[*].{Name:name, ResourceGroup:resourceGroup, Location:location, IpAddress:ipAddress, FQDN:dnsSettings.fqdn} | sort_by(@, &Name)")
cli_command('network public-ip list', list_public_ips)
cli_generic_update_command('network public-ip update', PublicIPAddressesOperations.get, PublicIPAddressesOperations.create_or_update, factory)
factory = lambda _: get_mgmt_service_client(PublicIPClient).public_ip

Просмотреть файл

@ -35,7 +35,7 @@ factory = lambda _: _resource_client_factory().resource_groups
cli_command('resource group delete', ResourceGroupsOperations.delete, factory)
cli_command('resource group show', ResourceGroupsOperations.get, factory)
cli_command('resource group exists', ResourceGroupsOperations.check_existence, factory)
cli_command('resource group list', list_resource_groups, simple_output_query="[*].{Name:name, Location:location, ProvisioningState:properties.provisioningState}")
cli_command('resource group list', list_resource_groups)
cli_command('resource group create', create_resource_group)
cli_command('resource group export', export_group_as_template)
@ -44,27 +44,26 @@ factory = lambda _: _resource_client_factory().resources
cli_command('resource exists', ResourcesOperations.check_existence, factory)
cli_command('resource delete', ResourcesOperations.delete, factory)
cli_command('resource show', ResourcesOperations.get, factory)
cli_command('resource list', list_resources, simple_output_query="[*].{Id:id,Name:name,ResourceGroup:resourceGroup,Type:type,Location:location}")
cli_command('resource list', list_resources)
cli_command('resource tag', tag_resource)
cli_command('resource move', move_resource)
# Resource provider commands
factory = lambda _: _resource_client_factory().providers
cli_command('resource provider list', ProvidersOperations.list, factory, simple_output_query="[*].{Namespace:namespace,Registration:registrationState}")
cli_command('resource provider list', ProvidersOperations.list, factory)
cli_command('resource provider show', ProvidersOperations.get, factory)
cli_command('resource provider register', register_provider)
cli_command('resource provider unregister', unregister_provider)
# Resource feature commands
feature_tab_query = '{Name:name, State:properties.state}'
factory = lambda _: _resource_feature_client_factory().features
cli_command('resource feature list', list_features, factory, simple_output_query='[].'+feature_tab_query)
cli_command('resource feature show', FeaturesOperations.get, factory, simple_output_query=feature_tab_query)
cli_command('resource feature register', FeaturesOperations.register, factory, simple_output_query=feature_tab_query)
cli_command('resource feature list', list_features, factory)
cli_command('resource feature show', FeaturesOperations.get, factory)
cli_command('resource feature register', FeaturesOperations.register, factory)
# Tag commands
factory = lambda _: _resource_client_factory().tags
cli_command('tag list', TagsOperations.list, factory, simple_output_query="[*].{Name:tagName,Count:count.value}")
cli_command('tag list', TagsOperations.list, factory)
cli_command('tag create', TagsOperations.create_or_update, factory)
cli_command('tag delete', TagsOperations.delete, factory)
cli_command('tag add-value', TagsOperations.create_or_update_value, factory)
@ -94,15 +93,13 @@ cli_generic_update_command('resource group update',
ResourceGroupsOperations.create_or_update,
lambda: _resource_client_factory().resource_groups)
policy_assignment_tab_query = '{Name:name, Scope:scope, Policy:policyDefinitionId}'
cli_command('resource policy assignment create', create_policy_assignment, simple_output_query=policy_assignment_tab_query)
cli_command('resource policy assignment create', create_policy_assignment)
cli_command('resource policy assignment delete', delete_policy_assignment)
cli_command('resource policy assignment list', list_policy_assignment, simple_output_query='[].'+policy_assignment_tab_query)
cli_command('resource policy assignment show', show_policy_assignment, simple_output_query=policy_assignment_tab_query)
cli_command('resource policy assignment list', list_policy_assignment)
cli_command('resource policy assignment show', show_policy_assignment)
factory = lambda _: _resource_policy_client_factory().policy_definitions
policy_definition_tab_query = '{Name:name, Description:description}'
cli_command('resource policy create', create_policy_definition, simple_output_query=policy_definition_tab_query)
cli_command('resource policy create', create_policy_definition)
cli_command('resource policy delete', PolicyDefinitionsOperations.delete, factory)
cli_command('resource policy list', PolicyDefinitionsOperations.list, factory, simple_output_query='[].'+policy_definition_tab_query)
cli_command('resource policy show', PolicyDefinitionsOperations.get, factory, simple_output_query=policy_definition_tab_query)
cli_command('resource policy update', update_policy_definition, simple_output_query=policy_definition_tab_query)
cli_command('resource policy list', PolicyDefinitionsOperations.list, factory)
cli_command('resource policy show', PolicyDefinitionsOperations.get, factory)
cli_command('resource policy update', update_policy_definition)

Просмотреть файл

@ -20,40 +20,32 @@ from .custom import (create_role_assignment, list_role_assignments, delete_role_
_auth_client_factory, _graph_client_factory)
factory = lambda _: _auth_client_factory().role_definitions
simple_output_query = '[*].{Name:properties.roleName, Id:name, Type:properties.type}'
cli_command('role list', list_role_definitions, simple_output_query=simple_output_query)
cli_command('role list', list_role_definitions)
cli_command('role delete', delete_role_definition)
cli_command('role create', create_role_definition, simple_output_query=simple_output_query)
cli_command('role create', create_role_definition)
cli_generic_update_command('role update',
RoleDefinitionsOperations.get,
RoleDefinitionsOperations.create_or_update,
factory)
simple_output_query = '[*].{Name:name, PrincipalName:properties.principalName, Role:properties.roleDefinitionName, Scope:properties.scope}'
factory = lambda _: _auth_client_factory().role_assignments
cli_command('role assignment delete', delete_role_assignments)
cli_command('role assignment list', list_role_assignments,
simple_output_query='[*].{Name:name, PrincipalName:properties.principalName, Role:properties.roleDefinitionName, Scope:properties.scope}')
cli_command('role assignment create', create_role_assignment,
simple_output_query="{Name:name, PrincipalId:properties.principalId, Scope:properties.scope}")
cli_command('role assignment list', list_role_assignments)
cli_command('role assignment create', create_role_assignment)
factory = lambda _: _graph_client_factory().applications
#for table ouput, display the 1st identifier and replyurl, so all can fit in a row
single_app_table_query = '{DisplayName:displayName, IdentifierUri:identifierUris[0], ObjectId:objectId, ReplyUrl:replyUrls[0]}'
cli_command('ad app create', create_application, factory, simple_output_query=single_app_table_query)
cli_command('ad app create', create_application, factory)
cli_command('ad app delete', delete_application, factory)
cli_command('ad app list', list_apps, factory, simple_output_query='[*].'+ single_app_table_query)
cli_command('ad app show', show_application, factory, simple_output_query=single_app_table_query)
cli_command('ad app list', list_apps, factory)
cli_command('ad app show', show_application, factory)
cli_command('ad app update', update_application, factory)
factory = lambda _: _graph_client_factory().service_principals
#for table ouput, display the 1st principal name, so all can fit in a row
single_sp_table_query = '{DisplayName:displayName, ServicePrincipalName:servicePrincipalNames[0], ObjectId:objectId}'
cli_command('ad sp create', create_service_principal, simple_output_query=single_sp_table_query)
cli_command('ad sp create', create_service_principal)
cli_command('ad sp delete', delete_service_principal, factory)
#paging is broken at SDK https://github.com/Azure/azure-cli/issues/540
cli_command('ad sp list', list_sps, factory, simple_output_query='[*].'+single_sp_table_query)
cli_command('ad sp show', show_service_principal, factory, simple_output_query=single_sp_table_query)
cli_command('ad sp list', list_sps, factory)
cli_command('ad sp show', show_service_principal, factory)
#RBAC related
cli_command('ad sp create-for-rbac', create_service_principal_for_rbac)
cli_command('ad sp reset-credentials', reset_service_principal_credential)

Просмотреть файл

@ -8,11 +8,11 @@ from azure.cli.commands import create_command, command_table
from azure.cli.command_modules.storage._validators import validate_client_parameters
def cli_storage_data_plane_command(name, operation, client_factory,
transform=None, simple_output_query=None):
transform=None, table_transformer=None):
""" Registers an Azure CLI Storage Data Plane command. These commands always include the
four parameters which can be used to obtain a storage client: account-name, account-key,
connection-string, and sas-token. """
command = create_command(name, operation, transform, simple_output_query, client_factory)
command = create_command(name, operation, transform, table_transformer, client_factory)
# add parameters required to create a storage client
group_name = 'Storage Account'

Просмотреть файл

@ -38,8 +38,8 @@ cli_command('storage account check-name', StorageAccountsOperations.check_name_a
cli_command('storage account delete', StorageAccountsOperations.delete, factory)
cli_command('storage account show', StorageAccountsOperations.get_properties, factory)
cli_command('storage account create', create_storage_account)
cli_command('storage account list', list_storage_accounts, simple_output_query='[*].{Name: name, ResourceGroup: resourceGroup, Location: location, SkuName: sku.name, SkuTier: sku.tier} | sort_by(@, &Name)')
cli_command('storage account show-usage', show_storage_account_usage, simple_output_query='{Name:name.localizedValue, Current:currentValue, Max:limit}')
cli_command('storage account list', list_storage_accounts)
cli_command('storage account show-usage', show_storage_account_usage)
cli_command('storage account update', set_storage_account_properties)
cli_command('storage account connection-string', show_storage_account_connection_string)
cli_command('storage account keys renew', renew_storage_account_keys)
@ -48,7 +48,7 @@ cli_storage_data_plane_command('storage account generate-sas', CloudStorageAccou
# container commands
factory = blob_data_service_factory
cli_storage_data_plane_command('storage container list', BlockBlobService.list_containers, factory, simple_output_query='items[*].{Name: name, LeaseState: properties.leaseState} | sort_by(@, &Name)')
cli_storage_data_plane_command('storage container list', BlockBlobService.list_containers, factory)
cli_storage_data_plane_command('storage container delete', BlockBlobService.delete_container, factory)
cli_storage_data_plane_command('storage container show', BlockBlobService.get_container_properties, factory)
cli_storage_data_plane_command('storage container create', BlockBlobService.create_container, factory)
@ -64,11 +64,11 @@ cli_storage_data_plane_command('storage container exists', BaseBlobService.exist
cli_storage_data_plane_command('storage container policy create', create_acl_policy, factory)
cli_storage_data_plane_command('storage container policy delete', delete_acl_policy, factory)
cli_storage_data_plane_command('storage container policy show', get_acl_policy, factory)
cli_storage_data_plane_command('storage container policy list', list_acl_policies, factory, simple_output_query=transform_acl_list_output)
cli_storage_data_plane_command('storage container policy list', list_acl_policies, factory, table_transformer=transform_acl_list_output)
cli_storage_data_plane_command('storage container policy update', set_acl_policy, factory)
# blob commands
cli_storage_data_plane_command('storage blob list', BlockBlobService.list_blobs, factory, simple_output_query='items[*].{Name: name, Type: properties.blobType, ContentLength: properties.contentLength, LeaseState: properties.lease.state} | sort_by(@, &Name)')
cli_storage_data_plane_command('storage blob list', BlockBlobService.list_blobs, factory)
cli_storage_data_plane_command('storage blob delete', BlockBlobService.delete_blob, factory)
cli_storage_data_plane_command('storage blob generate-sas', BlockBlobService.generate_blob_shared_access_signature, factory)
cli_storage_data_plane_command('storage blob url', BlockBlobService.make_blob_url, factory, transform=transform_url)
@ -91,7 +91,7 @@ cli_storage_data_plane_command('storage blob copy cancel', BlockBlobService.abor
# share commands
factory = file_data_service_factory
cli_storage_data_plane_command('storage share list', FileService.list_shares, factory, simple_output_query='items[*].{Name:name,"Quota (GB)":properties.quota} | sort_by(@, &Name)')
cli_storage_data_plane_command('storage share list', FileService.list_shares, factory)
cli_storage_data_plane_command('storage share create', FileService.create_share, factory)
cli_storage_data_plane_command('storage share delete', FileService.delete_share, factory)
cli_storage_data_plane_command('storage share generate-sas', FileService.generate_share_shared_access_signature, factory)
@ -104,7 +104,7 @@ cli_storage_data_plane_command('storage share exists', FileService.exists, facto
cli_storage_data_plane_command('storage share policy create', create_acl_policy, factory)
cli_storage_data_plane_command('storage share policy delete', delete_acl_policy, factory)
cli_storage_data_plane_command('storage share policy show', get_acl_policy, factory)
cli_storage_data_plane_command('storage share policy list', list_acl_policies, factory, simple_output_query=transform_acl_list_output)
cli_storage_data_plane_command('storage share policy list', list_acl_policies, factory, table_transformer=transform_acl_list_output)
cli_storage_data_plane_command('storage share policy update', set_acl_policy, factory)
# directory commands
@ -116,7 +116,7 @@ cli_storage_data_plane_command('storage directory metadata show', FileService.ge
cli_storage_data_plane_command('storage directory metadata update', FileService.set_directory_metadata, factory)
# file commands
cli_storage_data_plane_command('storage file list', FileService.list_directories_and_files, factory, simple_output_query=transform_file_list_output)
cli_storage_data_plane_command('storage file list', FileService.list_directories_and_files, factory, table_transformer=transform_file_list_output)
cli_storage_data_plane_command('storage file delete', FileService.delete_file, factory)
cli_storage_data_plane_command('storage file resize', FileService.resize_file, factory)
cli_storage_data_plane_command('storage file url', FileService.make_file_url, factory, transform=transform_url)
@ -135,20 +135,20 @@ cli_storage_data_plane_command('storage file copy cancel', FileService.abort_cop
factory = table_data_service_factory
cli_storage_data_plane_command('storage table generate-sas', TableService.generate_table_shared_access_signature, factory)
cli_storage_data_plane_command('storage table stats', TableService.get_table_service_stats, factory)
cli_storage_data_plane_command('storage table list', TableService.list_tables, factory, simple_output_query='items[*].{Name:name} | sort_by(@, &Name)')
cli_storage_data_plane_command('storage table list', TableService.list_tables, factory)
cli_storage_data_plane_command('storage table create', TableService.create_table, factory)
cli_storage_data_plane_command('storage table exists', TableService.exists, factory)
cli_storage_data_plane_command('storage table delete', TableService.delete_table, factory)
cli_storage_data_plane_command('storage table policy create', create_acl_policy, factory)
cli_storage_data_plane_command('storage table policy delete', delete_acl_policy, factory)
cli_storage_data_plane_command('storage table policy show', get_acl_policy, factory)
cli_storage_data_plane_command('storage table policy list', list_acl_policies, factory, simple_output_query=transform_acl_list_output)
cli_storage_data_plane_command('storage table policy list', list_acl_policies, factory, table_transformer=transform_acl_list_output)
cli_storage_data_plane_command('storage table policy update', set_acl_policy, factory)
cli_storage_data_plane_command('storage table batch commit', TableService.commit_batch, factory)
cli_storage_data_plane_command('storage table batch create', TableService.batch, factory)
# table entity commands
cli_storage_data_plane_command('storage entity query', TableService.query_entities, factory, simple_output_query=transform_entity_query_output)
cli_storage_data_plane_command('storage entity query', TableService.query_entities, factory, table_transformer=transform_entity_query_output)
cli_storage_data_plane_command('storage entity show', TableService.get_entity, factory)
cli_storage_data_plane_command('storage entity insert', insert_table_entity, factory)
cli_storage_data_plane_command('storage entity replace', TableService.update_entity, factory)
@ -159,7 +159,7 @@ cli_storage_data_plane_command('storage entity delete', TableService.delete_enti
factory = queue_data_service_factory
cli_storage_data_plane_command('storage queue generate-sas', QueueService.generate_queue_shared_access_signature, factory)
cli_storage_data_plane_command('storage queue stats', QueueService.get_queue_service_stats, factory)
cli_storage_data_plane_command('storage queue list', QueueService.list_queues, factory, simple_output_query='items[*].{Name:name} | sort_by(@, &Name)')
cli_storage_data_plane_command('storage queue list', QueueService.list_queues, factory)
cli_storage_data_plane_command('storage queue create', QueueService.create_queue, factory)
cli_storage_data_plane_command('storage queue delete', QueueService.delete_queue, factory)
cli_storage_data_plane_command('storage queue metadata show', QueueService.get_queue_metadata, factory)
@ -168,26 +168,26 @@ cli_storage_data_plane_command('storage queue exists', QueueService.exists, fact
cli_storage_data_plane_command('storage queue policy create', create_acl_policy, factory)
cli_storage_data_plane_command('storage queue policy delete', delete_acl_policy, factory)
cli_storage_data_plane_command('storage queue policy show', get_acl_policy, factory)
cli_storage_data_plane_command('storage queue policy list', list_acl_policies, factory, simple_output_query=transform_acl_list_output)
cli_storage_data_plane_command('storage queue policy list', list_acl_policies, factory, table_transformer=transform_acl_list_output)
cli_storage_data_plane_command('storage queue policy update', set_acl_policy, factory)
# queue message commands
cli_storage_data_plane_command('storage message put', QueueService.put_message, factory)
cli_storage_data_plane_command('storage message get', QueueService.get_messages, factory)
cli_storage_data_plane_command('storage message peek', QueueService.peek_messages, factory, simple_output_query='[*].{ID:id, Content:content, Insertion:insertionTime, Expiration:expirationTime} | sort_by(@, &Insertion)')
cli_storage_data_plane_command('storage message peek', QueueService.peek_messages, factory)
cli_storage_data_plane_command('storage message delete', QueueService.delete_message, factory)
cli_storage_data_plane_command('storage message clear', QueueService.clear_messages, factory)
cli_storage_data_plane_command('storage message update', QueueService.update_message, factory)
# cors commands
cli_storage_data_plane_command('storage cors list', list_cors, None, simple_output_query=transform_cors_list_output)
cli_storage_data_plane_command('storage cors list', list_cors, None, table_transformer=transform_cors_list_output)
cli_storage_data_plane_command('storage cors add', add_cors, None)
cli_storage_data_plane_command('storage cors clear', clear_cors, None)
# logging commands
cli_storage_data_plane_command('storage logging show', get_logging, None, simple_output_query=transform_logging_list_output)
cli_storage_data_plane_command('storage logging show', get_logging, None, table_transformer=transform_logging_list_output)
cli_storage_data_plane_command('storage logging update', set_logging, None)
# metrics commands
cli_storage_data_plane_command('storage metrics show', get_metrics, None, simple_output_query=transform_metrics_list_output)
cli_storage_data_plane_command('storage metrics show', get_metrics, None, table_transformer=transform_metrics_list_output)
cli_storage_data_plane_command('storage metrics update', set_metrics, None)

Просмотреть файл

@ -46,25 +46,23 @@ from ._factory import _compute_client_factory
# VM
factory = lambda _: get_mgmt_service_client(VMClient).vm
cli_command('vm create', VmOperations.create_or_update, factory, transform=DeploymentOutputLongRunningOperation('Starting vm create'),
simple_output_query="{ResourceGroup:resourceGroup, PublicIpAddress:publicIpAddress, PrivateIpAddress:privateIpAddress, MacAddress:macAddress, FQDN:fqdn}")
cli_command('vm create', VmOperations.create_or_update, factory, transform=DeploymentOutputLongRunningOperation('Starting vm create'))
factory = lambda _: _compute_client_factory().virtual_machines
cli_command('vm delete', VirtualMachinesOperations.delete, factory)
cli_command('vm deallocate', VirtualMachinesOperations.deallocate, factory)
cli_command('vm generalize', VirtualMachinesOperations.generalize, factory)
cli_command('vm show', VirtualMachinesOperations.get, factory, simple_output_query="{Name:name, ResourceGroup:resourceGroup, Location:location, VmSize:hardwareProfile.vmSize, OsType: storageProfile.osDisk.osType}")
cli_command('vm list-vm-resize-options', VirtualMachinesOperations.list_available_sizes, factory, simple_output_query="[*].{Name: name, NumberOfCores: numberOfCores, MemoryInMb: memoryInMb, MaxDataDiskCount: maxDataDiskCount, ResourceDiskSizeInMb: resourceDiskSizeInMb, OsDiskSizeInMb: osDiskSizeInMb} | sort_by(@, &Name)")
cli_command('vm get-instance-view', get_instance_view,
simple_output_query="{Name:name, VmSize:hardwareProfile.vmSize, OsType: storageProfile.osDisk.osType, Status1: instanceView.statuses[0].code, Status2: instanceView.statuses[1].code}")
cli_command('vm show', VirtualMachinesOperations.get, factory)
cli_command('vm list-vm-resize-options', VirtualMachinesOperations.list_available_sizes, factory)
cli_command('vm get-instance-view', get_instance_view)
cli_command('vm stop', VirtualMachinesOperations.power_off, factory)
cli_command('vm restart', VirtualMachinesOperations.restart, factory)
cli_command('vm start', VirtualMachinesOperations.start, factory)
cli_command('vm redeploy', VirtualMachinesOperations.redeploy, factory)
cli_command('vm list-ip-addresses', list_ip_addresses, simple_output_query="[*].{VmName: virtualMachine.name, VmResourceGroup: virtualMachine.resourceGroup, PublicIpAddressName: join(', ', virtualMachine.network.publicIpAddresses[].name), PublicIpAddress: join(', ', virtualMachine.network.publicIpAddresses[].ipAddress), PublicIpAllocationMethod: join(', ', virtualMachine.network.publicIpAddresses[].ipAllocationMethod)} | sort_by(@, &VmName)")
cli_command('vm list', list_vm, simple_output_query="[*].{Name: name, ResourceGroup: resourceGroup, ProvisioningState: provisioningState, Location: location, Size: hardwareProfile.vmSize} | sort_by(@, &Name)")
cli_command('vm resize', resize_vm, simple_output_query="{Name:name, ResourceGroup:resourceGroup, Location:location, VmSize:hardwareProfile.vmSize, OsType: storageProfile.osDisk.osType}")
cli_command('vm list-ip-addresses', list_ip_addresses)
cli_command('vm list', list_vm)
cli_command('vm resize', resize_vm)
cli_command('vm capture', capture_vm)
cli_command('vm nic add', vm_add_nics)
cli_command('vm nic delete', vm_delete_nics)
@ -83,9 +81,9 @@ cli_command('vm availability-set create', AvailSetOperations.create_or_update, f
factory = lambda _: _compute_client_factory().availability_sets
cli_command('vm availability-set delete', AvailabilitySetsOperations.delete, factory)
cli_command('vm availability-set show', AvailabilitySetsOperations.get, factory, simple_output_query="{Name:name, ResourceGroup:resourceGroup, Location:location, PlatformUpdateDomainCount:platformUpdateDomainCount, PlatformFaultDomainCount:platformFaultDomainCount}")
cli_command('vm availability-set list', AvailabilitySetsOperations.list, factory, simple_output_query="[*].{Name:name, ResourceGroup:resourceGroup, Location:location, PlatformUpdateDomainCount:platformUpdateDomainCount, PlatformFaultDomainCount:platformFaultDomainCount} | sort_by(@, &Name)")
cli_command('vm availability-set list-sizes', AvailabilitySetsOperations.list_available_sizes, factory, simple_output_query="[*].{Name: name, NumberOfCores: numberOfCores, MemoryInMb: memoryInMb, MaxDataDiskCount: maxDataDiskCount, ResourceDiskSizeInMb: resourceDiskSizeInMb, OsDiskSizeInMb: osDiskSizeInMb} | sort_by(@, &Name)")
cli_command('vm availability-set show', AvailabilitySetsOperations.get, factory)
cli_command('vm availability-set list', AvailabilitySetsOperations.list, factory)
cli_command('vm availability-set list-sizes', AvailabilitySetsOperations.list_available_sizes, factory)
# VM Boot Diagnostics
cli_command('vm boot-diagnostics disable', disable_boot_diagnostics)
@ -103,8 +101,8 @@ for a in ['id', 'name', 'type', 'location']:
ContainerService._attribute_map[a]['type'] = 'str'#pylint: disable=protected-access
ContainerService._attribute_map['tags']['type'] = '{str}'#pylint: disable=protected-access
######
cli_command('vm container show', ContainerServiceOperations.get, factory, simple_output_query="{Name:name, ResourceGroup:resourceGroup, ProvisioningState: provisioningState, Location:location, OrchestratorType:orchestratorProfile.orchestratorType, MasterCount:masterProfile.count, MasterFQDN:masterProfile.fqdn}")
cli_command('vm container list', ContainerServiceOperations.list, factory, simple_output_query="[*].{Name:name, ResourceGroup:resourceGroup, ProvisioningState: provisioningState, Location:location, OrchestratorType:orchestratorProfile.orchestratorType, MasterCount:masterProfile.count, MasterFQDN:masterProfile.fqdn} | sort_by(@, &Name)")
cli_command('vm container show', ContainerServiceOperations.get, factory)
cli_command('vm container list', ContainerServiceOperations.list, factory)
cli_command('vm container delete', ContainerServiceOperations.delete, factory)
cli_generic_update_command('vm container update', ContainerServiceOperations.get, ContainerServiceOperations.create_or_update, factory)
@ -120,46 +118,46 @@ cli_command('vmss diagnostics get-default-config', show_default_diagnostics_conf
cli_command('vm disk attach-new', attach_new_disk)
cli_command('vm disk attach-existing', attach_existing_disk)
cli_command('vm disk detach', detach_disk)
cli_command('vm disk list', list_disks, simple_output_query="[*].{Name:name, Lun:lun, DiskSizeGb:diskSizeGb, Caching:caching, Uri:vhd.uri} | sort_by(@, &Name)")
cli_command('vm disk list', list_disks)
# VM Extension
factory = lambda _: _compute_client_factory().virtual_machine_extensions
cli_command('vm extension delete', VirtualMachineExtensionsOperations.delete, factory)
cli_command('vm extension show', VirtualMachineExtensionsOperations.get, factory)
cli_command('vm extension set', set_extension)
cli_command('vm extension list', list_extensions, simple_output_query="[*].{Name:name, ResourceGroup:resourceGroup, ProvisioningState:provisioningState, Publisher:publisher, Version:typeHandlerVersion} | sort_by(@, &Name)")
cli_command('vm extension list', list_extensions)
# VMSS Extension
cli_command('vmss extension delete', delete_vmss_extension)
cli_command('vmss extension show', get_vmss_extension)
cli_command('vmss extension set', set_vmss_extension)
cli_command('vmss extension list', list_vmss_extensions, simple_output_query="[*].{Name:name, ResourceGroup:resourceGroup, ProvisioningState:provisioningState, Publisher:publisher, Version:typeHandlerVersion} | sort_by(@, &Name)")
cli_command('vmss extension list', list_vmss_extensions)
# VM Extension Image
factory = lambda _: _compute_client_factory().virtual_machine_extension_images
cli_command('vm extension image show', VirtualMachineExtensionImagesOperations.get, factory, simple_output_query="{Name:name, Location:location, OperatingSystem:operatingSystem, SupportsMultipleExtensions:supportsMultipleExtensions, VmScaleSetEnabled:vmScaleSetEnabled, ComputeRole:computeRole}")
cli_command('vm extension image list-names', VirtualMachineExtensionImagesOperations.list_types, factory, simple_output_query="[*].{Name:name, Location:location} | sort_by(@, &Name)")
cli_command('vm extension image list-versions', VirtualMachineExtensionImagesOperations.list_versions, factory, simple_output_query="[*].{Name:name, Location:location} | sort_by(@, &Name)")
cli_command('vm extension image list', list_vm_extension_images, simple_output_query="[*].{Publisher:publisher, Name:name, Version:version} | sort_by(@, &Publisher)")
cli_command('vm extension image show', VirtualMachineExtensionImagesOperations.get, factory)
cli_command('vm extension image list-names', VirtualMachineExtensionImagesOperations.list_types, factory)
cli_command('vm extension image list-versions', VirtualMachineExtensionImagesOperations.list_versions, factory)
cli_command('vm extension image list', list_vm_extension_images)
# VMSS Extension Image (convenience copy of VM Extension Image)
factory = lambda _: _compute_client_factory().virtual_machine_extension_images
cli_command('vmss extension image show', VirtualMachineExtensionImagesOperations.get, factory, simple_output_query="{Name:name, Location:location, OperatingSystem:operatingSystem, SupportsMultipleExtensions:supportsMultipleExtensions, VmScaleSetEnabled:vmScaleSetEnabled, ComputeRole:computeRole}")
cli_command('vmss extension image list-names', VirtualMachineExtensionImagesOperations.list_types, factory, simple_output_query="[*].{Name:name, Location:location} | sort_by(@, &Name)")
cli_command('vmss extension image list-versions', VirtualMachineExtensionImagesOperations.list_versions, factory, simple_output_query="[*].{Name:name, Location:location} | sort_by(@, &Name)")
cli_command('vmss extension image list', list_vm_extension_images, simple_output_query="[*].{Publisher:publisher, Name:name, Version:version} | sort_by(@, &Publisher)")
cli_command('vmss extension image show', VirtualMachineExtensionImagesOperations.get, factory)
cli_command('vmss extension image list-names', VirtualMachineExtensionImagesOperations.list_types, factory)
cli_command('vmss extension image list-versions', VirtualMachineExtensionImagesOperations.list_versions, factory)
cli_command('vmss extension image list', list_vm_extension_images)
# VM Image
factory = lambda _: _compute_client_factory().virtual_machine_images
cli_command('vm image show', VirtualMachineImagesOperations.get, factory, simple_output_query="{Publisher:plan.publisher, Offer:plan.product, Sku:plan.name, OS:osDiskImage.operatingSystem, Version:name, Location:location, Urn:join(':', [plan.publisher,plan.product,plan.name,name])}")
cli_command('vm image list-offers', VirtualMachineImagesOperations.list_offers, factory, simple_output_query="[*].{Name:name, Location:location} | sort_by(@, &Name)")
cli_command('vm image list-publishers', VirtualMachineImagesOperations.list_publishers, factory, simple_output_query="[*].{Name:name, Location:location} | sort_by(@, &Name)")
cli_command('vm image list-skus', VirtualMachineImagesOperations.list_skus, factory, simple_output_query="[*].{Name:name, Location:location} | sort_by(@, &Name)")
cli_command('vm image list', list_vm_images, simple_output_query="[*].{Publisher:publisher, Offer:offer, Sku:sku, Version:version, UrnAlias:\"urn alias\", Urn:urn}")
cli_command('vm image show', VirtualMachineImagesOperations.get, factory)
cli_command('vm image list-offers', VirtualMachineImagesOperations.list_offers, factory)
cli_command('vm image list-publishers', VirtualMachineImagesOperations.list_publishers, factory)
cli_command('vm image list-skus', VirtualMachineImagesOperations.list_skus, factory)
cli_command('vm image list', list_vm_images)
# VM Usage
factory = lambda _: _compute_client_factory().usage
cli_command('vm list-usage', UsageOperations.list, factory, simple_output_query="[*].{Name:name.localizedValue, CurrentValue:currentValue, Limit:limit} | sort_by(@, &Name)")
cli_command('vm list-usage', UsageOperations.list, factory)
# VM ScaleSet
factory = lambda _: get_mgmt_service_client(VMSSClient).vmss
@ -167,16 +165,16 @@ cli_command('vmss create', VmssOperations.create_or_update, factory, transform=D
factory = lambda _: _compute_client_factory().virtual_machine_scale_sets
cli_command('vmss delete', VirtualMachineScaleSetsOperations.delete, factory)
cli_command('vmss list-skus', VirtualMachineScaleSetsOperations.list_skus, factory, simple_output_query="[*].{SkuName:sku.name, SkuTier:sku.tier, CapacityMin:capacity.minimum, CapacityMax:capacity.maximum, CapacityDefault:capacity.defaultCapacity, CapacityScaleType:capacity.scaleType} | sort_by(@, &SkuName)")
cli_command('vmss list-skus', VirtualMachineScaleSetsOperations.list_skus, factory)
factory = lambda _: _compute_client_factory().virtual_machine_scale_set_vms
cli_command('vmss list-instances', VirtualMachineScaleSetVMsOperations.list, factory, simple_output_query="[*].{Name:name, ResourceGroup:resourceGroup, ProvisioningState:provisioningState, Location:location, SkuName:sku.name, SkuTier:sku.tier, InstanceId:instanceId} | sort_by(@, &Name)")
cli_command('vmss list-instances', VirtualMachineScaleSetVMsOperations.list, factory)
cli_command('vmss deallocate', vmss_deallocate)
cli_command('vmss delete-instances', vmss_delete_instances)
cli_command('vmss get-instance-view', vmss_get_instance_view)
cli_command('vmss show', vmss_show, simple_output_query="{Name:name, ResourceGroup:resourceGroup, ProvisioningState:provisioningState, Location:location, SkuCapacity:sku.capacity, SkuName:sku.name, SkuTier:skuTier}")
cli_command('vmss list ', vmss_list, simple_output_query="[*].{Name:name, ResourceGroup:resourceGroup, ProvisioningState:provisioningState, Location:location} | sort_by(@, &Name)")
cli_command('vmss show', vmss_show)
cli_command('vmss list ', vmss_list)
cli_command('vmss stop', vmss_stop)
cli_command('vmss restart', vmss_restart)
cli_command('vmss start', vmss_start)
@ -186,4 +184,4 @@ cli_command('vmss scale', vmss_scale)
# VM Size
factory = lambda _: _compute_client_factory().virtual_machine_sizes
cli_command('vm list-sizes', VirtualMachineSizesOperations.list, factory, simple_output_query="[*].{Name: name, NumberOfCores: numberOfCores, MemoryInMb: memoryInMb, MaxDataDiskCount: maxDataDiskCount, ResourceDiskSizeInMb: resourceDiskSizeInMb, OsDiskSizeInMb: osDiskSizeInMb} | sort_by(@, &Name)")
cli_command('vm list-sizes', VirtualMachineSizesOperations.list, factory)