本文整理汇总了Python中ansible.parsing.mod_args.ModuleArgsParser类的典型用法代码示例。如果您正苦于以下问题:Python ModuleArgsParser类的具体用法?Python ModuleArgsParser怎么用?Python ModuleArgsParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ModuleArgsParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_local_action_string
def test_local_action_string(self):
m = ModuleArgsParser(dict(local_action='copy src=a dest=b'))
mod, args, connection = m.parse()
self._debug(mod, args, connection)
self.assertEqual(mod, 'copy')
self.assertEqual(args, dict(src='a', dest='b', _local_action=True))
self.assertIs(connection, 'local')
示例2: test_action_with_complex_and_complex_args
def test_action_with_complex_and_complex_args(self):
m = ModuleArgsParser(dict(action=dict(module="copy", args=dict(src="a", dest="b"))))
mod, args, to = m.parse()
self._debug(mod, args, to)
self.assertEqual(mod, "copy")
self.assertEqual(args, dict(src="a", dest="b"))
self.assertIsNone(to)
示例3: munge
def munge(self, ds):
'''
tasks are especially complex arguments so need pre-processing.
keep it short.
'''
assert isinstance(ds, dict)
# the new, cleaned datastructure, which will have legacy
# items reduced to a standard structure suitable for the
# attributes of the task class
new_ds = dict()
# use the args parsing class to determine the action, args,
# and the delegate_to value from the various possible forms
# supported as legacy
args_parser = ModuleArgsParser()
(action, args, delegate_to) = args_parser.parse(ds)
new_ds['action'] = action
new_ds['args'] = args
new_ds['delegate_to'] = delegate_to
for (k,v) in ds.iteritems():
if k in ('action', 'local_action', 'args', 'delegate_to') or k == action:
# we don't want to re-assign these values, which were
# determined by the ModuleArgsParser() above
continue
elif "with_%s" % k in lookup_finder:
self._munge_loop(ds, new_ds, k, v)
else:
new_ds[k] = v
return new_ds
示例4: test_complex_args
def test_complex_args(self):
m = ModuleArgsParser(dict(copy=dict(src='a', dest='b')))
mod, args, to = m.parse()
self._debug(mod, args, to)
self.assertEqual(mod, 'copy')
self.assertEqual(args, dict(src='a', dest='b'))
self.assertIsNone(to)
示例5: normalize_task_v2
def normalize_task_v2(task):
'''Ensures tasks have an action key and strings are converted to python objects'''
result = dict()
mod_arg_parser = ModuleArgsParser(task)
action, arguments, result['delegate_to'] = mod_arg_parser.parse()
# denormalize shell -> command conversion
if '_use_shell' in arguments:
action = 'shell'
del(arguments['_use_shell'])
for (k, v) in list(task.items()):
if k in ('action', 'local_action', 'args', 'delegate_to') or k == action:
# we don't want to re-assign these values, which were
# determined by the ModuleArgsParser() above
continue
else:
result[k] = v
result['action'] = dict(module=action)
if '_raw_params' in arguments:
result['action']['module_arguments'] = arguments['_raw_params'].split()
del(arguments['_raw_params'])
else:
result['action']['module_arguments'] = list()
result['action'].update(arguments)
return result
示例6: test_action_with_complex
def test_action_with_complex(self):
m = ModuleArgsParser(dict(action=dict(module='copy', src='a', dest='b')))
mod, args, to = m.parse()
self._debug(mod, args, to)
self.assertEqual(mod, 'copy')
self.assertEqual(args, dict(src='a', dest='b'))
self.assertIsNone(to)
示例7: test_basic_shell
def test_basic_shell(self):
m = ModuleArgsParser(dict(shell="echo hi"))
mod, args, to = m.parse()
self._debug(mod, args, to)
self.assertEqual(mod, "command")
self.assertEqual(args, dict(_raw_params="echo hi", _uses_shell=True))
self.assertIsNone(to)
示例8: test_local_action_string
def test_local_action_string(self):
m = ModuleArgsParser(dict(local_action="copy src=a dest=b"))
mod, args, connection = m.parse()
self._debug(mod, args, connection)
self.assertEqual(mod, "copy")
self.assertEqual(args, dict(src="a", dest="b"))
self.assertIs(connection, "local")
示例9: test_basic_command
def test_basic_command(self):
m = ModuleArgsParser(dict(command="echo hi"))
mod, args, to = m.parse()
self._debug(mod, args, to)
self.assertEqual(mod, "command")
self.assertEqual(args, dict(_raw_params="echo hi"))
self.assertIsNone(to)
示例10: test_shell_with_modifiers
def test_shell_with_modifiers(self):
m = ModuleArgsParser(dict(shell="/bin/foo creates=/tmp/baz removes=/tmp/bleep"))
mod, args, to = m.parse()
self._debug(mod, args, to)
self.assertEqual(mod, "command")
self.assertEqual(args, dict(creates="/tmp/baz", removes="/tmp/bleep", _raw_params="/bin/foo", _uses_shell=True))
self.assertIsNone(to)
示例11: test_normal_usage
def test_normal_usage(self):
m = ModuleArgsParser(dict(copy="src=a dest=b"))
mod, args, to = m.parse()
self._debug(mod, args, to)
self.assertEqual(mod, "copy")
self.assertEqual(args, dict(src="a", dest="b"))
self.assertIsNone(to)
示例12: test_local_action_string
def test_local_action_string(self):
m = ModuleArgsParser(dict(local_action='copy src=a dest=b'))
mod, args, delegate_to = m.parse()
self._debug(mod, args, delegate_to)
self.assertEqual(mod, 'copy')
self.assertEqual(args, dict(src='a', dest='b'))
self.assertIs(delegate_to, 'localhost')
示例13: test_action_with_complex_and_complex_args
def test_action_with_complex_and_complex_args(self):
m = ModuleArgsParser(dict(action=dict(module='copy', args=dict(src='a', dest='b'))))
mod, args, to = m.parse()
self._debug(mod, args, to)
assert mod == 'copy'
assert args == dict(src='a', dest='b')
assert to is None
示例14: test_complex_args
def test_complex_args(self):
m = ModuleArgsParser(dict(copy=dict(src='a', dest='b')))
mod, args, to = m.parse()
self._debug(mod, args, to)
assert mod, 'copy'
assert args, dict(src='a', dest='b')
assert to is None
示例15: test_normal_usage
def test_normal_usage(self):
m = ModuleArgsParser(dict(copy='src=a dest=b'))
mod, args, to = m.parse()
self._debug(mod, args, to)
assert mod, 'copy'
assert args, dict(src='a', dest='b')
assert to is None