def main_menu(): global disk_volume, lun_size os.system("clear") print ("[ Storage Adm ]\n[ Version {0} - © 2015 ]\n\n".format(globalvar.version)) stgadm = raw_input( "STG Adm options\n\n" "1. Add new volumes to existent host. (create change)\n" "2. Execute changes created.\n" "\nPlease choose an option: " ) # Add new volumes to existent host menu if stgadm == "1": print ("\n\nRequest informations\n") change = fields.Fields("change", "Ticket/Change/Work Order: ") change.chkfieldstr() change = change.strvarout() hostname_client = fields.Fields("hostname", "Hostname Client: ") hostname_client.chkfieldstr() hostname_client = hostname_client.strvarout() wwn_client = fields.Fields("wwn_client", "WWN Server Client: ") wwn_client.chkfieldstr() wwn_client = wwn_client.strvarout() disk_volume = int() lun_size = int() while True: try: disk_volume = int(raw_input("Total Disk Required (GB): ")) break except (TypeError, ValueError): print ( "\tERROR: Total Disk need to be an int value in GB. " "\nDo not use GB. Example: 1000 for 1000GB (1TB)." ) while True: try: lun_size = int(raw_input("Default LUN size (GB): ")) break except (TypeError, ValueError): print ( "\tERROR: LUN Size need to be an int value." "\nDo not use GB. Example 100 for 100GB size of LUNs." ) if ":" in wwn_client: wwn_client = wwn_client.replace(":", "") # select storage get_stg = systemstorages.SystemStorages() get_stg.selectstorage() stg_type = get_stg.gettype() if stg_type == "EMC_VMAX": stg_sid = get_stg.getsid() stg_name = get_stg.getstorage() storage_name = stg_name menu_emc_vmax(change, hostname_client, storage_name, stg_name, stg_type, stg_sid, wwn_client) elif stg_type == "EMC_VNX": pass else: print ("ERROR: Storage type {0} invalid. Check config file".format(stg_type)) elif stgadm == "2": change_file = findchange.select().replace(".py", "") os.system('python -c "import stgadm.changes.{0}; ' 'stgadm.changes.{0}.preview()"'.format(change_file)) execute_change = fields.YesNo("Do you would like execute this " "change?[y/n]: ", "n") execute_change = execute_change.check() if execute_change == "y": os.system('python -c "import stgadm.changes.{0}; ' 'stgadm.changes.{0}.execute()"'.format(change_file)) orig_change = "{0}/stgadm/changes/{1}.py".format(config.stghome, change_file) dest_change = "{0}/stgadm/changes_executed/{1}.py".format(config.stghome, change_file) os.rename(orig_change, dest_change) else: print "Wrong option. Exiting."
def main_menu(): global disk_volume, lun_size os.system('clear') print('[ Storage Adm ]\n[ Version {0} - © 2016 ]\n\n'.format( globalvar.version)) stgadm = raw_input('STG Adm options\n\n' '1. Add new volumes to existent host. (create change)\n' '2. Execute changes created.\n' '\nPlease choose an option: ') # Add new volumes to existent host menu if stgadm == '1': print('\n\nRequest informations\n') change = fields.Fields('change', 'Ticket/Change/Work Order: ') change.chkfieldstr() change = change.strvarout() hostname_client = fields.Fields('hostname', 'Hostname Client: ') hostname_client.chkfieldstr() hostname_client = hostname_client.strvarout() wwn_client = fields.Fields('wwn_client', 'WWN Server Client: ') wwn_client.chkfieldstr() wwn_client = wwn_client.strvarout() disk_volume = int() lun_size = int() while True: try: disk_volume = int(raw_input("Total Disk Required (GB): ")) break except (TypeError, ValueError): print( '\tERROR: Total Disk need to be an int value in GB. ' '\nDo not use GB. Example: 1000 for 1000GB (1TB).') while True: try: lun_size = int(raw_input("Default LUN size (GB): ")) break except (TypeError, ValueError): print( '\tERROR: LUN Size need to be an int value.' '\nDo not use GB. Example 100 for 100GB size of LUNs.') if ':' in wwn_client: wwn_client = wwn_client.replace(':', '') # select storage get_stg = systemstorages.SystemStorages() get_stg.selectstorage() stg_type = get_stg.gettype() if stg_type == 'EMC_VMAX': stg_sid = get_stg.getsid() stg_name = get_stg.getstorage() storage_name = stg_name menu_emc_vmax(change, hostname_client, storage_name, stg_name, stg_type, stg_sid, wwn_client) elif stg_type == 'EMC_VNX': pass else: print('ERROR: Storage type {0} invalid. Check config file'.format( stg_type)) elif stgadm == '2': change_file = findchange.select().replace('.py', '') os.system('python -c \"import stgadm.changes.{0}; ' 'stgadm.changes.{0}.preview()\"' .format(change_file)) execute_change = fields.YesNo('Do you would like execute this ' 'change?[y/n]: ', 'n') execute_change = execute_change.check() if execute_change == 'y': os.system('python -c \"import stgadm.changes.{0}; ' 'stgadm.changes.{0}.execute()\"' .format(change_file)) orig_change = '{0}/stgadm/changes/{1}.py'.format(config.stghome, change_file) dest_change = '{0}/stgadm/changes_executed/{1}.py'.format( config.stghome, change_file) os.rename(orig_change, dest_change) else: print 'Wrong option. Exiting.'
def main_menu(): global disk_volume, lun_size, execute_change def _cancel_change(change_file_name): orig_change = '{0}/stgadm/changes/{1}.py'.format( config.stghome, change_file_name) dest_change = '{0}/stgadm/changes_canceled/{1}.py'.format( config.stghome, change_file_name) os.rename(orig_change, dest_change) def _finish_change(change_file_name): orig_change = '{0}/stgadm/changes/{1}.py'.format( config.stghome, change_file_name) dest_change = '{0}/stgadm/changes_executed/{1}.py'.format( config.stghome, change_file_name) os.rename(orig_change, dest_change) os.system('clear') print('') print('[ Storage Adm ]') print('[ ]') print('[ Version {0} - (c) 2016 Kairo Araujo ]'.format(globalvar.version)) print('[ http://github.com/kairoaraujo/STGAdm ]') print('[ BSD License ]') print('[ ]') stgadm = raw_input('\nMain Menu:\n\n' '1. Add new volumes to existent host. (create change)\n' '2. Execute changes created.\n' '\nPlease choose an option: ') # Add new volumes to existent host menu if stgadm == '1': print('\n\n[ REQUEST INFORMATIONS ]\n') change = fields.Fields('change', 'Ticket/Change/Work Order: ') change.chkfieldstr() change = change.strvarout() hostname_client = fields.Fields('hostname', 'Hostname Client: ') hostname_client.chkfieldstr() hostname_client = hostname_client.strvarout() wwn_client = fields.Fields('wwn_client', 'WWN Server Client: ') wwn_client.chkfieldstr() wwn_client = wwn_client.strvarout() disk_volume = int() lun_size = int() while True: try: disk_volume = int(raw_input("Total Disk Required (GB): ")) break except (TypeError, ValueError): print('\tERROR: Total Disk need to be an int value in GB. ' '\nDo not use GB. Example: 1000 for 1000GB (1TB).') while True: try: lun_size = int(raw_input("Default LUN size (GB): ")) if disk_volume % lun_size == 0: break else: print('\tERROR: The LUN size need to be a divisor of Total' 'required disk.' '\n\t If Total Disk Required is wrong, please ' 'use "Ctrl+C".') except (TypeError, ValueError): print('\tERROR: LUN Size need to be an int value.' '\nDo not use GB. Example 100 for 100GB size of LUNs.') if ':' in wwn_client: wwn_client = wwn_client.replace(':', '') # select storage get_stg = systemstorages.SystemStorages() get_stg.selectstorage() stg_type = get_stg.gettype() if stg_type == 'EMC_VMAX': stg_sid = get_stg.getsid() stg_name = get_stg.getstorage() storage_name = stg_name menu_emc_vmax(change, hostname_client, storage_name, stg_name, stg_type, stg_sid, wwn_client) elif stg_type == 'IBM_DS8K': stg_sid = get_stg.getsid() stg_name = get_stg.getstorage() storage_name = stg_name menu_ibm_ds8k(change, hostname_client, storage_name, stg_name, stg_type, stg_sid, wwn_client) elif stg_type == 'EMC_VNX': storage_name = get_stg.getstorage() stg_1ip = get_stg.getvnx_1ip() stg_2ip = get_stg.getvnx_2ip() stg_user = get_stg.getvnx_user() stg_pass = get_stg.getvnx_pass() stg_scope = get_stg.getvnx_scope() menu_emc_vnx(change, hostname_client, storage_name, storage_name, stg_type, stg_1ip, stg_2ip, stg_user, stg_pass, stg_scope, wwn_client) else: print('ERROR: Storage type {0} invalid. Check config file'.format( stg_type)) elif stgadm == '2': change_file = findchange.select().replace('.py', '') # import change_file change_module = importlib.import_module( 'stgadm.changes.{0}'.format(change_file)) try: change_module.preview() except ValueError: if change_module.stg_type == 'IBM_DS8K': print('Removing LUN ID reserve...') for l_1_id in change_module.lss_1_id_list: ds8k_add_dev.remove_reserved_id(l_1_id) for l_2_id in change_module.lss_2_id_list: ds8k_add_dev.remove_reserved_id(l_2_id) print('LUN ID cleanup finished.') elif change_module.stg_type == 'EMC_VNX': print('Removing LUN ID reserve...') # remove lu: for lu_id in change_module.lu_ids: vnx_add_dev.remove_reserved_id(lu_id) print('Removing HLU ID reserve... ') # remove hlu for hlu_id in change_module.hlu_ids: vnx_add_dev.remove_reserved_hlu_id( hlu_id, change_module.stggroup_name) # remove hlu if is for cluster for cluster_node in change_module.cls_nodes.keys(): for hlu_id in change_module.cls_nodes[cluster_node][3]: vnx_add_dev.remove_reserved_hlu_id( hlu_id, change_module.cls_nodes[cluster_node][1]) print('LUN and HLU ID cleanup finished.') _cancel_change(change_file) exit() execute_change = fields.YesNo( 'Do you would like execute this ' 'change?[y/n]: ', 'n') execute_change = execute_change.check() if execute_change == 'y': print("Executing the change. Please wait...\n") # import change_file change_module = importlib.import_module( 'stgadm.changes.{0}'.format(change_file)) try: change_module.execute() except ValueError as e: print("ERROR: {}".format(e)) _finish_change(change_file) else: print('Wrong option. Exiting.')
def main_menu(): global disk_volume, lun_size, execute_change def _cancel_change(change_file_name): orig_change = '{0}/stgadm/changes/{1}.py'.format( config.stghome, change_file_name) dest_change = '{0}/stgadm/changes_canceled/{1}.py'.format( config.stghome, change_file_name) os.rename(orig_change, dest_change) def _finish_change(change_file_name): orig_change = '{0}/stgadm/changes/{1}.py'.format( config.stghome, change_file_name) dest_change = '{0}/stgadm/changes_executed/{1}.py'.format( config.stghome, change_file_name) os.rename(orig_change, dest_change) os.system('clear') print('') print('[ Storage Adm ]') print('[ ]') print('[ Version {0} - (c) 2016 Kairo Araujo ]'.format(globalvar.version)) print('[ http://github.com/kairoaraujo/STGAdm ]') print('[ BSD License ]') print('[ ]') stgadm = raw_input('\nMain Menu:\n\n' '1. Add new volumes to existent host. (create change)\n' '2. Execute changes created.\n' '\nPlease choose an option: ') # Add new volumes to existent host menu if stgadm == '1': print('\n\n[ REQUEST INFORMATIONS ]\n') change = fields.Fields('change', 'Ticket/Change/Work Order: ') change.chkfieldstr() change = change.strvarout() hostname_client = fields.Fields('hostname', 'Hostname Client: ') hostname_client.chkfieldstr() hostname_client = hostname_client.strvarout() wwn_client = fields.Fields('wwn_client', 'WWN Server Client: ') wwn_client.chkfieldstr() wwn_client = wwn_client.strvarout() disk_volume = int() lun_size = int() while True: try: disk_volume = int(raw_input("Total Disk Required (GB): ")) break except (TypeError, ValueError): print( '\tERROR: Total Disk need to be an int value in GB. ' '\nDo not use GB. Example: 1000 for 1000GB (1TB).') while True: try: lun_size = int(raw_input("Default LUN size (GB): ")) if disk_volume % lun_size == 0: break else: print('\tERROR: The LUN size need to be a divisor of Total' 'required disk.' '\n\t If Total Disk Required is wrong, please ' 'use "Ctrl+C".') except (TypeError, ValueError): print( '\tERROR: LUN Size need to be an int value.' '\nDo not use GB. Example 100 for 100GB size of LUNs.') if ':' in wwn_client: wwn_client = wwn_client.replace(':', '') # select storage get_stg = systemstorages.SystemStorages() get_stg.selectstorage() stg_type = get_stg.gettype() if stg_type == 'EMC_VMAX': stg_sid = get_stg.getsid() stg_name = get_stg.getstorage() storage_name = stg_name menu_emc_vmax(change, hostname_client, storage_name, stg_name, stg_type, stg_sid, wwn_client) elif stg_type == 'IBM_DS8K': stg_sid = get_stg.getsid() stg_name = get_stg.getstorage() storage_name = stg_name menu_ibm_ds8k(change, hostname_client, storage_name, stg_name, stg_type, stg_sid, wwn_client) elif stg_type == 'EMC_VNX': storage_name = get_stg.getstorage() stg_1ip = get_stg.getvnx_1ip() stg_2ip = get_stg.getvnx_2ip() stg_user = get_stg.getvnx_user() stg_pass = get_stg.getvnx_pass() stg_scope = get_stg.getvnx_scope() menu_emc_vnx(change, hostname_client, storage_name, storage_name, stg_type, stg_1ip, stg_2ip, stg_user, stg_pass, stg_scope, wwn_client) else: print('ERROR: Storage type {0} invalid. Check config file'.format( stg_type)) elif stgadm == '2': change_file = findchange.select().replace('.py', '') # import change_file change_module = importlib.import_module( 'stgadm.changes.{0}'.format(change_file)) try: change_module.preview() except ValueError: if change_module.stg_type == 'IBM_DS8K': print('Removing LUN ID reserve...') for l_1_id in change_module.lss_1_id_list: ds8k_add_dev.remove_reserved_id(l_1_id) for l_2_id in change_module.lss_2_id_list: ds8k_add_dev.remove_reserved_id(l_2_id) print('LUN ID cleanup finished.') elif change_module.stg_type == 'EMC_VNX': print('Removing LUN ID reserve...') # remove lu: for lu_id in change_module.lu_ids: vnx_add_dev.remove_reserved_id(lu_id) print('Removing HLU ID reserve... ') # remove hlu for hlu_id in change_module.hlu_ids: vnx_add_dev.remove_reserved_hlu_id( hlu_id, change_module.stggroup_name) # remove hlu if is for cluster for cluster_node in change_module.cls_nodes.keys(): for hlu_id in change_module.cls_nodes[cluster_node][3]: vnx_add_dev.remove_reserved_hlu_id( hlu_id, change_module.cls_nodes[cluster_node][1] ) print('LUN and HLU ID cleanup finished.') _cancel_change(change_file) exit() execute_change = fields.YesNo('Do you would like execute this ' 'change?[y/n]: ', 'n') execute_change = execute_change.check() if execute_change == 'y': print("Executing the change. Please wait...\n") # import change_file change_module = importlib.import_module( 'stgadm.changes.{0}'.format(change_file)) try: change_module.execute() except ValueError as e: print("ERROR: {}".format(e)) _finish_change(change_file) else: print('Wrong option. Exiting.')