Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
 def list_asds(mountpoint):
     """
     Lists all ASDs found on a given mountpoint
     :param mountpoint: Mountpoint to list ASDs on
     :type mountpoint: str
     :return: Dictionary of ASDs
     :rtype: dict
     """
     asds = {}
     try:
         for asd_id in os.listdir(mountpoint):
             if os.path.isdir('/'.join([mountpoint, asd_id])) and Configuration.exists(ASDController.ASD_CONFIG.format(asd_id)):
                 asds[asd_id] = Configuration.get(ASDController.ASD_CONFIG.format(asd_id))
                 output, error = ASDController._local_client.run(['ls', '{0}/{1}/'.format(mountpoint, asd_id)], allow_nonzero=True, return_stderr=True)
                 output += error
                 if 'Input/output error' in output:
                     asds[asd_id].update({'state': 'error',
                                          'state_detail': 'io_error'})
                     continue
                 service_name = ASDController.ASD_SERVICE_PREFIX.format(asd_id)
                 if ServiceManager.has_service(service_name, ASDController._local_client):
                     if ServiceManager.get_service_status(service_name, ASDController._local_client)[0] is False:
                         asds[asd_id].update({'state': 'error',
                                              'state_detail': 'service_failure'})
                     else:
                         asds[asd_id].update({'state': 'ok'})
                 else:
                     asds[asd_id].update({'state': 'error',
                                          'state_detail': 'service_failure'})
     except OSError as ex:
         ASDController._logger.info('Error collecting ASD information: {0}'.format(str(ex)))
     return asds
Exemplo n.º 3
0
 def remove_maintenance_service(name):
     """
     Remove a maintenance service with a specific name
     :param name: Name of the service
     """
     if ServiceManager.has_service(name, MaintenanceController._local_client):
         ServiceManager.stop_service(name, MaintenanceController._local_client)
         ServiceManager.remove_service(name, MaintenanceController._local_client)
