summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--storage/deviceaction.py3
-rw-r--r--storage/formats/__init__.py30
-rw-r--r--storage/formats/fs.py2
-rw-r--r--storage/formats/luks.py11
-rw-r--r--storage/formats/lvmpv.py4
-rw-r--r--storage/formats/swap.py2
6 files changed, 33 insertions, 19 deletions
diff --git a/storage/deviceaction.py b/storage/deviceaction.py
index 09c2277de..3be35a14c 100644
--- a/storage/deviceaction.py
+++ b/storage/deviceaction.py
@@ -230,7 +230,8 @@ class ActionCreateFormat(DeviceAction):
# XXX we should set partition type flag as needed
# - or should that be in the CreateDevice action?
self.device.setup()
- self.device.format.create(options=self.device.formatArgs)
+ self.device.format.create(device=self.device.path,
+ options=self.device.formatArgs)
def cancel(self):
self.device.format = self.origFormat
diff --git a/storage/formats/__init__.py b/storage/formats/__init__.py
index 3abd77664..feb92f3dd 100644
--- a/storage/formats/__init__.py
+++ b/storage/formats/__init__.py
@@ -162,16 +162,16 @@ class DeviceFormat(object):
self.exists = kwargs.get("exists")
self.options = kwargs.get("options")
- def setDevice(self, devspec):
+ def _setDevice(self, devspec):
if devspec and not devspec.startswith("/"):
raise ValueError("device must be a fully qualified path")
self._device = devspec
- def getDevice(self):
+ def _getDevice(self):
return self._device
- device = property(lambda f: f.getDevice(),
- lambda f,d: f.setDevice(d),
+ device = property(lambda f: f._getDevice(),
+ lambda f,d: f._setDevice(d),
doc="Full path the device this format occupies")
@property
@@ -212,7 +212,13 @@ class DeviceFormat(object):
def create(self, *args, **kwargs):
log_method_call(self, device=os.path.basename(self.device),
type=self.type, status=self.status)
- pass
+ # allow late specification of device path
+ device = kwargs.get("device")
+ if device:
+ self.device = device
+
+ if not os.path.exists(device):
+ raise FormatCreateError("invalid device specification")
def destroy(self, *args, **kwargs):
log_method_call(self, device=os.path.basename(self.device),
@@ -234,7 +240,19 @@ class DeviceFormat(object):
def setup(self, *args, **kwargs):
log_method_call(self, device=os.path.basename(self.device),
type=self.type, status=self.status)
- pass
+ if not self.exists:
+ raise FormatSetupError("format has not been created")
+
+ if self.status:
+ return
+
+ # allow late specification of device path
+ device = kwargs.get("device")
+ if device:
+ self.device = device
+
+ if not os.path.exists(device):
+ raise FormatSetupError("invalid device specification")
def teardown(self, *args, **kwargs):
log_method_call(self, device=os.path.basename(self.device),
diff --git a/storage/formats/fs.py b/storage/formats/fs.py
index c5ec44a7e..0359b0b6a 100644
--- a/storage/formats/fs.py
+++ b/storage/formats/fs.py
@@ -533,6 +533,8 @@ class FS(DeviceFormat):
if self.exists:
raise FSError("filesystem already exists")
+ DeviceFormat.create(self, *args, **kwargs)
+
return self.format(*args, **kwargs)
def setup(self, *args, **kwargs):
diff --git a/storage/formats/luks.py b/storage/formats/luks.py
index 3485f56ad..607b44bd9 100644
--- a/storage/formats/luks.py
+++ b/storage/formats/luks.py
@@ -109,15 +109,10 @@ class LUKS(DeviceFormat):
""" Open, or set up, the format. """
log_method_call(self, device=os.path.basename(self.device),
type=self.type, status=self.status)
- if not self.exists:
- raise LUKSError("format has not been created")
-
if not self.configured:
raise LUKSError("luks device not configured")
- if self.status:
- return
-
+ DeviceFormat.setup(self, *args, **kwargs)
crypto.luks_open(self.device, self.mapName,
passphrase=self.__passphrase,
key_file=self._key_file)
@@ -137,12 +132,10 @@ class LUKS(DeviceFormat):
""" Create the format. """
log_method_call(self, device=os.path.basename(self.device),
type=self.type, status=self.status)
- if self.exists:
- raise LUKSError("format already exists")
-
if not self.configured:
raise LUKSError("luks device not configured")
+ DeviceFormat.create(self, *args, **kwargs)
crypto.luks_format(self.device,
passphrase=self.__passphrase,
key_file=self._key_file,
diff --git a/storage/formats/lvmpv.py b/storage/formats/lvmpv.py
index ac404f303..d27819859 100644
--- a/storage/formats/lvmpv.py
+++ b/storage/formats/lvmpv.py
@@ -81,9 +81,7 @@ class LVMPhysicalVolume(DeviceFormat):
""" Create the format. """
log_method_call(self, device=os.path.basename(self.device),
type=self.type, status=self.status)
- if self.exists:
- raise PhysicalVolumeError("format already exists")
-
+ DeviceFormat.create(self, *args, **kwargs)
""" Consider use of -Z|--zero
-f|--force or -y|--yes may be required
"""
diff --git a/storage/formats/swap.py b/storage/formats/swap.py
index 1888b9837..6b8646d28 100644
--- a/storage/formats/swap.py
+++ b/storage/formats/swap.py
@@ -108,6 +108,7 @@ class SwapSpace(DeviceFormat):
if self.status:
return
+ DeviceFormat.setup(self, *args, **kwargs)
swap.swapon(self.device, priority=self.priority)
def teardown(self, *args, **kwargs):
@@ -130,6 +131,7 @@ class SwapSpace(DeviceFormat):
if self.status:
raise SwapSpaceError("device exists and is active")
+ DeviceFormat.create(self, *args, **kwargs)
swap.mkswap(self.device, label=self.label)