Skip to content

Commit

Permalink
Move parents checking and update into a seprarate methods
Browse files Browse the repository at this point in the history
Internal LVs are not going to be referenced by the DeviceTree instance and are
going to have no parents. Their "parent" LVs are going to be referenced as
'self.parent_lv' instead of 'self.parents[0]' because all the other devices use
the opposite logic for parent-children relations -- children are consisting of
or built on top of parents (whereas "parent" LVs are consisting of their
internal LVs).

This way internal LVs can easily override these methods.
  • Loading branch information
vpodzime committed Jun 4, 2015
1 parent e47ad83 commit 6b58697
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions blivet/devices/lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,16 +489,6 @@ def __init__(self, name, parents=None, size=None, uuid=None,
:type percent: int
"""
if isinstance(parents, list):
if len(parents) != 1:
raise ValueError("constructor requires a single %s instance" % self._containerClass.__name__)

container = parents[0]
else:
container = parents

if not isinstance(container, self._containerClass):
raise ValueError("constructor requires a %s instance" % self._containerClass.__name__)

DMDevice.__init__(self, name, size=size, fmt=fmt,
sysfsPath=sysfsPath, parents=parents,
Expand All @@ -523,8 +513,29 @@ def __init__(self, name, parents=None, size=None, uuid=None,
self.req_size = self._size
self.req_percent = util.numeric_type(percent)

# here we go with the circular references
self.parents[0]._addLogVol(self)
# check that we got parents as expected and add this device to them
self._check_parents()
self._add_to_parents()

def _check_parents(self):
"""Check that this device has parents as expected"""

if isinstance(self.parents, list):
if len(self.parents) != 1:
raise ValueError("constructor requires a single %s instance" % self._containerClass.__name__)

container = self.parents[0]
else:
container = self.parents

if not isinstance(container, self._containerClass):
raise ValueError("constructor requires a %s instance" % self._containerClass.__name__)

def _add_to_parents(self):
"""Add this device to its parents"""

# a normal LV has only exactly parent -- the VG it belongs to
self._parents[0]._addLogVol(self)

def __repr__(self):
s = DMDevice.__repr__(self)
Expand Down

0 comments on commit 6b58697

Please sign in to comment.