storage: make Volumes sortable

But do not fetch any additional info just for this purpose.
This commit is contained in:
Marek Marczykowski-Górecki 2017-06-20 00:00:35 +02:00
parent e94bdca206
commit a5a459840a
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -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'''