def create_tsm(user_params, stdurl): logging.info('inside create_tsm method...') logging.debug('getting default parameters for creating tsm') tsm_def_params = get_tsm_default_params() logging.debug('default parameters for creating tsm: %s', str(tsm_def_params)) logging.debug('getting final parametrs for creating tsm') final_tsm_params = modify_params(tsm_def_params, user_params) logging.debug('final parameters for creating tsm: %s', str(final_tsm_params)) command = 'command=createTsm' querycommand = form_querycommand(command, final_tsm_params) rest_api = str(stdurl) + str(querycommand) logging.debug('REST API for creating tsm: %s', (rest_api)) logging.info('Executing command sendrequest...') resp_addTsm = sendrequest(stdurl, querycommand) data = json.loads(resp_addTsm.text) logging.debug('response for creating TSM: %s', str(data)) if 'errorcode' in str(data): errormsg = str(data['addTsmResponse']['errortext']) logging.error('Not able to create Tsm due to: %s', errormsg) result = ['FAILED', errormsg] return result job_id = data['addTsmResponse']['jobid'] logging.debug('create Tsm job id: %s', job_id) logging.info('calling queryAsyncJobResult method...') create_tsm_status = queryAsyncJobResult(stdurl, job_id) if create_tsm_status[0] == 'PASSED': result = ['PASSED', 'TSM created successfuly'] return result else: result = ['FAILED', create_tsm_status] logging.debug('result of create_tsm: %s', str(result)) return result
def addDiskGroup_vdev(pool_id, clstr_id, group, disk_list, iops, sctr_size, stdurl): if '_' or ' ' in group: group = group.replace('_', '%20').replace(' ', '%20') logging.info('inside addDiskGroup_vdev method..') throughput = iops * 128 querycommand = 'command=addDiskGroup&poolid=%s&clusterid=%s&'\ 'grouptype=%s&diskslist=%s§orsize=%s&totaliops=%s&totalthroughput=%s' \ %(pool_id, clstr_id, group, disk_list, sctr_size, iops, throughput) rest_api = str(stdurl) + str(querycommand) logging.debug('REST API adding Disk group: %s', str(rest_api)) add_diskGroup = sendrequest(stdurl, querycommand) data = json.loads(add_diskGroup.text) logging.debug('response for adding disk group: %s', str(data)) if 'errorcode' in str(data): errormsg = str(data['addDiskgroupResponse'].get('errortext')) print errormsg result = ['FAILED', errormsg] logging.error('Not able to add disk group due to: %s', errormsg) return result logging.info('getting add disk group job id...') job_id = data['addDiskgroupResponse']['jobid'] logging.info('calling queryAsyncJobResult method...') addDiskGrp_status = queryAsyncJobResult(stdurl, job_id) logging.debug('Adding disk group status: %s', addDiskGrp_status) if addDiskGrp_status[0] == 'PASSED': result = ['PASSED', 'Added Disk Group successfuly'] else: result = ['FAILED', addDiskGrp_status] logging.debug('result of Adding Disk Group : %s', str(result)) return result
def create_pool(user_params, stdurl): logging.info('inside create_pool method...') command = 'command=addHAPool' logging.info('getting defaults parameters for create pool...') pool_def_params = get_pool_default_params() logging.debug('defaults parameters for create pool: %s', str(pool_def_params)) logging.info('getting final parametrs for creating pool...') pool_params = get_params(pool_def_params, user_params) logging.info('final parametrs for creating pool: %s', str(pool_params)) querycommand = get_querycommand(command, pool_params, 'pool') rest_api = str(stdurl) + str(querycommand) logging.debug('REST API for creating pool: %s', str(rest_api)) resp_createPool = sendrequest(stdurl, querycommand) data = json.loads(resp_createPool.text) logging.debug('response for create Pool: %s', str(data)) if 'errorcode' in str(data): errormsg = str(data['addHAPoolResponse'].get('errortext')) logging.error('Not able to create pool due to: %s', errormsg) result = ['FAILED', errormsg] return result logging.info('getting create pool job id...') job_id = data['addHAPoolResponse']['jobid'] logging.debug('create pool job id: %s', job_id) logging.info('calling queryAsyncJobResult method...') create_pool_status = queryAsyncJobResult(stdurl, job_id) logging.debug('create_pool_status: %s', create_pool_status) if create_pool_status[0] == 'PASSED': result = ['PASSED', 'Pool created successfuly'] else: result = ['FAILED', create_pool_status] logging.debug('result of create_pool: %s', str(result)) return result
def deleteVolume(): #########Delete File Systems querycommand = 'command=listFileSystem' resp_listFileSystem = sendrequest(stdurl, querycommand) filesave("logs/ListFileSystem.txt", "w", resp_listFileSystem) data = json.loads(resp_listFileSystem.text) filesystems = data["listFilesystemResponse"].get("filesystem") if filesystems == None: print 'There are no volumes' else: for filesystem in filesystems: filesystem_id = filesystem['id'] filesystem_name = filesystem['name'] acct_id = filesystem.get('accountid') init_grp = filesystem.get('initiatorgroup') if init_grp == 'ALL': assign_iniator_gp_to_LUN(stdurl, filesystem_id, acct_id, 'None') time.sleep(1) querycommand = 'command=deleteFileSystem&id=%s&forcedelete=true' % ( filesystem_id) resp_delete_volume = sendrequest(stdurl, querycommand) data = json.loads(resp_delete_volume.text) if 'errorcode' in str(data): errormsg = str( data['deleteFileSystemResponse'].get('errortext')) print 'Not able to delete volume %s, due to%s' % ( filesystem_name, errormsg) else: deleteJobId = data['deleteFileSystemResponse'].get('jobid') delete_volume_status = queryAsyncJobResult(stdurl, deleteJobId) if delete_volume_status[0] == 'PASSED': print 'Volume %s deleted successfully' % (filesystem_name) else: print 'Not able to delete volume %s' % (filesystem_name)
def delete_volume(id, stdurl): # id is volume id logging.info('Inside the delete_volume method...') querycommand = 'command=deleteFileSystem&id=%s' % (id) rest_api = str(stdurl) + str(querycommand) logging.debug('REST API for deleting volume: %s', str(rest_api)) resp_deleteFileSystem = sendrequest(stdurl, querycommand) data = json.loads(resp_deleteFileSystem.text) logging.debug('response for deleting volume: %s', str(data)) if 'errorcode' in str(data): errormsg = str(data['deleteFileSystemResponse'].get('errortext')) result = ['FAILED', 'Not able to delete volume due to: %s', errormsg] logging.error('Not able to delete volume due to: %s', errormsg) return result logging.info('getting job_id for deleting volume...') job_id = data['deleteFileSystemResponse']['jobid'] logging.debug('job_id for delet volume: %s', job_id) logging.info('calling queryAsyncJobResult method...') delete_volume_status = queryAsyncJobResult(stdurl, job_id) logging.debug('delete_volume_status: %s', delete_volume_status) if delete_volume_status[0] == 'PASSED': result = ['PASSED', 'Volume deleted successfuly'] else: result = ['FAILED', delete_volume_status] logging.debug('result of delete_volume: %s', str(result)) return result
def change_state(stdurl, ctrl_id, mode, ctrl_name): querycommand = 'command=changeControllerState&id=%s&state=%s' \ %(ctrl_id, mode) logging.debug('Executing changeControllerState...') resp_stateofnode = sendrequest(stdurl, querycommand) data = json.loads(resp_stateofnode.text) if 'errorcode' in str(data): errormsg = str(data['changeControllerStateResponse']['errortext']) logging.error('Not able to execute changeControllerState: %s', errormsg) return ['FAILED', errormsg] hajob_id = data['changeControllerStateResponse']['controller']['hajobid'] querycommand = 'command=listHAJobActivities&hajobid=%s' % (hajob_id) logging.debug('Executing listHAJobActivities...') hajob = sendrequest(stdurl, querycommand) data = json.loads(hajob.text) if 'errorcode' in str(data): errormsg = str(data['listHAJobActivitiesResponse']['errortext']) logging.error('Not able to execute listHAJobActivitiesResponse: %s',\ errormsg) return ['FAILED', errormsg] job_id = data['listHAJobActivitiesResponse']['jobid'] rstatus = queryAsyncJobResult(stdurl, job_id) querycommand = 'command=listHAJob&jobstatus=running' logging.debug('Executing listHAJob...') hajob = sendrequest(stdurl, querycommand) data = json.loads(hajob.text) logging.debug('response for listHAJob... %s', hajob) logging.debug('executing queryAsyncJobResult method for job: %s', job_id) rstatus = queryAsyncJobResult(stdurl, job_id) if rstatus[0] == 'PASSED': logging.debug('Node %s moved to %s successfully', ctrl_name, mode) return ['PASSED', ''] else: logging.debug('Node %s failed to moved to %s', ctrl_name, mode) return ['FAILED', '']
(x)], config['volCifsBlocklength%d' % (x)], subVolName, config['volCifsProtocoltype%d' % (x)]) respCreateVolume = sendrequest(stdurl, querycommand) filesave("logs/createVolume.txt", "w", respCreateVolume) resultCreateVolume = json.loads(respCreateVolume.text) if 'errortext' in str(resultCreateVolume): endTime = ctime() errormsg = resultCreateVolume['createvolumeresponse'][ 'errortext'] resultCollection('Not able to createVolume', ['FAILED', errormsg], startTime, endTime) exit() job_id = resultCreateVolume["createvolumeresponse"]["jobid"] rstatus = queryAsyncJobResult(stdurl, job_id) endTime = ctime() if rstatus[0] == 'FAILED': resultCollection( 'Creation of CIFS sub filesystem %s is failed:' % (subVolName), ['FAILED', rstatus[1]], startTime, endTime) exit() elif rstatus[0] == 'NotSure': resultCollection( 'Creation of CIFS sub filesystem %s is failed:' % (subVolName), ['FAILED', rstatus[1]], startTime, endTime) exit() else: resultCollection(
def create_volume(user_params, stdurl): logging.info('inside create_volume method...') logging.debug('getting default parameters for creating QoS group') qos_def_params = get_qos_default_params() logging.debug('default parameters for creating QoS group: %s', str(qos_def_params)) logging.debug('getting final parametrs for creating QoS group') qos_params = get_params(qos_def_params, user_params) #logging.debug('final parameters for creating QoS group: %s', str(qos_params)) command = 'command=addQosGroup' logging.debug('getting REST API for creating QoS group...') querycommand = get_querycommand(command, qos_params, 'qosgroup') rest_api = str(stdurl) + str(querycommand) logging.debug('REST API for creating QoS group: %s', (rest_api)) logging.info('Executing command sendrequest...') resp_addQosGroup = sendrequest(stdurl, querycommand) data = json.loads(resp_addQosGroup.text) logging.debug('response for add QoS group: %s', str(data)) if 'errorcode' in str(data): errormsg = str(data['addqosgroupresponse'].get('errortext')) result = ['FAILED', errormsg] logging.error('FAILED: %s', errormsg) return result logging.info('Getting qosgroupid...') qosgroup_id = data["addqosgroupresponse"]["qosgroup"]["id"] logging.debug('qosgroupid: %s', str(qosgroup_id)) command = 'command=createVolume&qosgroupid=%s' % (qosgroup_id) logging.info('getting defaults parameters for create volume...') if user_params.get('protocoltype') is not None: if user_params['protocoltype'] == 'ISCSI' or user_params[ 'protocoltype'] == 'FC': vol_def_params = get_iscsi_fc_default_params() elif user_params['protocoltype'] == 'NFS' or user_params[ 'protocoltype'] == 'CIFS': vol_def_params = get_nfs_cifs_default_params() else: logging.error( 'protocol type is not correct, please specify correct...') else: vol_def_params = get_iscsi_fc_default_params() logging.debug('defaults parameters for create volume: %s', str(vol_def_params)) logging.info('getting final parametrs for creating volume...') vol_params = get_params(vol_def_params, user_params) #logging.info('final parametrs for creating volume: %s', str(vol_params)) querycommand = get_querycommand(command, vol_params, 'volume') rest_api = str(stdurl) + str(querycommand) logging.debug('REST API for creating volume: %s', str(rest_api)) resp_createVolume = sendrequest(stdurl, querycommand) data = json.loads(resp_createVolume.text) logging.debug('response for create volume: %s', str(data)) if 'errorcode' in str(data): errormsg = str(data['createvolumeresponse'].get('errortext')) logging.error('Not able to create volume due to: %s', errormsg) result = ['FAILED', errormsg] return result logging.info('getting create volume job id...') job_id = data['createvolumeresponse']['jobid'] logging.debug('create volume job id: %s', job_id) logging.info('calling queryAsyncJobResult method...') create_volume_status = queryAsyncJobResult(stdurl, job_id) logging.debug('create_volume_status: %s', create_volume_status) if create_volume_status[0] == 'PASSED': result = ['PASSED', 'Volume created successfuly'] else: result = ['FAILED', create_volume_status] logging.debug('result of create_volume: %s', str(result)) return result
is_nfs = filesystem['nfsenabled'] print "status :" + status print "is_nfs " print is_nfs if str(is_nfs).lower() == 'true': if status.lower() == 'online': querycommand = 'command=deleteFileSystem&id=%s' % ( filesystem_id) else: querycommand = 'command=deleteFileSystem&id=%s&forcedelete=true' % ( filesystem_id) resp_delete_volume = sendrequest(stdurl, querycommand) filesave("logs/DeleteFileSystem", "w", resp_delete_volume) data = json.loads(resp_delete_volume.text) job_id = data["deleteFileSystemResponse"]["jobid"] queryAsyncJobResult(stdurl, job_id) print "\n%s is deleted\n" % (filesystem_name) print "All NFS Volumes are Deleted" time.sleep(2) if cifsFlag == 1 or allFlag == 1: print "\nDeleting CIFS Volumes ...\n" for filesystem in filesystems: filesystem_id = filesystem['id'] filesystem_name = filesystem['name'] status = filesystem['status'] is_cifs = filesystem['cifsenabled'] if str(is_cifs).lower() == 'true': if status.lower() == 'online': querycommand = 'command=deleteFileSystem&id=%s' % ( filesystem_id)