def setup(): """ Interactive setup part for initial asd manager configuration """ _print_and_log(message=Interactive.boxed_message(['ASD Manager setup'])) # Gather information ipaddresses = OSFactory.get_manager().get_ip_addresses() if not ipaddresses: _print_and_log( level='error', message='\n' + Interactive.boxed_message( ['Could not retrieve IP information on local node'])) sys.exit(1) validation_ip_addresses = copy.deepcopy(ipaddresses) local_client = SSHClient(endpoint='127.0.0.1', username='******') service_manager = ServiceFactory.get_manager() if service_manager.has_service(MANAGER_SERVICE, local_client): _print_and_log(level='error', message='\n' + Interactive.boxed_message( ['The ASD Manager is already installed.'])) sys.exit(1) config = _validate_and_retrieve_pre_config() interactive = len(config) == 0 ipmi_info = {'ip': None, 'username': None, 'pwd': None} if interactive is False: api_ip = config['api_ip'] api_port = config.get('api_port', 8500) asd_ips = config.get('asd_ips', []) asd_start_port = config.get('asd_start_port', 8600) configuration_store = config.get('configuration_store', 'arakoon') ipmi_info = config.get('ipmi', ipmi_info) else: api_ip = Interactive.ask_choice( choice_options=ipaddresses, question='Select the public IP address to be used for the API', sort_choices=True) api_port = Interactive.ask_integer( question="Select the port to be used for the API", min_value=1025, max_value=65535, default_value=8500) asd_ips = [] add_ips = True ipaddresses.append('All') while add_ips: current_ips = ' - Current selected IPs: {0}'.format(asd_ips) new_asd_ip = Interactive.ask_choice( choice_options=ipaddresses, question= "Select an IP address to be used for the ASDs or 'All' (All current and future interfaces: 0.0.0.0){0}" .format(current_ips if len(asd_ips) > 0 else ''), default_value='All') if new_asd_ip == 'All': ipaddresses.remove('All') asd_ips = [ ] # Empty list maps to all IPs - checked when configuring ASDs add_ips = False else: asd_ips.append(new_asd_ip) ipaddresses.remove(new_asd_ip) add_ips = Interactive.ask_yesno( "Do you want to add another IP?") asd_start_port = Interactive.ask_integer( question="Select the port to be used for the ASDs", min_value=1025, max_value=65435, default_value=8600) configuration_store = 'arakoon' message = 'Do you want to set IPMI configuration keys?' proceed = Interactive.ask_yesno(message=message, default_value=False) if proceed is True: ipmi_info['ip'] = Interactive.ask_string( message='Enter the IPMI IP address', regex_info={'regex': ExtensionsToolbox.regex_ip}) ipmi_info['username'] = Interactive.ask_string( message='Enter the IPMI username') ipmi_info['pwd'] = Interactive.ask_password( message='Enter the IPMI password') if api_ip not in validation_ip_addresses: _print_and_log( level='error', message='\n' + Interactive.boxed_message(lines=[ 'Invalid API IP {0} specified. Please choose from:'.format( api_ip) ] + [' * {0}'.format(ip) for ip in ipaddresses])) sys.exit(1) different_ips = set(asd_ips).difference(set(validation_ip_addresses)) if different_ips: _print_and_log( level='error', message='\n' + Interactive.boxed_message(lines=[ 'Invalid ASD IPs {0} specified. Please choose from:'.format( asd_ips) ] + [' * {0}'.format(ip) for ip in ipaddresses])) sys.exit(1) if api_port in range(asd_start_port, asd_start_port + 100): _print_and_log( level='error', message='\n' + Interactive.boxed_message( ['API port cannot be in the range of the ASD port + 100'])) sys.exit(1) if interactive is True: while not local_client.file_exists(CACC_LOCATION): _print_and_log( level='warning', message= ' - Please place a copy of the Arakoon\'s client configuration file at: {0}' .format(CACC_LOCATION)) Interactive.ask_continue() local_client.file_write(filename=CONFIG_STORE_LOCATION, contents=json.dumps( {'configuration_store': configuration_store}, indent=4)) node_id = Configuration.initialize( config={ 'api_ip': api_ip, 'asd_ips': asd_ips, 'api_port': api_port, 'asd_start_port': asd_start_port, 'ipmi': ipmi_info }) # Model settings _print_and_log(message=' - Store settings in DB') for code, value in { 'api_ip': api_ip, 'api_port': api_port, 'configuration_store': configuration_store, 'node_id': node_id }.iteritems(): setting = Setting() setting.code = code setting.value = value setting.save() # Deploy/start services _print_and_log(message=' - Deploying and starting services') service_manager.add_service(name=MANAGER_SERVICE, client=local_client) service_manager.add_service(name=WATCHER_SERVICE, client=local_client) _print_and_log(message=' - Starting watcher service') try: service_manager.start_service(name=WATCHER_SERVICE, client=local_client) except Exception: Configuration.uninitialize() _print_and_log(level='exception', message='\n' + Interactive.boxed_message(['Starting watcher failed'])) sys.exit(1) _print_and_log(message='\n' + Interactive.boxed_message(['ASD Manager setup completed']))
def remove(silent=None): """ Interactive removal part for the ASD manager :param silent: If silent == '--force-yes' no question will be asked to confirm the removal :type silent: str :return: None :rtype: NoneType """ _print_and_log(message='\n' + Interactive.boxed_message(['ASD Manager removal'])) local_client = SSHClient(endpoint='127.0.0.1', username='******') if not local_client.file_exists( filename='{0}/main.db'.format(Setting.DATABASE_FOLDER)): _print_and_log(level='error', message='\n' + Interactive.boxed_message( ['The ASD Manager has already been removed'])) sys.exit(1) _print_and_log(message=' - Validating configuration management') try: Configuration.list(key='ovs') except: _print_and_log( level='exception', message='\n' + Interactive.boxed_message(['Could not connect to Arakoon'])) sys.exit(1) _print_and_log(message=' - Retrieving ASD information') all_asds = {} try: all_asds = ASDList.get_asds() except: _print_and_log(level='exception', message=' - Failed to retrieve the ASD information') interactive = silent != '--force-yes' if interactive is True: message = 'Are you sure you want to continue?' if len(all_asds) > 0: _print_and_log(message='\n\n+++ ALERT +++\n', level='warning') message = 'DATA LOSS possible if proceeding! Continue?' proceed = Interactive.ask_yesno(message=message, default_value=False) if proceed is False: _print_and_log(level='error', message='\n' + Interactive.boxed_message(['Abort removal'])) sys.exit(1) if len(all_asds) > 0: _print_and_log(message=' - Removing disks') for disk in DiskList.get_disks(): if disk.available is True: continue try: _print_and_log( message=' - Retrieving ASD information for disk {0}'. format(disk.name)) for asd in disk.asds: _print_and_log( message=' - Removing ASD {0}'.format(asd.name)) ASDController.remove_asd(asd) DiskController.clean_disk(disk) except Exception: _print_and_log(level='exception', message=' - Deleting ASDs failed') _print_and_log(message=' - Removing services') service_manager = ServiceFactory.get_manager() for service in MaintenanceController.get_services(): service_name = service _print_and_log( message=' - Removing service {0}'.format(service_name)) guid = None for alba_backend_guid in Configuration.list(key='/ovs/alba/backends'): for maintenance_service_name in Configuration.list( key='/ovs/alba/backends/{0}/maintenance/'.format( alba_backend_guid)): if maintenance_service_name == service_name: guid = alba_backend_guid break MaintenanceController.remove_maintenance_service( name=service_name, alba_backend_guid=guid) for service_name in [WATCHER_SERVICE, MANAGER_SERVICE]: if service_manager.has_service(name=service_name, client=local_client): _print_and_log( message=' - Removing service {0}'.format(service_name)) service_manager.stop_service(name=service_name, client=local_client) service_manager.remove_service(name=service_name, client=local_client) _print_and_log(message=' - Removing from configuration management') remaining_users = Configuration.uninitialize() if not remaining_users: local_client.file_delete(filenames=CACC_LOCATION) local_client.file_delete( filenames='{0}/main.db'.format(Setting.DATABASE_FOLDER)) _print_and_log( message='\n' + Interactive.boxed_message(['ASD Manager removal completed']))