Skip to content

Commit

Permalink
Add availability checking to non-FS formats.
Browse files Browse the repository at this point in the history
Related: #12

Make use of the availability information in method formattable,
controllable, supported, destroyable.

Signed-off-by: mulhern <amulhern@redhat.com>
  • Loading branch information
mulkieran committed Apr 22, 2015
1 parent d2db0d6 commit 5ae0fd3
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
16 changes: 16 additions & 0 deletions blivet/formats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ def _postDestroy(self, **kwargs):
self.exists = False
self.notifyKernel()

@property
def destroyable(self):
""" Do we have the facilities to destroy a format of this type. """
# assumes wipefs is always available
return True

def setup(self, **kwargs):
""" Activate the formatting.
Expand All @@ -459,6 +465,16 @@ def setup(self, **kwargs):
self._setup(**kwargs)
self._postSetup(**kwargs)

@property
def controllable(self):
""" Are external utilities available to allow this format to be both
setup and teared down.
:returns: True if this format can be set up, otherwise False
:rtype: bool
"""
return True

def _preSetup(self, **kwargs):
""" Return True if setup should proceed. """
if not self.exists:
Expand Down
18 changes: 18 additions & 0 deletions blivet/formats/luks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from . import DeviceFormat, register_device_format
from ..flags import flags
from ..i18n import _, N_
from ..tasks import availability

import logging
log = logging.getLogger("blivet")
Expand All @@ -44,6 +45,7 @@ class LUKS(DeviceFormat):
_linuxNative = True # for clearpart
_packages = ["cryptsetup"] # required packages
_minSize = crypto.LUKS_METADATA_SIZE
_plugin = availability.BLOCKDEV_CRYPTO_PLUGIN

def __init__(self, **kwargs):
"""
Expand Down Expand Up @@ -149,6 +151,18 @@ def hasKey(self):
return ((self.__passphrase not in ["", None]) or
(self._key_file and os.access(self._key_file, os.R_OK)))

@property
def formattable(self):
return super(LUKS, self).formattable and self._plugin.available

@property
def supported(self):
return super(LUKS, self).supported and self._plugin.available

@property
def controllable(self):
return super(LUKS, self).controllable and self._plugin.available

@property
def configured(self):
""" To be ready we need a key or passphrase and a map name. """
Expand Down Expand Up @@ -202,6 +216,10 @@ def _postCreate(self, **kwargs):
if flags.installer_mode or not self.mapName:
self.mapName = "luks-%s" % self.uuid

@property
def destroyable(self):
return self._plugin.available

@property
def keyFile(self):
""" Path to key file to be used in /etc/crypttab """
Expand Down
14 changes: 14 additions & 0 deletions blivet/formats/lvmpv.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from ..storage_log import log_method_call
from parted import PARTITION_LVM
from ..devicelibs import lvm
from ..tasks import availability
from ..i18n import N_
from ..size import Size
from . import DeviceFormat, register_device_format
Expand All @@ -47,6 +48,7 @@ class LVMPhysicalVolume(DeviceFormat):
_minSize = lvm.LVM_PE_SIZE * 2 # one for metadata and one for data
_packages = ["lvm2"] # required packages
_ksMountpoint = "pv."
_plugin = availability.BLOCKDEV_LVM_PLUGIN

def __init__(self, **kwargs):
"""
Expand Down Expand Up @@ -95,6 +97,14 @@ def dict(self):
"peStart": self.peStart, "dataAlignment": self.dataAlignment})
return d

@property
def formattable(self):
return super(LVMPhysicalVolume, self).formattable and self._plugin.available

@property
def supported(self):
return super(LVMPhysicalVolume, self).supported and self._plugin.available

def _create(self, **kwargs):
log_method_call(self, device=self.device,
type=self.type, status=self.status)
Expand All @@ -121,6 +131,10 @@ def _destroy(self, **kwargs):
finally:
blockdev.lvm_pvscan(self.device)

@property
def destroyable(self):
return self._plugin.available

@property
def status(self):
# XXX hack
Expand Down
14 changes: 14 additions & 0 deletions blivet/formats/mdraid.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from . import DeviceFormat, register_device_format
from ..flags import flags
from ..i18n import N_
from ..tasks import availability

import logging
log = logging.getLogger("blivet")
Expand All @@ -43,6 +44,7 @@ class MDRaidMember(DeviceFormat):
_linuxNative = True # for clearpart
_packages = ["mdadm"] # required packages
_ksMountpoint = "raid."
_plugin = availability.BLOCKDEV_MDRAID_PLUGIN

def __init__(self, **kwargs):
"""
Expand Down Expand Up @@ -74,9 +76,21 @@ def dict(self):
d.update({"mdUUID": self.mdUuid, "biosraid": self.biosraid})
return d

@property
def formattable(self):
return super(MDRaidMember, self).formattable and self._plugin.available

@property
def supported(self):
return super(MDRaidMember, self).supported and self._plugin.available

def _destroy(self, **kwargs):
blockdev.md_destroy(self.device)

@property
def destroyable(self):
return self._plugin.available

@property
def status(self):
# XXX hack -- we don't have a nice way to see if the array is active
Expand Down
14 changes: 14 additions & 0 deletions blivet/formats/swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from parted import PARTITION_SWAP, fileSystemType
from ..storage_log import log_method_call
from ..tasks import availability
from . import DeviceFormat, register_device_format
from ..size import Size
from gi.repository import BlockDev as blockdev
Expand All @@ -40,6 +41,7 @@ class SwapSpace(DeviceFormat):
_formattable = True # can be formatted
_supported = True # is supported
_linuxNative = True # for clearpart
_plugin = availability.BLOCKDEV_SWAP_PLUGIN

#see rhbz#744129 for details
_maxSize = Size("128 GiB")
Expand Down Expand Up @@ -80,6 +82,18 @@ def dict(self):
d.update({"priority": self.priority, "label": self.label})
return d

@property
def formattable(self):
return super(SwapSpace, self).formattable and self._plugin.available

@property
def supported(self):
return super(SwapSpace, self).supported and self._plugin.available

@property
def controllable(self):
return super(SwapSpace, self).controllable and self._plugin.available

def labeling(self):
"""Returns True as mkswap can write a label to the swap space."""
return True
Expand Down

0 comments on commit 5ae0fd3

Please sign in to comment.