diff --git a/salt/modules/zpool.py b/salt/modules/zpool.py index de3cbe2eb8..77c4a2137d 100644 --- a/salt/modules/zpool.py +++ b/salt/modules/zpool.py @@ -154,6 +154,7 @@ def destroy(pool_name): ret = {} if not exists(pool_name): ret['Error'] = 'Storage pool {0} does not exist'.format(pool_name) + ret['retcode'] = 1 return ret else: zpool = _check_zpool() @@ -177,6 +178,7 @@ def scrub(pool_name=None): ret = {} if not pool_name: ret['Error'] = 'zpool name parameter is mandatory.' + ret['retcode'] = 1 return ret if exists(pool_name): zpool = _check_zpool() @@ -186,6 +188,7 @@ def scrub(pool_name=None): return ret else: ret['Error'] = 'Storage pool {0} does not exist'.format(pool_name) + ret['retcode'] = 2 def create(pool_name, *vdevs, **kwargs): @@ -224,10 +227,12 @@ def create(pool_name, *vdevs, **kwargs): # Check if the pool_name is already being used if exists(pool_name): ret['Error'] = 'Storage Pool `{0}` already exists'.format(pool_name) + ret['retcode'] = 1 return ret if not vdevs: ret['Error'] = 'Missing vdev specification. Please specify vdevs.' + ret['retcode'] = 2 return ret # make sure files are present on filesystem @@ -236,11 +241,13 @@ def create(pool_name, *vdevs, **kwargs): if not os.path.exists(vdev): # Path doesn't exist so error and return ret[vdev] = '{0} not present on filesystem'.format(vdev) + ret['retcode'] = 3 return ret mode = os.stat(vdev).st_mode if not stat.S_ISBLK(mode) and not stat.S_ISREG(mode): # Not a block device or file vdev so error and return ret[vdev] = '{0} is not a block device or a file vdev'.format(vdev) + ret['retcode'] = 4 return ret dlist.append(vdev) @@ -274,6 +281,7 @@ def create(pool_name, *vdevs, **kwargs): ret['Error'] = {} ret['Error']['Messsage'] = 'Unable to create storage pool {0}'.format(pool_name) ret['Error']['Reason'] = res + ret['retcode'] = 5 return ret @@ -294,10 +302,12 @@ def add(pool_name, *vdevs): # check for pool if not exists(pool_name): ret['Error'] = 'Storage Pool `{0}` doesn\'t exist'.format(pool_name) + ret['retcode'] = 1 return ret if not vdevs: ret['Error'] = 'Missing vdev specification. Please specify vdevs.' + ret['retcode'] = 2 return ret # make sure files are present on filesystem @@ -306,11 +316,13 @@ def add(pool_name, *vdevs): if not os.path.exists(vdev): # Path doesn't exist so error and return ret[vdev] = '{0} not present on filesystem'.format(vdev) + ret['retcode'] = 3 return ret mode = os.stat(vdev).st_mode if not stat.S_ISBLK(mode) and not stat.S_ISREG(mode): # Not a block device or file vdev so error and return ret[vdev] = '{0} is not a block device or a file vdev'.format(vdev) + ret['retcode'] = 4 return ret dlist.append(vdev) @@ -324,6 +336,7 @@ def add(pool_name, *vdevs): ret['Added'] = '{0} to {1}'.format(devs, pool_name) return ret ret['Error'] = 'Something went wrong when adding {0} to {1}'.format(devs, pool_name) + ret['retcode'] = 5 def replace(pool_name, old, new): @@ -340,14 +353,17 @@ def replace(pool_name, old, new): # Make sure pools there if not exists(pool_name): ret['Error'] = '{0}: pool does not exists.'.format(pool_name) + ret['retcode'] = 1 return ret # make sure old, new vdevs are on filesystem if not os.path.isfile(old): ret['Error'] = '{0}: is not on the file system.'.format(old) + ret['retcode'] = 2 return ret if not os.path.isfile(new): ret['Error'] = '{0}: is not on the file system.'.format(new) + ret['retcode'] = 3 return ret # Replace vdevs @@ -362,6 +378,7 @@ def replace(pool_name, old, new): ret['replaced'] = '{0} with {1}'.format(old, new) return ret ret['Error'] = 'Does not look like devices were swapped; check status' + ret['retcode'] = 4 return ret @@ -402,6 +419,7 @@ def create_file_vdev(size, *vdevs): for vdev in vdevs: if not os.path.isfile(vdev): ret[vdev] = 'The vdev can\'t be created' + ret['retcode'] = 1 ret['status'] = True ret[cmd] = cmd return ret @@ -424,11 +442,13 @@ def export(*pools, **kwargs): pool_list = [] if not pools: ret['Error'] = 'zpool name parameter is mandatory' + ret['retcode'] = 1 return ret for pool in pools: if not exists(pool): ret['Error'] = 'Storage pool {0} does not exist'.format(pool) + ret['retcode'] = 2 return ret pool_list.append(pool) @@ -444,6 +464,7 @@ def export(*pools, **kwargs): ret['Error'] = {} ret['Error']['Message'] = 'Import failed!' ret['Error']['Reason'] = res + ret['retcode'] = 3 else: for pool in pool_list: ret[pool] = 'Exported' @@ -476,6 +497,7 @@ def import_(pool_name='', new_name='', **kwargs): res = __salt__['cmd.run'](cmd, ignore_retcode=True) if not res and import_all is False: ret['Error'] = 'No pools available for import' + ret['retcode'] = 1 elif import_all is False: pool_list = [l for l in res.splitlines()] ret['pools'] = pool_list @@ -485,8 +507,10 @@ def import_(pool_name='', new_name='', **kwargs): if exists(pool_name) and not new_name: ret['Error'] = 'Storage pool {0} already exists. Import the pool under a different name instead'.format(pool_name) + ret['retcode'] = 2 elif exists(new_name): ret['Error'] = 'Storage pool {0} already exists. Import the pool under a different name instead'.format(new_name) + ret['retcode'] = 3 else: if force is True: cmd = '{0} import -f {1} {2}'.format(zpool, pool_name, new_name) @@ -497,6 +521,7 @@ def import_(pool_name='', new_name='', **kwargs): ret['Error'] = {} ret['Error']['Message'] = 'Import failed!' ret['Error']['Reason'] = res + ret['retcode'] = 4 else: ret[pool_name] = 'Imported' return ret @@ -521,10 +546,12 @@ def online(pool_name, *vdevs, **kwargs): # Check if the pool_name exists if not exists(pool_name): ret['Error'] = 'Storage Pool `{0}` doesn\'t exist'.format(pool_name) + ret['retcode'] = 1 return ret if not vdevs: ret['Error'] = 'Missing vdev specification. Please specify vdevs.' + ret['retcode'] = 2 return ret # make sure files are present on filesystem @@ -532,11 +559,13 @@ def online(pool_name, *vdevs, **kwargs): if not os.path.exists(vdev): # Path doesn't exist so error and return ret[vdev] = '{0} not present on filesystem'.format(vdev) + ret['retcode'] = 3 return ret mode = os.stat(vdev).st_mode if not stat.S_ISBLK(mode) and not stat.S_ISREG(mode): # Not a block device or file vdev so error and return ret[vdev] = '{0} is not a block device or a file vdev'.format(vdev) + ret['retcode'] = 4 return ret dlist.append(vdev) @@ -550,6 +579,7 @@ def online(pool_name, *vdevs, **kwargs): ret['Error'] = {} ret['Error']['Message'] = 'Failure bringing device online.' ret['Error']['Reason'] = res + ret['retcode'] = 5 else: ret[pool_name] = 'Specified devices: {0} are online.'.format(vdevs) return ret @@ -578,10 +608,12 @@ def offline(pool_name, *vdevs, **kwargs): # Check if the pool_name exists if not exists(pool_name): ret['Error'] = 'Storage Pool `{0}` doesn\'t exist'.format(pool_name) + ret['retcode'] = 1 return ret if not vdevs: ret['Error'] = 'Missing vdev specification. Please specify vdevs.' + ret['retcode'] = 2 return ret # make sure files are present on filesystem @@ -589,11 +621,13 @@ def offline(pool_name, *vdevs, **kwargs): if not os.path.exists(vdev): # Path doesn't exist so error and return ret[vdev] = '{0} not present on filesystem'.format(vdev) + ret['retcode'] = 3 return ret mode = os.stat(vdev).st_mode if not stat.S_ISBLK(mode) and not stat.S_ISREG(mode): # Not a block device or file vdev so error and return ret[vdev] = '{0} is not a block device or a file vdev'.format(vdev) + ret['retcode'] = 4 return ret dlist.append(vdev) @@ -611,6 +645,7 @@ def offline(pool_name, *vdevs, **kwargs): ret['Error'] = {} ret['Error']['Message'] = 'Failure taking specified devices offline.' ret['Error']['Reason'] = res + ret['retcode'] = 5 else: ret[pool_name] = 'Specified devices: {0} are offline.'.format(vdevs) return ret