示例#1
0
    def test_register_command(self):
        command_table.clear()
        cli_command(None, 'test command sample-vm-get',
                    '{}#Test_command_registration.sample_vm_get'.format(__name__), None)

        self.assertEqual(len(command_table), 1,
                         'We expect exactly one command in the command table')
        command_table['test command sample-vm-get'].load_arguments()
        command_metadata = command_table['test command sample-vm-get']
        self.assertEqual(len(command_metadata.arguments), 4, 'We expected exactly 4 arguments')
        some_expected_arguments = {
            'resource_group_name': CliArgumentType(dest='resource_group_name',
                                                   required=True,
                                                   help='The name of the resource group.'),
            'vm_name': CliArgumentType(dest='vm_name',
                                       required=True,
                                       help='The name of the virtual machine.'),
            'opt_param': CliArgumentType(required=False,
                                         help='Used to verify reflection correctly identifies optional params.'),  # pylint: disable=line-too-long
            'expand': CliArgumentType(required=False,
                                      help='The expand expression to apply on the operation.')
        }

        for probe in some_expected_arguments:
            existing = next(arg for arg in command_metadata.arguments if arg == probe)
            self.assertDictContainsSubset(some_expected_arguments[existing].settings,
                                          command_metadata.arguments[existing].options)
        self.assertEqual(command_metadata.arguments['resource_group_name'].options_list,
                         ['--resource-group-name'])
示例#2
0
    def test_register_cli_argument(self):
        command_table.clear()
        cli_command(
            None, 'test register sample-vm-get',
            '{}#Test_command_registration.sample_vm_get'.format(__name__))
        register_cli_argument(
            'test register sample-vm-get', 'vm_name',
            CliArgumentType(options_list=('--wonky-name', '-n'),
                            metavar='VMNAME',
                            help='Completely WONKY name...',
                            required=False))

        command_table['test register sample-vm-get'].load_arguments()
        _update_command_definitions(command_table)

        self.assertEqual(len(command_table), 1,
                         'We expect exactly one command in the command table')
        command_metadata = command_table['test register sample-vm-get']
        self.assertEqual(len(command_metadata.arguments), 4,
                         'We expected exactly 4 arguments')
        some_expected_arguments = {
            'resource_group_name':
            CliArgumentType(dest='resource_group_name', required=True),
            'vm_name':
            CliArgumentType(dest='vm_name', required=False),
        }

        for probe in some_expected_arguments:
            existing = next(arg for arg in command_metadata.arguments
                            if arg == probe)
            self.assertDictContainsSubset(
                some_expected_arguments[existing].settings,
                command_metadata.arguments[existing].options)
        self.assertEqual(command_metadata.arguments['vm_name'].options_list,
                         ('--wonky-name', '-n'))
    def test_register_command(self):
        command_table.clear()
        cli_command(None, 'test command sample-vm-get',
                    '{}#Test_command_registration.sample_vm_get'.format(__name__), None)

        self.assertEqual(len(command_table), 1,
                         'We expect exactly one command in the command table')
        command_table['test command sample-vm-get'].load_arguments()
        command_metadata = command_table['test command sample-vm-get']
        self.assertEqual(len(command_metadata.arguments), 4, 'We expected exactly 4 arguments')
        some_expected_arguments = {
            'resource_group_name': CliArgumentType(dest='resource_group_name',
                                                   required=True,
                                                   help='The name of the resource group.'),
            'vm_name': CliArgumentType(dest='vm_name',
                                       required=True,
                                       help='The name of the virtual machine.'),
            'opt_param': CliArgumentType(required=False,
                                         help='Used to verify reflection correctly identifies optional params.'), # pylint: disable=line-too-long
            'expand': CliArgumentType(required=False,
                                      help='The expand expression to apply on the operation.')
        }

        for probe in some_expected_arguments:
            existing = next(arg for arg in command_metadata.arguments if arg == probe)
            self.assertDictContainsSubset(some_expected_arguments[existing].settings,
                                          command_metadata.arguments[existing].options)
        self.assertEqual(command_metadata.arguments['resource_group_name'].options_list,
                         ['--resource-group-name'])
    def test_override_using_register_cli_argument(self):
        def sample_sdk_method(param_a): # pylint: disable=unused-argument
            pass

        def test_validator_completer():
            pass

        command_table.clear()
        setattr(sys.modules[__name__], sample_sdk_method.__name__, sample_sdk_method)
        cli_command(None, 'override_using_register_cli_argument foo',
                    '{}#{}'.format(__name__, sample_sdk_method.__name__),
                    None)
        register_cli_argument('override_using_register_cli_argument',
                              'param_a',
                              options_list=('--overridden', '-r'),
                              validator=test_validator_completer,
                              completer=test_validator_completer,
                              required=False)

        command_table['override_using_register_cli_argument foo'].load_arguments()
        _update_command_definitions(command_table)

        command_metadata = command_table['override_using_register_cli_argument foo']
        self.assertEqual(len(command_metadata.arguments), 1, 'We expected exactly 1 arguments')

        actual_arg = command_metadata.arguments['param_a']
        self.assertEqual(actual_arg.options_list, ('--overridden', '-r'))
        self.assertEqual(actual_arg.validator, test_validator_completer)
        self.assertEqual(actual_arg.completer, test_validator_completer)
        self.assertFalse(actual_arg.options['required'])
        command_table.clear()
    def test_register_extra_cli_argument(self):
        command_table.clear()

        cli_command(None, 'test command sample-vm-get',
                    '{}#Test_command_registration.sample_vm_get'.format(__name__), None)
        register_extra_cli_argument(
            'test command sample-vm-get', 'added_param', options_list=('--added-param',),
            metavar='ADDED', help='Just added this right now!', required=True
        )

        command_table['test command sample-vm-get'].load_arguments()
        _update_command_definitions(command_table)

        self.assertEqual(len(command_table), 1,
                         'We expect exactly one command in the command table')
        command_metadata = command_table['test command sample-vm-get']
        self.assertEqual(len(command_metadata.arguments), 5, 'We expected exactly 5 arguments')

        some_expected_arguments = {
            'added_param': CliArgumentType(dest='added_param', required=True)
        }

        for probe in some_expected_arguments:
            existing = next(arg for arg in command_metadata.arguments if arg == probe)
            self.assertDictContainsSubset(some_expected_arguments[existing].settings,
                                          command_metadata.arguments[existing].options)

        command_table.clear()
    def test_command_build_argument_help_text(self):
        def sample_sdk_method_with_weird_docstring(param_a, param_b, param_c): # pylint: disable=unused-argument
            """
            An operation with nothing good.

            :param dict param_a:
            :param param_b: The name
            of
            nothing.
            :param param_c: The name
            of

            nothing2.
            """
        command_table.clear()
        setattr(sys.modules[__name__], sample_sdk_method_with_weird_docstring.__name__, sample_sdk_method_with_weird_docstring) #pylint: disable=line-too-long
        cli_command(None, 'test command foo', '{}#{}'.format(__name__, sample_sdk_method_with_weird_docstring.__name__), None) #pylint: disable=line-too-long

        command_table['test command foo'].load_arguments()
        _update_command_definitions(command_table)

        command_metadata = command_table['test command foo']
        self.assertEqual(len(command_metadata.arguments), 3, 'We expected exactly 3 arguments')
        some_expected_arguments = {
            'param_a': CliArgumentType(dest='param_a', required=True, help=''),
            'param_b': CliArgumentType(dest='param_b', required=True, help='The name of nothing.'),
            'param_c': CliArgumentType(dest='param_c', required=True, help='The name of nothing2.')
        }

        for probe in some_expected_arguments:
            existing = next(arg for arg in command_metadata.arguments if arg == probe)
            self.assertDictContainsSubset(some_expected_arguments[existing].settings,
                                          command_metadata.arguments[existing].options)
        command_table.clear()
