-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for creating encrypted Stratis pools
- Loading branch information
1 parent
a6fd67a
commit 95df74d
Showing
5 changed files
with
90 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
# Red Hat Author(s): Vojtech Trefny <[email protected]> | ||
# | ||
|
||
import os | ||
import uuid | ||
|
||
import logging | ||
|
@@ -27,7 +28,7 @@ | |
from .storage import StorageDevice | ||
from ..static_data import stratis_info | ||
from ..storage_log import log_method_call | ||
from ..errors import DeviceError | ||
from ..errors import DeviceError, StratisError | ||
from .. import devicelibs | ||
|
||
|
||
|
@@ -40,17 +41,47 @@ class StratisPoolDevice(StorageDevice): | |
_dev_dir = "/dev/stratis" | ||
_format_immutable = True | ||
|
||
def __init__(self, *args, **kwargs): | ||
""" | ||
:encrypted: whether this pool is encrypted or not | ||
:type encrypted: bool | ||
:keyword passphrase: device passphrase | ||
:type passphrase: str | ||
:keyword key_file: path to a file containing a key | ||
:type key_file: str | ||
""" | ||
self._encrypted = kwargs.pop("encrypted", False) | ||
self.__passphrase = kwargs.pop("passphrase", None) | ||
self._key_file = kwargs.pop("key_file", None) | ||
|
||
super(StratisPoolDevice, self).__init__(*args, **kwargs) | ||
|
||
@property | ||
def size(self): | ||
""" The size of this pool """ | ||
# sum up the sizes of the block devices | ||
return sum(parent.size for parent in self.parents) | ||
|
||
@property | ||
def has_key(self): | ||
return ((self.__passphrase not in ["", None]) or | ||
(self._key_file and os.access(self._key_file, os.R_OK))) | ||
|
||
def _pre_create(self, **kwargs): | ||
super(StratisPoolDevice, self)._pre_create(**kwargs) | ||
|
||
if self._encrypted and not self.has_key: | ||
raise StratisError("cannot create encrypted stratis pool without key") | ||
|
||
def _create(self): | ||
""" Create the device. """ | ||
log_method_call(self, self.name, status=self.status) | ||
bd_list = [bd.path for bd in self.parents] | ||
devicelibs.stratis.create_pool(self.name, bd_list) | ||
devicelibs.stratis.create_pool(name=self.name, | ||
devices=bd_list, | ||
encrypted=self._encrypted, | ||
passphrase=self.__passphrase, | ||
key_file=self._key_file) | ||
|
||
def _post_create(self): | ||
super(StratisPoolDevice, self)._post_create() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters