mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +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)
|
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:
|
CLI Example:
|
||||||
|
|
||||||
.. code-block:: bash
|
.. 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 = {}
|
ret = {}
|
||||||
dlist = []
|
dlist = []
|
||||||
@ -170,26 +172,36 @@ def create(pool_name, *vdevs):
|
|||||||
|
|
||||||
# make sure files are present on filesystem
|
# make sure files are present on filesystem
|
||||||
for vdev in vdevs:
|
for vdev in vdevs:
|
||||||
if not os.path.isfile(vdev):
|
if vdev != 'mirror':
|
||||||
# File is not there error and return
|
if not os.path.exists(vdev):
|
||||||
|
# Path doesn't exist so error and return
|
||||||
ret[vdev] = '{0} not present on filesystem'.format(vdev)
|
ret[vdev] = '{0} not present on filesystem'.format(vdev)
|
||||||
return ret
|
return ret
|
||||||
else:
|
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)
|
dlist.append(vdev)
|
||||||
|
|
||||||
devs = ' '.join(dlist)
|
devs = ' '.join(dlist)
|
||||||
zpool = _check_zpool()
|
zpool = _check_zpool()
|
||||||
|
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)
|
cmd = '{0} create {1} {2}'.format(zpool, pool_name, devs)
|
||||||
|
|
||||||
# Create storage pool
|
# Create storage pool
|
||||||
__salt__['cmd.run'](cmd)
|
res = __salt__['cmd.run'](cmd)
|
||||||
|
|
||||||
# Check and see if the pools is available
|
# Check and see if the pools is available
|
||||||
if exists(pool_name):
|
if exists(pool_name):
|
||||||
ret[pool_name] = 'created'
|
ret[pool_name] = 'created'
|
||||||
return ret
|
return ret
|
||||||
else:
|
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
|
return ret
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user