示例#7
0
文件: util.py 项目: xscript/azure-cli
 def command(self,
             name,
             method_name,
             transform=None,
             table_transformer=None,
             confirmation=None,
             exception_handler=None):
     """
     Register a CLI command
     :param name: Name of the command as it will be called on the command line
     :type name: str
     :param method_name: Name of the method the command maps to on the service adapter
     :type method_name: str
     :param transform: Transform function for transforming the output of the command
     :type transform: function
     :param table_transformer: Transform function to be applied to table output to create a
     better output format for tables.
     :type table_transformer: function
     :param confirmation: Prompt prior to the action being executed. This is useful if the action
     would cause a loss of data.
     :type confirmation: bool
     :param exception_handler: Exception handler for handling non-standard exceptions
     :type exception_handler: function
     :return: None
     :rtype: None
     """
     cli_command(self._scope,
                 '{} {}'.format(self._group_name, name),
                 self._service_adapter(method_name),
                 client_factory=self._client_factory,
                 transform=transform,
                 table_transformer=table_transformer,
                 confirmation=confirmation,
                 exception_handler=exception_handler
                 or self._exception_handler)
示例#8
0
    def test_register_extra_cli_argument(self):
        command_table.clear()

        cli_command(
            None, 'test command sample-vm-get',
            '{}#Test_command_registration.sample_vm_get'.format(__name__),
            None)
        register_extra_cli_argument('test command sample-vm-get',
                                    'added_param',
                                    options_list=('--added-param', ),
                                    metavar='ADDED',
                                    help='Just added this right now!',
                                    required=True)

        command_table['test command sample-vm-get'].load_arguments()
        _update_command_definitions(command_table)

        self.assertEqual(len(command_table), 1,
                         'We expect exactly one command in the command table')
        command_metadata = command_table['test command sample-vm-get']
        self.assertEqual(len(command_metadata.arguments), 5,
                         'We expected exactly 5 arguments')

        some_expected_arguments = {
            'added_param': CliArgumentType(dest='added_param', required=True)
        }

        for probe in some_expected_arguments:
            existing = next(arg for arg in command_metadata.arguments
                            if arg == probe)
            self.assertDictContainsSubset(
                some_expected_arguments[existing].settings,
                command_metadata.arguments[existing].options)

        command_table.clear()
    def test_command_build_argument_help_text(self):
        def sample_sdk_method_with_weird_docstring(param_a, param_b, param_c): # pylint: disable=unused-argument
            """
            An operation with nothing good.

            :param dict param_a:
            :param param_b: The name
            of
            nothing.
            :param param_c: The name
            of

            nothing2.
            """
        command_table.clear()
        setattr(sys.modules[__name__], sample_sdk_method_with_weird_docstring.__name__, sample_sdk_method_with_weird_docstring) #pylint: disable=line-too-long
        cli_command(None, 'test command foo', '{}#{}'.format(__name__, sample_sdk_method_with_weird_docstring.__name__), None) #pylint: disable=line-too-long

        command_table['test command foo'].load_arguments()
        _update_command_definitions(command_table)

        command_metadata = command_table['test command foo']
        self.assertEqual(len(command_metadata.arguments), 3, 'We expected exactly 3 arguments')
        some_expected_arguments = {
            'param_a': CliArgumentType(dest='param_a', required=True, help=''),
            'param_b': CliArgumentType(dest='param_b', required=True, help='The name of nothing.'),
            'param_c': CliArgumentType(dest='param_c', required=True, help='The name of nothing2.')
        }

        for probe in some_expected_arguments:
            existing = next(arg for arg in command_metadata.arguments if arg == probe)
            self.assertDictContainsSubset(some_expected_arguments[existing].settings,
                                          command_metadata.arguments[existing].options)
        command_table.clear()
示例#10
0
    def test_override_using_register_cli_argument(self):
        def sample_sdk_method(param_a):  # pylint: disable=unused-argument
            pass

        def test_validator_completer():
            pass

        command_table.clear()
        setattr(sys.modules[__name__], sample_sdk_method.__name__,
                sample_sdk_method)
        cli_command(None, 'override_using_register_cli_argument foo',
                    '{}#{}'.format(__name__, sample_sdk_method.__name__), None)
        register_cli_argument('override_using_register_cli_argument',
                              'param_a',
                              options_list=('--overridden', '-r'),
                              validator=test_validator_completer,
                              completer=test_validator_completer,
                              required=False)

        command_table[
            'override_using_register_cli_argument foo'].load_arguments()
        _update_command_definitions(command_table)

        command_metadata = command_table[
            'override_using_register_cli_argument foo']
        self.assertEqual(len(command_metadata.arguments), 1,
                         'We expected exactly 1 arguments')

        actual_arg = command_metadata.arguments['param_a']
        self.assertEqual(actual_arg.options_list, ('--overridden', '-r'))
        self.assertEqual(actual_arg.validator, test_validator_completer)
        self.assertEqual(actual_arg.completer, test_validator_completer)
        self.assertFalse(actual_arg.options['required'])
        command_table.clear()
示例#11
0
 def command(self, name, method_name, transform=None, table_transformer=None, confirmation=None,
             exception_handler=None):
     """
     Register a CLI command
     :param name: Name of the command as it will be called on the command line
     :type name: str
     :param method_name: Name of the method the command maps to on the service adapter
     :type method_name: str
     :param transform: Transform function for transforming the output of the command
     :type transform: function
     :param table_transformer: Transform function to be applied to table output to create a
     better output format for tables.
     :type table_transformer: function
     :param confirmation: Prompt prior to the action being executed. This is useful if the action
     would cause a loss of data.
     :type confirmation: bool
     :param exception_handler: Exception handler for handling non-standard exceptions
     :type exception_handler: function
     :return: None
     :rtype: None
     """
     cli_command(self._scope,
                 '{} {}'.format(self._group_name, name),
                 self._service_adapter(method_name),
                 client_factory=self._client_factory,
                 transform=transform,
                 table_transformer=table_transformer,
                 confirmation=confirmation,
                 exception_handler=exception_handler or self._exception_handler)
