mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Adding ability to create mirrored zpool and nested vdevs
This commit is contained in:
parent
49da83d5c3
commit
f9d0669cf2
@ -150,15 +150,17 @@ def scrub(pool_name=None):
|
||||
ret['Error'] = 'Storage pool {0} does not exist'.format(pool_name)
|
||||
|
||||
|
||||
def create(pool_name, *vdevs):
|
||||
def create(pool_name, *vdevs, **kwargs):
|
||||
'''
|
||||
Create a new storage pool
|
||||
Create a simple zpool, a mirrored zpool or nested VDEVs
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' zpool.create myzpool /path/to/vdev1 [/path/to/vdev2] [...]
|
||||
salt '*' zpool.create myzpool /path/to/vdev1 [/path/to/vdev2] [...] [force=True|False]
|
||||
salt '*' zpool.create myzpool mirror /path/to/vdev1 /path/to/vdev2 [...]
|
||||
salt '*' zpool.create myzpool mirror /path/to/vdev1 /path/to/vdev2 mirror /path/to/vdev3 /path/to/vdev4 [...]
|
||||
'''
|
||||
ret = {}
|
||||
dlist = []
|
||||
@ -170,26 +172,36 @@ def create(pool_name, *vdevs):
|
||||
|
||||
# make sure files are present on filesystem
|
||||
for vdev in vdevs:
|
||||
if not os.path.isfile(vdev):
|
||||
# File is not there error and return
|
||||
ret[vdev] = '{0} not present on filesystem'.format(vdev)
|
||||
return ret
|
||||
else:
|
||||
dlist.append(vdev)
|
||||
if vdev != 'mirror':
|
||||
if not os.path.exists(vdev):
|
||||
# Path doesn't exist so error and return
|
||||
ret[vdev] = '{0} not present on filesystem'.format(vdev)
|
||||
return ret
|
||||
mode = os.stat(vdev).st_mode
|
||||
if not stat.S_ISBLK(mode):
|
||||
# Not a block device so error and return
|
||||
ret[vdev] = '{0} is not a block device'.format(vdev)
|
||||
return ret
|
||||
dlist.append(vdev)
|
||||
|
||||
devs = ' '.join(dlist)
|
||||
zpool = _check_zpool()
|
||||
cmd = '{0} create {1} {2}'.format(zpool, pool_name, devs)
|
||||
if force is True:
|
||||
cmd = '{0} create -f {1} {2}'.format(zpool, pool_name, devs)
|
||||
else:
|
||||
cmd = '{0} create {1} {2}'.format(zpool, pool_name, devs)
|
||||
|
||||
# Create storage pool
|
||||
__salt__['cmd.run'](cmd)
|
||||
res = __salt__['cmd.run'](cmd)
|
||||
|
||||
# Check and see if the pools is available
|
||||
if exists(pool_name):
|
||||
ret[pool_name] = 'created'
|
||||
return ret
|
||||
else:
|
||||
ret['Error'] = 'Unable to create storage pool {0}'.format(pool_name)
|
||||
ret['Error'] = {}
|
||||
ret['Error']['Messsage'] = 'Unable to create storage pool {0}'.format(pool_name)
|
||||
ret['Error']['Reason'] = res
|
||||
|
||||
return ret
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user