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


Python six.iteritems方法代码示例

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


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

示例1: remove_empty_facts

# 需要导入模块: from ansible.module_utils import six [as 别名]
# 或者: from ansible.module_utils.six import iteritems [as 别名]
def remove_empty_facts(self, facts=None):
        """ Remove empty facts

            Args:
                facts (dict): facts to clean
        """
        facts_to_remove = []
        for fact, value in iteritems(facts):
            if isinstance(facts[fact], dict):
                facts[fact] = self.remove_empty_facts(facts[fact])
            else:
                if value == "" or value == [""] or value is None:
                    facts_to_remove.append(fact)
        for fact in facts_to_remove:
            del facts[fact]
        return facts 
开发者ID:openshift,项目名称:origin-ci-tool,代码行数:18,代码来源:openshift_facts.py

示例2: get_objects_by_filter

# 需要导入模块: from ansible.module_utils import six [as 别名]
# 或者: from ansible.module_utils.six import iteritems [as 别名]
def get_objects_by_filter(self, operation_name, params):

        def match_filters(filter_params, obj):
            for k, v in iteritems(filter_params):
                if k not in obj or obj[k] != v:
                    return False
            return True

        _, query_params, path_params = _get_user_params(params)
        # copy required params to avoid mutation of passed `params` dict
        url_params = {ParamName.QUERY_PARAMS: dict(query_params), ParamName.PATH_PARAMS: dict(path_params)}

        filters = params.get(ParamName.FILTERS) or {}
        if QueryParams.FILTER not in url_params[ParamName.QUERY_PARAMS] and 'name' in filters:
            # most endpoints only support filtering by name, so remaining `filters` are applied on returned objects
            url_params[ParamName.QUERY_PARAMS][QueryParams.FILTER] = self._stringify_name_filter(filters)

        item_generator = iterate_over_pageable_resource(
            partial(self.send_general_request, operation_name=operation_name), url_params
        )
        return (i for i in item_generator if match_filters(filters, i)) 
开发者ID:CiscoDevNet,项目名称:FTDAnsible,代码行数:23,代码来源:configuration.py

示例3: update

# 需要导入模块: from ansible.module_utils import six [as 别名]
# 或者: from ansible.module_utils.six import iteritems [as 别名]
def update(self, params=None):
        if params:
            for k, v in iteritems(params):
                if self.api_map is not None and k in self.api_map:
                    map_key = self.api_map[k]
                else:
                    map_key = k

                # Handle weird API parameters like `dns.proxy.__iter__` by
                # using a map provided by the module developer
                class_attr = getattr(type(self), map_key, None)
                if isinstance(class_attr, property):
                    # There is a mapped value for the api_map key
                    if class_attr.fset is None:
                        # If the mapped value does not have
                        # an associated setter
                        self._values[map_key] = v
                    else:
                        # The mapped value has a setter
                        setattr(self, map_key, v)
                else:
                    # If the mapped value is not a @property
                    self._values[map_key] = v 
开发者ID:mcgonagle,项目名称:ansible_f5,代码行数:25,代码来源:bigip_remote_syslog.py

示例4: __init__

# 需要导入模块: from ansible.module_utils import six [as 别名]
# 或者: from ansible.module_utils.six import iteritems [as 别名]
def __init__(self, params=None):
        self._values = defaultdict(lambda: None)
        if params:
            for k, v in iteritems(params):
                if self.api_map is not None and k in self.api_map:
                    dict_to_use = self.api_map
                    map_key = self.api_map[k]
                else:
                    dict_to_use = self._values
                    map_key = k

                # Handle weird API parameters like `dns.proxy.__iter__` by
                # using a map provided by the module developer
                class_attr = getattr(type(self), map_key, None)
                if isinstance(class_attr, property):
                    # There is a mapped value for the api_map key
                    if class_attr.fset is None:
                        # If the mapped value does not have an associated setter
                        self._values[map_key] = v
                    else:
                        # The mapped value has a setter
                        setattr(self, map_key, v)
                else:
                    # If the mapped value is not a @property
                    self._values[map_key] = v 
开发者ID:mcgonagle,项目名称:ansible_f5,代码行数:27,代码来源:f5_utils.py

示例5: update

# 需要导入模块: from ansible.module_utils import six [as 别名]
# 或者: from ansible.module_utils.six import iteritems [as 别名]
def update(self, params=None):
        if params:
            for k, v in iteritems(params):
                if self.api_map is not None and k in self.api_map:
                    map_key = self.api_map[k]
                else:
                    map_key = k

                # Handle weird API parameters like `dns.proxy.__iter__` by
                # using a map provided by the module developer
                class_attr = getattr(type(self), map_key, None)
                if isinstance(class_attr, property):
                    # There is a mapped value for the api_map key
                    if class_attr.fset is None:
                        # If the mapped value does not have an associated setter
                        self._values[map_key] = v
                    else:
                        # The mapped value has a setter
                        setattr(self, map_key, v)
                else:
                    # If the mapped value is not a @property
                    self._values[map_key] = v 