示例#12
0
    def test_help_long_description_from_docstring(self):
        """ Verifies that the first sentence of a docstring is extracted as the short description.
        Verifies that line breaks in the long summary are removed and leaves the text wrapping
        to the help system. """

        def test_handler():
            """Short Description. Long description with\nline break."""
            pass

        setattr(sys.modules[__name__], test_handler.__name__, test_handler)

        cli_command(None, "test", "{}#{}".format(__name__, test_handler.__name__))
        _update_command_definitions(command_table)

        config = Configuration([])
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute("test -h".split())
        self.assertEqual(
            True,
            io.getvalue().startswith(
                "\nCommand\n    az test: Short Description.\n        Long description with line break."
            ),
        )  # pylint: disable=line-too-long
    def test_register_cli_argument(self):
        command_table.clear()
        cli_command(None, 'test register sample-vm-get',
                    '{}#Test_command_registration.sample_vm_get'.format(__name__))
        register_cli_argument('test register sample-vm-get', 'vm_name', CliArgumentType(
            options_list=('--wonky-name', '-n'), metavar='VMNAME', help='Completely WONKY name...',
            required=False
        ))

        command_table['test register sample-vm-get'].load_arguments()
        _update_command_definitions(command_table)

        self.assertEqual(len(command_table), 1,
                         'We expect exactly one command in the command table')
        command_metadata = command_table['test register sample-vm-get']
        self.assertEqual(len(command_metadata.arguments), 4, 'We expected exactly 4 arguments')
        some_expected_arguments = {
            'resource_group_name': CliArgumentType(dest='resource_group_name', required=True),
            'vm_name': CliArgumentType(dest='vm_name', required=False),
        }

        for probe in some_expected_arguments:
            existing = next(arg for arg in command_metadata.arguments if arg == probe)
            self.assertDictContainsSubset(some_expected_arguments[existing].settings,
                                          command_metadata.arguments[existing].options)
        self.assertEqual(command_metadata.arguments['vm_name'].options_list, ('--wonky-name', '-n'))
示例#14
0
 def command(self, name, method_name):
     cli_command(
         self._scope,
         "{} {}".format(self._group_name, name),
         self._service_adapter(method_name),
         client_factory=self._client_factory,
     )
示例#15
0
 def custom_command(self, name, custom_func_name, confirmation=None,
                    exception_handler=None):
     cli_command(self._scope,
                 '{} {}'.format(self._group_name, name),
                 self._custom_path.format(custom_func_name),
                 client_factory=self._client_factory,
                 confirmation=confirmation,
                 exception_handler=exception_handler or self._exception_handler)
示例#16
0
 def custom_command(self, name, custom_func_name, confirmation=None,
                    exception_handler=None):
     cli_command(self._scope,
                 '{} {}'.format(self._group_name, name),
                 self._custom_path.format(custom_func_name),
                 client_factory=self._client_factory,
                 confirmation=confirmation,
                 exception_handler=exception_handler or self._exception_handler)
示例#17
0
 def command(self, name, method_name, transform=None, table_transformer=None, confirmation=None):
     cli_command(self._scope,
                 '{} {}'.format(self._group_name, name),
                 self._service_adapter(method_name),
                 client_factory=self._client_factory,
                 transform=transform,
                 table_transformer=table_transformer,
                 confirmation=confirmation)
示例#18
0
 def custom_command(self, name, custom_func_name, confirmation=None,
                    exception_handler=None, deprecate_info=None, no_wait_param=None):
     cli_command(self._scope,
                 '{} {}'.format(self._group_name, name),
                 self._custom_path.format(custom_func_name),
                 client_factory=self._client_factory,
                 confirmation=confirmation,
                 deprecate_info=deprecate_info,
                 exception_handler=exception_handler or self._exception_handler,
                 no_wait_param=no_wait_param)
    def test_register_command_from_extension(self):
        command_table.clear()

        # A standard command
        cli_command(None, 'hello world', 'dummy_operation', None)
        self.assertEqual(len(command_table), 1)
        self.assertEqual(command_table['hello world'].command_source, None)

        command_table.clear()

        # A command from an extension
        cli_command('{}myextension'.format(EXTENSIONS_MOD_PREFIX), 'hello world', 'dummy_operation', None)
        self.assertEqual(len(command_table), 1)
        cmd_source = command_table['hello world'].command_source
        self.assertTrue(isinstance(cmd_source, ExtensionCommandSource))
        self.assertFalse(cmd_source.overrides_command)

        command_table.clear()

        # A command from an extension that overrides the original command
        cli_command(None, 'hello world', 'dummy_operation', None)
        cli_command('{}myextension'.format(EXTENSIONS_MOD_PREFIX), 'hello world', 'dummy_operation', None)
        self.assertEqual(len(command_table), 1)
        cmd_source = command_table['hello world'].command_source
        self.assertTrue(isinstance(cmd_source, ExtensionCommandSource))
        self.assertTrue(cmd_source.overrides_command)

        command_table.clear()
示例#20
0
 def custom_command(self,
                    name,
                    custom_func_name,
                    confirmation=None,
                    exception_handler=None,
                    deprecate_info=None,
                    no_wait_param=None):
     cli_command(self._scope,
                 '{} {}'.format(self._group_name, name),
                 self._custom_path.format(custom_func_name),
                 client_factory=self._client_factory,
                 confirmation=confirmation,
                 deprecate_info=deprecate_info,
                 exception_handler=exception_handler
                 or self._exception_handler,
                 no_wait_param=no_wait_param)
示例#21
0
    def test_help_long_description_from_docstring(self):
        """ Verifies that the first sentence of a docstring is extracted as the short description.
        Verifies that line breaks in the long summary are removed and leaves the text wrapping
        to the help system. """

        def test_handler():
            """Short Description. Long description with\nline break."""
            pass

        cli_command('test', test_handler)
        _update_command_definitions(command_table)

        config = Configuration([])
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute('test -h'.split())
        self.assertEqual(True, io.getvalue().startswith('\nCommand\n    az test: Short Description.\n        Long description with line break.')) # pylint: disable=line-too-long
    def set_up_command_table(self, required_arg=False):
        command_table.clear()

        module_name = __name__ + '.' + self._testMethodName
        cli_command(module_name, 'test sample-vm-list',
                    '{}#TestCommandWithConfiguredDefaults.sample_vm_list'.format(__name__))

        register_cli_argument('test sample-vm-list', 'resource_group_name',
                              CliArgumentType(options_list=('--resource-group-name', '-g'),
                                              configured_default='group', required=required_arg))

        command_table['test sample-vm-list'].load_arguments()
        _update_command_definitions(command_table)

        self.argv = 'az test sample-vm-list'.split()
        config = Configuration()
        config.get_command_table = lambda argv: command_table
        self.application = Application(config)
    def set_up_command_table(self, required_arg=False):
        command_table.clear()

        module_name = __name__ + '.' + self._testMethodName
        cli_command(module_name, 'test sample-vm-list',
                    '{}#TestCommandWithConfiguredDefaults.sample_vm_list'.format(__name__))

        register_cli_argument('test sample-vm-list', 'resource_group_name',
                              CliArgumentType(options_list=('--resource-group-name', '-g'),
                                              configured_default='group', required=required_arg))

        command_table['test sample-vm-list'].load_arguments()
        _update_command_definitions(command_table)

        self.argv = 'az test sample-vm-list'.split()
        config = Configuration(self.argv)
        config.get_command_table = lambda: command_table
        self.application = Application(config)
    def test_register_cli_argument_with_overrides(self):
        command_table.clear()

        global_vm_name_type = CliArgumentType(
            options_list=('--foo', '-f'), metavar='FOO', help='foo help'
        )
        derived_vm_name_type = CliArgumentType(base_type=global_vm_name_type,
                                               help='first modification')

        cli_command('test vm-get', Test_command_registration.sample_vm_get, None)
        cli_command('test command vm-get-1', Test_command_registration.sample_vm_get, None)
        cli_command('test command vm-get-2', Test_command_registration.sample_vm_get, None)

        register_cli_argument('test', 'vm_name', global_vm_name_type)
        register_cli_argument('test command', 'vm_name', derived_vm_name_type)
        register_cli_argument('test command vm-get-2', 'vm_name', derived_vm_name_type,
                              help='second modification')

        _update_command_definitions(command_table)

        self.assertEqual(len(command_table), 3,
                         'We expect exactly three commands in the command table')
        command1 = command_table['test vm-get'].arguments['vm_name']
        command2 = command_table['test command vm-get-1'].arguments['vm_name']
        command3 = command_table['test command vm-get-2'].arguments['vm_name']

        self.assertTrue(command1.options['help'] == 'foo help')
        self.assertTrue(command2.options['help'] == 'first modification')
        self.assertTrue(command3.options['help'] == 'second modification')
        command_table.clear()
