Skip to content

Instantly share code, notes, and snippets.

@vpodzime
Created November 5, 2015 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vpodzime/b195b4e24f139cc6b048 to your computer and use it in GitHub Desktop.
Save vpodzime/b195b4e24f139cc6b048 to your computer and use it in GitHub Desktop.
diff --git a/blivet/devicefactory.py b/blivet/devicefactory.py
index 54f5d9d..b06e651 100644
--- a/blivet/devicefactory.py
+++ b/blivet/devicefactory.py
@@ -34,6 +34,7 @@ from .partitioning import SameSizeSet
from .partitioning import TotalSizeSet
from .partitioning import do_partitioning
from .size import Size
+from .util import default_namedtuple
import gi
gi.require_version("BlockDev", "1.0")
@@ -54,6 +55,16 @@ DEVICE_TYPE_BTRFS = 3
DEVICE_TYPE_DISK = 4
DEVICE_TYPE_LVM_THINP = 5
+ContainerSpec = default_namedtuple("ContainerSpec", [("encrypted", False), "name", "raid_level",
+ ("size", SIZE_POLICY_AUTO)],
+ """Container specification
+ :attr str name: name of requested container
+ :attr raid_level: raid level for container
+ :type raid_level: any valid RAID level descriptor
+ :attr bool encrypted: whether to encrypt the container
+ :attr size: requested container size
+ :type size: :class:`~.size.Size`
+""")
def is_supported_device_type(device_type):
""" Return True if blivet supports this device type.
@@ -252,9 +263,7 @@ class DeviceFactory(object):
def __init__(self, storage, size, disks, fstype=None, mountpoint=None,
label=None, raid_level=None, encrypted=False,
- container_encrypted=False, container_name=None,
- container_raid_level=None, container_size=SIZE_POLICY_AUTO,
- name=None, device=None, min_luks_entropy=0):
+ name=None, device=None, min_luks_entropy=0, container_spec=None):
"""
:param storage: a Blivet instance
:type storage: :class:`~.Blivet`
@@ -286,17 +295,11 @@ class DeviceFactory(object):
any device passed must be of the appropriate type for the
factory class it is passed to
- :keyword container_name: name of requested container
- :type container_name: str
- :keyword container_raid_level: raid level for container
- :type container_raid_level: any valid RAID level descriptor
- :keyword container_encrypted: whether to encrypt the container
- :type container_encrypted: bool
- :keyword container_size: requested container size
- :type container_size: :class:`~.size.Size`
:keyword min_luks_entropy: minimum entropy in bits required for
LUKS format creation
:type min_luks_entropy: int
+ :keyword container_spec: specification of the container
+ :type container_spec: :class:`ContainerSpec` or NoneType
"""
@@ -316,15 +319,17 @@ class DeviceFactory(object):
self.label = label
self.raid_level = raid_level
- self.container_raid_level = container_raid_level
+
+ container_spec = container_spec or ContainerSpec()
+ self.container_raid_level = container_spec.raid_level
self.encrypted = encrypted
- self.container_encrypted = container_encrypted
+ self.container_encrypted = container_spec.encrypted
- self.container_name = container_name
+ self.container_name = container_spec.name
self.device_name = name
- self.container_size = container_size
+ self.container_size = container_spec.size
self.container = None
self.device = device
diff --git a/examples/factory.py b/examples/factory.py
index a2f1649..7fe30cc 100644
--- a/examples/factory.py
+++ b/examples/factory.py
@@ -5,6 +5,7 @@ from examples.common import print_devices
import blivet
from blivet.size import Size
from blivet.util import set_up_logging, create_sparse_tempfile
+from blivet.devicefactory import ContainerSpec
set_up_logging()
b = blivet.Blivet() # create an instance of Blivet (don't add system devices)
@@ -29,11 +30,12 @@ try:
fstype="xfs", mountpoint="/data")
print_devices(b)
+ container_spec = ContainerSpec(raid_level="raid1")
# change testvg to have an md RAID1 pv instead of partition pvs
device = b.factory_device(blivet.devicefactory.DEVICE_TYPE_LVM,
Size("50GiB"), disks=[disk1, disk2],
fstype="xfs", mountpoint="/data",
- container_raid_level="raid1",
+ container_spec=container_spec,
device=device)
print_devices(b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment