当前位置: 首页>>代码示例>>Python>>正文


Python ModuleArgsParser.parse方法代码示例

本文整理汇总了Python中ansible.parsing.mod_args.ModuleArgsParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleArgsParser.parse方法的具体用法?Python ModuleArgsParser.parse怎么用?Python ModuleArgsParser.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ansible.parsing.mod_args.ModuleArgsParser的用法示例。


在下文中一共展示了ModuleArgsParser.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_multiple_actions

# 需要导入模块: from ansible.parsing.mod_args import ModuleArgsParser [as 别名]
# 或者: from ansible.parsing.mod_args.ModuleArgsParser import parse [as 别名]
    def test_multiple_actions(self):
        args_dict = {'ping': 'data=hi', 'shell': 'echo hi'}
        m = ModuleArgsParser(args_dict)
        with pytest.raises(AnsibleParserError) as err:
            m.parse()

        assert err.value.args[0].startswith("conflicting action statements: ")
        conflicts = set(err.value.args[0][len("conflicting action statements: "):].split(', '))
        assert conflicts == set(('ping', 'shell'))
开发者ID:awiddersheim,项目名称:ansible,代码行数:11,代码来源:test_mod_args.py

示例2: test_local_action_string

# 需要导入模块: from ansible.parsing.mod_args import ModuleArgsParser [as 别名]
# 或者: from ansible.parsing.mod_args.ModuleArgsParser import parse [as 别名]
 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')
开发者ID:JaredPennella,项目名称:DevOps_Script,代码行数:9,代码来源:test_mod_args.py

示例3: test_action_with_complex_and_complex_args

# 需要导入模块: from ansible.parsing.mod_args import ModuleArgsParser [as 别名]
# 或者: from ansible.parsing.mod_args.ModuleArgsParser import parse [as 别名]
 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)
开发者ID:thebeefcake,项目名称:masterless,代码行数:9,代码来源:test_mod_args.py

示例4: munge

# 需要导入模块: from ansible.parsing.mod_args import ModuleArgsParser [as 别名]
# 或者: from ansible.parsing.mod_args.ModuleArgsParser import parse [as 别名]
    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
开发者ID:conlini,项目名称:frozen-ansible,代码行数:36,代码来源:task.py

示例5: test_normal_usage

# 需要导入模块: from ansible.parsing.mod_args import ModuleArgsParser [as 别名]
# 或者: from ansible.parsing.mod_args.ModuleArgsParser import parse [as 别名]
 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)
开发者ID:thebeefcake,项目名称:masterless,代码行数:9,代码来源:test_mod_args.py

示例6: test_action_with_complex

# 需要导入模块: from ansible.parsing.mod_args import ModuleArgsParser [as 别名]
# 或者: from ansible.parsing.mod_args.ModuleArgsParser import parse [as 别名]
 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)
开发者ID:2ndQuadrant,项目名称:ansible,代码行数:9,代码来源:test_mod_args.py

示例7: test_complex_args

# 需要导入模块: from ansible.parsing.mod_args import ModuleArgsParser [as 别名]
# 或者: from ansible.parsing.mod_args.ModuleArgsParser import parse [as 别名]
 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)
开发者ID:2ndQuadrant,项目名称:ansible,代码行数:9,代码来源:test_mod_args.py

示例8: normalize_task_v2

# 需要导入模块: from ansible.parsing.mod_args import ModuleArgsParser [as 别名]
# 或者: from ansible.parsing.mod_args.ModuleArgsParser import parse [as 别名]
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
开发者ID:cloudnull,项目名称:ansible-lint,代码行数:31,代码来源:utils.py

示例9: test_basic_shell

# 需要导入模块: from ansible.parsing.mod_args import ModuleArgsParser [as 别名]
# 或者: from ansible.parsing.mod_args.ModuleArgsParser import parse [as 别名]
 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)
开发者ID:thebeefcake,项目名称:masterless,代码行数:9,代码来源:test_mod_args.py

示例10: test_local_action_string

# 需要导入模块: from ansible.parsing.mod_args import ModuleArgsParser [as 别名]
# 或者: from ansible.parsing.mod_args.ModuleArgsParser import parse [as 别名]
 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")
开发者ID:thebeefcake,项目名称:masterless,代码行数:9,代码来源:test_mod_args.py

示例11: test_shell_with_modifiers

# 需要导入模块: from ansible.parsing.mod_args import ModuleArgsParser [as 别名]
# 或者: from ansible.parsing.mod_args.ModuleArgsParser import parse [as 别名]
 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)
开发者ID:thebeefcake,项目名称:masterless,代码行数:9,代码来源:test_mod_args.py

示例12: test_basic_command

# 需要导入模块: from ansible.parsing.mod_args import ModuleArgsParser [as 别名]
# 或者: from ansible.parsing.mod_args.ModuleArgsParser import parse [as 别名]
 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)
开发者ID:thebeefcake,项目名称:masterless,代码行数:9,代码来源:test_mod_args.py

示例13: test_local_action_string

# 需要导入模块: from ansible.parsing.mod_args import ModuleArgsParser [as 别名]
# 或者: from ansible.parsing.mod_args.ModuleArgsParser import parse [as 别名]
 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')
开发者ID:2ndQuadrant,项目名称:ansible,代码行数:9,代码来源:test_mod_args.py

示例14: test_action_with_complex_and_complex_args

# 需要导入模块: from ansible.parsing.mod_args import ModuleArgsParser [as 别名]
# 或者: from ansible.parsing.mod_args.ModuleArgsParser import parse [as 别名]
    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
开发者ID:awiddersheim,项目名称:ansible,代码行数:10,代码来源:test_mod_args.py

示例15: test_complex_args

# 需要导入模块: from ansible.parsing.mod_args import ModuleArgsParser [as 别名]
# 或者: from ansible.parsing.mod_args.ModuleArgsParser import parse [as 别名]
    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
开发者ID:awiddersheim,项目名称:ansible,代码行数:10,代码来源:test_mod_args.py


注:本文中的ansible.parsing.mod_args.ModuleArgsParser.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。