示例#25
0
    def test_register_cli_argument_with_overrides(self):
        command_table.clear()

        global_vm_name_type = CliArgumentType(options_list=('--foo', '-f'),
                                              metavar='FOO',
                                              help='foo help')
        derived_vm_name_type = CliArgumentType(base_type=global_vm_name_type,
                                               help='first modification')

        cli_command(
            None, 'test vm-get',
            '{}#Test_command_registration.sample_vm_get'.format(__name__),
            None)
        cli_command(
            None, 'test command vm-get-1',
            '{}#Test_command_registration.sample_vm_get'.format(__name__),
            None)
        cli_command(
            None, 'test command vm-get-2',
            '{}#Test_command_registration.sample_vm_get'.format(__name__),
            None)

        register_cli_argument('test', 'vm_name', global_vm_name_type)
        register_cli_argument('test command', 'vm_name', derived_vm_name_type)
        register_cli_argument('test command vm-get-2',
                              'vm_name',
                              derived_vm_name_type,
                              help='second modification')

        command_table['test vm-get'].load_arguments()
        command_table['test command vm-get-1'].load_arguments()
        command_table['test command vm-get-2'].load_arguments()
        _update_command_definitions(command_table)

        self.assertEqual(
            len(command_table), 3,
            'We expect exactly three commands in the command table')
        command1 = command_table['test vm-get'].arguments['vm_name']
        command2 = command_table['test command vm-get-1'].arguments['vm_name']
        command3 = command_table['test command vm-get-2'].arguments['vm_name']

        self.assertTrue(command1.options['help'] == 'foo help')
        self.assertTrue(command2.options['help'] == 'first modification')
        self.assertTrue(command3.options['help'] == 'second modification')
        command_table.clear()
示例#26
0
# --------------------------------------------------------------------------------------------
# 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

cli_command(__name__, 'acs dcos browse',
            'azure.cli.command_modules.acs.custom#dcos_browse')
cli_command(__name__, 'acs dcos install-cli',
            'azure.cli.command_modules.acs.custom#dcos_install_cli')
cli_command(__name__, 'acs create',
            'azure.cli.command_modules.acs.custom#acs_create')
cli_command(__name__, 'acs kubernetes browse',
            'azure.cli.command_modules.acs.custom#k8s_browse')
cli_command(__name__, 'acs kubernetes install-cli',
            'azure.cli.command_modules.acs.custom#k8s_install_cli')
cli_command(__name__, 'acs kubernetes get-credentials',
            'azure.cli.command_modules.acs.custom#k8s_get_credentials')
示例#27
0
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.commands import cli_command
from azure.cli.core.commands.arm import cli_generic_update_command
from azure.cli.core.util import empty_on_404

from ._constants import WEBHOOK_API_VERSION
from ._format import output_format
from ._factory import get_acr_service_client

cli_command(__name__,
            'acr credential show',
            'azure.cli.command_modules.acr.credential#acr_credential_show',
            table_transformer=output_format,
            exception_handler=empty_on_404)
cli_command(__name__,
            'acr credential renew',
            'azure.cli.command_modules.acr.credential#acr_credential_renew',
            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',
示例#28
0
    get_resource_group_name_by_resource_id,
    registry_not_found
)

from ._format import output_format

import azure.cli.core._logging as _logging
logger = _logging.get_az_logger(__name__)

def acr_credential_show(registry_name, resource_group_name=None):
    '''Get admin username and password for a container registry.
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    '''
    registry = get_registry_by_name(registry_name)
    if registry is None:
        registry_not_found(registry_name)

    if resource_group_name is None:
        resource_group_name = get_resource_group_name_by_resource_id(registry.id)

    client = get_acr_service_client().registries
    if registry.properties.admin_user_enabled:
        return client.get_credentials(resource_group_name, registry_name)
    else:
        raise CLIError(
            'Admin user is not enabled for the container registry with name: {}'\
            .format(registry_name))

cli_command('acr credential show', acr_credential_show, table_transformer=output_format)
示例#29
0
base_blob_path = 'azure.storage.blob.baseblobservice#BaseBlobService.'
table_path = 'azure.storage.table.tableservice#TableService.'
queue_path = 'azure.storage.queue.queueservice#QueueService.'


def _dont_fail_not_exist(ex):
    from azure.storage._error import AzureMissingResourceHttpError
    if isinstance(ex, AzureMissingResourceHttpError):
        return None
    else:
        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
示例#30
0
#pylint: disable=unused-import
from azure.mgmt.web.operations import SitesOperations, ServerFarmsOperations, ProviderOperations
from azure.cli.core.commands import LongRunningOperation, cli_command

from ._params import web_client_factory
from .custom import (create_webapp, show_webapp, list_webapp,
                     delete_webapp, stop_webapp, restart_webapp,
                     enable_local_git, set_deployment_user,
                     get_git_url, view_in_browser, create_app_service_plan,
                     update_app_service_plan, config_diagnostics,
                     get_streaming_log, download_historical_logs,
                     create_webapp_slot, config_slot_auto_swap,
                     get_site_configs, update_site_configs,
                     get_app_settings, update_app_settings, delete_app_settings)

cli_command('appservice web create', create_webapp)
cli_command('appservice web list', list_webapp)
cli_command('appservice web show', show_webapp)
cli_command('appservice web delete', delete_webapp)
cli_command('appservice web stop', stop_webapp)
cli_command('appservice web restart', restart_webapp)

cli_command('appservice web config update', update_site_configs)
cli_command('appservice web config show', get_site_configs)
cli_command('appservice web config appsettings show', get_app_settings)
cli_command('appservice web config appsettings update', update_app_settings)
cli_command('appservice web config appsettings delete', delete_app_settings)

factory = lambda _: web_client_factory().sites
cli_command('appservice web show-publish-profile',
            SitesOperations.list_site_publishing_credentials, factory)
示例#31
0
# --------------------------------------------------------------------------------------------
# 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.command_modules.dls._client_factory import (
    cf_dls_account, cf_dls_account_firewall, cf_dls_account_trusted_provider)
