cloudmesh-common.cloudmesh.common.DictList

Module Contents

Classes

DictList

A class to convert lists of dicts to dicts.

class cloudmesh-common.cloudmesh.common.DictList.DictList(entries=None, key='name', position='x')

Bases: dict

A class to convert lists of dicts to dicts.

Example:

data = [ {“name”: “vm1”, “status”: “on”}, {“name”: “vm2”, “status”: “on”}, {“name”: “vm3”, “status”: “on”}, {“name”: “vm4”, “status”: “on”}, ]

d = DictList(data) pprint (d)

# {‘vm1’: {‘name’: ‘vm1’, ‘status’: ‘on’, ‘x’: 0}, # ‘vm2’: {‘name’: ‘vm2’, ‘status’: ‘on’, ‘x’: 1}, # ‘vm3’: {‘name’: ‘vm3’, ‘status’: ‘on’, ‘x’: 2}, # ‘vm4’: {‘name’: ‘vm4’, ‘status’: ‘on’, ‘x’: 3}}

print (d[‘vm1’]) # {‘name’: ‘vm1’, ‘status’: ‘on’, ‘x’: 0} # print (d.list()) # [{‘name’: ‘vm1’, ‘status’: ‘on’, ‘x’: 0}, # {‘name’: ‘vm2’, ‘status’: ‘on’, ‘x’: 1}, # {‘name’: ‘vm3’, ‘status’: ‘on’, ‘x’: 2}, # {‘name’: ‘vm4’, ‘status’: ‘on’, ‘x’: 3}]

list(self)

Lists the entries

Returns

cloudmesh-common.cloudmesh.common.DictList.data