def add_maintenance_service(name, backend_guid, abm_name): """ Add a maintenance service with a specific name :param name: Name of the service to add :type name: str :param backend_guid: Backend for which the maintenance service needs to run :type backend_guid: str :param abm_name: Name of the ABM cluster :type abm_name: str """ if ServiceManager.has_service(name, MaintenanceController._local_client) is False: config_location = '/ovs/alba/backends/{0}/maintenance/config'.format(backend_guid) alba_config = Configuration.get_configuration_path(config_location) node_id = os.environ.get('ASD_NODE_ID') params = {'ALBA_CONFIG': alba_config, 'LOG_SINK': LogHandler.get_sink_path('alba_maintenance')} Configuration.set(config_location, json.dumps({ 'log_level': 'info', 'albamgr_cfg_url': Configuration.get_configuration_path('/ovs/arakoon/{0}/config'.format(abm_name)), 'read_preference': [] if node_id is None else [node_id] }, indent=4), raw=True) ServiceManager.add_service(name=MaintenanceController.MAINTENANCE_PREFIX, client=MaintenanceController._local_client, params=params, target_name=name) ServiceManager.start_service(name, MaintenanceController._local_client)
def add_maintenance_service(name, backend_guid, abm_name): """ Add a maintenance service with a specific name :param name: Name of the service to add :type name: str :param backend_guid: Backend for which the maintenance service needs to run :type backend_guid: str :param abm_name: Name of the ABM cluster :type abm_name: str """ if ServiceManager.has_service(name, MaintenanceController._local_client): if not ServiceManager.is_enabled(name, MaintenanceController._local_client): ServiceManager.enable_service(name, MaintenanceController._local_client) else: config_location = '/ovs/alba/backends/{0}/maintenance/config'.format(backend_guid) alba_config = 'etcd://127.0.0.1:2379{0}'.format(config_location) params = {'ALBA_CONFIG': alba_config} EtcdConfiguration.set(config_location, json.dumps({ 'log_level': 'info', 'albamgr_cfg_url': 'etcd://127.0.0.1:2379/ovs/arakoon/{0}/config'.format(abm_name) }, indent=4), raw=True) ServiceManager.add_service(name='alba-maintenance', client=MaintenanceController._local_client, params=params, target_name=name) ServiceManager.start_service(name, MaintenanceController._local_client)
def start_asd(asd_id): """ Starts an ASD :param asd_id: ASD identifier :type asd_id: str :return: None """ service_name = ASDController.ASD_SERVICE_PREFIX.format(asd_id) if ServiceManager.has_service(service_name, ASDController._local_client): ServiceManager.start_service(service_name, ASDController._local_client)
def setup(): """ Interactive setup part for initial asd manager configuration with etcd """ print Interactive.boxed_message(['ASD Manager setup']) local_client = LocalClient() service_name = 'asd-manager' print '- Verifying distribution' if ServiceManager.has_service(service_name, local_client): print '' # Spacing print Interactive.boxed_message(['The ASD Manager is already installed.']) sys.exit(1) ipaddresses = check_output("ip a | grep 'inet ' | sed 's/\s\s*/ /g' | cut -d ' ' -f 3 | cut -d '/' -f 1", shell=True).strip().splitlines() ipaddresses = [found_ip.strip() for found_ip in ipaddresses if found_ip.strip() != '127.0.0.1'] if not ipaddresses: print Interactive.boxed_message(['Could not retrieve IP information on current node']) sys.exit(1) config = None preconfig = '/opt/OpenvStorage/config/openvstorage_preconfig.json' run_interactive = True if os.path.exists(preconfig): config = {} with open(preconfig, 'r') as pre_config: try: config = json.load(pre_config) except Exception as ex: raise ValueError('JSON contents could not be retrieved from file {0}.\nErrormessage: {1}'.format(preconfig, ex)) run_interactive = 'asdmanager' not in config if run_interactive is False: asd_preconfig = config['asdmanager'] required = {'api_ip': (str, Toolbox.regex_ip), 'asd_ips': (list, Toolbox.regex_ip, False), 'api_port': (int, {'min': 1025, 'max': 65535}, False), 'asd_start_port': (int, {'min': 1025, 'max': 65435}, False)} Toolbox.verify_required_params(required_params=required, actual_params=asd_preconfig) api_ip = asd_preconfig['api_ip'] api_port = asd_preconfig.get('api_port', 8500) asd_ips = asd_preconfig.get('asd_ips', []) asd_start_port = asd_preconfig.get('asd_start_port', 8600) if api_ip not in ipaddresses: print Interactive.boxed_message(['Unknown API IP provided, please choose from: {0}'.format(', '.join(ipaddresses))]) sys.exit(1) if set(asd_ips).difference(set(ipaddresses)): print Interactive.boxed_message(['Unknown ASD IP provided, please choose from: {0}'.format(', '.join(ipaddresses))]) sys.exit(1) else: api_ip = Interactive.ask_choice(ipaddresses, 'Select the public IP address to be used for the API') api_port = Interactive.ask_integer("Select the port to be used for the API", 1025, 65535, 8500) ipaddresses.append('All') asd_ips = [] add_ips = True while add_ips: current_ips = ' - Current selected IPs: {0}'.format(asd_ips) new_asd_ip = Interactive.ask_choice(ipaddresses, 'Select an IP address or all IP addresses to be used for the ASDs{0}'.format(current_ips if len(asd_ips) > 0 else ''), default_value='All') if new_asd_ip == 'All': ipaddresses.remove('All') asd_ips = [] 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("Select the port to be used for the ASDs", 1025, 65435, 8600) if api_port in range(asd_start_port, asd_start_port + 100): print Interactive.boxed_message(['API port cannot be in the range of the ASD port + 100']) sys.exit(1) print '- Initializing etcd' try: alba_node_id = EtcdConfiguration.initialize(api_ip, api_port, asd_ips, asd_start_port) except: print '' # Spacing print Interactive.boxed_message(['Could not connect to Etcd.', 'Please make sure an Etcd proxy is available, pointing towards an OpenvStorage cluster.']) sys.exit(1) ServiceManager.add_service(service_name, local_client, params={'ASD_NODE_ID': alba_node_id, 'PORT_NUMBER': str(api_port)}) print '- Starting ASD manager service' try: ServiceManager.start_service(service_name, local_client) except Exception as ex: EtcdConfiguration.uninitialize(alba_node_id) print Interactive.boxed_message(['Starting asd-manager failed with error:', str(ex)]) sys.exit(1) print Interactive.boxed_message(['ASD Manager setup completed'])
def setup(): """ Interactive setup part for initial asd manager configuration """ print Interactive.boxed_message(['ASD Manager setup']) print '- Verifying distribution' local_client = LocalClient() if ServiceManager.has_service(MANAGER_SERVICE, local_client): print '' # Spacing print Interactive.boxed_message(['The ASD Manager is already installed.']) sys.exit(1) ipaddresses = check_output("ip a | grep 'inet ' | sed 's/\s\s*/ /g' | cut -d ' ' -f 3 | cut -d '/' -f 1", shell=True).strip().splitlines() ipaddresses = [found_ip.strip() for found_ip in ipaddresses if found_ip.strip() != '127.0.0.1'] if not ipaddresses: print Interactive.boxed_message(['Could not retrieve IP information on current node']) sys.exit(1) config = _validate_and_retrieve_pre_config() if config is None: api_ip = Interactive.ask_choice(ipaddresses, 'Select the public IP address to be used for the API') asd_ips = [] add_ips = True api_port = Interactive.ask_integer("Select the port to be used for the API", 1025, 65535, 8500) ipaddresses.append('All') while add_ips: current_ips = ' - Current selected IPs: {0}'.format(asd_ips) new_asd_ip = Interactive.ask_choice(ipaddresses, 'Select an IP address or all IP addresses to be used for the ASDs{0}'.format(current_ips if len(asd_ips) > 0 else ''), default_value='All') if new_asd_ip == 'All': ipaddresses.remove('All') asd_ips = [] 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("Select the port to be used for the ASDs", 1025, 65435, 8600) store = Interactive.ask_choice(['Arakoon', 'Etcd'], question='Select the configuration management system', default_value='Arakoon').lower() else: store = config.get('store', 'arakoon') 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) if api_ip not in ipaddresses: print Interactive.boxed_message(['Unknown API IP provided, please choose from: {0}'.format(', '.join(ipaddresses))]) sys.exit(1) if set(asd_ips).difference(set(ipaddresses)): print Interactive.boxed_message(['Unknown ASD IP provided, please choose from: {0}'.format(', '.join(ipaddresses))]) sys.exit(1) if api_port in range(asd_start_port, asd_start_port + 100): print Interactive.boxed_message(['API port cannot be in the range of the ASD port + 100']) sys.exit(1) # Make sure to always have the information stored with open(PRECONFIG_FILE, 'w') as preconfig: preconfig.write(json.dumps({'asdmanager': {'store': store, 'api_ip': api_ip, 'asd_ips': asd_ips, 'api_port': api_port, 'asd_start_port': asd_start_port}}, indent=4)) if store == 'arakoon': from source.tools.configuration.arakoon_config import ArakoonConfiguration file_location = ArakoonConfiguration.CACC_LOCATION source_location = ArakoonConfiguration.CACC_SOURCE if not local_client.file_exists(file_location) and local_client.file_exists(source_location): # Try to copy automatically try: local_client.file_upload(file_location, source_location) except Exception: pass while not local_client.file_exists(file_location): print 'Please place a copy of the Arakoon\'s client configuration file at: {0}'.format(file_location) Interactive.ask_continue() bootstrap_location = Configuration.BOOTSTRAP_CONFIG_LOCATION if not local_client.file_exists(bootstrap_location): local_client.file_create(bootstrap_location) local_client.file_write(bootstrap_location, json.dumps({'configuration_store': store}, indent=4)) try: alba_node_id = Configuration.initialize(api_ip, api_port, asd_ips, asd_start_port) except: print '' if store == 'arakoon': print Interactive.boxed_message(['Could not connect to Arakoon']) else: print Interactive.boxed_message(['Could not connect to Etcd.', 'Please make sure an Etcd proxy is available, pointing towards an OpenvStorage cluster.']) sys.exit(1) with open(Toolbox.BOOTSTRAP_FILE, 'w') as bs_file: json.dump({'node_id': alba_node_id}, bs_file) ServiceManager.add_service(MANAGER_SERVICE, local_client) ServiceManager.add_service(WATCHER_SERVICE, local_client) print '- Starting watcher service' try: ServiceManager.start_service(WATCHER_SERVICE, local_client) except Exception as ex: Configuration.uninitialize(alba_node_id) print Interactive.boxed_message(['Starting watcher failed with error:', str(ex)]) sys.exit(1) print Interactive.boxed_message(['ASD Manager setup completed'])
CONFIG_ROOT = '/ovs/alba/asdnodes/{0}/config'.format(NODE_ID) CURRENT_VERSION = 1 _logger = LogHandler.get('asd-manager', name='post-update') _logger.info('Executing post-update logic of package openvstorage-sdm') with file_mutex('package_update_pu'): client = LocalClient('127.0.0.1', username='******') key = '{0}/versions'.format(CONFIG_ROOT) version = Configuration.get(key) if Configuration.exists(key) else 0 service_name = 'asd-manager' if ServiceManager.has_service(service_name, client) and ServiceManager.get_service_status(service_name, client)[0] is True: _logger.info('Stopping asd-manager service') ServiceManager.stop_service(service_name, client) if version < CURRENT_VERSION: try: # Put migration code here pass except: pass Configuration.set(key, CURRENT_VERSION) if ServiceManager.has_service(service_name, client) and ServiceManager.get_service_status(service_name, client)[0] is False: _logger.info('Starting asd-manager service') ServiceManager.start_service(service_name, client) _logger.info('Post-update logic executed')