adls_format_path = 'azure.mgmt.datalake.store.operations.{}#{}.{}'
adls_custom_format_path = 'azure.cli.command_modules.dls.custom#{}'

# account operations
cli_command(__name__, 'dls account create',
            adls_custom_format_path.format('create_adls_account'),
            cf_dls_account)
cli_command(__name__, 'dls account update',
            adls_custom_format_path.format('update_adls_account'),
            cf_dls_account)
cli_command(__name__, 'dls account list',
            adls_custom_format_path.format('list_adls_account'),
            cf_dls_account)
cli_command(
    __name__, 'dls account delete',
    adls_format_path.format('account_operations', 'AccountOperations',
                            'delete'), cf_dls_account)
cli_command(
    __name__, 'dls account show',
    adls_format_path.format('account_operations', 'AccountOperations', 'get'),
    cf_dls_account)
示例#32
0
# --------------------------------------------------------------------------------------------
# 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.command_modules.dls._client_factory import (cf_dls_account,
                                                           cf_dls_account_firewall,
                                                           cf_dls_account_trusted_provider)
adls_format_path = 'azure.mgmt.datalake.store.operations.{}#{}.{}'
adls_custom_format_path = 'azure.cli.command_modules.dls.custom#{}'

# account operations
cli_command(__name__, 'dls account create', adls_custom_format_path.format('create_adls_account'), cf_dls_account)
cli_command(__name__, 'dls account update', adls_custom_format_path.format('update_adls_account'), cf_dls_account)
cli_command(__name__, 'dls account list', adls_custom_format_path.format('list_adls_account'), cf_dls_account)
cli_command(__name__, 'dls account delete', adls_format_path.format('account_operations', 'AccountOperations', 'delete'), cf_dls_account)
cli_command(__name__, 'dls account show', adls_format_path.format('account_operations', 'AccountOperations', 'get'), cf_dls_account)
cli_command(__name__, 'dls account enable-key-vault', adls_format_path.format('account_operations', 'AccountOperations', 'enable_key_vault'), cf_dls_account)

# account firewall operations
cli_command(__name__, 'dls account firewall create', adls_custom_format_path.format('add_adls_firewall_rule'), cf_dls_account_firewall)
cli_command(__name__, 'dls account firewall update', adls_format_path.format('firewall_rules_operations', 'FirewallRulesOperations', 'update'), cf_dls_account_firewall)
cli_command(__name__, 'dls account firewall list', adls_format_path.format('firewall_rules_operations', 'FirewallRulesOperations', 'list_by_account'), cf_dls_account_firewall)
cli_command(__name__, 'dls account firewall show', adls_format_path.format('firewall_rules_operations', 'FirewallRulesOperations', 'get'), cf_dls_account_firewall)
cli_command(__name__, 'dls account firewall delete', adls_format_path.format('firewall_rules_operations', 'FirewallRulesOperations', 'delete'), cf_dls_account_firewall)

# account trusted id provider operations
cli_command(__name__, 'dls account trusted-provider create', adls_format_path.format('trusted_id_providers_operations', 'TrustedIdProvidersOperations', 'create_or_update'), cf_dls_account_trusted_provider)
cli_command(__name__, 'dls account trusted-provider update', adls_format_path.format('trusted_id_providers_operations', 'TrustedIdProvidersOperations', 'update'), cf_dls_account_trusted_provider)
示例#33
0
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.commands import cli_command
from azure.cli.core.commands.arm import cli_generic_update_command
from azure.cli.core.util import empty_on_404

from ._constants import WEBHOOK_API_VERSION
from ._format import output_format
from ._factory import get_acr_service_client

cli_command(__name__, 'acr credential show',
            'azure.cli.command_modules.acr.credential#acr_credential_show',
            table_transformer=output_format, exception_handler=empty_on_404)
cli_command(__name__, 'acr credential renew',
            'azure.cli.command_modules.acr.credential#acr_credential_renew',
            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(
示例#34
0
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

#pylint: disable=unused-import,line-too-long
from azure.cli.core.commands import LongRunningOperation, cli_command
from azure.cli.core.commands.arm import cli_generic_update_command

from ._client_factory import web_client_factory

cli_command(__name__, 'appservice web create', 'azure.cli.command_modules.appservice.custom#create_webapp')
cli_command(__name__, 'appservice web list', 'azure.cli.command_modules.appservice.custom#list_webapp')
cli_command(__name__, 'appservice web show', 'azure.cli.command_modules.appservice.custom#show_webapp')
cli_command(__name__, 'appservice web delete', 'azure.cli.command_modules.appservice.custom#delete_webapp')
cli_command(__name__, 'appservice web stop', 'azure.cli.command_modules.appservice.custom#stop_webapp')
cli_command(__name__, 'appservice web start', 'azure.cli.command_modules.appservice.custom#start_webapp')
cli_command(__name__, 'appservice web restart', 'azure.cli.command_modules.appservice.custom#restart_webapp')

cli_command(__name__, 'appservice web config update', 'azure.cli.command_modules.appservice.custom#update_site_configs')
cli_command(__name__, 'appservice web config show', 'azure.cli.command_modules.appservice.custom#get_site_configs')
cli_command(__name__, 'appservice web config appsettings show', 'azure.cli.command_modules.appservice.custom#get_app_settings')
cli_command(__name__, 'appservice web config appsettings update', 'azure.cli.command_modules.appservice.custom#update_app_settings')
cli_command(__name__, 'appservice web config appsettings delete', 'azure.cli.command_modules.appservice.custom#delete_app_settings')
cli_command(__name__, 'appservice web config hostname add', 'azure.cli.command_modules.appservice.custom#add_hostname')
cli_command(__name__, 'appservice web config hostname list', 'azure.cli.command_modules.appservice.custom#list_hostnames')
cli_command(__name__, 'appservice web config hostname delete', 'azure.cli.command_modules.appservice.custom#delete_hostname')
cli_command(__name__, 'appservice web config container update', 'azure.cli.command_modules.appservice.custom#update_container_settings')
cli_command(__name__, 'appservice web config container delete', 'azure.cli.command_modules.appservice.custom#delete_container_settings')
cli_command(__name__, 'appservice web config container show', 'azure.cli.command_modules.appservice.custom#show_container_settings')

def get_graph_client_service_principals(_):
    return _graph_client_factory().service_principals


def get_graph_client_users(_):
    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_command(__name__, 'role definition update',
            'azure.cli.command_modules.role.custom#update_role_definition')

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')
示例#36
0
    (transform_local_gateway_table_output, transform_dns_record_set_output,
     transform_dns_record_set_table_output, transform_dns_zone_table_output,
     transform_vnet_create_output, transform_public_ip_create_output,
     transform_traffic_manager_create_output, transform_nic_create_output,
     transform_nsg_create_output, transform_vnet_gateway_create_output,
     transform_vpn_connection, transform_vpn_connection_list,
     transform_vpn_connection_create_output, transform_geographic_hierachy_table_output,
     transform_service_community_table_output, transform_waf_rule_sets_table_output,
     transform_network_usage_list, transform_network_usage_table)


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)

示例#37
0
    job_client_factory,
    file_client_factory,
    file_server_client_factory)
