Martin Polednik has uploaded a new change for review. Change subject: vmDevices: introduce VmDeviceContainer ......................................................................
vmDevices: introduce VmDeviceContainer EARLY WORK IN PROGRESS: VmDeviceContainer is structure that will allow us to store devices as a class instances while keeping backwards compatibility with old self.conf['devices'] Change-Id: I65debd35115da078df0c0cb6f50c57feb984c5a3 Signed-off-by: Martin Polednik <mpole...@redhat.com> --- M vdsm/vm.py 1 file changed, 33 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/38/21138/1 diff --git a/vdsm/vm.py b/vdsm/vm.py index 5ae54d7..36cdbb1 100644 --- a/vdsm/vm.py +++ b/vdsm/vm.py @@ -1727,6 +1727,39 @@ return m +class VmDeviceContainer(dict): + @property + def legacy(self): + """ + Return list of device dicts that represents backwards-compatible + self.conf['devices'] + + [..., {..., 'type': 'disk', ...}, ...] + """ + deviceList = [] + for key in self.keys(): + for device in self[key]: + # loop through devices __slots__ and return all set attributes + deviceList.append(dict((attr, getattr(device, attr)) + for attr in device.__slots__ + if hasattr(device, attr))) + + return deviceList + + def restoreLegacy(self, state): + """ + Reconstruct container using old self.conf['devices'] structure of + + [..., {..., 'type': 'disk', ...}, ...] + to + + VmDeviceContainer[DISK_DEVICES] = + [..., {..., 'type': 'disk', ...}, ...] + """ + for device in state: + self[device['type']] = device + + class Vm(object): """ Used for abstracting communication between various parts of the -- To view, visit http://gerrit.ovirt.org/21138 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I65debd35115da078df0c0cb6f50c57feb984c5a3 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Martin Polednik <mpole...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches