本文整理汇总了Python中ansible.module_utils.network.NetworkModule.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Python NetworkModule.disconnect方法的具体用法?Python NetworkModule.disconnect怎么用?Python NetworkModule.disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ansible.module_utils.network.NetworkModule
的用法示例。
在下文中一共展示了NetworkModule.disconnect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from ansible.module_utils.network import NetworkModule [as 别名]
# 或者: from ansible.module_utils.network.NetworkModule import disconnect [as 别名]
def main():
spec = dict(
# { command: <str>, output: <str>, prompt: <str>, response: <str> }
commands=dict(type='list', required=True),
wait_for=dict(type='list', aliases=['waitfor']),
match=dict(default='all', choices=['any', 'all']),
retries=dict(default=10, type='int'),
interval=dict(default=1, type='int')
)
module = NetworkModule(argument_spec=spec,
supports_check_mode=True)
commands = list(parse_commands(module))
conditionals = module.params['wait_for'] or list()
warnings = list()
runner = CommandRunner(module)
try:
# This tries to detect command mode.
runner.add_command('tmsh')
runner.run()
shell = "bash"
except NetworkError:
shell = "tmsh"
# Resets the runner because raised exceptions do not remove the
# erroneous commands
module.disconnect()
runner.commands = []
runner.module.cli._commands = []
for cmd in commands:
cmd = strip_tmsh_prefix(cmd)
if module.check_mode and not is_config_mode_command(cmd):
warnings.append('only show or list commands are supported when '
'using check mode, not executing `%s`'
% cmd['command'])
else:
if is_config_mode_command(cmd):
module.fail_json(msg='bigip_command does not support running '
'config mode commands. Please use '
'bigip_config instead')
try:
if shell == 'tmsh':
disable_pager = dict(
output=None,
command='modify cli preference pager disabled'
)
runner.add_command(**disable_pager)
runner.add_command(**cmd)
else:
disable_pager = dict(
output=None,
command='tmsh modify cli preference pager disabled'
)
cmd['command'] = 'tmsh ' + cmd['command']
runner.add_command(**disable_pager)
runner.add_command(**cmd)
except AddCommandError:
exc = get_exception()
warnings.append('duplicate command detected: %s' % cmd)
try:
for item in conditionals:
runner.add_conditional(item)
except AddConditionError:
exc = get_exception()
module.fail_json(msg=str(exc), condition=exc.condition)
runner.retries = module.params['retries']
runner.interval = module.params['interval']
runner.match = module.params['match']
try:
runner.run()
except FailedConditionsError:
exc = get_exception()
module.fail_json(msg=str(exc), failed_conditions=exc.failed_conditions)
except FailedConditionalError:
exc = get_exception()
module.fail_json(msg=str(exc), failed_conditional=exc.failed_conditional)
except NetworkError:
exc = get_exception()
module.fail_json(msg=str(exc), **exc.kwargs)
result = dict(changed=False)
result['stdout'] = list()
for cmd in commands:
try:
output = runner.get_command(cmd['command'], cmd.get('output'))
except ValueError:
output = 'command not executed due to check_mode, see warnings'
#.........这里部分代码省略.........