def set_migrate(self, *args): group_list = GetObj.rest_groupinfo(self, ) if group_list: endpoint = 'groups/%s/actions/check_migrate' % group_list[0].id check_migrate = rest(hostname=self._hostname, username=self._username, password=self._password, endpoint=endpoint, action='POST', in_data='{}') retry = 1 while check_migrate != {} and retry <= 5: log.error( "%s >> GROUP MIGRATE: %s migrate check failed with error: %s \n. ** Retry %s in 20 sec **" % (self._hostname, group_list[0].leader_array_name, check_migrate['messages'][0]['text'], retry)) time.sleep(20) check_migrate = rest(hostname=self._hostname, username=self._username, password=self._password, endpoint=endpoint, action='POST', in_data='{}') retry = retry + 1 pp(check_migrate) if not check_migrate: log.info( "%s >> GROUP MIGRATE: %s migrate check - successful!" % (self._hostname, group_list[0].leader_array_name)) try: endpoint = 'groups/%s/actions/migrate' % group_list[0].id response = rest(hostname=self._hostname, username=self._username, password=self._password, endpoint=endpoint, action='POST', in_data='{}') except GenericError as e: log.error(e) else: if response and response['messages']: log.error( "%s >> GROUP MIGRATE: %s migrate failed with error: %s" % (self._hostname, group_list[0].leader_array_name, response['messages'][0]['text'])) else: log.info( "%s >> GROUP MIGRATE: %s migrate to partner - successful!" % (self._hostname, group_list[0].leader_array_name))
def set_volcoll_handover(self, volcoll_regex=None, partner_regex=None, *args): volcoll_list = GetObj.rest_volcolllist(self, volcoll_regex=volcoll_regex) partners_list = GetObj.rest_partnerlist(self, partner_regex=partner_regex) volcoll_list = [ vc for vc in volcoll_list if vc.replication_partner != '' ] all_handover_volcolls = list() for volcoll in volcoll_list: if len(partners_list) != 0: replication_partner_id = [ _id.repl_id for _id in partners_list if _id.full_name == volcoll.replication_partner ] data = '{"id":"%s","replication_partner_id":"%s"}' % ( volcoll.volcoll_id, replication_partner_id[0].strip()) try: endpoint = 'volume_collections/%s/actions/handover' % volcoll.volcoll_id response = rest(hostname=self._hostname, username=self._username, password=self._password, endpoint=endpoint, action='POST', in_data=data) # pp(response) # time.sleep(30) except GenericError as e: log.error(e) else: if response and response['messages']: log.error( "%s >> HANDOVER: volcoll %s handover to partner %s - failed with error: %s" % (self._hostname, volcoll.full_name, volcoll.replication_partner, response['messages'][0]['text'])) else: log.info( "%s >> HANDOVER: volcoll %s handover to partner %s - successful!" % (self._hostname, volcoll.full_name, volcoll.replication_partner)) all_handover_volcolls.append(volcoll.full_name) return all_handover_volcolls if len(all_handover_volcolls) > 0 else []
def rest_vollist(self, vol_regex=None, *args): try: out = rest(hostname=self._hostname, username=self._username, password=self._password, endpoint='volumes/detail') except GenericError as e: raise e else: vol = collections.namedtuple('vol', [ 'acl', 'clone', 'dest_pool', 'full', 'name', 'online', 'parent_vol', 'pool', 'stats', 'usage', 'volcoll', ]) vol.__new__.__defaults__ = (None, ) item_list = list() if out['data']: for each_vol in out['data']: ret_dict = dict() ret_dict['name'] = each_vol['name'] ret_dict['clone'] = each_vol['clone'] ret_dict['full'] = each_vol['full_name'] ret_dict['volcoll'] = each_vol['volcoll_name'] ret_dict['online'] = each_vol['online'] ret_dict['pool'] = each_vol['pool_name'] ret_dict['parent_vol'] = each_vol['parent_vol_name'] ret_dict['stats'] = each_vol['avg_stats_last_5mins'] ret_dict['dest_pool'] = each_vol['dest_pool_name'] ret_dict['usage'] = each_vol['total_usage_bytes'] if each_vol['access_control_records'] is not None: access_list = list() for initiator in each_vol['access_control_records']: access_list.append( initiator['initiator_group_name'] + ':/' + str(initiator['lun'])) ret_dict['acl'] = access_list if vol_regex in ret_dict['name']: item_list.append([ ret_dict[item] for item in sorted(ret_dict.keys()) ]) ret_list = [vol(*item) for item in item_list] return ret_list if len(ret_list) > 0 else None finally: log.debug("ran successfully")
def set_failover(self, array_regex=None, *args): array_list = GetObj.rest_arraylist(self, array_regex=array_regex) if array_list: ctrlr_list = GetObj.rest_ctrlrlist(self, array_regex=array_regex) healthy = [ ctrlr for ctrlr in ctrlr_list if ctrlr.state == 'active' ] pp('healthy ctrlr') pp(healthy) for ctrlr in healthy: endpoint = 'arrays/%s/actions/failover' % ctrlr.array_id response = rest(hostname=self._hostname, username=self._username, password=self._password, endpoint=endpoint, action='POST', in_data='{}') log.info("%s >> FAILOVER: %s : %s" % (self._hostname, ctrlr.hostname, response['messages'][0]['text'])) # pp(response) time.sleep(60)
def get_volcolllist(self, volcoll_regex=None, *args): try: out = rest(hostname=self._hostname, username=self._username, password=self._password, endpoint='volume_collections/detail') except GenericError as e: raise e else: volcoll = collections.namedtuple('volcoll', [ 'volcoll_name', 'replication_partner', 'replication_type', 'upstream_vollist' ]) volcoll.__new__.__defaults__ = (None, ) item_list = list() if out['data']: for each_volcoll in out['data']: ret_dict = dict() ret_dict['full_name'] = each_volcoll['full_name'] ret_dict['replication_partner'] = each_volcoll[ 'replication_partner'] ret_dict['replication_type'] = each_volcoll[ 'replication_type'] if each_volcoll['upstream_volume_list'] is not None: assoc_vols = list() for vol in each_volcoll['upstream_volume_list']: assoc_vols.append(vol['vol_name'] + ':/' + vol['pool_name']) ret_dict['upstream_volume_list'] = assoc_vols if volcoll_regex in ret_dict['full_name']: item_list.append([ ret_dict[item] for item in sorted(ret_dict.keys()) ]) ret_list = [volcoll(*item) for item in item_list] return ret_list if len(ret_list) > 0 else None finally: log.debug("ran successfully")
def set_volcoll_remove(self, vol_regex=None, dummy=None, delete_downstream=False, *args): all_list = GetObj.rest_vollist(self, vol_regex=vol_regex) if all_list is not None: vol_list = [ vol for vol in all_list if vol.volcoll_name != '' and vol.repl_role != 'synchronous_downstream' ] downstream_vols = [ vol for vol in all_list if vol.repl_role == 'synchronous_downstream' ] # pp(downstream_vols) all_vols = list() if len(vol_list) == 0: log.warning( "%s >> VOLCOLL REMOVE: No valid volume with string - '%s' found with associated volcoll." % (self._hostname, vol_regex)) return [] # return empty list log.list("%s Filtered volumes to remove volcoll %s" % (len(vol_list), str([vol.full_name for vol in vol_list]))) for vol in vol_list: try: # vol_pool = vol.path.split(':')[0] data = '{"id":"%s","volcoll_id":""}' % vol.vol_id # pp(data) endpoint = 'volumes/%s' % vol.vol_id response = rest(hostname=self._hostname, username=self._username, password=self._password, endpoint=endpoint, action='PUT', in_data=data) time.sleep(5) # sleep to re-sync the config except GenericError as e: log.error(e) else: if response and 'messages' in response: log.error( "%s >> VOLCOLL REMOVE: vol %s - failed with error: %s" % (self._hostname, vol.full_name, response['messages'][0]['text'])) pp(response) else: log.info("%s >> VOLCOLL REMOVE: vol %s - successful!" % (self._hostname, vol.full_name)) all_vols.append(vol.full_name) time.sleep(15) # let vol --dissoc take effect and vol goes offline if delete_downstream is not False: for vol in downstream_vols: out = GetObj.rest_vollist(self, vol_regex=vol.name) # pp(out) # time.sleep(5) delete_ok = [ del_ok for del_ok in out if del_ok.acl is None and del_ok.volcoll_name == '' and del_ok.state == 'offline' ] log.list("Filtered downstream volume to delete %s" % str([vol.full_name for vol in delete_ok])) time.sleep(5) for each in delete_ok: endpoint = 'volumes/%s' % each.vol_id delete = rest(hostname=self._hostname, username=self._username, password=self._password, endpoint=endpoint, action='DELETE', in_data='{}') if delete and 'messages' in delete: log.error( "%s >> DELETE DOWNSTREAM: vol %s - failed with error: %s" % (self._hostname, each.full_name, delete['messages'][0]['text'])) else: log.info( "%s >> DELETE DOWNSTREAM: vol %s - successful!" % (self._hostname, each.full_name)) return all_vols else: log.warning( "%s >> VOLCOLL REMOVE: No volume exists with string - '%s' found on array." % (self._hostname, vol_regex))
def set_volcoll_add(self, vol_regex=None, volcoll_regex=None, sync_repl=False, *args): volcoll_list = GetObj.rest_volcolllist(self, volcoll_regex=volcoll_regex) vol_list = GetObj.rest_vollist(self, vol_regex=vol_regex) all_vols = list( ) # all volumes with new volcoll added by this function qualified_vols = list() # all volumes that can be added to volcolls sync_repl_volcolls = list() # all volcoll with sync-repl enabled if vol_list and volcoll_list: qualified_vols = [ vol for vol in vol_list if vol.volcoll_name == '' ] sync_repl_volcolls = [ volcoll for volcoll in volcoll_list if volcoll.replication_type == 'synchronous' ] normal_volcolls = [ volcoll for volcoll in volcoll_list if volcoll.replication_type != 'synchronous' ] log.list("Filtered qualified volumes %s" % str([vol.full_name for vol in qualified_vols])) log.list("Filtered synchronous volcolls %s" % str([volcoll.full_name for volcoll in sync_repl_volcolls])) # todo Add support for non sync-repl vols else: log.warning( "%s >> VOLCOLL ADD: No volume with regex:'%s' or volcoll with regex:'%s' found to work on." % (self._hostname, vol_regex, volcoll_regex)) time.sleep(5) if sync_repl is not False and len(sync_repl_volcolls) != 0 and len( qualified_vols) != 0: for vol in qualified_vols: valid_volcolls = [ vc for vc in sync_repl_volcolls if vc.replication_partner != vol.pool_name ] # todo change to compare with pool id. if len(valid_volcolls) != 0: final_volcoll = random.choice(valid_volcolls) log.info( "%s >> VOLCOLL ADD: Valid volcoll for vol: %s is: %s with repl_partner as: %s" % (self._hostname, vol.full_name, final_volcoll.full_name, final_volcoll.replication_partner)) # time.sleep(10) try: data = '{"id":"%s","volcoll_id":"%s"}' % ( vol.vol_id, final_volcoll.volcoll_id) endpoint = 'volumes/%s' % vol.vol_id response = rest(hostname=self._hostname, username=self._username, password=self._password, endpoint=endpoint, action='PUT', in_data=data) except GenericError as e: log.error(e) else: if response and 'messages' in response: log.error( "%s >> VOLCOLL ADD: vol add of %s on volcoll %s - failed with error: %s" % (self._hostname, vol.full_name, final_volcoll.full_name, response['messages'][0]['text'])) else: log.info( "%s >> VOLCOLL ADD: vol add of %s on volcoll %s - successful!" % (self._hostname, vol.full_name, final_volcoll.full_name)) all_vols.append(vol.full_name) else: log.warning( "%s >> VOLCOLL ADD: No qualified sync-repl enabled volcoll found for volume %s." % (self._hostname, vol.full_name)) time.sleep(5) else: log.warning( "%s >> VOLCOLL ADD: No qualified volume or volcoll found to work on." % self._hostname) time.sleep(5) return all_vols if len(all_vols) > 0 else []