from azure.cli.command_modules.batchai._format import (
    cluster_list_table_format,
    job_list_table_format,
    file_list_table_format,
    file_server_table_format,
    remote_login_table_format,
)
from azure.cli.core.commands import cli_command

custom_path = 'azure.cli.command_modules.batchai.custom#{}'
mgmt_path = 'azure.mgmt.batchai.operations.{}_operations#{}.{}'

cli_command(__name__, 'batchai cluster create', custom_path.format('create_cluster'), batchai_client_factory, no_wait_param='raw')
cli_command(__name__, 'batchai cluster delete', mgmt_path.format('clusters', 'ClustersOperations', 'delete'), cluster_client_factory, confirmation=True, no_wait_param='raw')
cli_command(__name__, 'batchai cluster show', mgmt_path.format('clusters', 'ClustersOperations', 'get'), cluster_client_factory)
cli_command(__name__, 'batchai cluster list', custom_path.format('list_clusters'), cluster_client_factory, table_transformer=cluster_list_table_format)
cli_command(__name__, 'batchai cluster list-nodes', mgmt_path.format('clusters', 'ClustersOperations', 'list_remote_login_information'), cluster_client_factory, table_transformer=remote_login_table_format)
cli_command(__name__, 'batchai cluster resize', custom_path.format('resize_cluster'), cluster_client_factory)
cli_command(__name__, 'batchai cluster auto-scale', custom_path.format('set_cluster_auto_scale_parameters'), cluster_client_factory)

cli_command(__name__, 'batchai job create', custom_path.format('create_job'), batchai_client_factory, no_wait_param='raw')
cli_command(__name__, 'batchai job delete', mgmt_path.format('jobs', 'JobsOperations', 'delete'), job_client_factory, confirmation=True, no_wait_param='raw')
cli_command(__name__, 'batchai job terminate', mgmt_path.format('jobs', 'JobsOperations', 'terminate'), job_client_factory, no_wait_param='raw')
cli_command(__name__, 'batchai job show', mgmt_path.format('jobs', 'JobsOperations', 'get'), job_client_factory)
cli_command(__name__, 'batchai job list', custom_path.format('list_jobs'), job_client_factory, table_transformer=job_list_table_format)
cli_command(__name__, 'batchai job list-nodes', mgmt_path.format('jobs', 'JobsOperations', 'list_remote_login_information'), job_client_factory, table_transformer=remote_login_table_format)
cli_command(__name__, 'batchai job list-files', custom_path.format('list_files'), file_client_factory, table_transformer=file_list_table_format)
cli_command(__name__, 'batchai job stream-file', custom_path.format('tail_file'), file_client_factory)
示例#38
0
            temp = ['{}={}'.format(pair['name'], pair['value']) for pair in k['capabilities']]
            order_dict['capabilities'] = str(temp) if len(temp) > 1 else temp[0]
        else:
            order_dict['capabilities'] = None
        if k['restrictions']:
            reasons = [x['reasonCode'] for x in k['restrictions']]
            order_dict['restrictions'] = str(reasons) if len(reasons) > 1 else reasons[0]
        else:
            order_dict['restrictions'] = None
        result.append(order_dict)
    return result


op_var = 'virtual_machines_operations'
op_class = 'VirtualMachinesOperations'
cli_command(__name__, 'vm create', custom_path.format('create_vm'), transform=transform_vm_create_output, no_wait_param='no_wait', exception_handler=handle_long_running_operation_exception, table_transformer=deployment_validate_table_format)
cli_command(__name__, 'vm delete', mgmt_path.format(op_var, op_class, 'delete'), cf_vm, confirmation=True, no_wait_param='raw')
cli_command(__name__, 'vm deallocate', mgmt_path.format(op_var, op_class, 'deallocate'), cf_vm, no_wait_param='raw')
cli_command(__name__, 'vm generalize', mgmt_path.format(op_var, op_class, 'generalize'), cf_vm, no_wait_param='raw')
cli_command(__name__, 'vm show', custom_path.format('show_vm'), table_transformer=transform_vm, exception_handler=empty_on_404)
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'))
示例#39
0
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.commands import cli_command

cli_command(__name__, 'cloud list', 'azure.cli.command_modules.cloud.custom#list_clouds')
cli_command(__name__, 'cloud show', 'azure.cli.command_modules.cloud.custom#show_cloud')
cli_command(__name__, 'cloud register', 'azure.cli.command_modules.cloud.custom#register_cloud')
cli_command(__name__, 'cloud unregister', 'azure.cli.command_modules.cloud.custom#unregister_cloud')
cli_command(__name__, 'cloud set', 'azure.cli.command_modules.cloud.custom#set_cloud')
cli_command(__name__, 'cloud update', 'azure.cli.command_modules.cloud.custom#modify_cloud')
cli_command(__name__, 'cloud list-profiles', 'azure.cli.command_modules.cloud.custom#list_profiles')
示例#40
0
                              "supported regions, please refer to https://docs.microsoft.com/en-us/"
                              "azure/app-service-web/app-service-linux-intro")
                elif 'Not enough available reserved instance servers to satisfy' in detail:
                    detail = ("Plan with Linux worker can only be created in a group " +
                              "which has never contained a Windows worker, and vice versa. " +
                              "Please use a new resource group. Original error:" + detail)
            ex = CLIError(detail)
        except Exception:  # pylint: disable=broad-except
            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_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')
示例#41
0
        item.current_value = str(item.current_value)
        item.limit = str(item.limit)
        item.local_name = item.name.localized_value
    return result


def transform_vm_list(vm_list):
    return [transform_vm(v) for v in vm_list]


op_var = 'virtual_machines_operations'
op_class = 'VirtualMachinesOperations'
cli_command(__name__,
            'vm create',
            custom_path.format('create_vm'),
            transform=transform_vm_create_output,
            no_wait_param='no_wait',
            exception_handler=handle_long_running_operation_exception,
            table_transformer=deployment_validate_table_format)
cli_command(__name__,
            'vm delete',
            mgmt_path.format(op_var, op_class, 'delete'),
            cf_vm,
            confirmation=True,
            no_wait_param='raw')
cli_command(__name__,
            'vm deallocate',
            mgmt_path.format(op_var, op_class, 'deallocate'),
            cf_vm,
            no_wait_param='raw')
cli_command(__name__,
示例#42
0
                        +
                        "which has never contained a Windows worker, and vice versa. "
                        + "Please use a new resource group. Original error:" +
                        detail)
            ex = CLIError(detail)
        except Exception:  # pylint: disable=broad-except
            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_command(__name__, 'webapp traffic-routing set',
示例#43
0
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.commands import cli_command

cli_command(__name__, 'feedback',
            'azure.cli.command_modules.feedback.custom#handle_feedback')
示例#44
0
    job_list_table_format,
    task_create_table_format,
    account_keys_list_table_format,
    account_list_table_format,
    application_list_table_format,
    account_keys_renew_table_format)

