def revert_snapshot(stdurl, volid, snp_name): logging.debug('Inside revert_snapshot...') querycommand = 'command=listStorageSnapshots&id=%s' % volid logging.debug('Executing listStorageSnapshots method...') resp_list_snapshot = sendrequest(stdurl, querycommand) data = json.loads(resp_list_snapshot.text) if 'errorcode' in str(data): errormsg = str(data['listDatasetSnapshotsResponse']['errortext']) logging.error('Failed to list snapshot Error: %s', errormsg) return ['PASSED', ''] if 'snapshot' not in str(data): logging.debug('There is no snapshot to revert') return ['FAILED', 'There is no snapshot to revert'] snapshots = data['listDatasetSnapshotsResponse']['snapshot'] path = None for snapshot in snapshots: path = None if snapshot['name'] == snp_name: path = snapshot.get('path') break if path is None: logging.error('Not able to get snapshot path for reverting it') return ['FAILED', 'Not able to get snapshot path'] querycommand = 'command=rollbackToSnapshot&id=%s&path=%s' % (volid, path) logging.debug('Executing rollbackToSnapshot method...') resp_rollbackToSnapshot = sendrequest(stdurl, querycommand) data = json.loads(resp_rollbackToSnapshot.text) if 'errorcode' in str(data): errormsg = str(data['']['errortext']) logging.debug('Failed to revert snp %s Error: %s', snp_name, errormsg) return ['FAILED', ''] logging.debug('snapshot %s reverted successfully', snp_name) return ['PASSED', '']
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 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 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 edit_qos_syncronization(stdurl, volid, condition): ## Here condition refers to always or standard logging.info('Inside edit_qos_syncronization method....') logging.debug( 'getting REST API for editing QoS group syncronization property...') querycommand = 'command=updateFileSystem&id=%s&sync=%s' % (volid, condition) rest_api = stdurl + querycommand logging.debug('REST API for editing QoS group syncronization property: %s', (rest_api)) logging.info('Executing command sendrequest...') resp_updateQOS = sendrequest(stdurl, querycommand) upddata = json.loads(resp_updateQOS.text) logging.debug('Response for editing QoS group syncronization property: %s', str(upddata)) if 'errorcode' in str(upddata): errormsg = str(upddata['updatefilesystemresponse'].get('errortext')) result = ['FAILED', errormsg] return result logging.info('Getting new syncronization condition...') value = upddata['updatefilesystemresponse']['filesystem'][0]['sync'] new_value = str(value).lower() logging.debug('new syncronization condition is %s', (new_value)) if condition == new_value: result = [ 'PASSED', 'syncronization condition is updated to %s ' % (new_value) ] return result else: result = ['FAILED', 'syncronization condition is not updated'] return result
def edit_qos_readonly(stdurl, volid, condition): ##condition refers to true or false #print "condition ="+condition logging.info('Inside edit_qos_readonly method....') logging.debug( 'getting REST API for editing QoS group readonly property...') querycommand = 'command=updateFileSystem&id=%s&readonly=%s' % (volid, condition) rest_api = stdurl + querycommand logging.debug('REST API for editing QoS group read only property: %s', (rest_api)) logging.info('Executing command sendrequest...') resp_updateQOS = sendrequest(stdurl, querycommand) upddata = json.loads(resp_updateQOS.text) logging.debug('Response for editing QoS group readonly property: %s', str(upddata)) if 'errorcode' in str(upddata): errormsg = str(upddata['updatefilesystemresponse'].get('errortext')) result = ['FAILED', errormsg] return result logging.info('Getting new read only condition...') value = upddata['updatefilesystemresponse']['filesystem'][0]['readonly'] new_value = str(value).lower() logging.debug('new read only condition is %s', (new_value)) if condition == new_value: result = [ 'PASSED', 'Read only condition is updated to %s ' % (new_value) ] return result else: result = ['FAILED', 'New condition is not updated'] return result
def edit_qos_iops(group_id, iops_value, stdurl): logging.info('.....inside edit_qos_iops method....') logging.debug('getting REST API for editing QoS group IOPS properties...') querycommand = 'command=updateQosGroup&id=%s&iops=%s' % (group_id, iops_value) rest_api = stdurl + querycommand logging.debug('REST API for editing QoS group IOPS properties: %s', (rest_api)) logging.info('Executing command sendrequest...') resp_updateQOS = sendrequest(stdurl, querycommand) upddata = json.loads(resp_updateQOS.text) logging.debug('Response for editing QoS group IOPS properties: %s', str(upddata)) if 'errorcode' in str(upddata): errormsg = str(upddata['updateqosresponse'].get('errortext')) result = ['FAILED', errormsg] logging.error('FAILED: %s', errormsg) return result else: logging.info('Getting new ipos value') iops = upddata['updateqosresponse']['qosgroup'][0]['iops'] logging.debug('new iops value is %s', (iops)) vol_name = upddata['updateqosresponse']['qosgroup'][0]['name'] if int(iops_value) == int(iops): msg = "Updated Iops in " + vol_name + " is " + iops print msg result = ['PASSED', upddata] logging.debug('PASSED: %s', upddata) return result else: errormsg = "IOPS not updated in " + vol_name result = ['FAILED', errormsg] logging.error('FAILED: %s', errormsg) return result
def edit_qos_tp(groupid, tpvalue, stdurl): logging.info('.....inside edit_qos_tp method....') logging.debug( 'getting REST API for editing QoS group THROUGHPUT properties...') querycommand = 'command=updateQosGroup&id=%s&throughput=%s' % (groupid, tpvalue) rest_api = stdurl + querycommand logging.debug('REST API for editing QoS group THROUGHPUT properties: %s', (rest_api)) logging.info('Executing command sendrequest...') resp_updateQOS = sendrequest(stdurl, querycommand) upddata = json.loads(resp_updateQOS.text) logging.debug('Response for editing QoS group THROUGHPUT properties: %s', str(upddata)) if 'errorcode' in str(upddata): errormsg = str(upddata['updateqosresponse'].get('errortext')) result = ['FAILED', errormsg] logging.error('FAILED: %s', errormsg) return result else: logging.info('Getting new throuhput value') tp = upddata['updateqosresponse']['qosgroup'][0]['throughput'] logging.debug('new throughput value is %s', (tp)) vol_nametp = upddata['updateqosresponse']['qosgroup'][0]['name'] if int(tpvalue) == int(tp): print "Throughput is updated in " + vol_nametp + " is " + tp result = ['PASSED', upddata] logging.debug('PASSED: %s', upddata) return result else: errormsg = "Throughput is not updated in " + vol_nametp result = ['FAILED', errormsg] logging.error('FAILED: %s', errormsg) return result
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 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 get_account_id(stdurl, account_name): querycommand = 'command=listAccount' resp_listAccount = sendrequest(stdurl, querycommand) data = json.loads(resp_listAccount.text) if 'errorcode' in str(data): errormsg = str(data['listAccountResponse'].get('errortext')) print 'Not able to get accounts, Error: %s' % (errormsg) logging.error('Not able to get accounts, Error: %s', errormsg) return ['FAILED', errormsg] accounts = data['listAccountResponse'].get('account') if accounts is None: print 'There is no Accounts to list...' logging.debug('There is no Accounts to list, please create account '\ 'and procede...') return ['BLOCKED', 'There is no Accounts...'] isAccount = False for account in accounts: if account_name is None: account_id = account['id'] return ['PASSED', account_id] elif account['name'] == account_name: account_id = account['id'] return ['PASSED', account_id] else: continue if not isAccount: return ['BLOCKED', 'There is no account with given name']
def get_node2_ip(NODE1_IP, stdurl): querycommand = 'command=listController' logging.debug('executing listController...') listController_resp = sendrequest(stdurl, querycommand) data = json.loads(listController_resp.text) if 'errorcode' in str(data): errormsg = str(data['listControllerResponse'].get('errortext')) logging.error('ungracefull HA test case(iSCSI) blocked '\ 'due to %s', errormsg) is_blocked(startTime, FOOTER_MSG, errormsg) controllers = data['listControllerResponse']['controller'] has_second_node = False has_first_node = False NODE2_IP = None for controller in controllers: if controller['ipAddress'] == NODE1_IP: node1_clustername = controller['clustername'] has_first_node = True if has_second_node: if node2_clustername == node1_clustername: return NODE2_IP continue node2_clustername = controller['clustername'] NODE2_IP = controller['ipAddress'] has_second_node = True if has_first_node: if node1_clustername == node2_clustername: return NODE2_IP if NODE2_IP is None: logging.error('ungracefull HA test case(iSCSI) blocked '\ 'due to %s', 'There is no second Node') is_blocked(startTime, FOOTER_MSG, 'There is no second Node') return NODE2_IP
def deleteiscsiInitiatorGrp(stdurl, acc_id, grpName): querycommand = 'command=listiSCSIInitiator&accountid=%s'\ %(acc_id) rest_api = str(stdurl) + str(querycommand) logging.debug('REST API for listiSCSIInitiator...%s', rest_api) logging.debug('executing sendrequest command...') resp_listiSCSIInitiator = sendrequest(stdurl, querycommand) data = json.loads(resp_listiSCSIInitiator.text) if 'initiator' in str(data): init = data['listInitiatorsResponse']['initiator'] for initiator in init: if initiator['name'] == grpName: initID = initiator['id'] querycommand = 'command=deleteiSCSIInitiator&accountid=%s&id=%s'\ %(acc_id, initID) rest_api = str(stdurl) + str(querycommand) logging.debug('REST API for deleteIscsiInitiator... %s', rest_api) resp_deliSCSIInitiator = sendrequest(stdurl, querycommand) data = json.loads(resp_deliSCSIInitiator.text) if 'errorcode' in str(data): errormsg = data['deleteiscsiinitiatorResponse'][ 'errortext'] print errormsg logging.debug('%s', errormsg) result = ['FAILED', errormsg] return result else: print 'Deleted iscsiInitator Group %s' % grpName logging.debug('Deleted iscsiInitator Group "%s"', grpName) result = ['PASSED', 'Deleted iscsiInitator Group'] return result else: print 'Initiator group "%s" not present' % grpName logging.debug('iscsiInitator Group "%s" not present', grpName) result = ['FAILED', 'iscsiInitator Group not present'] return result else: errormsg = data['listInitiatorsResponse']['errortext'] logging.debug('%s', errormsg) print errormsg result = ['FAILED', errormsg] return result
def deletePool(): querycommand = 'command=listHAPool' resp_listHAPool = sendrequest(stdurl, querycommand) data = json.loads(resp_listHAPool.text) hapools = data["listHAPoolResponse"].get("hapool") if hapools == None: print 'There are no pools' else: for hapool in hapools: hapool_id = hapool['id'] hapool_name = hapool['name'] querycommand = 'command=deleteHAPool&id=%s&forcedelete=true' % ( hapool_id) resp_delete_hapool = sendrequest(stdurl, querycommand) data = json.loads(resp_delete_hapool.text) if 'errorcode' in str(data): errormsg = str(data['deleteHAPoolResponse']['errortext']) print errormsg else: print "Deleted the HAPool", hapool_name time.sleep(1)
def deleteVSM(): querycommand = 'command=listTsm' resp_listTsm = sendrequest(stdurl, querycommand) filesave("logs/listTSM.txt", "w", resp_listTsm) data = json.loads(resp_listTsm.text) tsms = data["listTsmResponse"].get("listTsm") if tsms == None: print 'There are no tsms' else: for tsm in tsms: tsm_id = tsm['id'] tsm_name = tsm['name'] querycommand = 'command=deleteTsm&id=%s&forcedelete=true' % ( tsm_id) resp_delete_tsm = sendrequest(stdurl, querycommand) data = json.loads(resp_delete_tsm.text) if 'errorcode' in str(data): errormsg = str(data['deleteTsmResponse']['errortext']) print errormsg else: print "Deleted the TSM", tsm_name time.sleep(1)
def mapUsertoRootToYes(volid, ClientIP): logging.info('Setting map user to root to yes method...') querycommand = 'command=listNfs&datasetid=%s' % (volid) resp_listNfsClient = sendrequest(stdurl, querycommand) data = json.loads(resp_listNfsClient.text) if 'nfs' in data["listNfsProtocolResponse"]: listNfs = data["listNfsProtocolResponse"]["nfs"] for nfs in listNfs: authnetwork = nfs['authnetwork'] if authnetwork == ClientIP: nfsClientID = nfs['id'] querycommand='command=updateNfs&id=%s&authnetwork=%s&'\ 'readonly=No&mapuserstoroot=Yes&alldirs=Yes&'\ 'managedstate=true&response=json' %(nfsClientID, ClientIP) resp_updateNfs = sendrequest(stdurl, querycommand) logging.debug('Rest api for map user to root to set it as '\ 'yes: %s',resp_updateNfs) data4 = json.loads(resp_updateNfs.text) logging.debug('map user set to yes response: %s', data4) if "errorcode" in data4["UpdateNfsProtocolResponse"]: errormsg = str( data4["UpdateNfsProtocolResponse"].get("errortext")) print errormsg result = ['FAILED', errormsg] return result else: msg = 'Map user to root is set to Yes for Authorized NFS '\ 'client "%s"' %authnetwork result = ["PASSED", msg] return result else: result = ['FAILED', 'Client not present, either it was deleted '\ 'or it was not created'] return result else: result = ['FAILED', 'NO NFS Clients Service are present in the volume'] return result
def allDirEdit(volid, ClientIP): logging.info('Setting All dir to no method...') querycommand = 'command=listNfs&datasetid=%s' % (volid) resp_listNfsClient = sendrequest(stdurl, querycommand) data = json.loads(resp_listNfsClient.text) if 'nfs' in data["listNfsProtocolResponse"]: listNfs = data["listNfsProtocolResponse"]["nfs"] for nfs in listNfs: authnetwork = nfs['authnetwork'] if authnetwork == ClientIP: nfsClientID = nfs['id'] querycommand='command=updateNfs&id=%s&authnetwork=%s&'\ 'readonly=No&mapuserstoroot=Yes&alldirs=No&'\ 'managedstate=true&response=json' %(nfsClientID, ClientIP) logging.info('Setting All Dir to "NO" for Authorized NFS '\ 'client "%s"', authnetwork) resp_updateNfs = sendrequest(stdurl, querycommand) data4 = json.loads(resp_updateNfs.text) if "errorcode" in data4["UpdateNfsProtocolResponse"]: errormsg = str( data4["UpdateNfsProtocolResponse"]["errortext"]) logging.error('%s', errormsg) print errormsg result = ['FAILED', errormsg] return result else: print 'ALL dir is set to no for Authorized NFS '\ 'client "%s"' %authnetwork result = ["PASSED", 'ALL DIR is set to NO'] return result else: result = ['FAILED', 'Client not present, either it was deleted '\ 'or it was not created'] return result else: result = ['FAILED', 'NO NFS Clients Service are present in the volume'] return result
def addNFSclient(stdurl, filesystemID, Client): logging.info('Adding NFS Client method...') querycommand = 'command=nfsService&datasetid=%s&authnetwork=%s&'\ 'managedstate=true&alldirs=Yes&mapuserstoroot=No&readonly=No&'\ 'response=json' %(filesystemID, Client) rest_api = str(stdurl) + str(querycommand) logging.debug('REST API for adding NFS client: %s', str(rest_api)) set_NFSService = sendrequest(stdurl, querycommand) data = json.loads(set_NFSService.text) logging.debug('response for add nfs client: %s', str(data)) if "errorcode" in data["nfsserviceprotocolresponse"]: errormsg = str(data["nfsserviceprotocolresponse"].get("errortext")) print errormsg logging.error('%s', errormsg) result = ['FAILED', errormsg] return result else: logging.info('Getting nfs id') nfs_id = data["nfsserviceprotocolresponse"]["nfs"]["id"] logging.debug('nfs id : "%s"', nfs_id) logging.info('Getting controller id') ctrl_id = data["nfsserviceprotocolresponse"]["nfs"]["controllerid"] logging.debug('controller id : "%s"', ctrl_id) querycommand = 'command=updateController&nfsid=%s&type=configurenfs'\ '&id=%s&response=json' %(nfs_id, ctrl_id) rest_api = str(stdurl) + str(querycommand) logging.debug('REST API for updating controller: %s', str(rest_api)) UpadateNFSService = sendrequest(stdurl, querycommand) data = json.loads(UpadateNFSService.text) logging.debug('response for updating controller: %s', str(data)) if "errorcode" in data["updateControllerResponse"]: errormsg = str(data["updateControllerResponse"].get("errortext")) logging.error('%s', errormsg) result1 = ['FAILED', errormsg] return result1 result = ['PASSED', 'NFS client added successfully'] return result
def listGlobalSettings_param(stdurl): logging.info('Inside the Global setting update method...') querycommand = 'command=listConfigurations' rest_api = str(stdurl) + str(querycommand) listGlobalSettings_param = sendrequest(stdurl, querycommand) data = json.loads(listGlobalSettings_param.text) logging.debug('response for global settings list: %s', str(data)) if 'errorcode' in str(data): errormsg = str(data['listglobalsettingsresponse'].get('errortext')) result = ['FAILED', errormsg] return result else: global_config = data["listconfigurationsresponse"]["configuration"] result = ['PASSED', global_config] 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', '']
def set_readonly(vol_id, operation, stdurl): logging.info('Setting read only method...') querycommand = 'command=updateFileSystem&id=%s&readonly=%s' \ %(vol_id, operation) rest_api = str(stdurl) + str(querycommand) logging.debug('REST API for setting readonly: %s', str(rest_api)) response_read = sendrequest(stdurl, querycommand) data = json.loads(response_read.text) logging.debug('response for ready only: %s', str(data)) if 'errorcode' in str(data['updatefilesystemresponse']): errormsg = str(data['updatefilesystemresponse'].get('errortext')) print errormsg return ['FAILED', errormsg] else: return ['PASSED', 'Successfully updated readonly']
def monitorFilesystemQoS(stdurl, volid): querycommand = 'command=monitorFileSystemQoS&id=%s' % (volid) rest_api = str(stdurl) + str(querycommand) logging.debug('Rest Api for Monitor FS Qos : %s', str(rest_api)) resp_FSqos = sendrequest(stdurl, querycommand) data = json.loads(resp_FSqos.text) logging.debug('Response for Monitor FS Qos: %s', str(data)) if 'monitorFilesystemQoS' in str(data['monitorFileSystemResponse']): fs_qos = data['monitorFileSystemResponse']['monitorFilesystemQoS'] result = ['PASSED', fs_qos] return result else: errormsg = str(data['monitorFileSystemResponse'].get('errortext')) result = ['FAILED', errormsg] return result
def create_account(account_name, stdurl): logging.info('inside create_ccount method...') querycommand = 'command=createAccount&name=%s&description=None' % ( account_name) rest_api = str(stdurl) + str(querycommand) logging.debug('REST API for creating tsm: %s', (rest_api)) resp_createAccount = sendrequest(stdurl, querycommand) data = json.loads(resp_createAccount.text) logging.debug('response for creating Account: %s', str(data)) if 'errorcode' in str(data): errormsg = str(data['createaccountresponse'].get('errortext')) print errormsg return ['FAILED', errormsg] else: return ['PASSED', 'Successfully created account']
def addInitiator(account_id, initGroup, bothInitiatorIqn, network, stdurl): querycommand = 'command=addiSCSIInitiator&accountid=%s&name=%s&'\ 'initiatorgroup=%s&netmask=%s' \ %(account_id, initGroup, bothInitiatorIqn, network) logging.info('Executing command to add ISCSI InitiatorGroup in Account') resp_addInitiator = sendrequest(stdurl, querycommand) data = json.loads(resp_addInitiator.text) AddInitiators = data["tsmiSCSIInitiatorResponse"] if 'errorcode' in str(AddInitiators): errormsg = str(data['tsmiSCSIInitiatorResponse']['errortext']) print errormsg result = ["FAILED", errormsg] return result else: result = ['PASSED', 'Added initiator group'] return result
def editNFSthreads(tsm_id, threads, stdurl): logging.info('Editing NFS thread value method...') querycommand = 'command=updateTsmNfsOptions&tsmid=%s&nfsworkerthreads=%s' \ %(tsm_id, threads) rest_api = str(stdurl) + str(querycommand) logging.debug('REST API for editing tsm IOPS: %s', str(rest_api)) resp_threadUpdate = sendrequest(stdurl, querycommand) data = json.loads(resp_threadUpdate.text) if 'errorcode' in str(data): errormsg = str(data['updateTsmNfsOptionsResponse']['errortext']) print errormsg logging.error('%s', errormsg) result = ['FAILED', errormsg] return result else: result = ['PASSED', 'Successfully updated thread value'] return result
def editTsmQuota(dataset_id, quota, stdurl): logging.info('Editing tsm quota method..') querycommand = 'command=updateStorage&id=%s"asize=%s' %(dataset_id, quota) rest_api = str(stdurl) + str(querycommand) logging.debug('REST API for editing tsm quota: %s', str(rest_api)) edit_tsmQuota = sendrequest(stdurl, querycommand) data = json.loads(edit_tsmQuota.text) logging.debug('response for editing tsm quota: %s', str(data)) if 'errorcode' in data['updatedatasetresponse']: errormsg = str(data['updatedatasetresponse']['errortext']) print errormsg logging.error('%s', errormsg) result = ['FAILED', errormsg] return result else: result = ['PASSED', 'Successfully updated TSM quota size'] return result
def delete_tsm(tsm_id, stdurl): logging.info('Inside the delete tsm method...') querycommand = 'command=deleteTsm&id=%s' %(tsm_id) rest_api = str(stdurl) + str(querycommand) logging.debug('REST API for deleting TSM: %s', str(rest_api)) resp_deleteTsm = sendrequest(stdurl, querycommand) data = json.loads(resp_deleteTsm.text) logging.debug('response for deleting tsm: %s', str(data)) if 'errorcode' in str(data): errormsg = str(data['deleteTsmResponse']['errortext']) print errormsg result = ['FAILED', 'Not able to delete tsm due to: %s', errormsg] logging.error('Not able to delete tsm due to: %s', errormsg) return result else: result = ['PASSED', 'Successfully deleted Tsm'] return result
def updateGlobalSettings(config_name , value, stdurl): logging.info('Inside the Global setting update method...') querycommand = 'command=updateConfiguration&name=%s&value=%s' \ %(config_name, value) logging.info('updating the global setting : %s', config_name) rest_api = str(stdurl) + str(querycommand) logging.debug('REST API for global settings update: %s', str(rest_api)) update_global = sendrequest(stdurl, querycommand) data = json.loads(update_global.text) logging.debug('response for global settings update: %s', str(data)) if 'errorcode' in str(data): errormsg = str(data['updateconfigurationresponse'].get('errortext')) result = ['FAILED', errormsg] return result else: result = ['PASSED', 'Successfully updated global configuration'] return result
def get_node_ip(stdurl, controllerid): node_ip = None querycommand = 'command=listController&id=%s' %(controllerid) rest_api = str(stdurl) + str(querycommand) logging.debug('REST API for listController... %s', rest_api) logging.debug('getting controllers IP...') resp_listController = sendrequest(stdurl, querycommand) data = json.loads(resp_listController.text) if 'errorcode' in str(data): errormsg = str(data['listControllerResponse']['errortext']) logging.error('Not able to get list controllers... %s', errormsg) return ['FAILED', ''] node_ip = (data['listControllerResponse']['controller'][0]).get('ipAddress') if node_ip is not None: return ['PASSED', node_ip] logging.debug('Not able to get Node IP... %s') return ['FAILED', '']
def list_controller(stdurl): querycommand = 'command=listController' logging.debug('Executing listController...') resp_listcontroller = sendrequest(stdurl, querycommand) data = json.loads(resp_listcontroller.text) if 'errorcode' in str(data): errormsg = str(data['listControllerResponse']['errortext']) logging.error('Not able to list controllers Error: %s', errormsg) result = ['FAILED', errormsg] elif 'controller' in data['listControllerResponse']: controllerlist = data['listControllerResponse']['controller'] result = ['PASSED', controllerlist] else: print 'There is no Node' logging.debug('There is no Node available to list') result = ['FAILED', 'There is no Node available to list'] return result