From a5a459840a91689c5b388105efb66be94c106f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Tue, 20 Jun 2017 00:00:35 +0200 Subject: [PATCH] storage: make Volumes sortable But do not fetch any additional info just for this purpose. --- qubesadmin/storage.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/qubesadmin/storage.py b/qubesadmin/storage.py index fb32fd2..5a72719 100644 --- a/qubesadmin/storage.py +++ b/qubesadmin/storage.py @@ -93,6 +93,16 @@ class Volume(object): return self.pool == other.pool and self.vid == other.vid return NotImplemented + def __lt__(self, other): + # pylint: disable=protected-access + if isinstance(other, Volume): + if self._vm and other._vm: + return (self._vm, self._vm_name) < (other._vm, other._vm_name) + elif self._vid and other._vid: + return (self._pool, self._vid) < (other._pool, other._vid) + return NotImplemented + + @property def name(self): '''per-VM volume name, if available'''