Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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)