if not supported_api_version(PROFILE_TYPE, max_api='2017-03-09-profile'):
    data_path = 'azure.batch.operations.{}_operations#{}'
    custom_path = 'azure.cli.command_modules.batch.custom#{}'
    mgmt_path = 'azure.mgmt.batch.operations.{}_operations#{}'

    # pylint: disable=line-too-long
    # Mgmt Account Operations

    cli_command(__name__, 'batch account list', custom_path.format('list_accounts'), account_mgmt_client_factory, table_transformer=account_list_table_format)
    cli_command(__name__, 'batch account show', mgmt_path.format('batch_account', 'BatchAccountOperations.get'), account_mgmt_client_factory)
    cli_command(__name__, 'batch account create', custom_path.format('create_account'), account_mgmt_client_factory)
    cli_command(__name__, 'batch account set', custom_path.format('update_account'), account_mgmt_client_factory)
    cli_command(__name__, 'batch account delete', mgmt_path.format('batch_account', 'BatchAccountOperations.delete'), account_mgmt_client_factory, confirmation=True)
    cli_command(__name__, 'batch account autostorage-keys sync', mgmt_path.format('batch_account', 'BatchAccountOperations.synchronize_auto_storage_keys'), account_mgmt_client_factory)
    cli_command(__name__, 'batch account keys list', mgmt_path.format('batch_account', 'BatchAccountOperations.get_keys'), account_mgmt_client_factory, table_transformer=account_keys_list_table_format)
    cli_command(__name__, 'batch account keys renew', mgmt_path.format('batch_account', 'BatchAccountOperations.regenerate_key'), account_mgmt_client_factory, table_transformer=account_keys_renew_table_format)
    cli_command(__name__, 'batch account login', custom_path.format('login_account'), account_mgmt_client_factory)

    cli_command(__name__, 'batch application list', mgmt_path.format('application', 'ApplicationOperations.list'), application_mgmt_client_factory, table_transformer=application_list_table_format)
    cli_command(__name__, 'batch application show', mgmt_path.format('application', 'ApplicationOperations.get'), application_mgmt_client_factory)
    cli_command(__name__, 'batch application create', mgmt_path.format('application', 'ApplicationOperations.create'), application_mgmt_client_factory)
    cli_command(__name__, 'batch application set', custom_path.format('update_application'), application_mgmt_client_factory)
    cli_command(__name__, 'batch application delete', mgmt_path.format('application', 'ApplicationOperations.delete'), application_mgmt_client_factory, confirmation=True)
示例#45
0
    (transform_local_gateway_table_output, transform_dns_record_set_output,
     transform_dns_record_set_table_output, transform_dns_zone_table_output,
     transform_vnet_create_output, transform_public_ip_create_output,
     transform_traffic_manager_create_output, transform_nic_create_output,
     transform_nsg_create_output, transform_vnet_gateway_create_output,
     transform_vpn_connection, transform_vpn_connection_list,
     transform_vpn_connection_create_output, transform_geographic_hierachy_table_output,
     transform_service_community_table_output, transform_waf_rule_sets_table_output)

from azure.cli.core.profiles import supported_api_version, ResourceType

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)

示例#46
0
def load_commands():
    from azure.cli.core.commands import cli_command
    cli_command(__name__, 'image copy', 'azext_imagecopy.custom#imagecopy')
示例#47
0
def billing_command(*args, **kwargs):
    cli_command(*args, exception_handler=billing_exception_handler, **kwargs)
示例#48
0
from azure.cli.command_modules.dla._client_factory import (cf_dla_account,
                                                           cf_dla_account_firewall,
                                                           cf_dla_account_adls,
                                                           cf_dla_account_storage,
                                                           cf_dla_job,
                                                           cf_dla_catalog,
                                                           cf_dla_job_pipeline,
                                                           cf_dla_job_recurrence,
                                                           cf_dla_account_compute_policy)

if not supported_api_version(PROFILE_TYPE, max_api='2017-03-09-profile'):
    adla_format_path = 'azure.mgmt.datalake.analytics.{}.operations.{}#{}.{}'
    adla_custom_format_path = 'azure.cli.command_modules.dla.custom#{}'

    # account operations
    cli_command(__name__, 'dla account create', adla_custom_format_path.format('create_adla_account'), cf_dla_account)
    cli_command(__name__, 'dla account update', adla_custom_format_path.format('update_adla_account'), cf_dla_account)
    cli_command(__name__, 'dla account list', adla_custom_format_path.format('list_adla_account'), cf_dla_account)
    cli_command(__name__, 'dla account show', adla_format_path.format('account', 'account_operations', 'AccountOperations', 'get'), cf_dla_account)
    cli_command(__name__, 'dla account delete', adla_format_path.format('account', 'account_operations', 'AccountOperations', 'delete'), cf_dla_account)

    # account fire wall operations
    cli_command(__name__, 'dla account firewall create', adla_custom_format_path.format('add_adla_firewall_rule'), cf_dla_account_firewall)
    cli_command(__name__, 'dla account firewall update', adla_format_path.format('account', 'firewall_rules_operations', 'FirewallRulesOperations', 'update'), cf_dla_account_firewall)
    cli_command(__name__, 'dla account firewall list', adla_format_path.format('account', 'firewall_rules_operations', 'FirewallRulesOperations', 'list_by_account'), cf_dla_account_firewall)
    cli_command(__name__, 'dla account firewall show', adla_format_path.format('account', 'firewall_rules_operations', 'FirewallRulesOperations', 'get'), cf_dla_account_firewall)
    cli_command(__name__, 'dla account firewall delete', adla_format_path.format('account', 'firewall_rules_operations', 'FirewallRulesOperations', 'delete'), cf_dla_account_firewall)

    # job operations
    # todo: update to allow for inclusion of statistics/debug data in show
    cli_command(__name__, 'dla job submit', adla_custom_format_path.format('submit_adla_job'), cf_dla_job)
示例#49
0

def get_graph_client_service_principals(_):
    return _graph_client_factory().service_principals


def get_graph_client_users(_):
    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_command(__name__, 'role definition update',
            'azure.cli.command_modules.role.custom#update_role_definition')

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',
示例#50
0
# --------------------------------------------------------------------------------------------
# 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

cli_command(__name__, 'taskhelp deploy-arm-template', 'azure.cli.command_modules.taskhelp.custom#deploy_arm_template')
示例#51
0
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.commands import cli_command

cli_command(__name__, 'cloud list', 'azure.cli.command_modules.cloud.custom#list_clouds')
cli_command(__name__, 'cloud show', 'azure.cli.command_modules.cloud.custom#show_cloud')
cli_command(__name__, 'cloud register', 'azure.cli.command_modules.cloud.custom#register_cloud')
cli_command(__name__, 'cloud unregister', 'azure.cli.command_modules.cloud.custom#unregister_cloud')
示例#52
0
# 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.util import empty_on_404
from azure.cli.core.commands.arm import \
    (cli_generic_wait_command, handle_long_running_operation_exception, deployment_validate_table_format)
from azure.cli.core.profiles import supported_api_version, PROFILE_TYPE
from ._client_factory import _acs_client_factory

