예제 #1
0
        def keyvault_command_handler(command_args):
            from azure.cli.core.commands.client_factory import resolve_client_arg_name
            from azure.cli.core.profiles import ResourceType
            from azure.cli.core.util import get_arg_list, poller_classes
            from msrest.paging import Paged

            op = get_op_handler()
            op_args = get_arg_list(op)
            command_type = merged_kwargs.get('command_type', None)
            client_factory = command_type.settings.get('client_factory', None) if command_type \
                else merged_kwargs.get('client_factory', None)

            client_arg_name = resolve_client_arg_name(
                operations_tmpl.format(method_name), kwargs)
            if client_arg_name in op_args:
                client = client_factory(self.command_loader.cli_ctx,
                                        command_args)
                command_args[client_arg_name] = client
            if 'cmd' not in op_args:
                command_args.pop('cmd')

            try:
                if command_type.settings.get(
                        'resource_type'
                ) == ResourceType.DATA_KEYVAULT_ADMINISTRATION_BACKUP:
                    abandoned_args = ['identifier', 'vault_base_url']
                    for arg in abandoned_args:
                        if arg in command_args:
                            command_args.pop(arg)

                result = op(**command_args)
                # apply results transform if specified
                transform_result = merged_kwargs.get('transform', None)
                if transform_result:
                    return _encode_hex(transform_result(
                        result, **command_args))

                # otherwise handle based on return type of results
                if isinstance(result, poller_classes()):
                    return _encode_hex(
                        LongRunningOperation(
                            self.command_loader.cli_ctx,
                            'Starting {}'.format(name))(result))
                if isinstance(result, Paged):
                    try:
                        return _encode_hex(list(result))
                    except TypeError:
                        # TODO: Workaround for an issue in either KeyVault server-side or msrest
                        # See https://github.com/Azure/autorest/issues/1309
                        return []
                return _encode_hex(result)
            except Exception as ex:  # pylint: disable=broad-except
                if name == 'show':
                    # show_exception_handler needs to be called before the keyvault_exception_handler
                    from azure.cli.core.commands.arm import show_exception_handler
                    try:
                        show_exception_handler(ex)
                    except Exception:  # pylint: disable=broad-except
                        pass
                return keyvault_exception_handler(self.command_loader, ex)
예제 #2
0
    def __call__(self, result):
        from msrest.pipeline import ClientRawResponse

        if isinstance(result, poller_classes()):
            # most deployment operations return a poller
            result = super(DeploymentOutputLongRunningOperation, self).__call__(result)
            outputs = result.properties.outputs
            return {key: val['value'] for key, val in outputs.items()} if outputs else {}
        elif isinstance(result, ClientRawResponse):
            # --no-wait returns a ClientRawResponse
            return None

        # --validate returns a 'normal' response
        return result
예제 #3
0
    def __call__(self, result):
        '''
        Function call operator which will do polling (if necessary)
        and then transforms the result.
        '''

        if result is None:
            return None

        from azure.cli.core.util import poller_classes
        if isinstance(result, poller_classes()):
            # Poll for long-running operation result result by calling base class
            result = super(LongRunningOperationResultTransform, self).__call__(result)

        # Apply transform function
        return self._transform_func(result)
예제 #4
0
    def __call__(self, result):
        '''
        Function call operator which will do polling (if necessary)
        and then transforms the result.
        '''

        if result is None:
            return None

        from azure.cli.core.util import poller_classes
        if isinstance(result, poller_classes()):
            # Poll for long-running operation result result by calling base class
            result = super(LongRunningOperationResultTransform, self).__call__(result)

        # Apply transform function
        return self._transform_func(result)
예제 #5
0
        def keyvault_command_handler(command_args):
            from azure.cli.core.util import get_arg_list
            from azure.cli.core.commands.client_factory import resolve_client_arg_name
            from msrest.paging import Paged
            from azure.cli.core.util import poller_classes

            op = get_op_handler()
            op_args = get_arg_list(op)
            command_type = merged_kwargs.get('command_type', None)
            client_factory = command_type.settings.get('client_factory', None) if command_type \
                else merged_kwargs.get('client_factory', None)

            client_arg_name = resolve_client_arg_name(operations_tmpl.format(method_name), kwargs)
            if client_arg_name in op_args:
                client = client_factory(self.command_loader.cli_ctx, command_args)
                command_args[client_arg_name] = client
            if 'cmd' not in op_args:
                command_args.pop('cmd')
            try:
                result = op(**command_args)
                # apply results transform if specified
                transform_result = merged_kwargs.get('transform', None)
                if transform_result:
                    return _encode_hex(transform_result(result))

                # otherwise handle based on return type of results
                if isinstance(result, poller_classes()):
                    return _encode_hex(
                        LongRunningOperation(self.command_loader.cli_ctx, 'Starting {}'.format(name))(result))
                if isinstance(result, Paged):
                    try:
                        return _encode_hex(list(result))
                    except TypeError:
                        # TODO: Workaround for an issue in either KeyVault server-side or msrest
                        # See https://github.com/Azure/autorest/issues/1309
                        return []
                return _encode_hex(result)
            except Exception as ex:  # pylint: disable=broad-except
                if name == 'show':
                    # show_exception_handler needs to be called before the keyvault_exception_handler
                    from azure.cli.core.commands.arm import show_exception_handler
                    try:
                        show_exception_handler(ex)
                    except Exception:  # pylint: disable=broad-except
                        pass
                return keyvault_exception_handler(self.command_loader, ex)
예제 #6
0
        def keyvault_command_handler(command_args):
            from azure.cli.core.util import get_arg_list
            from azure.cli.core.commands.client_factory import resolve_client_arg_name
            from msrest.paging import Paged
            from azure.cli.core.util import poller_classes

            op = get_op_handler()
            op_args = get_arg_list(op)
            command_type = merged_kwargs.get('command_type', None)
            client_factory = command_type.settings.get('client_factory', None) if command_type \
                else merged_kwargs.get('client_factory', None)

            client_arg_name = resolve_client_arg_name(
                operations_tmpl.format(method_name), kwargs)
            if client_arg_name in op_args:
                client = client_factory(self.command_loader.cli_ctx,
                                        command_args)
                command_args[client_arg_name] = client
            try:
                result = op(**command_args)
                # apply results transform if specified
                transform_result = merged_kwargs.get('transform', None)
                if transform_result:
                    return _encode_hex(transform_result(result))

                # otherwise handle based on return type of results
                if isinstance(result, poller_classes()):
                    return _encode_hex(
                        LongRunningOperation(
                            self.command_loader.cli_ctx,
                            'Starting {}'.format(name))(result))
                elif isinstance(result, Paged):
                    try:
                        return _encode_hex(list(result))
                    except TypeError:
                        # TODO: Workaround for an issue in either KeyVault server-side or msrest
                        # See https://github.com/Azure/autorest/issues/1309
                        return []
                else:
                    return _encode_hex(result)
            except Exception as ex:  # pylint: disable=broad-except
                return keyvault_exception_handler(ex)
예제 #7
0
def _is_poller(obj):
    # Since loading msrest is expensive, we avoid it until we have to
    if obj.__class__.__name__ in ['AzureOperationPoller', 'LROPoller']:
        from azure.cli.core.util import poller_classes
        return isinstance(obj, poller_classes())
    return False
예제 #8
0
def _is_poller(obj):
    # Since loading msrest is expensive, we avoid it until we have to
    if obj.__class__.__name__ in ['AzureOperationPoller', 'LROPoller']:
        return isinstance(obj, poller_classes())
    return False