本文整理汇总了Python中salt.utils.odict.OrderedDict.append方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.append方法的具体用法?Python OrderedDict.append怎么用?Python OrderedDict.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类salt.utils.odict.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.append方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list_vms
# 需要导入模块: from salt.utils.odict import OrderedDict [as 别名]
# 或者: from salt.utils.odict.OrderedDict import append [as 别名]
def list_vms(search=None, sort=None, order='uuid,type,ram,state,alias', keyed=True):
'''
Return a list of VMs
search : string
vmadm filter property
sort : string
vmadm sort (-s) property
order : string
vmadm order (-o) property -- Default: uuid,type,ram,state,alias
keyed : boolean
specified if the output should be an array (False) or dict (True)
For a dict the key is the first item from the order parameter.
Note: If key is not unique last vm wins.
CLI Example:
.. code-block:: bash
salt '*' vmadm.list
salt '*' vmadm.list order=alias,ram,cpu_cap sort=-ram,-cpu_cap
salt '*' vmadm.list search='type=KVM'
'''
ret = {}
vmadm = _check_vmadm()
# vmadm list [-p] [-H] [-o field,...] [-s field,...] [field=value ...]
cmd = '{vmadm} list -p -H {order} {sort} {search}'.format(
vmadm=vmadm,
order='-o {0}'.format(order) if order else '',
sort='-s {0}'.format(sort) if sort else '',
search=search if search else ''
)
res = __salt__['cmd.run_all'](cmd)
retcode = res['retcode']
result = OrderedDict() if keyed else []
if retcode != 0:
ret['Error'] = res['stderr'] if 'stderr' in res else _exit_status(retcode)
return ret
fields = order.split(',')
for vm in res['stdout'].splitlines():
vm_data = OrderedDict()
vm = vm.split(':')
if keyed:
for field in fields:
if fields.index(field) == 0:
continue
vm_data[field.strip()] = vm[fields.index(field)].strip()
result[vm[0]] = vm_data
else:
if len(vm) > 1:
for field in fields:
vm_data[field.strip()] = vm[fields.index(field)].strip()
else:
vm_data = vm[0]
result.append(vm_data)
return result