Merge pull request #492 from mwhudson/fsmodel-tweaks
filesystem model tweaks
This commit is contained in:
commit
fd7a56a8b5
|
@ -75,7 +75,7 @@ def fsobj(typ):
|
||||||
c.__attrs_post_init__ = _set_backlinks
|
c.__attrs_post_init__ = _set_backlinks
|
||||||
c.type = attributes.const(typ)
|
c.type = attributes.const(typ)
|
||||||
c.id = attributes.idfield(typ)
|
c.id = attributes.idfield(typ)
|
||||||
c._m = attr.ib(default=None)
|
c._m = attr.ib(repr=None, default=None)
|
||||||
c = attr.s(cmp=False)(c)
|
c = attr.s(cmp=False)(c)
|
||||||
return c
|
return c
|
||||||
return wrapper
|
return wrapper
|
||||||
|
@ -92,6 +92,17 @@ def dependencies(obj):
|
||||||
yield from v
|
yield from v
|
||||||
|
|
||||||
|
|
||||||
|
def reverse_dependencies(obj):
|
||||||
|
for f in attr.fields(type(obj)):
|
||||||
|
if not f.metadata.get('is_backlink', False):
|
||||||
|
continue
|
||||||
|
v = getattr(obj, f.name)
|
||||||
|
if isinstance(v, (list, set)):
|
||||||
|
yield from v
|
||||||
|
elif v is not None:
|
||||||
|
yield v
|
||||||
|
|
||||||
|
|
||||||
@attr.s(cmp=False)
|
@attr.s(cmp=False)
|
||||||
class RaidLevel:
|
class RaidLevel:
|
||||||
name = attr.ib()
|
name = attr.ib()
|
||||||
|
@ -243,6 +254,12 @@ class attributes:
|
||||||
metadata['backlink'] = backlink
|
metadata['backlink'] = backlink
|
||||||
return attr.ib(metadata=metadata)
|
return attr.ib(metadata=metadata)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def backlink(*, default=None):
|
||||||
|
return attr.ib(
|
||||||
|
init=False, repr=False, default=default,
|
||||||
|
metadata={'is_backlink': True})
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def const(value):
|
def const(value):
|
||||||
return attr.ib(default=value)
|
return attr.ib(default=value)
|
||||||
|
@ -365,9 +382,9 @@ class _Formattable(ABC):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# Filesystem
|
# Filesystem
|
||||||
_fs = attr.ib(init=False, default=None, repr=False)
|
_fs = attributes.backlink()
|
||||||
# Raid or LVM_VolGroup for now, but one day ZPool, BCache...
|
# Raid or LVM_VolGroup for now, but one day ZPool, BCache...
|
||||||
_constructed_device = attr.ib(init=False, default=None, repr=False)
|
_constructed_device = attributes.backlink()
|
||||||
|
|
||||||
def _is_entirely_used(self):
|
def _is_entirely_used(self):
|
||||||
return self._fs is not None or self._constructed_device is not None
|
return self._fs is not None or self._constructed_device is not None
|
||||||
|
@ -425,7 +442,7 @@ class _Device(_Formattable, ABC):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# [Partition]
|
# [Partition]
|
||||||
_partitions = attr.ib(init=False, default=attr.Factory(list), repr=False)
|
_partitions = attributes.backlink(default=attr.Factory(list))
|
||||||
|
|
||||||
def partitions(self):
|
def partitions(self):
|
||||||
return self._partitions
|
return self._partitions
|
||||||
|
@ -856,7 +873,7 @@ class DM_Crypt:
|
||||||
dm_name = attr.ib(default=None)
|
dm_name = attr.ib(default=None)
|
||||||
preserve = attr.ib(default=False)
|
preserve = attr.ib(default=False)
|
||||||
|
|
||||||
_constructed_device = attr.ib(default=None, repr=False)
|
_constructed_device = attributes.backlink()
|
||||||
|
|
||||||
def constructed_device(self):
|
def constructed_device(self):
|
||||||
return self._constructed_device
|
return self._constructed_device
|
||||||
|
@ -875,7 +892,7 @@ class Filesystem:
|
||||||
uuid = attr.ib(default=None)
|
uuid = attr.ib(default=None)
|
||||||
preserve = attr.ib(default=False)
|
preserve = attr.ib(default=False)
|
||||||
|
|
||||||
_mount = attr.ib(default=None, repr=False) # Mount
|
_mount = attributes.backlink()
|
||||||
|
|
||||||
def mount(self):
|
def mount(self):
|
||||||
return self._mount
|
return self._mount
|
||||||
|
@ -1002,9 +1019,10 @@ class FilesystemModel(object):
|
||||||
else:
|
else:
|
||||||
next_work.append(obj)
|
next_work.append(obj)
|
||||||
if len(next_work) == len(work):
|
if len(next_work) == len(work):
|
||||||
raise Exception(
|
msg = ["rendering block devices made no progress processing:"]
|
||||||
"rendering block devices made no progress: {}".format(
|
for w in work:
|
||||||
work))
|
msg.append(" - " + str(w))
|
||||||
|
raise Exception("\n".join(msg))
|
||||||
work = next_work
|
work = next_work
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
Loading…
Reference in New Issue