开发者ID:mcgonagle,项目名称:ansible_f5,代码行数:24,代码来源:bigip_pool.py

示例6: variables

# 需要导入模块: from ansible.module_utils import six [as 别名]
# 或者: from ansible.module_utils.six import iteritems [as 别名]
def variables(self):
        result = []
        if not self._values['variables']:
            return None
        variables = self._values['variables']
        for variable in variables:
            tmp = dict((str(k), str(v)) for k, v in iteritems(variable))
            if 'encrypted' not in tmp:
                # BIG-IP will inject an 'encrypted' key if you don't provide one.
                # If you don't provide one, then we give you the default 'no', by
                # default.
                tmp['encrypted'] = 'no'
            if 'value' not in tmp:
                tmp['value'] = ''

            # This seems to happen only on 12.0.0
            elif tmp['value'] == 'none':
                tmp['value'] = ''
            result.append(tmp)
        result = sorted(result, key=lambda k: k['name'])
        return result 
开发者ID:mcgonagle,项目名称:ansible_f5,代码行数:23,代码来源:bigip_iapp_service.py

示例7: lists

# 需要导入模块: from ansible.module_utils import six [as 别名]
# 或者: from ansible.module_utils.six import iteritems [as 别名]
def lists(self):
        result = []
        if not self._values['lists']:
            return None
        lists = self._values['lists']
        for list in lists:
            tmp = dict((str(k), str(v)) for k, v in iteritems(list) if k != 'value')
            if 'encrypted' not in list:
                # BIG-IP will inject an 'encrypted' key if you don't provide one.
                # If you don't provide one, then we give you the default 'no', by
                # default.
                tmp['encrypted'] = 'no'
            if 'value' in list:
                if len(list['value']) > 0:
                    # BIG-IP removes empty values entries, so mimic this behavior
                    # for user-supplied values.
                    tmp['value'] = [str(x) for x in list['value']]
            result.append(tmp)
        result = sorted(result, key=lambda k: k['name'])
        return result 
开发者ID:mcgonagle,项目名称:ansible_f5,代码行数:22,代码来源:bigip_iapp_service.py

示例8: raw_triage

# 需要导入模块: from ansible.module_utils import six [as 别名]
# 或者: from ansible.module_utils.six import iteritems [as 别名]
def raw_triage(self, key_string, item, patterns):
        # process dict values
        if isinstance(item, AnsibleMapping):
            return AnsibleMapping(dict((key,self.raw_triage('.'.join([key_string, key]), value, patterns)) for key,value in iteritems(item)))

        # process list values
        elif isinstance(item, AnsibleSequence):
            return AnsibleSequence([self.raw_triage('.'.join([key_string, str(i)]), value, patterns) for i,value in enumerate(item)])

        # wrap values if they match raw_vars pattern
        elif isinstance(item, AnsibleUnicode):
            match = next((pattern for pattern in patterns if re.match(pattern, key_string)), None)
            return wrap_var(item) if match else item

        else:
            return item 
开发者ID:roots,项目名称:trellis,代码行数:18,代码来源:vars.py

示例9: cli_options

# 需要导入模块: from ansible.module_utils import six [as 别名]
# 或者: from ansible.module_utils.six import iteritems [as 别名]
def cli_options(self):
        options = []

        strings = {
            '--connection': 'connection',
            '--private-key': 'private_key_file',
            '--ssh-common-args': 'ssh_common_args',
            '--ssh-extra-args': 'ssh_extra_args',
            '--timeout': 'timeout',
            '--vault-password-file': 'vault_password_file',
            }

        for option,value in iteritems(strings):
            if self._options.get(value, False):
                options.append("{0}='{1}'".format(option, str(self._options.get(value))))

        for inventory in self._options.get('inventory'):
            options.append("--inventory='{}'".format(str(inventory)))

        if self._options.get('ask_vault_pass', False):
            options.append('--ask-vault-pass')

        return ' '.join(options) 
开发者ID:roots,项目名称:trellis,代码行数:25,代码来源:vars.py

示例10: child_to_element

