本文整理汇总了Python中salt.utils.odict.OrderedDict.setdefault方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.setdefault方法的具体用法?Python OrderedDict.setdefault怎么用?Python OrderedDict.setdefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类salt.utils.odict.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.setdefault方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_vms_per_type
# 需要导入模块: from salt.utils.odict import OrderedDict [as 别名]
# 或者: from salt.utils.odict.OrderedDict import setdefault [as 别名]
def get_vms_per_type(target):
'''Return all vms indexed by virt_type for a special target'''
all_targets = OrderedDict()
for virt_type in VIRT_TYPES:
per_type = all_targets.setdefault(virt_type, set())
all_infos = get_targets_and_vms_for_virt_type(virt_type)
for vmname in all_infos.get(target, []):
per_type.add(vmname)
for i in [a for a in all_targets]:
all_targets[i] = [a for a in all_targets[i]]
return all_targets
示例2: element
# 需要导入模块: from salt.utils.odict import OrderedDict [as 别名]
# 或者: from salt.utils.odict.OrderedDict import setdefault [as 别名]
def element(self, root=None, abspath=None, **kwargs):
'''
kwargs contain extra information for custom methods.
This method must return a valid empty object if no vars are passed
to allow introspection to create patterns.
:param root:
:param abspath:
'''
if root is None and abspath is None:
root = os.path.abspath('.')
abspath = os.path.abspath('.')
relpath = os.path.relpath(abspath, root)
try:
element = self._elements.get(relpath, OrderedDict())
except AttributeError:
element = OrderedDict()
if not element:
for field in PATHINFO_FIELDS:
element.setdefault(field, '')
element['saltenv'] = kwargs.get('saltenv', 'base')
element['relpath'] = relpath
element['abspath'] = abspath
element['is_pillar'] = kwargs.get('is_pillar', False)
cachedir = kwargs.get('cachedir', '')
if cachedir and os.path.commonprefix([abspath, cachedir]) == cachedir:
element['cache_root'] = root
else:
element['file_root'] = root
element_hook = kwargs.get('_element_hook', None)
if element_hook:
element = element_hook(self, element, **kwargs)
return element
示例3: get_vms
# 需要导入模块: from salt.utils.odict import OrderedDict [as 别名]
# 或者: from salt.utils.odict.OrderedDict import setdefault [as 别名]
def get_vms():
'''Return all vms indexed by targets'''
data = OrderedDict()
for virt_type in VIRT_TYPES:
all_infos = get_targets_and_vms_for_virt_type(virt_type)
for t in all_infos:
target = data.setdefault(t, {})
vms = {}
vts = set()
for vmname in all_infos[t]:
vms.setdefault(vmname, virt_type)
vts.add(virt_type)
target['virt_types'] = [a for a in vts]
target['vms'] = vms
return data