def set_snap_create(self, vol_regex="nap", snap_prefix="nSnap", writable_snap="No", snap_count=1, snap_suffix="sNap"): all_created_snap = list() all_vols = GetObj.get_vollist(self, vol_regex=vol_regex) if all_vols: vol_list = [(each.name, each.path.split(':')[0]) for each in all_vols] for vol, pool in vol_list: created_snap = list() for snap_number in range(int(snap_count)): snap_name = ("%s.%s-%s.%s" % (snap_prefix, vol, snap_number, snap_suffix)) try: if writable_snap.lower() == "yes": _create = ssh( hostname=self._hostname, username=self._username, password=self._password, command= "vol --snap %s --snapname %s --start_online --allow_writes --pool %s" % (vol, snap_name, pool)) else: _create = ssh( hostname=self._hostname, username=self._username, password=self._password, command="vol --snap %s --snapname %s --pool %s" % (vol, snap_name, pool)) except GenericError as e: log.error(e) else: if _create['error']: log.error( "%s >> CREATE: snap create %s on vol %s - failed with error: %s" % (self._hostname, snap_name, str(vol + ':/' + pool), _create['error'])) else: log.info( "%s >> CREATE: snap create %s on vol %s - successful!" % (self._hostname, str(vol + ':/' + pool), snap_name)) created_snap.append(snap_name) if created_snap: log.list("%s >> LIST: %s snap created on vol %s: %s" % (self._hostname, len(created_snap), str(vol + ':/' + pool), ', '.join(created_snap))) all_created_snap.append( {str(vol + ':/' + pool): created_snap}) return all_created_snap
def set_vol_delete(self, vol_regex=None, *args): deleted_vols = [] all_vols = GetObj.rest_vollist(self, vol_regex=vol_regex) if all_vols: # vol_list = [(each.name, each.path.split(':')[0]) for each in all_vols] vol_list = [ each for each in all_vols if each.acl is None and each.volcoll_name == '' ] pp(vol_list) time.sleep(30) else: return None for vol in vol_list: try: dissoc = ssh(hostname=self._hostname, username=self._username, password=self._password, command="vol --dissoc %s --pool %s --force " % (vol.name, vol.pool_name)) offline = ssh(hostname=self._hostname, username=self._username, password=self._password, command="vol --offline %s --pool %s --force" % (vol.name, vol.pool_name)) if offline['error']: log.error("%s >> vol offline %s - failed with error %s" % (self._hostname, vol.name, dissoc['error'])) else: log.info("%s >> vol offline %s - successful!" % (self._hostname, vol.name)) except GenericError as e: log.error(e) else: delete = ssh(hostname=self._hostname, username=self._username, password=self._password, command="vol --delete %s --pool %s" % (vol.name, vol.pool_name)) if delete['error']: log.error( "%s >> DELETE: vol delete %s - failed with error: %s" % (self._hostname, vol.full_name, delete['error'])) else: log.info("%s >> DELETE: vol delete %s - successful!" % (self._hostname, vol.full_name)) deleted_vols.append(vol.full_name) log.list("%s >> LIST: %s vol deleted %s " % (self._hostname, len(deleted_vols), ', '.join(deleted_vols))) return deleted_vols
def get_initiatorlist(self, client_regex=None, *args): try: out = ssh( hostname=self._hostname, username=self._username, password=self._password, command= "initiatorgrp --list | sed '1,/--+--/d'| grep -i '%s' | awk '{print $1, $2, $3}'" % client_regex) except GenericError as e: raise e else: initiator = collections.namedtuple( 'initiator', ['name', 'init_count', 'sub_count']) initiator.__new__.__defaults__ = (None, ) if out['data']: initiatorlist = [ initiator(*item.split()) for item in out['data'] ] return initiatorlist finally: log.debug("ran successfully")
def get_snaplist(self, vol_regex=None, snap_regex=None, *args): try: out = ssh( hostname=self._hostname, username=self._username, password=self._password, command="snap --list --all | sed '1,/--+--/d'| grep -i '%s' | " "awk '{print $1, $2, $3, $4, $5, $7}'" % vol_regex) except GenericError as e: raise e else: snap = collections.namedtuple( 'snap', ['vol_name', 'snap_name', 'size', 'online', 'status', 'path']) snap.__new__.__defaults__ = (None, ) if out['data']: snaplist = [snap(*item.split()) for item in out['data']] if snap_regex and snap_regex != '': return list( filter(lambda each: snap_regex in each.snap_name, snaplist)) else: return snaplist finally: log.debug("ran successfully")
def set_vol_move(self, vol_regex=None, pool_regex=None): vol_list = GetObj.get_vollist(self, vol_regex=vol_regex) all_pool_list = GetObj.get_poollist(self, pool_regex=pool_regex) pool_list = [item.pool_name for item in all_pool_list] all_moved_vols = list() if vol_list and pool_list: for vol in vol_list: try: vol_pool = vol.path.split(':')[0] dest_pool = random.choice(pool_list) out = ssh( hostname=self._hostname, username=self._username, password=self._password, command="vol --move %s --pool %s --dest_pool %s" % (vol.name, vol_pool, dest_pool)) except GenericError as e: log.error(e) else: if out['error']: log.error( "%s >> VOLMOVE: vol move of %s to pool %s - failed with error: %s" % (self._hostname, vol.name, dest_pool, out['error'])) else: log.info( "%s >> VOLMOVE: vol move of %s to pool %s - successful! %s" % (self._hostname, vol.name + ':/' + vol_pool, dest_pool, out['info'])) all_moved_vols.append(str(vol.name + ':/' + vol_pool)) return all_moved_vols
def get_nsproc(self, array_regex=None, proc_state=None, *args): ctrlrs = GetObj.get_ctrlrlist(self, array_regex=array_regex) if ctrlrs is None: log.error( "get_ctrlrlist: No valid array return with string: %s from host : %s" % (array_regex, self._hostname)) return None all_proc_list = list() for ctrlr in ctrlrs: try: out = ssh( hostname=ctrlr.supp_ip, username='******', password=self._password, command= "nsproc --list | sed '1,/--+--/d' | grep -v 'N/A\|USER' | " "grep -i 'gmd\|dsd\|amd\|gdd\|postgres\|cmd\|emd' | " "grep -i '%s' | awk '{print $1, $2, $3, $NF}'" % proc_state) except GenericError as e: raise e else: proc = collections.namedtuple('proc', [ 'proc_name', 'proc_id', 'proc_state', 'num_restarts', 'ctrlr_name', 'ctrlr_state' ]) proc.__new__.__defaults__ = (None, ) if out['data']: proc_list = [ proc(*item.split(), ctrlr.hostname, ctrlr.state) for item in out['data'] ] all_proc_list.append(proc_list) return list(itertools.chain(*all_proc_list))
def get_ctrlrlist(self, array_regex=None, *args): ctrlrlist = [] arrays = GetObj.get_arraylist(self, array_regex=array_regex) if arrays is None: log.error( "get_arraylist: No valid array return with string: %s from host : %s" % (array_regex, self._hostname)) return None for array in arrays: try: out = ssh( hostname=self._hostname, username=self._username, password=self._password, command="ctrlr --list --array '%s' | sed '1,/--+--/d'" % array.array_name) except GenericError as e: raise e else: ctrlr = collections.namedtuple('ctrlr', [ 'name', 'state', 'hostname', 'supp_ip', 'power_status', 'fan_status', 'temp_status' ]) ctrlr.__new__.__defaults__ = (None, ) if out['data']: ctrlrlist.append( list(ctrlr(*item.split()) for item in out['data'])) return list(itertools.chain(*ctrlrlist))
def get_disklist(self, array_regex=None, disk_regex=None, *args): disklist = [] arrays = GetObj.get_arraylist(self, array_regex=array_regex) if arrays is None: log.error( "get_arraylist: No valid array return with string: %s from host : %s" % (array_regex, self._hostname)) return None for array in arrays: try: out = ssh( hostname=self._hostname, username=self._username, password=self._password, command= "disk --list --array %s | sed '1,/--+--/d' | grep -i '%s'" % (array.array_name, disk_regex)) except GenericError as e: raise e else: disk = collections.namedtuple('disk', [ 'slot', 'serial', 'type', 'size', 'state', 'raid', 'shelf', 'location' ]) disk.__new__.__defaults__ = (None, ) if out['data']: disklist.append( list( disk(*item.replace('in use', 'in-use').split()) for item in out['data'] if "in use" in item)) return list(itertools.chain(*disklist))
def set_vol_create(self, vol_prefix="nVol", vol_suffix="nap", vol_size="1", vol_count=1, vol_pool="default", vol_dedup="off", vol_perfpolicy="default", vol_initiatorgrp="nap-dummy"): vol_size = 1024 * int(vol_size) pool_list = GetObj.get_poollist(self, pool_regex="") pool = [ each.pool_name for each in pool_list if vol_pool in each.pool_name ] policy_list = GetObj.get_perfpolicy(self, policy_arg=vol_perfpolicy) initiator_list = GetObj.get_initiatorlist(self, client_regex="") print(initiator_list) initiator = [ each.name for each in initiator_list if vol_initiatorgrp in each.name ] pp("=======================") print(initiator) # todo add create_initiator created_vols = list() for vol in range(int(vol_count)): vol_name = vol_prefix + str(vol) + vol_suffix try: this_pool = random.choice(pool) output = ssh( hostname=self._hostname, username=self._username, password=self._password, command= "vol --create %s --size %s --pool %s --perfpolicy '%s' --dedupe_enabled %s " "--initiatorgrp %s " % (vol_name, vol_size, this_pool, random.choice(policy_list), vol_dedup, initiator[0])) except GenericError as e: log.error(e) else: if output['error']: log.error( "%s >> CREATE: vol create %s - failed with error %s" % (self._hostname, str(vol_name + ':/' + this_pool), output['error'])) else: created_vols.append(str(vol_name + ':/' + this_pool)) log.info( "%s >> CREATE: vol create %s - successful!" % (self._hostname, str(vol_name + ':/' + this_pool))) log.list("%s >> LIST: %s vol created %s" % (self._hostname, len(created_vols), ', '.join(created_vols))) return created_vols
def set_clone_create(self, vol_regex="nap", snap_regex="nSnap", clone_prefix="nClone", clone_count=1, read_only='no'): all_vols = GetObj.get_vollist(self, vol_regex=vol_regex) all_clones_created = list() # pp(all_vols) if all_vols: for vol in all_vols: vol_all_snaps = GetObj.get_snaplist(self, vol_regex=vol.name, snap_regex=snap_regex) # pp(vol_all_snaps) if vol_all_snaps: for snap in vol_all_snaps: while int(clone_count) > 0: # pp(snap) # pp(vol) clone_name = clone_prefix + '.' + str( clone_count) + '-' + vol.name + vol.path.split( ':')[0] + '-' + snap.snap_name try: clone = ssh( hostname=self._hostname, username=self._username, password=self._password, command= "vol --clone %s --snapname %s --pool %s --clonename " "%s --readonly=%s" % (vol.name, snap.snap_name, vol.path.split(':')[0], clone_name, read_only.lower())) except GenericError as e: log.error(e) else: if clone['error']: log.error( "%s >> CLONE_CREATE: clone create %s - failed with error: %s" % (self._hostname, clone_name, clone['error'])) else: log.info( "%s >> CLONE_CREATE: clone create of %s - successful! %s" % (self._hostname, clone_name, clone['info'])) all_clones_created.append(clone_name) clone_count -= 1 return all_clones_created
def get_groupinfo(self, field_arg=None, *args): try: out = ssh(hostname=self._hostname, username=self._username, password=self._password, command="group --info | grep -i '%s'" % field_arg) except GenericError as e: raise e else: group_dict = [(item.split(':')[0], item.strip().split(':')[1].strip()) for item in out['data']] return group_dict finally: log.debug("ran successfully")
def get_iplist(self, array_regex=None, *args): try: out = ssh(hostname=self._hostname, username=self._username, password=self._password, command="ip --list | grep eth | grep '%s'" % array_regex) except GenericError as e: raise e else: ip = collections.namedtuple( 'ip', ['ip', 'nic', 'status', 'type', 'array', 'controller']) ip.__new__.__defaults__ = (None, ) if out['data']: iplist = [ip(*item.split()) for item in out['data']] return iplist
def get_perfpolicy(self, policy_arg=None, *args): try: out = ssh( hostname=self._hostname, username=self._username, password=self._password, command= "perfpolicy --list | sed '1,/--+--/d' | cut -d ' ' -f 1-4 | grep -i '%s'" % policy_arg) except GenericError as e: raise e else: group_dict = [item.strip() for item in out['data']] return group_dict finally: log.debug("ran successfully")
def get_volmove(self, vol_regex=None, *args): try: out = ssh( hostname=self._hostname, username=self._username, password=self._password, command= "vol --list --moving | sed '1,/--+--/d' | grep -i '%s' | awk '{print $1, $2, $3, $5, $8}'" % vol_regex) except GenericError as e: raise e else: volmove = collections.namedtuple( 'volmove', ['name', 'size', 'online', 'usage', 'path']) volmove.__new__.__defaults__ = (None, ) if out['data']: move_list = [volmove(*item.split()) for item in out['data']] return move_list finally: log.debug("ran successfully")
def get_arraylist(self, array_regex=None, *args): try: out = ssh( hostname=self._hostname, username=self._username, password=self._password, command= "array --list | sed '1,/--+--/d'| grep -i '%s' | awk '{print $1, $2, $3, $4, $5}'" % array_regex) except GenericError as e: raise e else: array = collections.namedtuple( 'array', ['array_name', 'serial', 'model', 'version', 'status']) array.__new__.__defaults__ = (None, ) if out['data']: arraylist = [array(*item.split()) for item in out['data']] return arraylist finally: log.debug("ran successfully")
def get_poollist(self, pool_regex=None, *args): try: out = ssh( hostname=self._hostname, username=self._username, password=self._password, command= "pool --list | sed '1,/--+--/d'| grep -i '%s' | awk '{print $1, $2, $3, $4 }'" % pool_regex) except GenericError as e: raise e else: pool = collections.namedtuple( 'pool', ['pool_name', 'capacity', 'usage', 'array']) pool.__new__.__defaults__ = (None, ) if out['data']: poollist = [pool(*item.split()) for item in out['data']] return poollist finally: log.debug("ran successfully")
def set_snap_delete(self, vol_regex=None, snap_regex=None): all_deleted_snap = list() all_snaps = GetObj.get_snaplist(self, vol_regex=vol_regex, snap_regex=snap_regex) if all_snaps: snap_list = [(each.vol_name, each.snap_name, each.path.split(':')[0]) for each in all_snaps] for vol, snap, pool in snap_list: try: delete = ssh( hostname=self._hostname, username=self._username, password=self._password, command="snap --delete %s --vol %s --pool %s" % (snap, vol, pool)) except GenericError as e: log.error(e) else: if delete['error']: log.error( "%s >> DELETE: snap delete %s on vol %s - failed with error: %s" % (self._hostname, snap, str(vol + ':/' + pool), delete['error'])) else: log.info( "%s >> DELETE: snap delete %s on vol %s - successful!" % (self._hostname, snap, str(vol + ':/' + pool))) all_deleted_snap.append((str(vol + ':/' + pool), snap)) log.list("%s >> LIST: %s snap deleted %s " % (self._hostname, len(all_deleted_snap), ', '.join( [item[0] + ' ' + item[1] for item in all_deleted_snap]))) return all_deleted_snap