compile.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:netscaler-ansible-modules 作者: citrix 项目源码 文件源码
def produce_module_arguments_from_json_schema(json_doc, skip_attrs):
    module_arguments = list()
    for property in json_doc:
        # Skip readonly attributes
        if property['readonly'] is True:
            continue

        # Skip attributes in skip_attrs
        if property['name'] in skip_attrs:
            continue

        key = property['name']
        entry = {}
        entry['key'] = key
        entry['transforms'] = []

        # Convert json type to ansible module argument type declaration

        entry['type'] = property['type']

        # Add choices if applicable
        if 'choices' in property:
            choice_set = frozenset([choice.lower() for choice in property['choices']])
            if choice_set == frozenset(['yes', 'no']):
                # Overwrite type to bool
                entry['type'] = 'bool'
                entry['transforms'] = ['bool_yes_no']
            elif choice_set == frozenset(['on', 'off']):
                # Overwrite type to bool
                entry['type'] = 'bool'
                entry['transforms'] = ['bool_on_off']
            elif choice_set == frozenset(['enabled', 'disabled']):
                entry['choices'] = ['enabled', 'disabled']
            else:
                entry['choices'] = property['choices']

        # Add to ansible modules argument
        module_arguments.append(entry)

    return module_arguments
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号