From 59c1cb8551968365ad3d63f95c470a9ec116435c Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Fri, 13 Nov 2020 11:24:30 +0100 Subject: [PATCH] items/zfs_pool: support raidz2 and raidz3 --- items/zfs_pool.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/items/zfs_pool.py b/items/zfs_pool.py index e0d8a31..e8caca0 100644 --- a/items/zfs_pool.py +++ b/items/zfs_pool.py @@ -18,12 +18,12 @@ def create_mirrors(node, path, mirrors): node.run("zfs unmount {}".format(quote(path))) -def create_raidz(node, path, devices): +def create_raidz(node, path, devices, raid='raidz'): cmd = "" actual_targets = [] for device in devices: actual_targets.append(quote(prepare_blockdevice(node, device))) - cmd += "raidz {} ".format(" ".join(actual_targets)) + cmd += "{} {} ".format(raid, " ".join(actual_targets)) node.run("zpool create {} {}".format(quote(path), cmd)) node.run("zfs unmount {}".format(quote(path))) @@ -95,6 +95,8 @@ class ZFSPool(Item): 'device': None, 'mirrors': None, 'raidz': None, + 'raidz2': None, + 'raidz3': None, } ITEM_TYPE_NAME = "zfs_pool" @@ -129,6 +131,10 @@ class ZFSPool(Item): create_mirrors(self.node, self.name, self.attributes['mirrors']) elif self.attributes['raidz'] is not None: create_raidz(self.node, self.name, self.attributes['raidz']) + elif self.attributes['raidz2'] is not None: + create_raidz(self.node, self.name, self.attributes['raidz'], 'raidz2') + elif self.attributes['raidz2'] is not None: + create_raidz(self.node, self.name, self.attributes['raidz'], 'raidz3') def sdict(self): # We don't care about the device if the pool already exists. @@ -168,13 +174,13 @@ class ZFSPool(Item): @classmethod def validate_attributes(cls, bundle, item_id, attributes): device_config = [] - for key in ('device', 'mirrors', 'raidz'): + for key in ('device', 'mirrors', 'raidz', 'raidz2', 'raidz3'): device_config.append(attributes.get(key)) device_config = [key for key in device_config if key is not None] if len(device_config) != 1: raise BundleError(_( "{item} on node {node} must have exactly one of " - "'device', 'mirrors', or 'raidz'" + "'device', 'mirrors', 'raidz', 'raidz2' or 'raidz3'" ).format( item=item_id, node=bundle.node.name,