Exemplo n.º 4
0
 def restart_asd(asd_id):
     """
     Restart 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.restart_service(service_name, ASDController._local_client)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
 def get_services():
     """
     Retrieve all configured maintenance service running on this node for each backend
     :return: generator
     """
     for service_name in ServiceManager.list_services(MaintenanceController._local_client):
         if service_name.startswith(MaintenanceController.MAINTENANCE_PREFIX):
             yield service_name
Exemplo n.º 7
0
 def list_asd_services():
     """
     Retrieve all ASD services
     :return: generator
     """
     for service_name in ServiceManager.list_services(ASDController._local_client):
         if service_name.startswith(ASDController.ASD_SERVICE_PREFIX.format('')):
             yield service_name
Exemplo n.º 8
0
 def remove_asd(asd_id, mountpoint):
     """
     Removes an ASD
     :param asd_id: ASD identifier
     :type asd_id: str
     :param mountpoint: Mountpoint of the ASDs disk
     :type mountpoint: str
     :return: None
     """
     service_name = ASDController.ASD_SERVICE_PREFIX.format(asd_id)
     if ServiceManager.has_service(service_name, ASDController._local_client):
         ServiceManager.stop_service(service_name, ASDController._local_client)
         ServiceManager.remove_service(service_name, ASDController._local_client)
     try:
         ASDController._local_client.dir_delete('{0}/{1}'.format(mountpoint, asd_id))
     except Exception as ex:
         ASDController._logger.warning('Could not clean ASD data: {0}'.format(ex))
     Configuration.delete(ASDController.ASD_CONFIG_ROOT.format(asd_id), raw=True)
Exemplo n.º 9
0
    def restart_services():
        """
        Restart the services ASD services and the Maintenance services
        :return: None
        """
        service_names = [service_name for service_name in ASDController.list_asd_services()]
        service_names.extend([service_name for service_name in MaintenanceController.get_services()])
        for service_name in service_names:
            status, _ = ServiceManager.get_service_status(service_name, SDMUpdateController._local_client)
            if status is False:
                SDMUpdateController._logger.warning('Found stopped service {0}. Will not start it.'.format(service_name))
                continue

            SDMUpdateController._logger.debug('Restarting service {0}'.format(service_name))
            try:
                ServiceManager.restart_service(service_name, SDMUpdateController._local_client)
            except CalledProcessError as cpe:
                SDMUpdateController._logger.debug('Failed to restart service {0} {1}'.format(service_name, cpe))
Exemplo n.º 10
0
 def get_sdm_services():
     services = {}
     for file_name in ServiceManager.list_service_files(UpdateController._local_client):
         if file_name.startswith(UpdateController.ASD_SERVICE_PREFIX):
             file_path = '/opt/asd-manager/run/{0}.version'.format(file_name)
             if os.path.isfile(file_path):
                 with open(file_path) as fp:
                     services[file_name] = fp.read().strip()
     return services
Exemplo n.º 11
0
    def restart_services():
        UpdateController.update_package_cache()
        alba_package_info = UpdateController.get_package_information(package_name='alba')
        result = {}
        for service, running_version in UpdateController.get_sdm_services().iteritems():
            if running_version != alba_package_info[1]:
                status = ServiceManager.get_service_status(service, UpdateController._local_client)
                if status is False:
                    UpdateController._log('Found stopped service {0}. Will not start it.'.format(service))
                    result[service] = 'stopped'
                else:
                    UpdateController._log('Restarting service {0}'.format(service))
                    try:
                        status = ServiceManager.restart_service(service, UpdateController._local_client)
                        UpdateController._log(status)
                        result[service] = 'restarted'
                    except CalledProcessError as cpe:
                        UpdateController._log('Failed to restart service {0} {1}'.format(service, cpe))
                        result[service] = 'failed'

        return {'result': result}
Exemplo n.º 12
0
    def execute_update(status):
        try:
            UpdateController.update_package_cache()
            sdm_package_info = UpdateController.get_package_information(package_name=UpdateController.PACKAGE_NAME)
        except CalledProcessError:
            return {'status': 'started'}

        if sdm_package_info[0] != sdm_package_info[1]:
            if status == 'started':
                UpdateController._log('Updating package {0}'.format(UpdateController.PACKAGE_NAME))
                UpdateController._local_client.run('echo "python {0} >> /var/log/upgrade-openvstorage-sdm.log 2>&1" > /tmp/update'.format(UpdateController.INSTALL_SCRIPT))
                UpdateController._local_client.run('at -f /tmp/update now')
                UpdateController._local_client.run('rm /tmp/update')
            return {'status': 'running'}
        else:
            status = ServiceManager.get_service_status('asd-manager', UpdateController._local_client)
            return {'status': 'done' if status is True else 'running'}
Exemplo n.º 13
0
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'])
Exemplo n.º 14
0
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'])
Exemplo n.º 15
0
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'])
Exemplo n.º 16
0
    def create_asd(partition_alias):
        """
        Creates and starts an ASD on a given disk
        :param partition_alias: Alias of the partition of a disk  (eg: /dev/disk/by-id/scsi-1ATA_TOSHIBA_MK2002TSKB_92M1KDMHF-part1)
        :type partition_alias: str
        :return: None
        """
        all_asds = {}
        mountpoint = None
        for alias, mtpt in FSTab.read().iteritems():
            all_asds.update(ASDController.list_asds(mtpt))
            if alias == partition_alias:
                mountpoint = mtpt
        if mountpoint is None:
            raise RuntimeError('Failed to retrieve the mountpoint for partition with alias: {0}'.format(partition_alias))

        # Fetch disk information
        disk_size = int(ASDController._local_client.run(['df', '-B', '1', '--output=size', mountpoint]).splitlines()[1])

        # Find out appropriate disk size
        asds = 1.0
        for asd_id in os.listdir(mountpoint):
            if os.path.isdir('/'.join([mountpoint, asd_id])) and Configuration.exists(ASDController.ASD_CONFIG.format(asd_id)):
                asds += 1
        asd_size = int(math.floor(disk_size / asds))
        for asd_id in os.listdir(mountpoint):
            if os.path.isdir('/'.join([mountpoint, asd_id])) and Configuration.exists(ASDController.ASD_CONFIG.format(asd_id)):
                config = json.loads(Configuration.get(ASDController.ASD_CONFIG.format(asd_id), raw=True))
                config['capacity'] = asd_size
                config['rocksdb_block_cache_size'] = int(asd_size / 1024 / 4)
                Configuration.set(ASDController.ASD_CONFIG.format(asd_id), json.dumps(config, indent=4), raw=True)
                try:
                    ServiceManager.send_signal(ASDController.ASD_SERVICE_PREFIX.format(asd_id),
                                               signal.SIGUSR1,
                                               ASDController._local_client)
                except Exception as ex:
                    ASDController._logger.info('Could not send signal to ASD for reloading the quota: {0}'.format(ex))

        # Prepare & start service
        asd_id = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(32))
        ASDController._logger.info('Setting up service for disk {0}'.format(partition_alias))
        homedir = '{0}/{1}'.format(mountpoint, asd_id)
        base_port = Configuration.get('{0}/network|port'.format(ASDController.CONFIG_ROOT))
        ips = Configuration.get('{0}/network|ips'.format(ASDController.CONFIG_ROOT))
        used_ports = []
        for asd in all_asds.itervalues():
            used_ports.append(asd['port'])
            if 'rora_port' in asd:
                used_ports.append(asd['rora_port'])
        asd_port = base_port
        rora_port = base_port + 1
        while asd_port in used_ports:
            asd_port += 1
        used_ports.append(asd_port)
        while rora_port in used_ports:
            rora_port += 1

        asd_config = {'home': homedir,
                      'node_id': ASDController.NODE_ID,
                      'asd_id': asd_id,
                      'capacity': asd_size,
                      'log_level': 'info',
                      'port': asd_port,
                      'transport': 'tcp',
                      'rocksdb_block_cache_size': int(asd_size / 1024 / 4)}
        if Configuration.get('/ovs/framework/rdma'):
            asd_config['rora_port'] = rora_port
            asd_config['rora_transport'] = 'rdma'
        if ips is not None and len(ips) > 0:
            asd_config['ips'] = ips

        if Configuration.exists('{0}/extra'.format(ASDController.CONFIG_ROOT)):
            data = Configuration.get('{0}/extra'.format(ASDController.CONFIG_ROOT))
            asd_config.update(data)

        Configuration.set(ASDController.ASD_CONFIG.format(asd_id), json.dumps(asd_config, indent=4), raw=True)

        service_name = ASDController.ASD_SERVICE_PREFIX.format(asd_id)
        params = {'CONFIG_PATH': Configuration.get_configuration_path('/ovs/alba/asds/{0}/config'.format(asd_id)),
                  'SERVICE_NAME': service_name,
                  'LOG_SINK': LogHandler.get_sink_path('alba_asd')}
        os.mkdir(homedir)
        ASDController._local_client.run(['chown', '-R', 'alba:alba', homedir])
        ServiceManager.add_service('alba-asd', ASDController._local_client, params, service_name)
        ASDController.start_asd(asd_id)
Exemplo n.º 17
0
if __name__ == '__main__':
    import os
    import json
    import glob
    from source.tools.filemutex import file_mutex
    from source.tools.localclient import LocalClient
    from source.tools.services.service import ServiceManager
    from source.tools.configuration import EtcdConfiguration

    _log('Executing post-upgrade logic of package openvstorage-sdm')
    with file_mutex('package_update'):
        client = LocalClient('127.0.0.1', username='******')

        migrate = False
        service_name = 'alba-asdmanager'
        if ServiceManager.has_service(service_name, client):
            _log('Removing old alba-asdmanager service')
            ServiceManager.stop_service(service_name, client)
            ServiceManager.remove_service(service_name, client)

        service_name = 'asd-manager'
        if ServiceManager.has_service(service_name, client) and ServiceManager.get_service_status(service_name, client) is True:
            _log('Stopping asd-manager service')
            ServiceManager.stop_service(service_name, client)

        # Migrate main configuration file
        path = '/opt/alba-asdmanager/config/config.json'
        if client.file_exists(path):
            _log('Migrating old configuration file to Etcd')
            with open(path) as config_file:
                config = json.load(config_file)
Exemplo n.º 18
0
        os.environ['ASD_NODE_ID'] = NODE_ID

    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)