Skip to content

Commit

Permalink
Track external dependencies in devices.
Browse files Browse the repository at this point in the history
Related: #12

Signed-off-by: mulhern <amulhern@redhat.com>
  • Loading branch information
mulkieran committed Apr 22, 2015
1 parent 5ae0fd3 commit 7db7bbe
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions blivet/devices/btrfs.py
Expand Up @@ -42,10 +42,13 @@
from .container import ContainerDevice
from .raid import RaidDevice

from ..tasks import availability

class BTRFSDevice(StorageDevice):
""" Base class for BTRFS volume and sub-volume devices. """
_type = "btrfs"
_packages = ["btrfs-progs"]
_external_dependencies = [availability.BLOCKDEV_BTRFS_PLUGIN]

def __init__(self, *args, **kwargs):
""" Passing None or no name means auto-generate one like btrfs.%d """
Expand Down
3 changes: 3 additions & 0 deletions blivet/devices/disk.py
Expand Up @@ -29,6 +29,7 @@
from ..storage_log import log_method_call
from .. import udev
from ..size import Size
from ..tasks import availability

from ..fcoe import fcoe

Expand Down Expand Up @@ -163,6 +164,7 @@ class DMRaidArrayDevice(DMDevice, ContainerDevice):
_isDisk = True
_formatClassName = property(lambda s: "dmraidmember")
_formatUUIDAttr = property(lambda s: None)
_external_dependencies = [availability.BLOCKDEV_DM_PLUGIN]

def __init__(self, name, fmt=None,
size=None, parents=None, sysfsPath=''):
Expand Down Expand Up @@ -242,6 +244,7 @@ class MultipathDevice(DMDevice):
_packages = ["device-mapper-multipath"]
_partitionable = True
_isDisk = True
_external_dependencies = [availability.application("multipath")]

def __init__(self, name, fmt=None, size=None, serial=None,
parents=None, sysfsPath=''):
Expand Down
4 changes: 4 additions & 0 deletions blivet/devices/dm.py
Expand Up @@ -28,6 +28,7 @@
from .. import util
from ..storage_log import log_method_call
from .. import udev
from ..tasks import availability

import logging
log = logging.getLogger("blivet")
Expand All @@ -39,6 +40,9 @@ class DMDevice(StorageDevice):
""" A device-mapper device """
_type = "dm"
_devDir = "/dev/mapper"
_external_dependencies = \
[availability.application("kpartx"), availability.BLOCKDEV_DM_PLUGIN]


def __init__(self, name, fmt=None, size=None, dmUuid=None, uuid=None,
target=None, exists=False, parents=None, sysfsPath=''):
Expand Down
2 changes: 2 additions & 0 deletions blivet/devices/loop.py
Expand Up @@ -24,6 +24,7 @@

from .. import errors
from ..storage_log import log_method_call
from ..tasks import availability

import logging
log = logging.getLogger("blivet")
Expand All @@ -33,6 +34,7 @@
class LoopDevice(StorageDevice):
""" A loop device. """
_type = "loop"
_external_dependencies = [availability.BLOCKDEV_LOOP_PLUGIN]

def __init__(self, name=None, fmt=None, size=None, sysfsPath=None,
exists=False, parents=None):
Expand Down
2 changes: 2 additions & 0 deletions blivet/devices/lvm.py
Expand Up @@ -36,6 +36,7 @@
from ..storage_log import log_method_call
from .. import udev
from ..size import Size, KiB, MiB, ROUND_UP, ROUND_DOWN
from ..tasks import availability

import logging
log = logging.getLogger("blivet")
Expand Down Expand Up @@ -446,6 +447,7 @@ class LVMLogicalVolumeDevice(DMDevice):
_resizable = True
_packages = ["lvm2"]
_containerClass = LVMVolumeGroupDevice
_external_dependencies = default=[availability.BLOCKDEV_LVM_PLUGIN]

def __init__(self, name, parents=None, size=None, uuid=None,
copies=1, logSize=None, segType=None,
Expand Down
2 changes: 2 additions & 0 deletions blivet/devices/md.py
Expand Up @@ -33,6 +33,7 @@
from ..storage_log import log_method_call
from .. import udev
from ..size import Size
from ..tasks import availability

import logging
log = logging.getLogger("blivet")
Expand All @@ -48,6 +49,7 @@ class MDRaidArrayDevice(ContainerDevice, RaidDevice):
_devDir = "/dev/md"
_formatClassName = property(lambda s: "mdmember")
_formatUUIDAttr = property(lambda s: "mdUuid")
_external_dependencies = [availability.BLOCKDEV_MDRAID_PLUGIN]

def __init__(self, name, level=None, major=None, minor=None, size=None,
memberDevices=None, totalDevices=None,
Expand Down
34 changes: 34 additions & 0 deletions blivet/devices/storage.py
Expand Up @@ -56,6 +56,7 @@ class StorageDevice(Device):
_partitionable = False
_isDisk = False
_encrypted = False
_external_dependencies = []

def __init__(self, name, fmt=None, uuid=None,
size=None, major=None, minor=None,
Expand Down Expand Up @@ -748,3 +749,36 @@ def isNameValid(cls, name):

badchars = any(c in ('\x00', '/') for c in name)
return not(badchars or name == '.' or name == '..')

@property
def typeExternalDependencies(self):
""" A list of external dependencies of this device type.
:returns: a set of external dependencies
:rtype: set of availability.ExternalResource
The external dependencies include the dependencies of this
device type and of all superclass device types.
"""
return set(
d for p in self.__class__.__mro__ if issubclass(p, StorageDevice) for d in p._external_dependencies
)

@property
def externalDependencies(self):
""" A list of external dependencies of this device and its parents.
:returns: the external dependencies of this device and all parents.
:rtype: set of availability.ExternalResource
"""
return set(d for p in self.ancestors for d in p.typeExternalDependencies)

@property
def unavailableDependencies(self):
""" Any unavailable external dependencies of this device or its
parents.
:returns: A list of unavailable external dependencies.
:rtype: set of availability.externalResource
"""
return set(e for e in self.externalDependencies if not e.available)

0 comments on commit 7db7bbe

Please sign in to comment.