def services_running(self, target): """ Check all services are running :param target: Target to check :return: Boolean """ try: if target == 'config': self.log_message(target, 'Testing configuration store...', 0) from source.tools.configuration.configuration import Configuration try: Configuration.list('/') except Exception as ex: self.log_message(target, ' Error during configuration store test: {0}'.format(ex), 2) return False if Configuration.get_store() == 'arakoon': from source.tools.configuration.arakoon_config import ArakoonConfiguration from source.tools.pyrakoon.pyrakoon.compat import NoGuarantee client = ArakoonConfiguration.get_client() contents = client.get(Watcher.INTERNAL_CONFIG_KEY, consistency=NoGuarantee()) if Watcher.LOG_CONTENTS != contents: try: # Validate whether the contents are not corrupt parser = RawConfigParser() parser.readfp(StringIO(contents)) except Exception as ex: self.log_message(target, ' Configuration stored in configuration store seems to be corrupt: {0}'.format(ex), 2) return False temp_filename = '{0}~'.format(ArakoonConfiguration.CACC_LOCATION) with open(temp_filename, 'w') as config_file: config_file.write(contents) config_file.flush() os.fsync(config_file) os.rename(temp_filename, ArakoonConfiguration.CACC_LOCATION) if Watcher.LOG_CONTENTS is not None: self.log_message(target, ' Configuration changed, trigger restart', 1) sys.exit(1) Watcher.LOG_CONTENTS = contents self.log_message(target, ' Configuration store OK', 0) return True except Exception as ex: self.log_message(target, 'Unexpected exception: {0}'.format(ex), 2) return False
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 """ os.environ['OVS_LOGTYPE_OVERRIDE'] = 'file' print '\n' + Interactive.boxed_message(['ASD Manager removal']) ############## # VALIDATION # ############## local_client = LocalClient() if not local_client.file_exists(filename=Toolbox.BOOTSTRAP_FILE): print '\n' + Interactive.boxed_message(['The ASD Manager has already been removed']) sys.exit(1) print ' - Validating configuration file' config = _validate_and_retrieve_pre_config() if config is None or 'store' not in config: print '\n' + Interactive.boxed_message(['Cannot remove the ASD manager because not all information could be retrieved from the pre-configuration file']) sys.exit(1) print ' - Validating node ID' with open(Toolbox.BOOTSTRAP_FILE, 'r') as bs_file: try: alba_node_id = json.loads(bs_file.read())['node_id'] except: print '\n' + Interactive.boxed_message(['JSON contents could not be retrieved from file {0}'.format(Toolbox.BOOTSTRAP_FILE)]) sys.exit(1) print ' - Validating configuration management' store = config['store'] try: Configuration.list(key='ovs') except: if store == 'arakoon': print '\n' + Interactive.boxed_message(['Could not connect to Arakoon']) else: print '\n' + Interactive.boxed_message(['Could not connect to Etcd.', 'Please make sure an Etcd proxy is available, pointing towards an OpenvStorage cluster.']) sys.exit(1) ################ # CONFIRMATION # ################ os.environ['ASD_NODE_ID'] = alba_node_id from source.app.api import API print ' - Retrieving ASD information' all_asds = {} try: all_asds = API.list_asds.original() except: print ' - ERROR: 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 '\n\n+++ ALERT +++\n' message = 'DATA LOSS possible if proceeding! Continue?' proceed = Interactive.ask_yesno(message=message, default_value=False) if proceed is False: print '\n' + Interactive.boxed_message(['Abort removal']) sys.exit(1) ########### # REMOVAL # ########### print ' - Removing from configuration management' Configuration.uninitialize(node_id=alba_node_id) if len(all_asds) > 0: print ' - Removing disks' for device_id, disk_info in API.list_disks.original().iteritems(): if disk_info['available'] is True: continue try: print ' - Retrieving ASD information for disk {0}'.format(disk_info['device']) for asd_id, asd_info in API.list_asds_disk.original(disk_id=device_id).iteritems(): print ' - Removing ASD {0}'.format(asd_id) API.asd_delete.original(disk_id=device_id, asd_id=asd_id) API.delete_disk.original(disk_id=device_id) except Exception as ex: print ' - Deleting ASDs failed: {0}'.format(ex) print ' - Removing services' for service_name in API.list_maintenance_services.original()['services']: print ' - Removing service {0}'.format(service_name) API.remove_maintenance_service.original(name=service_name) for service_name in [WATCHER_SERVICE, MANAGER_SERVICE]: if ServiceManager.has_service(name=service_name, client=local_client): print ' - Removing service {0}'.format(service_name) ServiceManager.stop_service(name=service_name, client=local_client) ServiceManager.remove_service(name=service_name, client=local_client) if store == 'arakoon': from source.tools.configuration.arakoon_config import ArakoonConfiguration local_client.file_delete(filenames=ArakoonConfiguration.CACC_LOCATION) local_client.file_delete(filenames=Toolbox.BOOTSTRAP_FILE) print '\n' + Interactive.boxed_message(['ASD Manager removal completed'])