if not supported_api_version(PROFILE_TYPE, max_api='2017-03-09-profile'):
    cli_command(
        __name__,
        'acs show',
        'azure.mgmt.containerservice.operations.container_services_operations#ContainerServicesOperations.get',
        _acs_client_factory,
        exception_handler=empty_on_404)
    cli_command(
        __name__, 'acs delete',
        'azure.mgmt.containerservice.operations.container_services_operations#ContainerServicesOperations.delete',
        _acs_client_factory)

    # Per conversation with ACS team, hide the update till we have something meaningful to tweak
    # from azure.cli.command_modules.acs.custom import update_acs
    # cli_generic_update_command(__name__, 'acs update', ContainerServicesOperations.get, ContainerServicesOperations.create_or_update, cf_acs)

    # custom commands
    cli_command(__name__, 'acs list-locations',
                'azure.cli.command_modules.acs.custom#list_acs_locations')
    cli_command(__name__, 'acs scale',
示例#53
0
table_path = 'azure.storage.table.tableservice#TableService.'
queue_path = 'azure.storage.queue.queueservice#QueueService.'


def _dont_fail_not_exist(ex):
    from azure.storage._error import AzureMissingResourceHttpError
    if isinstance(ex, AzureMissingResourceHttpError):
        return None
    else:
        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',
示例#54
0
     update_network_vpn_gateway, create_vpn_gateway_root_cert, delete_vpn_gateway_root_cert,
     create_vpn_gateway_revoked_cert, delete_vpn_gateway_revoked_cert, create_express_route_auth,
     list_traffic_manager_profiles, create_traffic_manager_endpoint, list_dns_zones,
     create_dns_record_set, add_dns_aaaa_record, add_dns_a_record, add_dns_cname_record,
     add_dns_ns_record, add_dns_ptr_record, update_dns_soa_record, add_dns_srv_record,
     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',
示例#55
0
    (transform_local_gateway_table_output, transform_dns_record_set_output,
     transform_dns_record_set_table_output, transform_dns_zone_table_output,
     transform_vnet_create_output, transform_public_ip_create_output,
     transform_traffic_manager_create_output, transform_nic_create_output,
     transform_nsg_create_output, transform_vnet_gateway_create_output,
     transform_vpn_connection, transform_vpn_connection_list,
     transform_vpn_connection_create_output)

from azure.cli.core.profiles import supported_api_version, ResourceType

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',
示例#56
0
                if 'Requested features are not supported in region' in detail:
                    detail = ("Plan with linux worker is not supported in current region. For " +
                              "supported regions, please refer to https://docs.microsoft.com/en-us/"
                              "azure/app-service-web/app-service-linux-intro")
                elif 'Not enough available reserved instance servers to satisfy' in detail:
                    detail = ("Plan with Linux worker can only be created in a group " +
                              "which has never contained a Windows worker, and vice versa. " +
                              "Please use a new resource group. Original error:" + detail)
            ex = CLIError(detail)
        except Exception:  # pylint: disable=broad-except
            pass
        raise ex
    return _polish_bad_errors


cli_command(__name__, 'appservice web create', 'azure.cli.command_modules.appservice.custom#create_webapp', exception_handler=ex_handler_factory())
cli_command(__name__, 'appservice web list', 'azure.cli.command_modules.appservice.custom#list_webapp', table_transformer=transform_web_list_output)
cli_command(__name__, 'appservice web show', 'azure.cli.command_modules.appservice.custom#show_webapp', exception_handler=empty_on_404, table_transformer=transform_web_output)
cli_command(__name__, 'appservice web delete', 'azure.cli.command_modules.appservice.custom#delete_webapp')
cli_command(__name__, 'appservice web stop', 'azure.cli.command_modules.appservice.custom#stop_webapp')
cli_command(__name__, 'appservice web start', 'azure.cli.command_modules.appservice.custom#start_webapp')
cli_command(__name__, 'appservice web restart', 'azure.cli.command_modules.appservice.custom#restart_webapp')

cli_command(__name__, 'appservice web config update', 'azure.cli.command_modules.appservice.custom#update_site_configs')
cli_command(__name__, 'appservice web config show', 'azure.cli.command_modules.appservice.custom#get_site_configs', exception_handler=empty_on_404)
cli_command(__name__, 'appservice web config appsettings show', 'azure.cli.command_modules.appservice.custom#get_app_settings', exception_handler=empty_on_404)
cli_command(__name__, 'appservice web config appsettings update', 'azure.cli.command_modules.appservice.custom#update_app_settings')
cli_command(__name__, 'appservice web config appsettings delete', 'azure.cli.command_modules.appservice.custom#delete_app_settings')
cli_command(__name__, 'appservice web config hostname add', 'azure.cli.command_modules.appservice.custom#add_hostname', exception_handler=ex_handler_factory())
cli_command(__name__, 'appservice web config hostname list', 'azure.cli.command_modules.appservice.custom#list_hostnames')
cli_command(__name__, 'appservice web config hostname delete', 'azure.cli.command_modules.appservice.custom#delete_hostname')
示例#57
0
                     ('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__,
示例#58
0
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

#pylint: disable=unused-import,line-too-long
from azure.cli.core.commands import LongRunningOperation, cli_command
from azure.cli.core.commands.arm import cli_generic_update_command
from azure.cli.core._util import empty_on_404

from ._client_factory import web_client_factory

cli_command(__name__, 'appservice web create', 'azure.cli.command_modules.appservice.custom#create_webapp')
cli_command(__name__, 'appservice web list', 'azure.cli.command_modules.appservice.custom#list_webapp')
cli_command(__name__, 'appservice web show', 'azure.cli.command_modules.appservice.custom#show_webapp', exception_handler=empty_on_404)
cli_command(__name__, 'appservice web delete', 'azure.cli.command_modules.appservice.custom#delete_webapp')
cli_command(__name__, 'appservice web stop', 'azure.cli.command_modules.appservice.custom#stop_webapp')
cli_command(__name__, 'appservice web start', 'azure.cli.command_modules.appservice.custom#start_webapp')
cli_command(__name__, 'appservice web restart', 'azure.cli.command_modules.appservice.custom#restart_webapp')

cli_command(__name__, 'appservice web config update', 'azure.cli.command_modules.appservice.custom#update_site_configs')
cli_command(__name__, 'appservice web config show', 'azure.cli.command_modules.appservice.custom#get_site_configs', exception_handler=empty_on_404)
cli_command(__name__, 'appservice web config appsettings show', 'azure.cli.command_modules.appservice.custom#get_app_settings', exception_handler=empty_on_404)
cli_command(__name__, 'appservice web config appsettings update', 'azure.cli.command_modules.appservice.custom#update_app_settings')
cli_command(__name__, 'appservice web config appsettings delete', 'azure.cli.command_modules.appservice.custom#delete_app_settings')
cli_command(__name__, 'appservice web config hostname add', 'azure.cli.command_modules.appservice.custom#add_hostname')
cli_command(__name__, 'appservice web config hostname list', 'azure.cli.command_modules.appservice.custom#list_hostnames')
cli_command(__name__, 'appservice web config hostname delete', 'azure.cli.command_modules.appservice.custom#delete_hostname')
cli_command(__name__, 'appservice web config container update', 'azure.cli.command_modules.appservice.custom#update_container_settings')
cli_command(__name__, 'appservice web config container delete', 'azure.cli.command_modules.appservice.custom#delete_container_settings')
cli_command(__name__, 'appservice web config container show', 'azure.cli.command_modules.appservice.custom#show_container_settings', exception_handler=empty_on_404)