# 需要导入模块: from ansible.module_utils import six [as 别名]
# 或者: from ansible.module_utils.six import iteritems [as 别名]
def child_to_element(module, child, in_type):
    if in_type == 'xml':
        infile = BytesIO(to_bytes(child, errors='surrogate_or_strict'))

        try:
            parser = etree.XMLParser()
            node = etree.parse(infile, parser)
            return node.getroot()
        except etree.XMLSyntaxError as e:
            module.fail_json(msg="Error while parsing child element: %s" % e)
    elif in_type == 'yaml':
        if isinstance(child, string_types):
            return etree.Element(child)
        elif isinstance(child, MutableMapping):
            if len(child) > 1:
                module.fail_json(msg="Can only create children from hashes with one key")

            (key, value) = next(iteritems(child))
            if isinstance(value, MutableMapping):
                children = value.pop('_', None)

                node = etree.Element(key, value)

                if children is not None:
                    if not isinstance(children, list):
                        module.fail_json(msg="Invalid children type: %s, must be list." % type(children))

                    subnodes = children_to_nodes(module, children)
                    node.extend(subnodes)
            else:
                node = etree.Element(key)
                node.text = value
            return node
        else:
            module.fail_json(msg="Invalid child type: %s. Children must be either strings or hashes." % type(child))
    else:
        module.fail_json(msg="Invalid child input type: %s. Type must be either xml or yaml." % in_type) 
开发者ID:cmprescott,项目名称:ansible-xml,代码行数:39,代码来源:xml.py

示例11: is_upsert_operation_supported

# 需要导入模块: from ansible.module_utils import six [as 别名]
# 或者: from ansible.module_utils.six import iteritems [as 别名]
def is_upsert_operation_supported(cls, operations):
        """
        Checks if all operations required for upsert object operation are defined in 'operations'.

        :param operations: specification of the operations supported by model
        :type operations: dict
        :return: True if all criteria required to provide requested called operation are satisfied, otherwise False
        :rtype: bool
        """
        has_edit_op = next((name for name, spec in iteritems(operations) if cls.is_edit_operation(name, spec)), None)
        has_get_list_op = next((name for name, spec in iteritems(operations)
                                if cls.is_get_list_operation(name, spec)), None)
        return has_edit_op and has_get_list_op 
开发者ID:CiscoDevNet,项目名称:FTDAnsible,代码行数:15,代码来源:configuration.py

示例12: get_operation_specs_by_model_name

# 需要导入模块: from ansible.module_utils import six [as 别名]
# 或者: from ansible.module_utils.six import iteritems [as 别名]
def get_operation_specs_by_model_name(self, model_name):
        if model_name not in self._models_operations_specs_cache:
            model_op_specs = self._conn.get_operation_specs_by_model_name(model_name)
            self._models_operations_specs_cache[model_name] = model_op_specs
            for op_name, op_spec in iteritems(model_op_specs):
                self._operation_spec_cache.setdefault(op_name, op_spec)
        return self._models_operations_specs_cache[model_name] 
开发者ID:CiscoDevNet,项目名称:FTDAnsible,代码行数:9,代码来源:configuration.py

示例13: _get_operation_name

# 需要导入模块: from ansible.module_utils import six [as 别名]
# 或者: from ansible.module_utils.six import iteritems [as 别名]
def _get_operation_name(checker, operations):
        return next((op_name for op_name, op_spec in iteritems(operations) if checker(op_name, op_spec)), None) 
开发者ID:CiscoDevNet,项目名称:FTDAnsible,代码行数:4,代码来源:configuration.py

示例14: _get_model_operations

# 需要导入模块: from ansible.module_utils import six [as 别名]
# 或者: from ansible.module_utils.six import iteritems [as 别名]
def _get_model_operations(self, operations):
        model_operations = {}
        for operations_name, params in iteritems(operations):
            model_name = params[OperationField.MODEL_NAME]
            model_operations.setdefault(model_name, {})[operations_name] = params
        return model_operations 
开发者ID:CiscoDevNet,项目名称:FTDAnsible,代码行数:8,代码来源:fdm_swagger_client.py

示例15: _parse_group

# 需要导入模块: from ansible.module_utils import six [as 别名]
# 或者: from ansible.module_utils.six import iteritems [as 别名]
def _parse_group(self, group, data):

        self.inventory.add_group(group)

        if not isinstance(data, dict):
            data = {'hosts': data}
        # is not those subkeys, then simplified syntax, host with vars
        elif not any(k in data for k in ('hosts', 'vars', 'children')):
            data = {'hosts': [group], 'vars': data}

        if 'hosts' in data:
            if not isinstance(data['hosts'], list):
                raise AnsibleError("You defined a group '%s' with bad data for the host list:\n %s" % (group, data))

            for hostname in data['hosts']:
                self._hosts.add(hostname)
                self.inventory.add_host(hostname, group)

        if 'vars' in data:
            if not isinstance(data['vars'], dict):
                raise AnsibleError("You defined a group '%s' with bad data for variables:\n %s" % (group, data))

            for k, v in iteritems(data['vars']):
                self.inventory.set_variable(group, k, v)

        if group != '_meta' and isinstance(data, dict) and 'children' in data:
            for child_name in data['children']:
                self.inventory.add_group(child_name)
                self.inventory.add_child(group, child_name) 
开发者ID:AlanCoding,项目名称:Ansible-inventory-file-examples,代码行数:31,代码来源:fast_script.py


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