def generic_update_command(self, name, getter_op, setter_op): cli_generic_update_command( self._scope, '{} {}'.format(self._group_name, name), self._service_adapter(getter_op), self._service_adapter(setter_op), factory=self._client_factory)
def test_generic_update_empty_nodes(self): my_obj = { 'prop': None, 'list': [], 'dict': { 'dict2': None }, 'dict3': {} } def my_get(): return my_obj def my_set(**kwargs): # pylint:disable=unused-argument return my_obj config = Configuration() app = Application() app.initialize(config) setattr(sys.modules[__name__], my_get.__name__, my_get) setattr(sys.modules[__name__], my_set.__name__, my_set) cli_generic_update_command(None, 'gencommand', '{}#{}'.format(__name__, my_get.__name__), '{}#{}'.format(__name__, my_set.__name__)) # add to prop app.execute('gencommand --add prop a=b'.split()) self.assertEqual(my_obj['prop'][0]['a'], 'b', 'verify object added to null list') self.assertEqual(len(my_obj['prop'][0]), 1, 'verify only one object added to null list') # add to list app.execute('gencommand --add list c=d'.split()) self.assertEqual(my_obj['list'][0]['c'], 'd', 'verify object added to empty list') self.assertEqual(len(my_obj['list']), 1, 'verify only one object added to empty list') # set dict2 app.execute('gencommand --set dict.dict2.e=f'.split()) self.assertEqual(my_obj['dict']['dict2']['e'], 'f', 'verify object added to null dict') self.assertEqual(len(my_obj['dict']['dict2']), 1, 'verify only one object added to null dict') # set dict3 app.execute('gencommand --set dict3.g=h'.split()) self.assertEqual(my_obj['dict3']['g'], 'h', 'verify object added to empty dict') self.assertEqual(len(my_obj['dict3']), 1, 'verify only one object added to empty dict')
def generic_update_command(self, name, getter_op, setter_op, custom_func_name=None): if custom_func_name: custom_function_op = self._custom_path.format(custom_func_name) else: custom_function_op = None cli_generic_update_command( self._scope, '{} {}'.format(self._group_name, name), self._service_adapter(getter_op), self._service_adapter(setter_op), factory=self._client_factory, custom_function_op=custom_function_op)
def generic_update_command(self, name, getter_op, setter_op, custom_func_name=None, setter_arg_name='parameters'): if custom_func_name: custom_function_op = self._custom_path.format(custom_func_name) else: custom_function_op = None cli_generic_update_command( self._scope, '{} {}'.format(self._group_name, name), self._service_adapter(getter_op), self._service_adapter(setter_op), factory=self._client_factory, custom_function_op=custom_function_op, setter_arg_name=setter_arg_name)
def test_generic_update_empty_nodes(self): my_obj = { 'prop': None, 'list': [], 'dict': { 'dict2': None }, 'dict3': {} } def my_get(): return my_obj def my_set(**kwargs): # pylint:disable=unused-argument return my_obj config = Configuration() app = Application() app.initialize(config) setattr(sys.modules[__name__], my_get.__name__, my_get) setattr(sys.modules[__name__], my_set.__name__, my_set) cli_generic_update_command(None, 'gencommand', '{}#{}'.format( __name__, my_get.__name__), '{}#{}'.format(__name__, my_set.__name__)) # add to prop app.execute('gencommand --add prop a=b'.split()) self.assertEqual(my_obj['prop'][0]['a'], 'b', 'verify object added to null list') self.assertEqual(len(my_obj['prop'][0]), 1, 'verify only one object added to null list') # add to list app.execute('gencommand --add list c=d'.split()) self.assertEqual(my_obj['list'][0]['c'], 'd', 'verify object added to empty list') self.assertEqual(len(my_obj['list']), 1, 'verify only one object added to empty list') # set dict2 app.execute('gencommand --set dict.dict2.e=f'.split()) self.assertEqual(my_obj['dict']['dict2']['e'], 'f', 'verify object added to null dict') self.assertEqual(len(my_obj['dict']['dict2']), 1, 'verify only one object added to null dict') # set dict3 app.execute('gencommand --set dict3.g=h'.split()) self.assertEqual(my_obj['dict3']['g'], 'h', 'verify object added to empty dict') self.assertEqual(len(my_obj['dict3']), 1, 'verify only one object added to empty dict')
def test_generic_update_ids(self): my_objs = [{ 'prop': 'val', 'list': ['a', 'b', ['c', { 'd': 'e' }]] }, { 'prop': 'val', 'list': ['a', 'b', ['c', { 'd': 'e' }]] }] def my_get(name, resource_group): #pylint:disable=unused-argument # name is None when tests are run in a batch on Python <=2.7.9 if sys.version_info < (2, 7, 10): return my_objs[0] return my_objs[int(name)] def my_set(**kwargs): #pylint:disable=unused-argument return my_objs register_cli_argument( 'gencommand', 'name', CliArgumentType(options_list=('--name', '-n'), metavar='NAME', id_part='name')) cli_generic_update_command('gencommand', my_get, my_set) config = Configuration([]) APPLICATION.initialize(config) id_str = ( '/subscriptions/00000000-0000-0000-0000-0000000000000/resourceGroups/rg/' 'providers/Microsoft.Compute/virtualMachines/') APPLICATION.execute( 'gencommand --ids {0}0 {0}1 --resource-group bar --set prop=newval' .format(id_str).split()) self.assertEqual(my_objs[0]['prop'], 'newval', 'first object updated') # name is None when tests are run in a batch on Python <=2.7.9 if not sys.version_info < (2, 7, 10): self.assertEqual(my_objs[1]['prop'], 'newval', 'second object updated')
def test_generic_update_ids(self): my_objs = [ { 'prop': 'val', 'list': [ 'a', 'b', ['c', {'d': 'e'}] ] }, { 'prop': 'val', 'list': [ 'a', 'b', ['c', {'d': 'e'}] ] }] def my_get(name, resource_group): #pylint:disable=unused-argument # name is None when tests are run in a batch on Python <=2.7.9 if sys.version_info < (2, 7, 10): return my_objs[0] return my_objs[int(name)] def my_set(**kwargs): #pylint:disable=unused-argument return my_objs register_cli_argument('gencommand', 'name', CliArgumentType(options_list=('--name', '-n'), metavar='NAME', id_part='name')) cli_generic_update_command('gencommand', my_get, my_set) config = Configuration([]) APPLICATION.initialize(config) id_str = ('/subscriptions/00000000-0000-0000-0000-0000000000000/resourceGroups/rg/' 'providers/Microsoft.Compute/virtualMachines/') APPLICATION.execute('gencommand --ids {0}0 {0}1 --resource-group bar --set prop=newval' .format(id_str).split()) self.assertEqual(my_objs[0]['prop'], 'newval', 'first object updated') # name is None when tests are run in a batch on Python <=2.7.9 if not sys.version_info < (2, 7, 10): self.assertEqual(my_objs[1]['prop'], 'newval', 'second object updated')
def generic_update_command(self, name, getter_op, setter_op, custom_func_name=None, setter_arg_name='parameters', no_wait_param=None, **kwargs): if custom_func_name: custom_function_op = self._custom_path.format(custom_func_name) else: custom_function_op = None cli_generic_update_command(self._scope, '{} {}'.format(self._group_name, name), self._service_adapter(getter_op), self._service_adapter(setter_op), factory=self._client_factory, custom_function_op=custom_function_op, setter_arg_name=setter_arg_name, no_wait_param=no_wait_param, **kwargs)
def test_generic_update_empty_nodes(self): my_obj = {"prop": None, "list": [], "dict": {"dict2": None}, "dict3": {}} def my_get(): return my_obj def my_set(**kwargs): # pylint:disable=unused-argument return my_obj config = Configuration([]) app = Application(config) setattr(sys.modules[__name__], my_get.__name__, my_get) setattr(sys.modules[__name__], my_set.__name__, my_set) cli_generic_update_command( None, "gencommand", "{}#{}".format(__name__, my_get.__name__), "{}#{}".format(__name__, my_set.__name__) ) # add to prop app.execute("gencommand --add prop a=b".split()) self.assertEqual(my_obj["prop"][0]["a"], "b", "verify object added to null list") self.assertEqual(len(my_obj["prop"][0]), 1, "verify only one object added to null list") # add to list app.execute("gencommand --add list c=d".split()) self.assertEqual(my_obj["list"][0]["c"], "d", "verify object added to empty list") self.assertEqual(len(my_obj["list"]), 1, "verify only one object added to empty list") # set dict2 app.execute("gencommand --set dict.dict2.e=f".split()) self.assertEqual(my_obj["dict"]["dict2"]["e"], "f", "verify object added to null dict") self.assertEqual(len(my_obj["dict"]["dict2"]), 1, "verify only one object added to null dict") # set dict3 app.execute("gencommand --set dict3.g=h".split()) self.assertEqual(my_obj["dict3"]["g"], "h", "verify object added to empty dict") self.assertEqual(len(my_obj["dict3"]), 1, "verify only one object added to empty dict")
from azure.cli.core.commands.arm import cli_generic_update_command from .custom import (_auth_client_factory, _graph_client_factory) def transform_definition_list(result): return [OrderedDict([('Name', r['properties']['roleName']), ('Type', r['properties']['type']), ('Descritpion', r['properties']['description'])]) for r in result] def transform_assignment_list(result): return [OrderedDict([('Principal', r['properties']['principalName']), ('Role', r['properties']['roleDefinitionName']), ('Scope', r['properties']['scope'])]) for r in result] factory = lambda _: _auth_client_factory().role_definitions cli_command(__name__, 'role definition list', 'azure.cli.command_modules.role.custom#list_role_definitions', table_transformer=transform_definition_list) cli_command(__name__, 'role definition delete', 'azure.cli.command_modules.role.custom#delete_role_definition') cli_command(__name__, 'role definition create', 'azure.cli.command_modules.role.custom#create_role_definition') cli_generic_update_command(__name__, 'role definition update', 'azure.mgmt.authorization.operations.role_definitions_operations#RoleDefinitionsOperations.get', 'azure.mgmt.authorization.operations.role_definitions_operations#RoleDefinitionsOperations.create_or_update', factory) factory = lambda _: _auth_client_factory().role_assignments cli_command(__name__, 'role assignment delete', 'azure.cli.command_modules.role.custom#delete_role_assignments') cli_command(__name__, 'role assignment list', 'azure.cli.command_modules.role.custom#list_role_assignments', table_transformer=transform_assignment_list) cli_command(__name__, 'role assignment create', 'azure.cli.command_modules.role.custom#create_role_assignment') factory = lambda _: _graph_client_factory().applications cli_command(__name__, 'ad app create', 'azure.cli.command_modules.role.custom#create_application', factory) cli_command(__name__, 'ad app delete', 'azure.cli.command_modules.role.custom#delete_application', factory) cli_command(__name__, 'ad app list', 'azure.cli.command_modules.role.custom#list_apps', factory) cli_command(__name__, 'ad app show', 'azure.cli.command_modules.role.custom#show_application', factory) cli_command(__name__, 'ad app update', 'azure.cli.command_modules.role.custom#update_application', factory) factory = lambda _: _graph_client_factory().service_principals
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- #pylint: disable=line-too-long from azure.cli.core.commands import cli_command from azure.cli.core.commands.arm import cli_generic_update_command from azure.cli.command_modules.redis._client_factory import (cf_redis, cf_patch_schedules) cli_command(__name__, 'redis create', 'azure.cli.command_modules.redis.custom#cli_redis_create', cf_redis) cli_command(__name__, 'redis delete', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.delete', cf_redis) cli_command(__name__, 'redis export', 'azure.cli.command_modules.redis.custom#cli_redis_export', cf_redis) cli_command(__name__, 'redis force-reboot', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.force_reboot', cf_redis) cli_command(__name__, 'redis import-method', 'azure.cli.command_modules.redis.custom#cli_redis_import_method', cf_redis) cli_command(__name__, 'redis list', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.list_by_resource_group', cf_redis) cli_command(__name__, 'redis list-all', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.list', cf_redis) cli_command(__name__, 'redis list-keys', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.list_keys', cf_redis) cli_command(__name__, 'redis regenerate-keys', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.regenerate_key', cf_redis) cli_command(__name__, 'redis show', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.get', cf_redis) cli_command(__name__, 'redis update-settings', 'azure.cli.command_modules.redis.custom#cli_redis_update_settings', cf_redis) cli_generic_update_command(__name__, 'redis update', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.get', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.create_or_update', cf_redis, custom_function_op='azure.cli.command_modules.redis.custom#cli_redis_update') cli_command(__name__, 'redis patch-schedule set', 'azure.mgmt.redis.operations.patch_schedules_operations#PatchSchedulesOperations.create_or_update', cf_patch_schedules) cli_command(__name__, 'redis patch-schedule delete', 'azure.mgmt.redis.operations.patch_schedules_operations#PatchSchedulesOperations.delete', cf_patch_schedules) cli_command(__name__, 'redis patch-schedule show', 'azure.mgmt.redis.operations.patch_schedules_operations#PatchSchedulesOperations.get', cf_patch_schedules)
'webapp list', custom_path + 'list_webapp', table_transformer=transform_web_list_output) cli_command(__name__, 'webapp show', custom_path + 'show_webapp', exception_handler=empty_on_404, table_transformer=transform_web_output) cli_command(__name__, 'webapp delete', custom_path + 'delete_webapp') cli_command(__name__, 'webapp stop', custom_path + 'stop_webapp') cli_command(__name__, 'webapp start', custom_path + 'start_webapp') cli_command(__name__, 'webapp restart', custom_path + 'restart_webapp') cli_generic_update_command( __name__, 'webapp update', 'azure.mgmt.web.operations.web_apps_operations#WebAppsOperations.get', 'azure.mgmt.web.operations.web_apps_operations#WebAppsOperations.create_or_update', custom_function_op=custom_path + 'update_webapp', setter_arg_name='site_envelope', factory=cf_webapps) cli_command(__name__, 'webapp traffic-routing set', custom_path + 'set_traffic_routing') cli_command(__name__, 'webapp traffic-routing show', custom_path + 'show_traffic_routing') cli_command(__name__, 'webapp traffic-routing clear', custom_path + 'clear_traffic_routing') cli_command(__name__, 'webapp config set', custom_path + 'update_site_configs') cli_command(__name__, 'webapp config show', custom_path + 'get_site_configs',
raise ex # storage account commands factory = lambda kwargs: storage_client_factory().storage_accounts # noqa: E731 lambda vs def cli_command(__name__, 'storage account check-name', mgmt_path + 'check_name_availability', factory) cli_command(__name__, 'storage account delete', mgmt_path + 'delete', factory, confirmation=True) cli_command(__name__, 'storage account show', mgmt_path + 'get_properties', factory, exception_handler=empty_on_404) cli_command(__name__, 'storage account create', custom_path + 'create_storage_account') cli_command(__name__, 'storage account list', custom_path + 'list_storage_accounts') cli_command(__name__, 'storage account show-usage', custom_path + 'show_storage_account_usage') cli_command(__name__, 'storage account show-connection-string', custom_path + 'show_storage_account_connection_string') cli_command(__name__, 'storage account keys renew', mgmt_path + 'regenerate_key', factory, transform=lambda x: x.keys) cli_command(__name__, 'storage account keys list', mgmt_path + 'list_keys', factory, transform=lambda x: x.keys) cli_generic_update_command(__name__, 'storage account update', mgmt_path + 'get_properties', mgmt_path + 'create', factory, custom_function_op=custom_path + 'update_storage_account') cli_storage_data_plane_command('storage account generate-sas', 'azure.storage.cloudstorageaccount#CloudStorageAccount.generate_shared_access_signature', cloud_storage_account_service_factory) # container commands factory = blob_data_service_factory cli_storage_data_plane_command('storage container list', block_blob_path + 'list_containers', factory, transform=transform_storage_list_output, table_transformer=transform_container_list) cli_storage_data_plane_command('storage container delete', block_blob_path + 'delete_container', factory, transform=create_boolean_result_output_transformer('deleted'), table_transformer=transform_boolean_for_table) cli_storage_data_plane_command('storage container show', block_blob_path + 'get_container_properties', factory, table_transformer=transform_container_show, exception_handler=_dont_fail_not_exist) cli_storage_data_plane_command('storage container create', block_blob_path + 'create_container', factory, transform=create_boolean_result_output_transformer('created'), table_transformer=transform_boolean_for_table) cli_storage_data_plane_command('storage container generate-sas', block_blob_path + 'generate_container_shared_access_signature', factory) cli_storage_data_plane_command('storage container metadata update', block_blob_path + 'set_container_metadata', factory) cli_storage_data_plane_command('storage container metadata show', block_blob_path + 'get_container_metadata', factory, exception_handler=_dont_fail_not_exist) cli_storage_data_plane_command('storage container lease acquire', block_blob_path + 'acquire_container_lease', factory) cli_storage_data_plane_command('storage container lease renew', block_blob_path + 'renew_container_lease', factory) cli_storage_data_plane_command('storage container lease release', block_blob_path + 'release_container_lease', factory)
table_transformer=output_format) cli_command(__name__, 'acr delete', 'azure.cli.command_modules.acr.custom#acr_delete', table_transformer=output_format) cli_command(__name__, 'acr show', 'azure.cli.command_modules.acr.custom#acr_show', table_transformer=output_format, exception_handler=empty_on_404) cli_command(__name__, 'acr login', 'azure.cli.command_modules.acr.custom#acr_login') cli_generic_update_command( __name__, 'acr update', 'azure.cli.command_modules.acr.custom#acr_update_get', 'azure.cli.command_modules.acr.custom#acr_update_set', factory=lambda: get_acr_service_client().registries, custom_function_op='azure.cli.command_modules.acr.custom#acr_update_custom', table_transformer=output_format) cli_command(__name__, 'acr repository list', 'azure.cli.command_modules.acr.repository#acr_repository_list') cli_command( __name__, 'acr repository show-tags', 'azure.cli.command_modules.acr.repository#acr_repository_show_tags') cli_command( __name__, 'acr repository show-manifests', 'azure.cli.command_modules.acr.repository#acr_repository_show_manifests') cli_command(__name__, 'acr repository delete', 'azure.cli.command_modules.acr.repository#acr_repository_delete')
table_transformer=output_format) cli_command(__name__, 'acr check-name', 'azure.cli.command_modules.acr.custom#acr_check_name') cli_command(__name__, 'acr list', 'azure.cli.command_modules.acr.custom#acr_list', table_transformer=output_format) cli_command(__name__, 'acr create', 'azure.cli.command_modules.acr.custom#acr_create', table_transformer=output_format) cli_command(__name__, 'acr delete', 'azure.cli.command_modules.acr.custom#acr_delete', table_transformer=output_format) cli_command(__name__, 'acr show', 'azure.cli.command_modules.acr.custom#acr_show', table_transformer=output_format, exception_handler=empty_on_404) cli_command(__name__, 'acr login', 'azure.cli.command_modules.acr.custom#acr_login') cli_generic_update_command( __name__, 'acr update', 'azure.cli.command_modules.acr.custom#acr_update_get', 'azure.cli.command_modules.acr.custom#acr_update_set', factory=lambda: get_acr_service_client().registries, custom_function_op='azure.cli.command_modules.acr.custom#acr_update_custom', table_transformer=output_format) cli_command(__name__, 'acr repository list', 'azure.cli.command_modules.acr.repository#acr_repository_list') cli_command(__name__, 'acr repository show-tags', 'azure.cli.command_modules.acr.repository#acr_repository_show_tags') cli_command(__name__, 'acr repository show-manifests', 'azure.cli.command_modules.acr.repository#acr_repository_show_manifests') cli_command(__name__, 'acr repository delete', 'azure.cli.command_modules.acr.repository#acr_repository_delete') cli_command(__name__, 'acr webhook list', 'azure.cli.command_modules.acr.webhook#acr_webhook_list',
def test_generic_update_errors(self): #pylint: disable=no-self-use my_obj = TestObject() def my_get(a1, a2): #pylint: disable=unused-argument return my_obj def my_set(**kwargs): #pylint:disable=unused-argument return my_obj config = Configuration([]) app = Application(config) setattr(sys.modules[__name__], my_get.__name__, my_get) setattr(sys.modules[__name__], my_set.__name__, my_set) cli_generic_update_command(None, 'gencommand', '{}#{}'.format(__name__, my_get.__name__), '{}#{}'.format(__name__, my_set.__name__)) def _execute_with_error(command, error, message): try: app.execute(command.split()) except CLIError as err: if not error in str(err): raise AssertionError('{}\nExpected: {}\nActual: {}'.format( message, error, str(err))) else: raise AssertionError('exception not thrown') missing_remove_message = "Couldn't find 'doesntExist' in ''. Available options: ['myDict', 'myList', 'myListOfCamelDicts', 'myListOfObjects', 'myListOfSnakeDicts', 'myProp']" _execute_with_error('gencommand --a1 1 --a2 2 --remove doesntExist', missing_remove_message, 'remove non-existent property by name') _execute_with_error('gencommand --a1 1 --a2 2 --remove doesntExist 2', missing_remove_message, 'remove non-existent property by index') remove_prop_message = "Couldn't find 'doesntExist' in 'myList.doesntExist'. Available options: index into the collection 'myList.doesntExist' with [<index>] or [<key=value>]" _execute_with_error( 'gencommand --a1 1 --a2 2 --remove myList.doesntExist.missing 2', remove_prop_message, 'remove non-existent sub-property by index') _execute_with_error('gencommand --a1 1 --a2 2 --remove myList 20', "index 20 doesn't exist on myList", 'remove out-of-range index') set_on_list_message = "Couldn't find 'doesnt_exist' in 'myList'. Available options: index into the collection 'myList' with [<index>] or [<key=value>]" _execute_with_error( 'gencommand --a1 1 --a2 2 --set myList.doesnt_exist=foo', set_on_list_message, 'set shouldn\'t work on a list') _execute_with_error( 'gencommand --a1 1 --a2 2 --set myList.doesnt_exist.doesnt_exist2=foo', set_on_list_message, 'set shouldn\'t work on a list') _execute_with_error( 'gencommand --a1 1 --a2 2 --set myList[5].doesnt_exist=foo', "index 5 doesn't exist on myList", 'index out of range in path') _execute_with_error( 'gencommand --a1 1 --a2 2 --remove myList[0]', 'invalid syntax: --remove property.list <indexToRemove> OR --remove propertyToRemove', 'remove requires index to be space-separated') app.execute( "gencommand --a1 1 --a2 2 --set myDict={'foo':'bar'}".split()) _execute_with_error( 'gencommand --a1 1 --a2 2 --set myDict.foo.doo=boo', "Couldn't find 'foo' in 'myDict'. 'myDict' does not support further indexing.", 'Cannot dot index from a scalar value') _execute_with_error( 'gencommand --a1 1 --a2 2 --set myDict.foo[0]=boo', "Couldn't find 'foo' in 'myDict'. 'myDict' does not support further indexing.", 'Cannot list index from a scalar value') _execute_with_error( 'gencommand --a1 1 --a2 2 --add myDict la=da', "invalid syntax: --add property.listProperty <key=value, string or JSON string>", 'Add only works with lists') # add an entry which makes 'myKey' no longer unique app.execute( 'gencommand --a1 1 --a2 2 --add myListOfCamelDicts myKey=value_2'. split()) _execute_with_error( 'gencommand --a1 1 --a2 2 --set myListOfCamelDicts[myKey=value_2].myKey=foo', "non-unique key 'myKey' found multiple matches on myListOfCamelDicts. " "Key must be unique.", 'indexing by key must be unique') _execute_with_error( 'gencommand --a1 1 --a2 2 --set myListOfCamelDicts[myKey=foo].myKey=foo', "item with value 'foo' doesn\'t exist for key 'myKey' on myListOfCamelDicts", 'no match found when indexing by key and value')
custom_path = 'azure.cli.command_modules.network.custom#{}' # Application gateways cli_command(__name__, 'network application-gateway create', custom_path.format('create_application_gateway'), transform=DeploymentOutputLongRunningOperation('Starting network application-gateway create'), no_wait_param='no_wait') cli_command(__name__, 'network application-gateway delete', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.delete', cf_application_gateways, no_wait_param='raw') cli_command(__name__, 'network application-gateway show', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.get', cf_application_gateways, exception_handler=empty_on_404) cli_command(__name__, 'network application-gateway list', custom_path.format('list_application_gateways')) cli_command(__name__, 'network application-gateway start', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.start', cf_application_gateways) cli_command(__name__, 'network application-gateway stop', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.stop', cf_application_gateways) if supported_api_version(ResourceType.MGMT_NETWORK, min_api='2016-09-01'): cli_command(__name__, 'network application-gateway show-backend-health', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.backend_health', cf_application_gateways) cli_generic_update_command(__name__, 'network application-gateway update', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.get', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.create_or_update', cf_application_gateways, no_wait_param='raw', custom_function_op=custom_path.format('update_application_gateway')) cli_generic_wait_command(__name__, 'network application-gateway wait', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.get', cf_application_gateways) property_map = { 'authentication_certificates': 'auth-cert', 'ssl_certificates': 'ssl-cert', 'frontend_ip_configurations': 'frontend-ip', 'frontend_ports': 'frontend-port', 'backend_address_pools': 'address-pool', 'backend_http_settings_collection': 'http-settings', 'http_listeners': 'http-listener', 'request_routing_rules': 'rule',
redis_custom = 'azure.cli.command_modules.redis.custom#' redis_patch_operation = \ 'azure.mgmt.redis.operations.patch_schedules_operations#PatchSchedulesOperations.' cli_command(__name__, 'redis create', redis_custom + 'cli_redis_create', cf_redis, exception_handler=wrong_vmsize_argument_exception_handler) cli_command(__name__, 'redis delete', redis_operation + 'delete', cf_redis) cli_command(__name__, 'redis export', redis_custom + 'cli_redis_export', cf_redis) cli_command(__name__, 'redis force-reboot', redis_operation + 'force_reboot', cf_redis) cli_command(__name__, 'redis import-method', redis_custom + 'cli_redis_import_method', cf_redis) cli_command(__name__, 'redis list', redis_operation + 'list_by_resource_group', cf_redis) cli_command(__name__, 'redis list-all', redis_operation + 'list', cf_redis) cli_command(__name__, 'redis list-keys', redis_operation + 'list_keys', cf_redis) cli_command(__name__, 'redis regenerate-keys', redis_operation + 'regenerate_key', cf_redis) cli_command(__name__, 'redis show', redis_operation + 'get', cf_redis) cli_command(__name__, 'redis update-settings', redis_custom + 'cli_redis_update_settings', cf_redis) cli_generic_update_command(__name__, 'redis update', redis_operation + 'get', redis_operation + 'create_or_update', cf_redis, custom_function_op=redis_custom + 'cli_redis_update', exception_handler=wrong_vmsize_argument_exception_handler) cli_command(__name__, 'redis patch-schedule set', redis_patch_operation + 'create_or_update', cf_patch_schedules) cli_command(__name__, 'redis patch-schedule delete', redis_patch_operation + 'delete', cf_patch_schedules) cli_command(__name__, 'redis patch-schedule show', redis_patch_operation + 'get', cf_patch_schedules)
cli_generic_wait_command(__name__, 'group deployment wait', 'azure.mgmt.resource.resources.operations.deployments_operations#DeploymentsOperations.get', cf_deployments) if supported_api_version(resource_type=ResourceType.MGMT_RESOURCE_RESOURCES, min_api='2017-05-10'): cli_command(__name__, 'group deployment list', 'azure.mgmt.resource.resources.operations.deployments_operations#DeploymentsOperations.list_by_resource_group', cf_deployments, table_transformer=transform_deployments_list) else: cli_command(__name__, 'group deployment list', 'azure.mgmt.resource.resources.operations.deployments_operations#DeploymentsOperations.list', cf_deployments, table_transformer=transform_deployments_list) cli_command(__name__, 'group deployment show', 'azure.mgmt.resource.resources.operations.deployments_operations#DeploymentsOperations.get', cf_deployments, exception_handler=empty_on_404) cli_command(__name__, 'group deployment delete', 'azure.mgmt.resource.resources.operations.deployments_operations#DeploymentsOperations.delete', cf_deployments) cli_command(__name__, 'group deployment validate', 'azure.cli.command_modules.resource.custom#validate_arm_template', table_transformer=deployment_validate_table_format) cli_command(__name__, 'group deployment export', 'azure.cli.command_modules.resource.custom#export_deployment_as_template') # Resource group deployment operations commands cli_command(__name__, 'group deployment operation list', 'azure.mgmt.resource.resources.operations.deployment_operations#DeploymentOperations.list', cf_deployment_operations) cli_command(__name__, 'group deployment operation show', 'azure.cli.command_modules.resource.custom#get_deployment_operations', cf_deployment_operations, exception_handler=empty_on_404) cli_generic_update_command(__name__, 'resource update', 'azure.cli.command_modules.resource.custom#show_resource', 'azure.cli.command_modules.resource.custom#update_resource') cli_generic_update_command(__name__, 'group update', 'azure.mgmt.resource.resources.operations.resource_groups_operations#ResourceGroupsOperations.get', 'azure.mgmt.resource.resources.operations.resource_groups_operations#ResourceGroupsOperations.create_or_update', lambda: _resource_client_factory().resource_groups) cli_command(__name__, 'policy assignment create', 'azure.cli.command_modules.resource.custom#create_policy_assignment') cli_command(__name__, 'policy assignment delete', 'azure.cli.command_modules.resource.custom#delete_policy_assignment') cli_command(__name__, 'policy assignment list', 'azure.cli.command_modules.resource.custom#list_policy_assignment') cli_command(__name__, 'policy assignment show', 'azure.cli.command_modules.resource.custom#show_policy_assignment', exception_handler=empty_on_404) cli_command(__name__, 'policy definition create', 'azure.cli.command_modules.resource.custom#create_policy_definition') cli_command(__name__, 'policy definition delete', 'azure.mgmt.resource.policy.operations#PolicyDefinitionsOperations.delete', cf_policy_definitions) cli_command(__name__, 'policy definition list', 'azure.mgmt.resource.policy.operations#PolicyDefinitionsOperations.list', cf_policy_definitions)
pass raise ex return _polish_bad_errors custom_path = 'azure.cli.command_modules.appservice.custom#' cli_command(__name__, 'webapp create', custom_path + 'create_webapp', exception_handler=ex_handler_factory()) cli_command(__name__, 'webapp list', custom_path + 'list_webapp', table_transformer=transform_web_list_output) cli_command(__name__, 'webapp show', custom_path + 'show_webapp', exception_handler=empty_on_404, table_transformer=transform_web_output) cli_command(__name__, 'webapp delete', custom_path + 'delete_webapp') cli_command(__name__, 'webapp stop', custom_path + 'stop_webapp') cli_command(__name__, 'webapp start', custom_path + 'start_webapp') cli_command(__name__, 'webapp restart', custom_path + 'restart_webapp') cli_generic_update_command(__name__, 'webapp update', 'azure.mgmt.web.operations.web_apps_operations#WebAppsOperations.get', 'azure.mgmt.web.operations.web_apps_operations#WebAppsOperations.create_or_update', custom_function_op=custom_path + 'update_webapp', setter_arg_name='site_envelope', factory=cf_webapps) cli_command(__name__, 'webapp traffic-routing set', custom_path + 'set_traffic_routing') cli_command(__name__, 'webapp traffic-routing show', custom_path + 'show_traffic_routing') cli_command(__name__, 'webapp traffic-routing clear', custom_path + 'clear_traffic_routing') cli_command(__name__, 'webapp config set', custom_path + 'update_site_configs') cli_command(__name__, 'webapp config show', custom_path + 'get_site_configs', exception_handler=empty_on_404) cli_command(__name__, 'webapp config appsettings list', custom_path + 'get_app_settings', exception_handler=empty_on_404) cli_command(__name__, 'webapp config appsettings set', custom_path + 'update_app_settings') cli_command(__name__, 'webapp config appsettings delete', custom_path + 'delete_app_settings') cli_command(__name__, 'webapp config connection-string list', custom_path + 'get_connection_strings', exception_handler=empty_on_404) cli_command(__name__, 'webapp config connection-string set', custom_path + 'update_connection_strings') cli_command(__name__, 'webapp config connection-string delete', custom_path + 'delete_connection_strings')
def load_commands_from_factory(server_type, command_group_name, management_client): # server server_sa = create_service_adapter( 'azure.mgmt.rdbms.{}.operations.servers_operations'.format(server_type), 'ServersOperations') def server_factory(args): return management_client(args).servers with ServiceGroup(__name__, server_factory, server_sa, custom_path) as s: with s.group('{} server'.format(command_group_name)) as c: c.command('create', 'create_or_update') c.custom_command('restore', '_server_restore') c.command('delete', 'delete', confirmation=True) c.command('show', 'get') c.custom_command('list', '_server_list_custom_func') c.generic_update_command('update', 'get', 'update', custom_func_name='_server_update_custom_func') # firewall rule firewall_rule_sa = create_service_adapter( 'azure.mgmt.rdbms.{}.operations.firewall_rules_operations'.format(server_type), 'FirewallRulesOperations') def firewall_rule_factory(args): return management_client(args).firewall_rules with ServiceGroup(__name__, firewall_rule_factory, firewall_rule_sa, custom_path) as s: with s.group('{} server firewall-rule'.format(command_group_name)) as c: c.command('create', 'create_or_update') c.command('delete', 'delete', confirmation=True) c.command('show', 'get') c.command('list', 'list_by_server') cli_generic_update_command(__name__, '{} server firewall-rule update'.format(command_group_name), firewall_rule_sa('get'), custom_path.format('_firewall_rule_custom_setter'), firewall_rule_factory, custom_function_op=custom_path.format('_firewall_rule_update_custom_func')) # configuration configuration_sa = create_service_adapter( 'azure.mgmt.rdbms.{}.operations.configurations_operations'.format(server_type), 'ConfigurationsOperations') def configuration_factory(args): return management_client(args).configurations with ServiceGroup(__name__, configuration_factory, configuration_sa) as s: with s.group('{} server configuration'.format(command_group_name)) as c: c.command('set', 'create_or_update') c.command('show', 'get') c.command('list', 'list_by_server') # log_files log_file_sa = create_service_adapter( 'azure.mgmt.rdbms.{}.operations.log_files_operations'.format(server_type), 'LogFilesOperations') def log_file_factory(args): return management_client(args).log_files with ServiceGroup(__name__, log_file_factory, log_file_sa, custom_path) as s: with s.group('{} server-logs'.format(command_group_name)) as c: c.custom_command('list', '_list_log_files_with_filter') c.custom_command('download', '_download_log_files') # database database_sa = create_service_adapter( 'azure.mgmt.rdbms.{}.operations.databases_operations'.format(server_type), 'DatabasesOperations') def database_factory(args): return management_client(args).databases with ServiceGroup(__name__, database_factory, database_sa) as s: with s.group('{} db'.format(command_group_name)) as c: # c.command('create', 'create_or_update') # c.command('delete', 'delete', confirmation=True) # c.command('show', 'get') c.command('list', 'list_by_server')
def test_generic_update_errors(self): #pylint: disable=no-self-use my_obj = TestObject() def my_get(a1, a2): #pylint: disable=unused-argument return my_obj def my_set(**kwargs): #pylint:disable=unused-argument return my_obj config = Configuration([]) app = Application(config) setattr(sys.modules[__name__], my_get.__name__, my_get) setattr(sys.modules[__name__], my_set.__name__, my_set) cli_generic_update_command(None, 'gencommand', '{}#{}'.format(__name__, my_get.__name__), '{}#{}'.format(__name__, my_set.__name__)) def _execute_with_error(command, error, message): try: app.execute(command.split()) except CLIError as err: if not error in str(err): raise AssertionError('{}\nExpected: {}\nActual: {}'.format(message, error, str(err))) else: raise AssertionError('exception not thrown') missing_remove_message = "Couldn't find 'doesntExist' in ''. Available options: ['myDict', 'myList', 'myListOfCamelDicts', 'myListOfObjects', 'myListOfSnakeDicts', 'myProp']" _execute_with_error('gencommand --a1 1 --a2 2 --remove doesntExist', missing_remove_message, 'remove non-existent property by name') _execute_with_error('gencommand --a1 1 --a2 2 --remove doesntExist 2', missing_remove_message, 'remove non-existent property by index') remove_prop_message = "Couldn't find 'doesntExist' in 'myList.doesntExist'. Available options: index into the collection 'myList.doesntExist' with [<index>] or [<key=value>]" _execute_with_error('gencommand --a1 1 --a2 2 --remove myList.doesntExist.missing 2', remove_prop_message, 'remove non-existent sub-property by index') _execute_with_error('gencommand --a1 1 --a2 2 --remove myList 20', "index 20 doesn't exist on myList", 'remove out-of-range index') set_on_list_message = "Couldn't find 'doesnt_exist' in 'myList'. Available options: index into the collection 'myList' with [<index>] or [<key=value>]" _execute_with_error('gencommand --a1 1 --a2 2 --set myList.doesnt_exist=foo', set_on_list_message, 'set shouldn\'t work on a list') _execute_with_error('gencommand --a1 1 --a2 2 --set myList.doesnt_exist.doesnt_exist2=foo', set_on_list_message, 'set shouldn\'t work on a list') _execute_with_error('gencommand --a1 1 --a2 2 --set myList[5].doesnt_exist=foo', "index 5 doesn't exist on myList", 'index out of range in path') _execute_with_error('gencommand --a1 1 --a2 2 --remove myList[0]', 'invalid syntax: --remove property.list <indexToRemove> OR --remove propertyToRemove', 'remove requires index to be space-separated') app.execute("gencommand --a1 1 --a2 2 --set myDict={'foo':'bar'}".split()) _execute_with_error('gencommand --a1 1 --a2 2 --set myDict.foo.doo=boo', "Couldn't find 'foo' in 'myDict'. 'myDict' does not support further indexing.", 'Cannot dot index from a scalar value') _execute_with_error('gencommand --a1 1 --a2 2 --set myDict.foo[0]=boo', "Couldn't find 'foo' in 'myDict'. 'myDict' does not support further indexing.", 'Cannot list index from a scalar value') _execute_with_error('gencommand --a1 1 --a2 2 --add myDict la=da', "invalid syntax: --add property.listProperty <key=value, string or JSON string>", 'Add only works with lists') # add an entry which makes 'myKey' no longer unique app.execute('gencommand --a1 1 --a2 2 --add myListOfCamelDicts myKey=value_2'.split()) _execute_with_error( 'gencommand --a1 1 --a2 2 --set myListOfCamelDicts[myKey=value_2].myKey=foo', "non-unique key 'myKey' found multiple matches on myListOfCamelDicts. " "Key must be unique.", 'indexing by key must be unique') _execute_with_error( 'gencommand --a1 1 --a2 2 --set myListOfCamelDicts[myKey=foo].myKey=foo', "item with value 'foo' doesn\'t exist for key 'myKey' on myListOfCamelDicts", 'no match found when indexing by key and value')
add_dns_txt_record, add_dns_mx_record, remove_dns_aaaa_record, remove_dns_a_record, remove_dns_cname_record, remove_dns_ns_record, remove_dns_ptr_record, remove_dns_srv_record, remove_dns_txt_record, remove_dns_mx_record, list_traffic_manager_endpoints, export_zone, import_zone) from ._factory import _network_client_factory # pylint: disable=line-too-long # Application gateways 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) 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) factory = lambda _: get_mgmt_service_client(AppGatewayClient).app_gateway cli_command('network application-gateway create', AppGatewayOperations.create_or_update, factory, transform=DeploymentOutputLongRunningOperation('Starting network application-gateway create')) property_map = { 'ssl_certificates': 'ssl-cert', 'frontend_ip_configurations': 'frontend-ip', 'frontend_ports': 'frontend-port', 'backend_address_pools': 'address-pool', 'backend_http_settings_collection': 'http-settings', 'http_listeners': 'http-listener', 'request_routing_rules': 'rule', 'probes': 'probe', 'url_path_maps': 'url-path-map' }
def test_generic_update(self): # pylint: disable=too-many-statements my_obj = TestObject() def my_get(): return my_obj def my_set(**kwargs): # pylint:disable=unused-argument return my_obj config = Configuration([]) app = Application(config) setattr(sys.modules[__name__], my_get.__name__, my_get) setattr(sys.modules[__name__], my_set.__name__, my_set) cli_generic_update_command( None, "update-obj", "{}#{}".format(__name__, my_get.__name__), "{}#{}".format(__name__, my_set.__name__) ) # Test simplest ways of setting properties app.execute("update-obj --set myProp=newValue".split()) self.assertEqual(my_obj.my_prop, "newValue", "set simple property") app.execute("update-obj --set myProp=val3".split()) self.assertEqual(my_obj.my_prop, "val3", "set simple property again") app.execute("update-obj --set myList[0]=newValA".split()) self.assertEqual(my_obj.my_list[0], "newValA", "set simple list element") app.execute("update-obj --set myList[-4]=newValB".split()) self.assertEqual(my_obj.my_list[0], "newValB", "set simple list element") app.execute("update-obj --set myDict.myCamelKey=success".split()) self.assertEqual(my_obj.my_dict["myCamelKey"], "success", "set simple dict element with camel case key") app.execute("update-obj --set myDict.my_snake_key=success".split()) self.assertEqual(my_obj.my_dict["my_snake_key"], "success", "set simple dict element with snake case key") # Test the different ways of indexing into a list of objects or dictionaries by filter app.execute("update-obj --set myListOfCamelDicts[myKey=value_2].myKey=new_value".split()) self.assertEqual( my_obj.my_list_of_camel_dicts[1]["myKey"], "new_value", "index into list of dictionaries by camel-case key" ) app.execute("update-obj --set myListOfSnakeDicts[my_key=value2].my_key=new_value".split()) self.assertEqual( my_obj.my_list_of_snake_dicts[1]["my_key"], "new_value", "index into list of dictionaries by snake-case key" ) app.execute("update-obj --set myListOfObjects[myString=1.2.3.4].myString=new_value".split()) self.assertEqual(my_obj.my_list_of_objects[1].my_string, "new_value", "index into list of objects by key") # Test setting on elements nested within lists app.execute("update-obj --set myList[1][1]=newValue".split()) self.assertEqual(my_obj.my_list[1][1], "newValue", "set nested list element") app.execute("update-obj --set myList[2].myKey=newValue".split()) self.assertEqual(my_obj.my_list[2]["myKey"], "newValue", "set nested dict element") app.execute("update-obj --set myList[3].myInt=50".split()) self.assertEqual(my_obj.my_list[3].my_int, 50, "set nested object element") # Test overwriting and removing values app.execute("update-obj --set myProp={} myProp.foo=bar".split()) self.assertEqual(my_obj.my_prop["foo"], "bar", "replace scalar with dict") app.execute("update-obj --set myProp=[] --add myProp key1=value1 --set myProp[0].key2=value2".split()) self.assertEqual(my_obj.my_prop[0]["key1"], "value1", "replace scalar with new list and add a dict entry") self.assertEqual(my_obj.my_prop[0]["key2"], "value2", "add a second value to the new dict entry") app.execute("update-obj --remove myProp --add myProp str1 str2 --remove myProp 0".split()) self.assertEqual(len(my_obj.my_prop), 1, "nullify property, add two and remove one") self.assertEqual(my_obj.my_prop[0], "str2", "nullify property, add two and remove one") # Test various --add to lists app.execute("update-obj --set myList=[]".split()) app.execute(shlex.split('update-obj --add myList key1=value1 key2=value2 foo "string in quotes" [] {} foo=bar')) self.assertEqual(my_obj.my_list[0]["key1"], "value1", "add a value to a dictionary") self.assertEqual(my_obj.my_list[0]["key2"], "value2", "add a second value to the dictionary") self.assertEqual(my_obj.my_list[1], "foo", "add scalar value to list") self.assertEqual(my_obj.my_list[2], "string in quotes", "add scalar value with quotes to list") self.assertEqual(my_obj.my_list[3], [], "add list to a list") self.assertEqual(my_obj.my_list[4], {}, "add dict to a list") self.assertEqual(my_obj.my_list[-1]["foo"], "bar", "add second dict and verify when dict is at the end") # Test --remove self.assertEqual(len(my_obj.my_list), 6, "pre-verify length of list") app.execute("update-obj --remove myList -2".split()) self.assertEqual(len(my_obj.my_list), 5, "verify one item removed") self.assertEqual(my_obj.my_list[4]["foo"], "bar", "verify correct item removed") self.assertEqual("key1" in my_obj.my_list[0], True, "verify dict item exists") app.execute("update-obj --remove myList[0].key1".split()) self.assertEqual("key1" not in my_obj.my_list[0], True, "verify dict entry can be removed")
cli_command(__name__, 'appservice web deployment slot delete', 'azure.cli.command_modules.appservice.custom#delete_slot') cli_command(__name__, 'appservice web deployment slot auto-swap', 'azure.cli.command_modules.appservice.custom#config_slot_auto_swap') cli_command(__name__, 'appservice web deployment slot swap', 'azure.cli.command_modules.appservice.custom#swap_slot') cli_command(__name__, 'appservice web deployment slot create', 'azure.cli.command_modules.appservice.custom#create_webapp_slot') cli_command(__name__, 'appservice web deployment user set', 'azure.cli.command_modules.appservice.custom#set_deployment_user') cli_command(__name__, 'appservice web deployment list-site-credentials', 'azure.mgmt.web.operations.web_apps_operations#WebAppsOperations.list_publishing_credentials', factory) factory = lambda _: web_client_factory() cli_command(__name__, 'appservice web deployment user show', 'azure.mgmt.web.web_site_management_client#WebSiteManagementClient.get_publishing_user', factory, exception_handler=empty_on_404) factory = lambda _: web_client_factory().app_service_plans cli_command(__name__, 'appservice plan create', 'azure.cli.command_modules.appservice.custom#create_app_service_plan') cli_command(__name__, 'appservice plan delete', 'azure.mgmt.web.operations.app_service_plans_operations#AppServicePlansOperations.delete', factory, confirmation=True) cli_generic_update_command(__name__, 'appservice plan update', 'azure.mgmt.web.operations.app_service_plans_operations#AppServicePlansOperations.get', 'azure.mgmt.web.operations.app_service_plans_operations#AppServicePlansOperations.create_or_update', custom_function_op='azure.cli.command_modules.appservice.custom#update_app_service_plan', setter_arg_name='app_service_plan', factory=factory) cli_command(__name__, 'appservice plan list', 'azure.cli.command_modules.appservice.custom#list_app_service_plans') cli_command(__name__, 'appservice plan show', 'azure.mgmt.web.operations.app_service_plans_operations#AppServicePlansOperations.get', factory, exception_handler=empty_on_404) factory = lambda _: web_client_factory() cli_command(__name__, 'appservice list-locations', 'azure.mgmt.web.web_site_management_client#WebSiteManagementClient.list_geo_regions', factory) #Not for ignite release #cli_command(__name__, 'webapp plan update-vnet-route', # ServerFarmsOperations.update_vnet_route, factory) #cli_command(__name__, 'webapp plan update-vnet-gateway', # ServerFarmsOperations.update_server_farm_vnet_gateway,factory) #cli_command(__name__, 'webapp plan update-vnet-route',
__name__, 'resource group deployment export', 'azure.cli.command_modules.resource.custom#export_deployment_as_template') # Resource group deployment operations commands cli_command( __name__, 'resource group deployment operation list', 'azure.mgmt.resource.resources.operations.deployment_operations_operations#DeploymentOperationsOperations.list', cf_deployment_operations) cli_command( __name__, 'resource group deployment operation show', 'azure.mgmt.resource.resources.operations.deployment_operations_operations#DeploymentOperationsOperations.get', cf_deployment_operations) cli_generic_update_command( __name__, 'resource update', 'azure.mgmt.resource.resources.operations.resources_operations#ResourcesOperations.get', 'azure.mgmt.resource.resources.operations.resources_operations#ResourcesOperations.create_or_update', lambda: _resource_client_factory().resources) cli_generic_update_command( __name__, 'resource group update', 'azure.mgmt.resource.resources.operations.resource_groups_operations#ResourceGroupsOperations.get', 'azure.mgmt.resource.resources.operations.resource_groups_operations#ResourceGroupsOperations.create_or_update', lambda: _resource_client_factory().resource_groups) cli_command( __name__, 'resource policy assignment create', 'azure.cli.command_modules.resource.custom#create_policy_assignment') cli_command( __name__, 'resource policy assignment delete', 'azure.cli.command_modules.resource.custom#delete_policy_assignment')
cli_command(__name__, 'storage account show-connection-string', custom_path + 'show_storage_account_connection_string') cli_command(__name__, 'storage account keys renew', mgmt_path + 'regenerate_key', factory, transform=lambda x: x.keys) cli_command(__name__, 'storage account keys list', mgmt_path + 'list_keys', factory, transform=lambda x: x.keys) cli_generic_update_command(__name__, 'storage account update', mgmt_path + 'get_properties', mgmt_path + 'create', factory, custom_function_op=custom_path + 'update_storage_account') cli_storage_data_plane_command( 'storage account generate-sas', 'azure.storage.cloudstorageaccount#CloudStorageAccount.generate_shared_access_signature', cloud_storage_account_service_factory) # container commands factory = blob_data_service_factory cli_storage_data_plane_command('storage container list', block_blob_path + 'list_containers', factory, transform=transform_storage_list_output, table_transformer=transform_container_list)
keyvault_client_vaults_factory, exception_handler=empty_on_404) cli_command(__name__, 'keyvault delete', mgmt_path.format('VaultsOperations.delete'), keyvault_client_vaults_factory) cli_command(__name__, 'keyvault set-policy', custom_path.format('set_policy'), keyvault_client_vaults_factory) cli_command(__name__, 'keyvault delete-policy', custom_path.format('delete_policy'), keyvault_client_vaults_factory) cli_generic_update_command( __name__, 'keyvault update', mgmt_path.format('VaultsOperations.get'), custom_path.format('update_keyvault_setter'), lambda: keyvault_client_factory().vaults, custom_function_op=custom_path.format('update_keyvault')) # Data Plane Commands cli_keyvault_data_plane_command( 'keyvault key list', data_client_path.format('KeyVaultClient.get_keys')) cli_keyvault_data_plane_command( 'keyvault key list-versions', data_client_path.format('KeyVaultClient.get_key_versions')) cli_keyvault_data_plane_command('keyvault key create', custom_path.format('create_key')) cli_keyvault_data_plane_command( 'keyvault key set-attributes',
) from azure.cli.core.commands import cli_command from azure.cli.core.commands.client_factory import get_mgmt_service_client from azure.cli.core.commands.arm import cli_generic_update_command def _keyvault_client_factory(**_): return get_mgmt_service_client(KeyVaultManagementClient) factory = lambda args: _keyvault_client_factory(**args).vaults 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) 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 return client.create_or_update(resource_group_name=resource_group_name, vault_name=vault_name, parameters=VaultCreateOrUpdateParameters( location=parameters.location, properties=parameters.properties)) cli_generic_update_command('keyvault update', VaultsOperations.get, keyvault_update_setter, lambda: _keyvault_client_factory().vaults)
'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.get', cf_application_gateways) cli_command( __name__, 'network application-gateway list', 'azure.cli.command_modules.network.custom#list_application_gateways') cli_command( __name__, 'network application-gateway start', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.start', cf_application_gateways) cli_command( __name__, 'network application-gateway stop', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.stop', cf_application_gateways) cli_generic_update_command( __name__, 'network application-gateway update', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.get', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.create_or_update', cf_application_gateways) cli_command( __name__, 'network application-gateway create', 'azure.cli.command_modules.network.mgmt_app_gateway.lib.operations.app_gateway_operations#AppGatewayOperations.create_or_update', cf_application_gateway_create, transform=DeploymentOutputLongRunningOperation( 'Starting network application-gateway create')) property_map = { 'ssl_certificates': 'ssl-cert', 'frontend_ip_configurations': 'frontend-ip', 'frontend_ports': 'frontend-port',
cli_command(*args, exception_handler=monitor_exception_handler, **kwargs) # MANAGEMENT COMMANDS custom_path = 'azure.cli.command_modules.monitor.custom#' # region Alerts ar_path = 'azure.mgmt.monitor.operations.alert_rules_operations#AlertRulesOperations.' monitor_command(__name__, 'monitor alert create', custom_path + 'create_metric_rule', cf_alert_rules) monitor_command(__name__, 'monitor alert delete', ar_path + 'delete', cf_alert_rules) monitor_command(__name__, 'monitor alert show', ar_path + 'get', cf_alert_rules) monitor_command(__name__, 'monitor alert list', ar_path + 'list_by_resource_group', cf_alert_rules) cli_generic_update_command(__name__, 'monitor alert update', ar_path + 'get', ar_path + 'create_or_update', cf_alert_rules, custom_function_op=custom_path + 'update_metric_rule', exception_handler=monitor_exception_handler) ari_path = 'azure.mgmt.monitor.operations.alert_rule_incidents_operations#AlertRuleIncidentsOperations.' monitor_command(__name__, 'monitor alert show-incident', ari_path + 'get', cf_alert_rule_incidents) monitor_command(__name__, 'monitor alert list-incidents', ari_path + 'list_by_alert_rule', cf_alert_rule_incidents) # endregion # region Metrics monitor_command(__name__, 'monitor metrics list', custom_path + 'list_metrics', cf_metrics) monitor_command(__name__, 'monitor metrics list-definitions', custom_path + 'list_metric_definitions', cf_metric_def) # endregion
cli_command('appservice web deployment slot create', create_webapp_slot) cli_command('appservice web deployment user set', set_deployment_user) cli_command('appservice web deployment list-site-credentials', SitesOperations.list_site_publishing_credentials, factory) factory = lambda _: web_client_factory().provider cli_command('appservice web deployment user show', ProviderOperations.get_publishing_user, factory) factory = lambda _: web_client_factory().server_farms cli_command('appservice plan create', create_app_service_plan) cli_command('appservice plan delete', ServerFarmsOperations.delete_server_farm, factory) cli_generic_update_command('appservice plan update', ServerFarmsOperations.get_server_farm, ServerFarmsOperations.create_or_update_server_farm, custom_function=update_app_service_plan, setter_arg_name='server_farm_envelope', factory=factory) cli_command('appservice plan list', list_app_service_plans) cli_command('appservice plan show', ServerFarmsOperations.get_server_farm, factory) cli_command('appservice list-locations', GlobalModelOperations.get_subscription_geo_regions, factory) #Not for ignite release #cli_command('webapp plan update-vnet-route', ServerFarmsOperations.update_vnet_route, factory) #cli_command('webapp plan update-vnet-gateway', # ServerFarmsOperations.update_server_farm_vnet_gateway,factory) #cli_command('webapp plan update-vnet-route', ServerFarmsOperations.update_vnet_route, factory)
cli_command(__name__, 'vm list-vm-resize-options', mgmt_path.format(op_var, op_class, 'list_available_sizes'), cf_vm) cli_command(__name__, 'vm stop', mgmt_path.format(op_var, op_class, 'power_off'), cf_vm, no_wait_param='raw') cli_command(__name__, 'vm restart', mgmt_path.format(op_var, op_class, 'restart'), cf_vm, no_wait_param='raw') cli_command(__name__, 'vm start', mgmt_path.format(op_var, op_class, 'start'), cf_vm, no_wait_param='raw') cli_command(__name__, 'vm redeploy', mgmt_path.format(op_var, op_class, 'redeploy'), cf_vm, no_wait_param='raw') cli_command(__name__, 'vm list-ip-addresses', custom_path.format('list_ip_addresses'), table_transformer=transform_ip_addresses) cli_command(__name__, 'vm get-instance-view', custom_path.format('get_instance_view'), table_transformer='{Name:name, ResourceGroup:resourceGroup, Location:location, ProvisioningState:provisioningState, PowerState:instanceView.statuses[1].displayStatus}') cli_command(__name__, 'vm list', custom_path.format('list_vm'), table_transformer=transform_vm_list) cli_command(__name__, 'vm resize', custom_path.format('resize_vm'), no_wait_param='no_wait') cli_command(__name__, 'vm capture', custom_path.format('capture_vm')) cli_command(__name__, 'vm open-port', custom_path.format('vm_open_port')) cli_command(__name__, 'vm format-secret', custom_path.format('get_vm_format_secret')) cli_generic_update_command(__name__, 'vm update', mgmt_path.format(op_var, op_class, 'get'), mgmt_path.format(op_var, op_class, 'create_or_update'), cf_vm, no_wait_param='raw') cli_generic_wait_command(__name__, 'vm wait', 'azure.cli.command_modules.vm.custom#get_instance_view') if supported_api_version(ResourceType.MGMT_COMPUTE, min_api='2017-03-30'): cli_command(__name__, 'vm perform-maintenance', mgmt_path.format(op_var, op_class, 'perform_maintenance'), cf_vm) if supported_api_version(ResourceType.MGMT_COMPUTE, min_api='2016-04-30-preview'): cli_command(__name__, 'vm convert', mgmt_path.format(op_var, op_class, 'convert_to_managed_disks'), cf_vm) # VM encryption cli_command(__name__, 'vm encryption enable', 'azure.cli.command_modules.vm.disk_encryption#encrypt_vm') cli_command(__name__, 'vm encryption disable', 'azure.cli.command_modules.vm.disk_encryption#decrypt_vm') cli_command(__name__, 'vm encryption show', 'azure.cli.command_modules.vm.disk_encryption#show_vm_encryption_status', exception_handler=empty_on_404)
cli_command(__name__, 'appservice web deployment slot delete', 'azure.cli.command_modules.appservice.custom#delete_slot') cli_command(__name__, 'appservice web deployment slot auto-swap', 'azure.cli.command_modules.appservice.custom#config_slot_auto_swap') cli_command(__name__, 'appservice web deployment slot swap', 'azure.cli.command_modules.appservice.custom#swap_slot') cli_command(__name__, 'appservice web deployment slot create', 'azure.cli.command_modules.appservice.custom#create_webapp_slot') cli_command(__name__, 'appservice web deployment user set', 'azure.cli.command_modules.appservice.custom#set_deployment_user') cli_command(__name__, 'appservice web deployment list-site-credentials', 'azure.mgmt.web.operations.sites_operations#SitesOperations.list_site_publishing_credentials', factory) factory = lambda _: web_client_factory().provider cli_command(__name__, 'appservice web deployment user show', 'azure.mgmt.web.operations.provider_operations#ProviderOperations.get_publishing_user', factory) factory = lambda _: web_client_factory().server_farms cli_command(__name__, 'appservice plan create', 'azure.cli.command_modules.appservice.custom#create_app_service_plan') cli_command(__name__, 'appservice plan delete', 'azure.mgmt.web.operations.server_farms_operations#ServerFarmsOperations.delete_server_farm', factory) cli_generic_update_command(__name__, 'appservice plan update', 'azure.mgmt.web.operations.server_farms_operations#ServerFarmsOperations.get_server_farm', 'azure.mgmt.web.operations.server_farms_operations#ServerFarmsOperations.create_or_update_server_farm', custom_function_op='azure.cli.command_modules.appservice.custom#update_app_service_plan', setter_arg_name='server_farm_envelope', factory=factory) cli_command(__name__, 'appservice plan list', 'azure.cli.command_modules.appservice.custom#list_app_service_plans') cli_command(__name__, 'appservice plan show', 'azure.mgmt.web.operations.server_farms_operations#ServerFarmsOperations.get_server_farm', factory) factory = lambda _: web_client_factory().global_model cli_command(__name__, 'appservice list-locations', 'azure.mgmt.web.operations.global_model_operations#GlobalModelOperations.get_subscription_geo_regions', factory) #Not for ignite release #cli_command(__name__, 'webapp plan update-vnet-route', # ServerFarmsOperations.update_vnet_route, factory) #cli_command(__name__, 'webapp plan update-vnet-gateway', # ServerFarmsOperations.update_server_farm_vnet_gateway,factory) #cli_command(__name__, 'webapp plan update-vnet-route',
cli_command(__name__, 'keyvault delete-policy', custom_path.format('delete_policy'), factory) def keyvault_update_setter(client, resource_group_name, vault_name, parameters): from azure.mgmt.keyvault.models import VaultCreateOrUpdateParameters return client.create_or_update(resource_group_name=resource_group_name, vault_name=vault_name, parameters=VaultCreateOrUpdateParameters( location=parameters.location, properties=parameters.properties)) cli_generic_update_command( __name__, 'keyvault update', mgmt_path.format('VaultsOperations.get'), 'azure.cli.command_modules.keyvault.commands#keyvault_update_setter', lambda: keyvault_client_factory().vaults) # Data Plane Commands cli_keyvault_data_plane_command( 'keyvault key list', convenience_path.format('KeyVaultClient.get_keys')) cli_keyvault_data_plane_command( 'keyvault key list-versions', convenience_path.format('KeyVaultClient.get_key_versions')) cli_keyvault_data_plane_command('keyvault key create', custom_path.format('create_key')) cli_keyvault_data_plane_command( 'keyvault key set-attributes', base_client_path.format('KeyVaultClient.update_key')) cli_keyvault_data_plane_command(
mgmt_path = 'azure.mgmt.keyvault.operations.vaults_operations#{}' factory = lambda args: keyvault_client_factory(**args).vaults cli_command(__name__, 'keyvault create', custom_path.format('create_keyvault'), factory) cli_command(__name__, 'keyvault list', custom_path.format('list_keyvault'), factory) cli_command(__name__, 'keyvault show', mgmt_path.format('VaultsOperations.get'), factory, exception_handler=empty_on_404) cli_command(__name__, 'keyvault delete', mgmt_path.format('VaultsOperations.delete'), factory) cli_command(__name__, 'keyvault set-policy', custom_path.format('set_policy'), factory) cli_command(__name__, 'keyvault delete-policy', custom_path.format('delete_policy'), factory) cli_generic_update_command(__name__, 'keyvault update', mgmt_path.format('VaultsOperations.get'), custom_path.format('update_keyvault_setter'), lambda: keyvault_client_factory().vaults, custom_function_op=custom_path.format('update_keyvault')) # Data Plane Commands cli_keyvault_data_plane_command('keyvault key list', convenience_path.format('KeyVaultClient.get_keys')) cli_keyvault_data_plane_command('keyvault key list-versions', convenience_path.format('KeyVaultClient.get_key_versions')) cli_keyvault_data_plane_command('keyvault key create', custom_path.format('create_key')) cli_keyvault_data_plane_command('keyvault key set-attributes', base_client_path.format('KeyVaultClient.update_key')) cli_keyvault_data_plane_command('keyvault key show', base_client_path.format('KeyVaultClient.get_key')) cli_keyvault_data_plane_command('keyvault key delete', convenience_path.format('KeyVaultClient.delete_key')) cli_keyvault_data_plane_command('keyvault key backup', custom_path.format('backup_key')) cli_keyvault_data_plane_command('keyvault key restore', custom_path.format('restore_key')) cli_keyvault_data_plane_command('keyvault key import', custom_path.format('import_key'))
'azure.cli.command_modules.resource.custom#export_deployment_as_template') # Resource group deployment operations commands cli_command( __name__, 'group deployment operation list', 'azure.mgmt.resource.resources.operations.deployment_operations#DeploymentOperations.list', cf_deployment_operations) cli_command( __name__, 'group deployment operation show', 'azure.cli.command_modules.resource.custom#get_deployment_operations', cf_deployment_operations, exception_handler=empty_on_404) cli_generic_update_command( __name__, 'resource update', 'azure.cli.command_modules.resource.custom#show_resource', 'azure.cli.command_modules.resource.custom#update_resource') cli_generic_update_command( __name__, 'group update', 'azure.mgmt.resource.resources.operations.resource_groups_operations#ResourceGroupsOperations.get', 'azure.mgmt.resource.resources.operations.resource_groups_operations#ResourceGroupsOperations.create_or_update', lambda: _resource_client_factory().resource_groups) cli_command( __name__, 'policy assignment create', 'azure.cli.command_modules.resource.custom#create_policy_assignment') cli_command( __name__, 'policy assignment delete', 'azure.cli.command_modules.resource.custom#delete_policy_assignment') cli_command(
from azure.cli.core.util import CLIError try: super(HubDeleteResultTransform, self).__call__(poller) except CLIError as e: if 'not found' not in str(e): raise e return None # iot hub commands cli_command(__name__, 'iot hub create', custom_path.format('iot_hub_create'), factory) cli_command(__name__, 'iot hub list', custom_path.format('iot_hub_list'), factory) cli_command(__name__, 'iot hub show-connection-string', custom_path.format('iot_hub_show_connection_string'), factory) cli_command(__name__, 'iot hub show', custom_path.format('iot_hub_get'), factory) cli_generic_update_command(__name__, 'iot hub update', custom_path.format('iot_hub_get'), custom_path.format('iot_hub_update'), factory) cli_command(__name__, 'iot hub delete', custom_path.format('iot_hub_delete'), factory, transform=HubDeleteResultTransform()) cli_command(__name__, 'iot hub list-skus', custom_path.format('iot_hub_sku_list'), factory) cli_command(__name__, 'iot hub consumer-group create', custom_path.format('iot_hub_consumer_group_create'), factory) cli_command(__name__, 'iot hub consumer-group list', custom_path.format('iot_hub_consumer_group_list'), factory) cli_command(__name__, 'iot hub consumer-group show', custom_path.format('iot_hub_consumer_group_get'), factory) cli_command(__name__, 'iot hub consumer-group delete', custom_path.format('iot_hub_consumer_group_delete'), factory) cli_command(__name__, 'iot hub policy list', custom_path.format('iot_hub_policy_list'), factory) cli_command(__name__, 'iot hub policy show', custom_path.format('iot_hub_policy_get'), factory) cli_command(__name__, 'iot hub policy create', custom_path.format('iot_hub_policy_create'), factory, transform=PolicyUpdateResultTransform()) cli_command(__name__, 'iot hub policy delete', custom_path.format('iot_hub_policy_delete'), factory, transform=PolicyUpdateResultTransform()) cli_command(__name__, 'iot hub job list', custom_path.format('iot_hub_job_list'), factory) cli_command(__name__, 'iot hub job show', custom_path.format('iot_hub_job_get'), factory) cli_command(__name__, 'iot hub job cancel', custom_path.format('iot_hub_job_cancel'), factory) cli_command(__name__, 'iot hub show-quota-metrics', custom_path.format('iot_hub_get_quota_metrics'), factory) cli_command(__name__, 'iot hub show-stats', custom_path.format('iot_hub_get_stats'), factory)
vm_scale_set_name, instance_ids=instance_ids) def vmss_start(resource_group_name, vm_scale_set_name, instance_ids=None): '''start virtual machines in a virtual machine scale set.''' client = _compute_client_factory() if instance_ids and len(instance_ids) == 1: return client.virtual_machine_scale_set_vms.start(resource_group_name, vm_scale_set_name, instance_ids[0]) else: return client.virtual_machine_scale_sets.start(resource_group_name, vm_scale_set_name, instance_ids=instance_ids) def availset_get(resource_group_name, name): return _compute_client_factory().availability_sets.get(resource_group_name, name) def availset_set(**kwargs): return _compute_client_factory().availability_sets.create_or_update(**kwargs) cli_generic_update_command('vm availability-set update', availset_get, availset_set) def vmss_get(resource_group_name, name): return _compute_client_factory().virtual_machine_scale_sets.get(resource_group_name, name) def vmss_set(**kwargs): return _compute_client_factory().virtual_machine_scale_sets.create_or_update(**kwargs) cli_generic_update_command('vmss update', vmss_get, vmss_set)
cli_command(__name__, 'redis force-reboot', redis_operation + 'force_reboot', cf_redis) cli_command(__name__, 'redis import-method', redis_custom + 'cli_redis_import_method', cf_redis) cli_command(__name__, 'redis list', redis_operation + 'list_by_resource_group', cf_redis) cli_command(__name__, 'redis list-all', redis_operation + 'list', cf_redis) cli_command(__name__, 'redis list-keys', redis_operation + 'list_keys', cf_redis) cli_command(__name__, 'redis regenerate-keys', redis_operation + 'regenerate_key', cf_redis) cli_command(__name__, 'redis show', redis_operation + 'get', cf_redis) cli_command(__name__, 'redis update-settings', redis_custom + 'cli_redis_update_settings', cf_redis) cli_generic_update_command( __name__, 'redis update', redis_operation + 'get', redis_operation + 'update', cf_redis, custom_function_op=redis_custom + 'cli_redis_update', exception_handler=wrong_vmsize_argument_exception_handler) cli_command(__name__, 'redis patch-schedule set', redis_patch_operation + 'create_or_update', cf_patch_schedules) cli_command(__name__, 'redis patch-schedule delete', redis_patch_operation + 'delete', cf_patch_schedules) cli_command(__name__, 'redis patch-schedule show', redis_patch_operation + 'get', cf_patch_schedules)
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) 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 return client.create_or_update(resource_group_name=resource_group_name, vault_name=vault_name, parameters=VaultCreateOrUpdateParameters( location=parameters.location, properties=parameters.properties)) cli_generic_update_command('keyvault update', VaultsOperations.get, keyvault_update_setter, lambda: _keyvault_client_factory().vaults) # Data Plane Commands cli_keyvault_data_plane_command('keyvault key list', KeyVaultClient.get_keys) cli_keyvault_data_plane_command('keyvault key list-versions', KeyVaultClient.get_key_versions) cli_keyvault_data_plane_command('keyvault key create', create_key) cli_keyvault_data_plane_command('keyvault key set-attributes', BaseKeyVaultClient.update_key) cli_keyvault_data_plane_command('keyvault key show', BaseKeyVaultClient.get_key) cli_keyvault_data_plane_command('keyvault key delete', KeyVaultClient.delete_key) # TODO: Round 3 #cli_keyvault_data_plane_command('keyvault key import', import_key) #cli_keyvault_data_plane_command('keyvault key backup', KeyVaultClient.backup_key) #cli_keyvault_data_plane_command('keyvault key restore', KeyVaultClient.restore_key) cli_keyvault_data_plane_command('keyvault secret list', KeyVaultClient.get_secrets)
cli_command(__name__, 'vm start', mgmt_path.format(op_var, op_class, 'start'), cf_vm) cli_command(__name__, 'vm redeploy', mgmt_path.format(op_var, op_class, 'redeploy'), cf_vm) cli_command(__name__, 'vm list-ip-addresses', custom_path.format('list_ip_addresses')) cli_command(__name__, 'vm get-instance-view', custom_path.format('get_instance_view')) cli_command(__name__, 'vm list', custom_path.format('list_vm')) cli_command(__name__, 'vm resize', custom_path.format('resize_vm')) cli_command(__name__, 'vm capture', custom_path.format('capture_vm')) cli_command(__name__, 'vm open-port', custom_path.format('vm_open_port')) cli_generic_update_command(__name__, 'vm update', mgmt_path.format(op_var, op_class, 'get'), mgmt_path.format(op_var, op_class, 'create_or_update'), cf_vm, no_wait_param='raw') cli_generic_wait_command( __name__, 'vm wait', 'azure.cli.command_modules.vm.custom#get_instance_view') # VM NIC cli_command(__name__, 'vm nic add', custom_path.format('vm_add_nics')) cli_command(__name__, 'vm nic remove', custom_path.format('vm_remove_nics')) cli_command(__name__, 'vm nic set', custom_path.format('vm_set_nics')) cli_command(__name__, 'vm nic show', custom_path.format('vm_show_nic')) cli_command(__name__, 'vm nic list', custom_path.format('vm_list_nics')) # VMSS NIC
def load_commands_from_factory(server_type, command_group_name, management_client): # server server_sa = create_service_adapter( 'azure.mgmt.rdbms.{}.operations.servers_operations'.format( server_type), 'ServersOperations') def server_factory(args): return management_client(args).servers with ServiceGroup(__name__, server_factory, server_sa, custom_path) as s: with s.group('{} server'.format(command_group_name)) as c: c.command('create', 'create_or_update') c.custom_command('restore', '_server_restore') c.command('delete', 'delete', confirmation=True) c.command('show', 'get') c.custom_command('list', '_server_list_custom_func') c.generic_update_command( 'update', 'get', 'update', custom_func_name='_server_update_custom_func') # firewall rule firewall_rule_sa = create_service_adapter( 'azure.mgmt.rdbms.{}.operations.firewall_rules_operations'.format( server_type), 'FirewallRulesOperations') def firewall_rule_factory(args): return management_client(args).firewall_rules with ServiceGroup(__name__, firewall_rule_factory, firewall_rule_sa, custom_path) as s: with s.group( '{} server firewall-rule'.format(command_group_name)) as c: c.command('create', 'create_or_update') c.command('delete', 'delete', confirmation=True) c.command('show', 'get') c.command('list', 'list_by_server') cli_generic_update_command( __name__, '{} server firewall-rule update'.format(command_group_name), firewall_rule_sa('get'), custom_path.format('_firewall_rule_custom_setter'), firewall_rule_factory, custom_function_op=custom_path.format( '_firewall_rule_update_custom_func')) # configuration configuration_sa = create_service_adapter( 'azure.mgmt.rdbms.{}.operations.configurations_operations'.format( server_type), 'ConfigurationsOperations') def configuration_factory(args): return management_client(args).configurations with ServiceGroup(__name__, configuration_factory, configuration_sa) as s: with s.group( '{} server configuration'.format(command_group_name)) as c: c.command('set', 'create_or_update') c.command('show', 'get') c.command('list', 'list_by_server') # log_files log_file_sa = create_service_adapter( 'azure.mgmt.rdbms.{}.operations.log_files_operations'.format( server_type), 'LogFilesOperations') def log_file_factory(args): return management_client(args).log_files with ServiceGroup(__name__, log_file_factory, log_file_sa, custom_path) as s: with s.group('{} server-logs'.format(command_group_name)) as c: c.custom_command('list', '_list_log_files_with_filter') c.custom_command('download', '_download_log_files') # database database_sa = create_service_adapter( 'azure.mgmt.rdbms.{}.operations.databases_operations'.format( server_type), 'DatabasesOperations') def database_factory(args): return management_client(args).databases with ServiceGroup(__name__, database_factory, database_sa) as s: with s.group('{} db'.format(command_group_name)) as c: # c.command('create', 'create_or_update') # c.command('delete', 'delete', confirmation=True) # c.command('show', 'get') c.command('list', 'list_by_server')
cli_command(__name__, 'keyvault delete', mgmt_path.format('VaultsOperations.delete'), factory) cli_command(__name__, 'keyvault set-policy', custom_path.format('set_policy'), factory) cli_command(__name__, 'keyvault delete-policy', custom_path.format('delete_policy'), factory) def keyvault_update_setter(client, resource_group_name, vault_name, parameters): from azure.mgmt.keyvault.models import VaultCreateOrUpdateParameters return client.create_or_update(resource_group_name=resource_group_name, vault_name=vault_name, parameters=VaultCreateOrUpdateParameters( location=parameters.location, properties=parameters.properties)) cli_generic_update_command(__name__, 'keyvault update', mgmt_path.format('VaultsOperations.get'), 'azure.cli.command_modules.keyvault.commands#keyvault_update_setter', lambda: keyvault_client_factory().vaults) # Data Plane Commands cli_keyvault_data_plane_command('keyvault key list', convenience_path.format('KeyVaultClient.get_keys')) cli_keyvault_data_plane_command('keyvault key list-versions', convenience_path.format('KeyVaultClient.get_key_versions')) cli_keyvault_data_plane_command('keyvault key create', custom_path.format('create_key')) cli_keyvault_data_plane_command('keyvault key set-attributes', base_client_path.format('KeyVaultClient.update_key')) cli_keyvault_data_plane_command('keyvault key show', base_client_path.format('KeyVaultClient.get_key')) cli_keyvault_data_plane_command('keyvault key delete', convenience_path.format('KeyVaultClient.delete_key')) cli_keyvault_data_plane_command('keyvault key backup', custom_path.format('backup_key')) cli_keyvault_data_plane_command('keyvault key restore', custom_path.format('restore_key')) cli_keyvault_data_plane_command('keyvault key import', custom_path.format('import_key'))
def test_generic_update(self): # pylint: disable=too-many-statements my_obj = TestObject() def my_get(): return my_obj def my_set(**kwargs): #pylint:disable=unused-argument return my_obj config = Configuration([]) app = Application(config) setattr(sys.modules[__name__], my_get.__name__, my_get) setattr(sys.modules[__name__], my_set.__name__, my_set) cli_generic_update_command(None, 'update-obj', '{}#{}'.format(__name__, my_get.__name__), '{}#{}'.format(__name__, my_set.__name__)) # Test simplest ways of setting properties app.execute('update-obj --set myProp=newValue'.split()) self.assertEqual(my_obj.my_prop, 'newValue', 'set simple property') app.execute('update-obj --set myProp=val3'.split()) self.assertEqual(my_obj.my_prop, 'val3', 'set simple property again') app.execute('update-obj --set myList[0]=newValA'.split()) self.assertEqual(my_obj.my_list[0], 'newValA', 'set simple list element') app.execute('update-obj --set myList[-4]=newValB'.split()) self.assertEqual(my_obj.my_list[0], 'newValB', 'set simple list element') app.execute('update-obj --set myDict.myCamelKey=success'.split()) self.assertEqual(my_obj.my_dict['myCamelKey'], 'success', 'set simple dict element with camel case key') app.execute('update-obj --set myDict.my_snake_key=success'.split()) self.assertEqual(my_obj.my_dict['my_snake_key'], 'success', 'set simple dict element with snake case key') # Test the different ways of indexing into a list of objects or dictionaries by filter app.execute('update-obj --set myListOfCamelDicts[myKey=value_2].myKey=new_value'.split()) self.assertEqual(my_obj.my_list_of_camel_dicts[1]['myKey'], 'new_value', 'index into list of dictionaries by camel-case key') app.execute('update-obj --set myListOfSnakeDicts[my_key=value2].my_key=new_value'.split()) self.assertEqual(my_obj.my_list_of_snake_dicts[1]['my_key'], 'new_value', 'index into list of dictionaries by snake-case key') app.execute('update-obj --set myListOfObjects[myString=1.2.3.4].myString=new_value'.split()) self.assertEqual(my_obj.my_list_of_objects[1].my_string, 'new_value', 'index into list of objects by key') # Test setting on elements nested within lists app.execute('update-obj --set myList[1][1]=newValue'.split()) self.assertEqual(my_obj.my_list[1][1], 'newValue', 'set nested list element') app.execute('update-obj --set myList[2].myKey=newValue'.split()) self.assertEqual(my_obj.my_list[2]['myKey'], 'newValue', 'set nested dict element') app.execute('update-obj --set myList[3].myInt=50'.split()) self.assertEqual(my_obj.my_list[3].my_int, 50, 'set nested object element') # Test overwriting and removing values app.execute('update-obj --set myProp={} myProp.foo=bar'.split()) self.assertEqual(my_obj.my_prop['foo'], 'bar', 'replace scalar with dict') app.execute('update-obj --set myProp=[] --add myProp key1=value1 --set myProp[0].key2=value2'.split()) self.assertEqual(my_obj.my_prop[0]['key1'], 'value1', 'replace scalar with new list and add a dict entry') self.assertEqual(my_obj.my_prop[0]['key2'], 'value2', 'add a second value to the new dict entry') app.execute('update-obj --remove myProp --add myProp str1 str2 --remove myProp 0'.split()) self.assertEqual(len(my_obj.my_prop), 1, 'nullify property, add two and remove one') self.assertEqual(my_obj.my_prop[0], 'str2', 'nullify property, add two and remove one') # Test various --add to lists app.execute('update-obj --set myList=[]'.split()) app.execute(shlex.split('update-obj --add myList key1=value1 key2=value2 foo "string in quotes" [] {} foo=bar')) self.assertEqual(my_obj.my_list[0]['key1'], 'value1', 'add a value to a dictionary') self.assertEqual(my_obj.my_list[0]['key2'], 'value2', 'add a second value to the dictionary') self.assertEqual(my_obj.my_list[1], 'foo', 'add scalar value to list') self.assertEqual(my_obj.my_list[2], 'string in quotes', 'add scalar value with quotes to list') self.assertEqual(my_obj.my_list[3], [], 'add list to a list') self.assertEqual(my_obj.my_list[4], {}, 'add dict to a list') self.assertEqual(my_obj.my_list[-1]['foo'], 'bar', 'add second dict and verify when dict is at the end') # Test --remove self.assertEqual(len(my_obj.my_list), 6, 'pre-verify length of list') app.execute('update-obj --remove myList -2'.split()) self.assertEqual(len(my_obj.my_list), 5, 'verify one item removed') self.assertEqual(my_obj.my_list[4]['foo'], 'bar', 'verify correct item removed') self.assertEqual('key1' in my_obj.my_list[0], True, 'verify dict item exists') app.execute('update-obj --remove myList[0].key1'.split()) self.assertEqual('key1' not in my_obj.my_list[0], True, 'verify dict entry can be removed')
from azure.cli.core.commands.arm import cli_generic_update_command from .custom import (create_role_assignment, list_role_assignments, delete_role_assignments, list_role_definitions, delete_role_definition, create_role_definition, list_sps, list_users, create_user, list_groups, list_apps, create_application, update_application, delete_application, show_application, create_service_principal, show_service_principal, delete_service_principal, create_service_principal_for_rbac, reset_service_principal_credential, _auth_client_factory, _graph_client_factory) factory = lambda _: _auth_client_factory().role_definitions cli_command('role list', list_role_definitions) cli_command('role delete', delete_role_definition) cli_command('role create', create_role_definition) cli_generic_update_command('role update', RoleDefinitionsOperations.get, RoleDefinitionsOperations.create_or_update, factory) factory = lambda _: _auth_client_factory().role_assignments cli_command('role assignment delete', delete_role_assignments) cli_command('role assignment list', list_role_assignments) cli_command('role assignment create', create_role_assignment) factory = lambda _: _graph_client_factory().applications cli_command('ad app create', create_application, factory) cli_command('ad app delete', delete_application, factory) 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
cli_command(__name__, 'appservice web source-control show', 'azure.cli.command_modules.appservice.custom#show_source_control', exception_handler=empty_on_404) cli_command(__name__, 'appservice web source-control delete', 'azure.cli.command_modules.appservice.custom#delete_source_control') cli_command(__name__, 'appservice web source-control update-token', 'azure.cli.command_modules.appservice.custom#update_git_token', exception_handler=ex_handler_factory()) cli_command(__name__, 'appservice web log tail', 'azure.cli.command_modules.appservice.custom#get_streaming_log') cli_command(__name__, 'appservice web log download', 'azure.cli.command_modules.appservice.custom#download_historical_logs') cli_command(__name__, 'appservice web log config', 'azure.cli.command_modules.appservice.custom#config_diagnostics') cli_command(__name__, 'appservice web browse', 'azure.cli.command_modules.appservice.custom#view_in_browser') cli_command(__name__, 'appservice web deployment slot list', 'azure.cli.command_modules.appservice.custom#list_slots', table_transformer=output_slots_in_table) cli_command(__name__, 'appservice web deployment slot delete', 'azure.cli.command_modules.appservice.custom#delete_slot') cli_command(__name__, 'appservice web deployment slot auto-swap', 'azure.cli.command_modules.appservice.custom#config_slot_auto_swap') cli_command(__name__, 'appservice web deployment slot swap', 'azure.cli.command_modules.appservice.custom#swap_slot', exception_handler=ex_handler_factory()) cli_command(__name__, 'appservice web deployment slot create', 'azure.cli.command_modules.appservice.custom#create_webapp_slot', exception_handler=ex_handler_factory()) cli_command(__name__, 'appservice web deployment user set', 'azure.cli.command_modules.appservice.custom#set_deployment_user') cli_command(__name__, 'appservice web deployment list-publishing-profiles', 'azure.cli.command_modules.appservice.custom#list_publish_profiles') cli_command(__name__, 'appservice plan create', 'azure.cli.command_modules.appservice.custom#create_app_service_plan', exception_handler=ex_handler_factory(creating_plan=True)) cli_command(__name__, 'appservice plan delete', 'azure.mgmt.web.operations.app_service_plans_operations#AppServicePlansOperations.delete', cf_plans, confirmation=True) cli_command(__name__, 'appservice plan list', 'azure.cli.command_modules.appservice.custom#list_app_service_plans') cli_command(__name__, 'appservice plan show', 'azure.mgmt.web.operations.app_service_plans_operations#AppServicePlansOperations.get', cf_plans, exception_handler=empty_on_404) cli_generic_update_command(__name__, 'appservice plan update', 'azure.mgmt.web.operations.app_service_plans_operations#AppServicePlansOperations.get', 'azure.mgmt.web.operations.app_service_plans_operations#AppServicePlansOperations.create_or_update', custom_function_op='azure.cli.command_modules.appservice.custom#update_app_service_plan', setter_arg_name='app_service_plan', factory=cf_plans) cli_command(__name__, 'appservice web deployment user show', 'azure.mgmt.web.web_site_management_client#WebSiteManagementClient.get_publishing_user', cf_web_client, exception_handler=empty_on_404) cli_command(__name__, 'appservice list-locations', 'azure.mgmt.web.web_site_management_client#WebSiteManagementClient.list_geo_regions', cf_web_client, transform=transform_list_location_output)
cli_command(__name__, 'vm generalize', mgmt_path.format(op_var, op_class, 'generalize'), cf_vm) cli_command(__name__, 'vm show', custom_path.format('show_vm'), table_transformer=transform_vm) cli_command(__name__, 'vm list-vm-resize-options', mgmt_path.format(op_var, op_class, 'list_available_sizes'), cf_vm) cli_command(__name__, 'vm stop', mgmt_path.format(op_var, op_class, 'power_off'), cf_vm) cli_command(__name__, 'vm restart', mgmt_path.format(op_var, op_class, 'restart'), cf_vm) cli_command(__name__, 'vm start', mgmt_path.format(op_var, op_class, 'start'), cf_vm) cli_command(__name__, 'vm redeploy', mgmt_path.format(op_var, op_class, 'redeploy'), cf_vm) cli_command(__name__, 'vm list-ip-addresses', custom_path.format('list_ip_addresses'), table_transformer=transform_ip_addresses) cli_command(__name__, 'vm get-instance-view', custom_path.format('get_instance_view')) cli_command(__name__, 'vm list', custom_path.format('list_vm'), table_transformer=transform_vm_list) cli_command(__name__, 'vm resize', custom_path.format('resize_vm')) cli_command(__name__, 'vm capture', custom_path.format('capture_vm')) cli_command(__name__, 'vm open-port', custom_path.format('vm_open_port')) cli_generic_update_command(__name__, 'vm update', mgmt_path.format(op_var, op_class, 'get'), mgmt_path.format(op_var, op_class, 'create_or_update'), cf_vm, no_wait_param='raw') cli_generic_wait_command(__name__, 'vm wait', 'azure.cli.command_modules.vm.custom#get_instance_view') # VM NIC cli_command(__name__, 'vm nic add', custom_path.format('vm_add_nics')) cli_command(__name__, 'vm nic remove', custom_path.format('vm_remove_nics')) cli_command(__name__, 'vm nic set', custom_path.format('vm_set_nics')) cli_command(__name__, 'vm nic show', custom_path.format('vm_show_nic')) cli_command(__name__, 'vm nic list', custom_path.format('vm_list_nics')) # VMSS NIC cli_command(__name__, 'vmss nic list', 'azure.mgmt.network.operations.network_interfaces_operations#NetworkInterfacesOperations.list_virtual_machine_scale_set_network_interfaces', cf_ni) cli_command(__name__, 'vmss nic list-vm-nics', 'azure.mgmt.network.operations.network_interfaces_operations#NetworkInterfacesOperations.list_virtual_machine_scale_set_vm_network_interfaces', cf_ni) cli_command(__name__, 'vmss nic show', 'azure.mgmt.network.operations.network_interfaces_operations#NetworkInterfacesOperations.get_virtual_machine_scale_set_network_interface', cf_ni)
def test_generic_update(self): # pylint: disable=too-many-statements my_obj = TestObject() def my_get(): return my_obj def my_set(**kwargs): #pylint:disable=unused-argument return my_obj config = Configuration([]) app = Application(config) setattr(sys.modules[__name__], my_get.__name__, my_get) setattr(sys.modules[__name__], my_set.__name__, my_set) cli_generic_update_command(None, 'update-obj', '{}#{}'.format(__name__, my_get.__name__), '{}#{}'.format(__name__, my_set.__name__)) # Test simplest ways of setting properties app.execute('update-obj --set myProp=newValue'.split()) self.assertEqual(my_obj.my_prop, 'newValue', 'set simple property') app.execute('update-obj --set myProp=val3'.split()) self.assertEqual(my_obj.my_prop, 'val3', 'set simple property again') app.execute('update-obj --set myList[0]=newValA'.split()) self.assertEqual(my_obj.my_list[0], 'newValA', 'set simple list element') app.execute('update-obj --set myList[-4]=newValB'.split()) self.assertEqual(my_obj.my_list[0], 'newValB', 'set simple list element') app.execute('update-obj --set myDict.myCamelKey=success'.split()) self.assertEqual(my_obj.my_dict['myCamelKey'], 'success', 'set simple dict element with camel case key') app.execute('update-obj --set myDict.my_snake_key=success'.split()) self.assertEqual(my_obj.my_dict['my_snake_key'], 'success', 'set simple dict element with snake case key') # Test the different ways of indexing into a list of objects or dictionaries by filter app.execute( 'update-obj --set myListOfCamelDicts[myKey=value_2].myKey=new_value' .split()) self.assertEqual(my_obj.my_list_of_camel_dicts[1]['myKey'], 'new_value', 'index into list of dictionaries by camel-case key') app.execute( 'update-obj --set myListOfSnakeDicts[my_key=value2].my_key=new_value' .split()) self.assertEqual(my_obj.my_list_of_snake_dicts[1]['my_key'], 'new_value', 'index into list of dictionaries by snake-case key') app.execute( 'update-obj --set myListOfObjects[myString=1.2.3.4].myString=new_value' .split()) self.assertEqual(my_obj.my_list_of_objects[1].my_string, 'new_value', 'index into list of objects by key') # Test setting on elements nested within lists app.execute('update-obj --set myList[1][1]=newValue'.split()) self.assertEqual(my_obj.my_list[1][1], 'newValue', 'set nested list element') app.execute('update-obj --set myList[2].myKey=newValue'.split()) self.assertEqual(my_obj.my_list[2]['myKey'], 'newValue', 'set nested dict element') app.execute('update-obj --set myList[3].myInt=50'.split()) self.assertEqual(my_obj.my_list[3].my_int, 50, 'set nested object element') # Test overwriting and removing values app.execute('update-obj --set myProp={} myProp.foo=bar'.split()) self.assertEqual(my_obj.my_prop['foo'], 'bar', 'replace scalar with dict') app.execute( 'update-obj --set myProp=[] --add myProp key1=value1 --set myProp[0].key2=value2' .split()) self.assertEqual(my_obj.my_prop[0]['key1'], 'value1', 'replace scalar with new list and add a dict entry') self.assertEqual(my_obj.my_prop[0]['key2'], 'value2', 'add a second value to the new dict entry') app.execute( 'update-obj --remove myProp --add myProp str1 str2 --remove myProp 0' .split()) self.assertEqual(len(my_obj.my_prop), 1, 'nullify property, add two and remove one') self.assertEqual(my_obj.my_prop[0], 'str2', 'nullify property, add two and remove one') # Test various --add to lists app.execute('update-obj --set myList=[]'.split()) app.execute( shlex.split( 'update-obj --add myList key1=value1 key2=value2 foo "string in quotes" [] {} foo=bar' )) self.assertEqual(my_obj.my_list[0]['key1'], 'value1', 'add a value to a dictionary') self.assertEqual(my_obj.my_list[0]['key2'], 'value2', 'add a second value to the dictionary') self.assertEqual(my_obj.my_list[1], 'foo', 'add scalar value to list') self.assertEqual(my_obj.my_list[2], 'string in quotes', 'add scalar value with quotes to list') self.assertEqual(my_obj.my_list[3], [], 'add list to a list') self.assertEqual(my_obj.my_list[4], {}, 'add dict to a list') self.assertEqual(my_obj.my_list[-1]['foo'], 'bar', 'add second dict and verify when dict is at the end') # Test --remove self.assertEqual(len(my_obj.my_list), 6, 'pre-verify length of list') app.execute('update-obj --remove myList -2'.split()) self.assertEqual(len(my_obj.my_list), 5, 'verify one item removed') self.assertEqual(my_obj.my_list[4]['foo'], 'bar', 'verify correct item removed') self.assertEqual('key1' in my_obj.my_list[0], True, 'verify dict item exists') app.execute('update-obj --remove myList[0].key1'.split()) self.assertEqual('key1' not in my_obj.my_list[0], True, 'verify dict entry can be removed')
from azure.cli.core.commands.arm import cli_generic_update_command from azure.cli.core.commands import DeploymentOutputLongRunningOperation, cli_command from ._client_factory import * #pylint: disable=wildcard-import from ._util import (list_network_resource_property, get_network_resource_property_entry, delete_network_resource_property_entry) # Application gateways cli_command(__name__, 'network application-gateway delete', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.delete', cf_application_gateways) cli_command(__name__, 'network application-gateway show', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.get', cf_application_gateways) cli_command(__name__, 'network application-gateway list', 'azure.cli.command_modules.network.custom#list_application_gateways') cli_command(__name__, 'network application-gateway start', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.start', cf_application_gateways) cli_command(__name__, 'network application-gateway stop', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.stop', cf_application_gateways) cli_generic_update_command(__name__, 'network application-gateway update', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.get', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.create_or_update', cf_application_gateways) cli_command(__name__, 'network application-gateway create', 'azure.cli.command_modules.network.mgmt_app_gateway.lib.operations.app_gateway_operations#AppGatewayOperations.create_or_update', cf_application_gateway_create, transform=DeploymentOutputLongRunningOperation('Starting network application-gateway create')) property_map = { 'ssl_certificates': 'ssl-cert', 'frontend_ip_configurations': 'frontend-ip', 'frontend_ports': 'frontend-port', 'backend_address_pools': 'address-pool', 'backend_http_settings_collection': 'http-settings', 'http_listeners': 'http-listener', 'request_routing_rules': 'rule',
cli_command(__name__, 'vm list', custom_path.format('list_vm'), table_transformer=transform_vm_list) cli_command(__name__, 'vm resize', custom_path.format('resize_vm'), no_wait_param='no_wait') cli_command(__name__, 'vm capture', custom_path.format('capture_vm')) cli_command(__name__, 'vm open-port', custom_path.format('vm_open_port')) cli_command(__name__, 'vm format-secret', custom_path.format('get_vm_format_secret')) cli_generic_update_command(__name__, 'vm update', mgmt_path.format(op_var, op_class, 'get'), mgmt_path.format(op_var, op_class, 'create_or_update'), cf_vm, no_wait_param='raw') cli_generic_wait_command( __name__, 'vm wait', 'azure.cli.command_modules.vm.custom#get_instance_view') if supported_api_version(ResourceType.MGMT_COMPUTE, min_api='2016-04-30-preview'): cli_command(__name__, 'vm convert', mgmt_path.format(op_var, op_class, 'convert_to_managed_disks'), cf_vm) # VM encryption cli_command(__name__, 'vm encryption enable',
return _graph_client_factory().users def get_graph_client_groups(_): return _graph_client_factory().groups cli_command(__name__, 'role definition list', 'azure.cli.command_modules.role.custom#list_role_definitions', table_transformer=transform_definition_list) cli_command(__name__, 'role definition delete', 'azure.cli.command_modules.role.custom#delete_role_definition') cli_command(__name__, 'role definition create', 'azure.cli.command_modules.role.custom#create_role_definition') cli_generic_update_command(__name__, 'role definition update', get_role_definition_op('get'), get_role_definition_op('create_or_update'), get_role_definitions) cli_command(__name__, 'role assignment delete', 'azure.cli.command_modules.role.custom#delete_role_assignments') cli_command(__name__, 'role assignment list', 'azure.cli.command_modules.role.custom#list_role_assignments', table_transformer=transform_assignment_list) cli_command(__name__, 'role assignment create', 'azure.cli.command_modules.role.custom#create_role_assignment') cli_command(__name__, 'ad app create', 'azure.cli.command_modules.role.custom#create_application', get_graph_client_applications) cli_command(__name__, 'ad app delete', 'azure.cli.command_modules.role.custom#delete_application', get_graph_client_applications) cli_command(__name__, 'ad app list', 'azure.cli.command_modules.role.custom#list_apps',
custom_path = 'azure.cli.command_modules.network.custom#' # Application gateways ag_path = 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.' cli_command(__name__, 'network application-gateway create', custom_path + 'create_application_gateway', transform=DeploymentOutputLongRunningOperation('Starting network application-gateway create'), no_wait_param='no_wait') cli_command(__name__, 'network application-gateway delete', ag_path + 'delete', cf_application_gateways, no_wait_param='raw') cli_command(__name__, 'network application-gateway show', ag_path + 'get', cf_application_gateways, exception_handler=empty_on_404) cli_command(__name__, 'network application-gateway list', custom_path + 'list_application_gateways') cli_command(__name__, 'network application-gateway start', ag_path + 'start', cf_application_gateways) cli_command(__name__, 'network application-gateway stop', ag_path + 'stop', cf_application_gateways) if supported_api_version(ResourceType.MGMT_NETWORK, min_api='2016-09-01'): cli_command(__name__, 'network application-gateway show-backend-health', ag_path + 'backend_health', cf_application_gateways) cli_generic_update_command(__name__, 'network application-gateway update', ag_path + 'get', ag_path + 'create_or_update', cf_application_gateways, no_wait_param='raw', custom_function_op=custom_path + 'update_application_gateway') cli_generic_wait_command(__name__, 'network application-gateway wait', ag_path + 'get', cf_application_gateways) property_map = { 'authentication_certificates': 'auth-cert', 'ssl_certificates': 'ssl-cert', 'frontend_ip_configurations': 'frontend-ip', 'frontend_ports': 'frontend-port', 'backend_address_pools': 'address-pool', 'backend_http_settings_collection': 'http-settings', 'http_listeners': 'http-listener', 'request_routing_rules': 'rule', 'probes': 'probe', 'url_path_maps': 'url-path-map',
from .custom import ( create_role_assignment, list_role_assignments, delete_role_assignments, list_role_definitions, delete_role_definition, create_role_definition, list_sps, list_users, create_user, list_groups, list_apps, create_application, update_application, delete_application, show_application, create_service_principal, show_service_principal, delete_service_principal, create_service_principal_for_rbac, reset_service_principal_credential, _auth_client_factory, _graph_client_factory) factory = lambda _: _auth_client_factory().role_definitions cli_command('role list', list_role_definitions) cli_command('role delete', delete_role_definition) cli_command('role create', create_role_definition) cli_generic_update_command('role update', RoleDefinitionsOperations.get, RoleDefinitionsOperations.create_or_update, factory) factory = lambda _: _auth_client_factory().role_assignments cli_command('role assignment delete', delete_role_assignments) cli_command('role assignment list', list_role_assignments) cli_command('role assignment create', create_role_assignment) factory = lambda _: _graph_client_factory().applications cli_command('ad app create', create_application, factory) cli_command('ad app delete', delete_application, factory) 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 cli_command('ad sp create', create_service_principal)
cf_application_gateways) cli_command( __name__, 'network application-gateway stop', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.stop', cf_application_gateways) if supported_api_version(ResourceType.MGMT_NETWORK, min_api='2016-09-01'): cli_command( __name__, 'network application-gateway show-backend-health', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.backend_health', cf_application_gateways) cli_generic_update_command( __name__, 'network application-gateway update', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.get', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.create_or_update', cf_application_gateways, no_wait_param='raw', custom_function_op=custom_path.format('update_application_gateway')) cli_generic_wait_command( __name__, 'network application-gateway wait', 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.get', cf_application_gateways) property_map = { 'authentication_certificates': 'auth-cert', 'ssl_certificates': 'ssl-cert', 'frontend_ip_configurations': 'frontend-ip', 'frontend_ports': 'frontend-port', 'backend_address_pools': 'address-pool', 'backend_http_settings_collection': 'http-settings',
custom_path = 'azure.cli.command_modules.network.custom#' # Application gateways ag_path = 'azure.mgmt.network.operations.application_gateways_operations#ApplicationGatewaysOperations.' cli_command(__name__, 'network application-gateway create', custom_path + 'create_application_gateway', transform=DeploymentOutputLongRunningOperation('Starting network application-gateway create'), no_wait_param='no_wait', exception_handler=handle_long_running_operation_exception, table_transformer=deployment_validate_table_format) cli_command(__name__, 'network application-gateway delete', ag_path + 'delete', cf_application_gateways, no_wait_param='raw') cli_command(__name__, 'network application-gateway show', ag_path + 'get', cf_application_gateways, exception_handler=empty_on_404) cli_command(__name__, 'network application-gateway list', custom_path + 'list_application_gateways') cli_command(__name__, 'network application-gateway start', ag_path + 'start', cf_application_gateways) cli_command(__name__, 'network application-gateway stop', ag_path + 'stop', cf_application_gateways) if supported_api_version(ResourceType.MGMT_NETWORK, min_api='2016-09-01'): cli_command(__name__, 'network application-gateway show-backend-health', ag_path + 'backend_health', cf_application_gateways) cli_generic_update_command(__name__, 'network application-gateway update', ag_path + 'get', ag_path + 'create_or_update', cf_application_gateways, no_wait_param='raw', custom_function_op=custom_path + 'update_application_gateway') cli_generic_wait_command(__name__, 'network application-gateway wait', ag_path + 'get', cf_application_gateways) property_map = { 'authentication_certificates': 'auth-cert', 'ssl_certificates': 'ssl-cert', 'frontend_ip_configurations': 'frontend-ip', 'frontend_ports': 'frontend-port', 'backend_address_pools': 'address-pool', 'backend_http_settings_collection': 'http-settings', 'http_listeners': 'http-listener', 'request_routing_rules': 'rule', 'probes': 'probe', 'url_path_maps': 'url-path-map',
('Scope', r['properties']['scope'])]) for r in result ] factory = lambda _: _auth_client_factory().role_definitions cli_command(__name__, 'role definition list', 'azure.cli.command_modules.role.custom#list_role_definitions', table_transformer=transform_definition_list) cli_command(__name__, 'role definition delete', 'azure.cli.command_modules.role.custom#delete_role_definition') cli_command(__name__, 'role definition create', 'azure.cli.command_modules.role.custom#create_role_definition') cli_generic_update_command( __name__, 'role definition update', 'azure.mgmt.authorization.operations.role_definitions_operations#RoleDefinitionsOperations.get', 'azure.mgmt.authorization.operations.role_definitions_operations#RoleDefinitionsOperations.create_or_update', factory) factory = lambda _: _auth_client_factory().role_assignments cli_command(__name__, 'role assignment delete', 'azure.cli.command_modules.role.custom#delete_role_assignments') cli_command(__name__, 'role assignment list', 'azure.cli.command_modules.role.custom#list_role_assignments', table_transformer=transform_assignment_list) cli_command(__name__, 'role assignment create', 'azure.cli.command_modules.role.custom#create_role_assignment') factory = lambda _: _graph_client_factory().applications cli_command(__name__, 'ad app create',
# Resource group deployment commands factory = lambda _: _resource_client_factory().deployments cli_command('resource group deployment create', deploy_arm_template) cli_command('resource group deployment list', DeploymentsOperations.list, factory) cli_command('resource group deployment show', DeploymentsOperations.get, factory) cli_command('resource group deployment validate', validate_arm_template) cli_command('resource group deployment exists', DeploymentsOperations.check_existence, factory) cli_command('resource group deployment export', export_deployment_as_template) # Resource group deployment operations commands factory = lambda _: _resource_client_factory().deployment_operations cli_command('resource group deployment operation list', DeploymentOperationsOperations.list, factory) cli_command('resource group deployment operation show', DeploymentOperationsOperations.get, factory) cli_generic_update_command('resource update', ResourcesOperations.get, ResourcesOperations.create_or_update, lambda: _resource_client_factory().resources) cli_generic_update_command('resource group update', ResourceGroupsOperations.get, ResourceGroupsOperations.create_or_update, lambda: _resource_client_factory().resource_groups) 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) cli_command('resource policy assignment show', show_policy_assignment) factory = lambda _: _resource_policy_client_factory().policy_definitions cli_command('resource policy create', create_policy_definition) cli_command('resource policy delete', PolicyDefinitionsOperations.delete, factory) cli_command('resource policy list', PolicyDefinitionsOperations.list, factory)