def gen_manifest(path):
    try:
        lck, err = lock.get_lock('generate_manifest')
        if err:
            raise Exception(err)
        if not lck:
            raise Exception('Could not acquire lock.')
        ret, err = manifest_status.generate_manifest_info()
        if not ret:
            if err:
                raise Exception(err)
            else:
                raise Exception('No manifest info obtained')
        else:
            fullpath = os.path.normpath("%s/master.manifest" % path)
            fulltmppath = "/tmp/master.manifest.tmp"
            fullcopypath = os.path.normpath(
                "%s/master.manifest.%s" % (path, datetime.datetime.now().strftime("%B_%d_%Y_%H_%M_%S")))
            # Generate into a tmp file
            with open(fulltmppath, 'w') as fd:
                json.dump(ret, fd, indent=2)
            # Copy original to a backup
            if os.path.isfile(fullpath):
                shutil.copyfile(fullpath, fullcopypath)
            # Now move the tmp to the actual manifest file name
            shutil.move(fulltmppath, fullpath)
    except Exception, e:
        lock.release_lock('generate_manifest')
        return -1, 'Error generating manifest : %s' % str(e)
Example #2
0
def gen_manifest(path):
    try:
        lck, err = lock.get_lock('generate_manifest')
        if err:
            raise Exception(err)
        if not lck:
            raise Exception('Could not acquire lock.')
        ret, err = manifest_status.generate_manifest_info()
        if not ret:
            if err:
                raise Exception(err)
            else:
                raise Exception('No manifest info obtained')
        else:
            fullpath = os.path.normpath("%s/master.manifest" % path)
            fulltmppath = "/tmp/master.manifest.tmp"
            fullcopypath = os.path.normpath(
                "%s/master.manifest.%s" %
                (path, datetime.datetime.now().strftime("%B_%d_%Y_%H_%M_%S")))
            # Generate into a tmp file
            with open(fulltmppath, 'w') as fd:
                json.dump(ret, fd, indent=2)
            # Copy original to a backup
            if os.path.isfile(fullpath):
                shutil.copyfile(fullpath, fullcopypath)
            # Now move the tmp to the actual manifest file name
            shutil.move(fulltmppath, fullpath)
    except Exception, e:
        lock.release_lock('generate_manifest')
        return -1, 'Error generating manifest : %s' % str(e)
Example #3
0
def main():
    lg = None
    try:
        lg, err = logger.get_script_logger(
            'Poll for alerts', '/var/log/integralstor/scripts.log', level=logging.DEBUG)

        logger.log_or_print('Poll for alerts initiated.', lg, level='info')

        lck, err = lock.get_lock('poll_for_alerts')
        if err:
            raise Exception(err)
        if not lck:
            raise Exception('Could not acquire lock. Exiting.')

        active, err = grid_ops.is_active_admin_gridcell()
        if err:
            raise Exception(err)

        if not active:
            logger.log_or_print(
                'Not active admin GRIDCell so exiting.', lg, level='info')
            sys.exit(0)

        gluster_lck, err = lock.get_lock('gluster_commands')
        if err:
            raise Exception(err)

        si, err = system_info.load_system_config()
        if err:
            raise Exception(err)

        if not si:
            raise Exception('Could not load system information')

        alerts_list = []

        alerts_list, err = check_quotas()
        if err:
            raise Exception("Error getting quota information : %s" % err)

        lock.release_lock('gluster_commands')

        common_alerts, err = check_for_gridcell_errors(si)
        if err:
            raise Exception(err)

        alerts_list.extend(common_alerts)

        if alerts_list:
            alerts.raise_alert(alerts_list)
            str = ' | '.join(alerts_list)
            logger.log_or_print(str, lg, level='info')
        else:
            logger.log_or_print('No alerts to raise', lg, level='info')

        lock.release_lock('poll_for_alerts')
    except Exception, e:
        str = 'Error running poll for alerts  : %s' % e
        logger.log_or_print(str, lg, level='critical')
        sys.exit(-1)
Example #4
0
def gen_status(path, lg=None):
    try:
        lck, err = lock.get_lock('generate_status')
        if err:
            raise Exception(err)
        if not lck:
            raise Exception('Generate Status : Could not acquire lock.')
        fullmanifestpath = os.path.normpath("%s/master.manifest" % path)
        ret, err = manifest_status.generate_status_info(fullmanifestpath)
        if not ret:
            if err:
                raise Exception(err)
            else:
                raise Exception('No status info obtained')
        fullpath = os.path.normpath("%s/master.status" % path)
        fulltmppath = "/tmp/master.status.tmp"
        # Generate into a tmp file
        with open(fulltmppath, 'w') as fd:
            json.dump(ret, fd, indent=2)
        # Now move the tmp to the actual manifest file name
        # print 'fullpath is ', fullpath
        shutil.move(fulltmppath, fullpath)
    except Exception, e:
        logger.log_or_print('Error generating status : %s' % e,
                            lg,
                            level='critical')
        lock.release_lock('generate_status')
        return -1, 'Error generating status : %s' % e
def gen_status(path, lg=None):
    try:
        lck, err = lock.get_lock('generate_status')
        if err:
            raise Exception(err)
        if not lck:
            raise Exception('Generate Status : Could not acquire lock.')
        fullmanifestpath = os.path.normpath("%s/master.manifest" % path)
        ret, err = manifest_status.generate_status_info(fullmanifestpath)
        if not ret:
            if err:
                raise Exception(err)
            else:
                raise Exception('No status info obtained')
        fullpath = os.path.normpath("%s/master.status" % path)
        fulltmppath = "/tmp/master.status.tmp"
        # Generate into a tmp file
        with open(fulltmppath, 'w') as fd:
            json.dump(ret, fd, indent=2)
        # Now move the tmp to the actual manifest file name
        # print 'fullpath is ', fullpath
        shutil.move(fulltmppath, fullpath)
    except Exception, e:
        logger.log_or_print('Error generating status : %s' %
                            e, lg, level='critical')
        lock.release_lock('generate_status')
        return -1,  'Error generating status : %s' % e
Example #6
0
def main():
    try:
        lck, err = lock.get_lock('integralstor_poll_for_alerts')
        if err:
            raise Exception(err)
        if not lck:
            raise Exception('Could not acquire lock. Exiting.')

        alert_list = []
        now = int(time.time())

        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)

        tasks_query = "select * from tasks where last_run_time > '%d' and (status = 'error-retrying' or status = 'failed');" % (
            now - 110)
        # print "\ntasks_query: ", tasks_query
        rows, err = db.get_multiple_rows(db_path, tasks_query)
        # print "\nrows: ", rows
        if err:
            raise Exception(err)

        if rows:
            for row in rows:
                msg = "%s: %s." % (row['status'], row['description'])
                alert_list.append(msg)

        # print "\nalert_list: ", alert_list
        if alert_list:
            alerts.raise_alert(alert_list)

        lock.release_lock('integralstor_poll_for_alerts')

    except Exception, e:
        print "Error generating alerts : %s ! Exiting." % str(e)
        sys.exit(-1)
Example #7
0
def main():
    try:
        platform, err = config.get_platform()
        if err:
            raise Exception(err)

        lck, err = lock.get_lock('poll_for_alerts')
        if err:
            raise Exception(err)
        if not lck:
            raise Exception('Could not acquire lock. Exiting.')

        if platform == 'gridcell':
            from integralstor_gridcell import system_info
            gluster_lck, err = lock.get_lock('gluster_commands')
        else:
            from integralstor import system_info

        si, err = system_info.load_system_config()
        if platform == 'gridcell':
            lock.release_lock('gluster_commands')
        if err:
            raise Exception(err)
        if not si:
            raise Exception('Could not load system information')

        alert_list = []

        for node_name, node in si.items():
            if 'errors' in node and node['errors']:
                if platform == 'gridcell':
                    msg = 'GRIDCell : %s. ' % node_name
                else:
                    msg = ''
                msg += '. '.join(node['errors'])

                alert_list.append(msg)

        hw_platform, err = config.get_hardware_platform()
        if hw_platform:
            if hw_platform == 'dell':
                from integralstor_utils.platforms import dell
                alerts_dict, err = dell.get_alert_logs()
                if alerts_dict:
                    current_time = int(time.time())
                    for time_stamp, alerts_list in alerts_dict.items():
                        for alert_dict in alerts_list:
                            if alert_dict['Severity'] == 'Critical':
                                if (current_time - time_stamp) < (60 * 60):
                                    alert_list.append(
                                        alert_dict['description'])
                                    # print time_stamp, alert_dict

        # print "======================"
        # print alert_list
        # print "======================"
        if alert_list:
            alerts.raise_alert(alert_list)

        lock.release_lock('poll_for_alerts')
    except Exception, e:
        print "Error generating alerts : %s ! Exiting." % str(e)
        sys.exit(-1)
            fulltmppath = "/tmp/master.manifest.tmp"
            fullcopypath = os.path.normpath(
                "%s/master.manifest.%s" % (path, datetime.datetime.now().strftime("%B_%d_%Y_%H_%M_%S")))
            # Generate into a tmp file
            with open(fulltmppath, 'w') as fd:
                json.dump(ret, fd, indent=2)
            # Copy original to a backup
            if os.path.isfile(fullpath):
                shutil.copyfile(fullpath, fullcopypath)
            # Now move the tmp to the actual manifest file name
            shutil.move(fulltmppath, fullpath)
    except Exception, e:
        lock.release_lock('generate_manifest')
        return -1, 'Error generating manifest : %s' % str(e)
    else:
        lock.release_lock('generate_manifest')
        return 0, None


import atexit
atexit.register(lock.release_lock, 'generate_manifest')


def main():

    lg = None
    try:
        lg, err = logger.get_script_logger(
            'Generate manifest', '/var/log/integralstor/scripts.log', level=logging.DEBUG)
        logger.log_or_print('Generate manifest initiated.', lg, level='info')
Example #9
0
            fullcopypath = os.path.normpath(
                "%s/master.manifest.%s" %
                (path, datetime.datetime.now().strftime("%B_%d_%Y_%H_%M_%S")))
            # Generate into a tmp file
            with open(fulltmppath, 'w') as fd:
                json.dump(ret, fd, indent=2)
            # Copy original to a backup
            if os.path.isfile(fullpath):
                shutil.copyfile(fullpath, fullcopypath)
            # Now move the tmp to the actual manifest file name
            shutil.move(fulltmppath, fullpath)
    except Exception, e:
        lock.release_lock('generate_manifest')
        return -1, 'Error generating manifest : %s' % str(e)
    else:
        lock.release_lock('generate_manifest')
        return 0, None


import atexit
atexit.register(lock.release_lock, 'generate_manifest')


def main():

    lg = None
    try:
        lg, err = logger.get_script_logger('Generate manifest',
                                           '/var/log/integralstor/scripts.log',
                                           level=logging.DEBUG)
        logger.log_or_print('Generate manifest initiated.', lg, level='info')
            return django.shortcuts.render_to_response(url, return_dict, context_instance=django.template.context.RequestContext(request))

        if settings.APP_DEBUG:
            return_dict['app_debug'] = True

        return_dict['form'] = form
        return django.shortcuts.render_to_response('vol_create_wiz_confirm.html', return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error_details"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
    finally:
        lock.release_lock('gluster_commands')


def create_volume(request):
    """ Used to actually create the volume"""

    return_dict = {}
    try:
        gluster_lck, err = lock.get_lock('gluster_commands')
        if err:
            raise Exception(err)

        if not gluster_lck:
            raise Exception(
                'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.')
Example #11
0
        fullpath = os.path.normpath("%s/master.status" % path)
        fulltmppath = "/tmp/master.status.tmp"
        # Generate into a tmp file
        with open(fulltmppath, 'w') as fd:
            json.dump(ret, fd, indent=2)
        # Now move the tmp to the actual manifest file name
        # print 'fullpath is ', fullpath
        shutil.move(fulltmppath, fullpath)
    except Exception, e:
        logger.log_or_print('Error generating status : %s' % e,
                            lg,
                            level='critical')
        lock.release_lock('generate_status')
        return -1, 'Error generating status : %s' % e
    else:
        lock.release_lock('generate_status')
        return 0, None


import atexit
atexit.register(lock.release_lock, 'generate_status')


def main():

    lg = None
    try:
        lg, err = logger.get_script_logger('Generate status',
                                           '/var/log/integralstor/scripts.log',
                                           level=logging.DEBUG)
Example #12
0
            'view_dashboard.html',
            return_dict,
            context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict[
                "error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error_details"] = s
        return django.shortcuts.render_to_response(
            "logged_in_error.html",
            return_dict,
            context_instance=django.template.context.RequestContext(request))
    finally:
        lock.release_lock('gluster_commands')


def access_shell(request):
    return_dict = {}
    try:
        status, err = services_management.get_service_status(['shellinaboxd'])
        if err:
            raise Exception(err)
        if status['status_str'] == "Running":
            return django.shortcuts.render_to_response(
                "shell_access.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
def main():
    lg = None
    try:
        lg, err = logger.get_script_logger(
            'Gluster batch processing', '/var/log/integralstor/scripts.log', level=logging.DEBUG)

        logger.log_or_print('Batch processing initiated.', lg, level='info')

        active, err = grid_ops.is_active_admin_gridcell()
        if err:
            raise Exception(err)

        if not active:
            logger.log_or_print(
                'Not active admin GRIDCell so exiting.', lg, level='info')
            sys.exit(0)

        batch_files_path, err = config.get_batch_files_path()
        if err:
            raise Exception(err)

        ret, err = lock.get_lock('batch_process')
        if err:
            raise Exception(err)

        if not ret:
            raise Exception('Could not acquire batch lock. Exiting.')

        gluster_lck, err = lock.get_lock('gluster_commands')
        if err:
            raise Exception(err)

        if not gluster_lck:
            raise Exception('Could not acquire gluster lock. Exiting.')

        fl = os.listdir(os.path.normpath(batch_files_path))
        if fl:
            for file in fl:
                if not file.startswith("bp_"):
                    # unknown file type so ignore
                    continue
                else:
                    logger.log_or_print('Processing file %s/%s' %
                                        (batch_files_path, file), lg, level='info')
                    with open(os.path.normpath("%s/%s" % (batch_files_path, file)), "r") as f:
                        # print 'a'
                        # print
                        # os.path.normpath("%s/%s"%(batch_files_path,file))
                        d = json.load(f)
                        # print 'a1'
                        ret, err = process_batch(d, file, logger)
                        if err:
                            str = "Error loading json content for %s/%s : %s" % (
                                batch_files_path, file, err)
                            logger.log_or_print(str, lg, level='error')
                            continue
        else:
            logger.log_or_print(
                'No batch processes pending.', lg, level='info')

        ret, err = lock.release_lock('gluster_commands')
        if err:
            raise Exception(err)

        ret, err = lock.release_lock('batch_process')
        if err:
            raise Exception(err)

    except Exception, e:
        str = "Error processing batch files : %s" % e
        logger.log_or_print(str, lg, level='critical')
        sys.exit(-1)
                raise Exception('No status info obtained')
        fullpath = os.path.normpath("%s/master.status" % path)
        fulltmppath = "/tmp/master.status.tmp"
        # Generate into a tmp file
        with open(fulltmppath, 'w') as fd:
            json.dump(ret, fd, indent=2)
        # Now move the tmp to the actual manifest file name
        # print 'fullpath is ', fullpath
        shutil.move(fulltmppath, fullpath)
    except Exception, e:
        logger.log_or_print('Error generating status : %s' %
                            e, lg, level='critical')
        lock.release_lock('generate_status')
        return -1,  'Error generating status : %s' % e
    else:
        lock.release_lock('generate_status')
        return 0, None


import atexit
atexit.register(lock.release_lock, 'generate_status')


def main():

    lg = None
    try:
        lg, err = logger.get_script_logger(
            'Generate status', '/var/log/integralstor/scripts.log', level=logging.DEBUG)

        logger.log_or_print('Generate status initiated.', lg, level='info')
Example #15
0
def main():
    lg = None
    try:
        lg, err = logger.get_script_logger('Gluster batch processing',
                                           '/var/log/integralstor/scripts.log',
                                           level=logging.DEBUG)

        logger.log_or_print('Batch processing initiated.', lg, level='info')

        active, err = grid_ops.is_active_admin_gridcell()
        if err:
            raise Exception(err)

        if not active:
            logger.log_or_print('Not active admin GRIDCell so exiting.',
                                lg,
                                level='info')
            sys.exit(0)

        batch_files_path, err = config.get_batch_files_path()
        if err:
            raise Exception(err)

        ret, err = lock.get_lock('batch_process')
        if err:
            raise Exception(err)

        if not ret:
            raise Exception('Could not acquire batch lock. Exiting.')

        gluster_lck, err = lock.get_lock('gluster_commands')
        if err:
            raise Exception(err)

        if not gluster_lck:
            raise Exception('Could not acquire gluster lock. Exiting.')

        fl = os.listdir(os.path.normpath(batch_files_path))
        if fl:
            for file in fl:
                if not file.startswith("bp_"):
                    # unknown file type so ignore
                    continue
                else:
                    logger.log_or_print('Processing file %s/%s' %
                                        (batch_files_path, file),
                                        lg,
                                        level='info')
                    with open(
                            os.path.normpath(
                                "%s/%s" % (batch_files_path, file)), "r") as f:
                        # print 'a'
                        # print
                        # os.path.normpath("%s/%s"%(batch_files_path,file))
                        d = json.load(f)
                        # print 'a1'
                        ret, err = process_batch(d, file, logger)
                        if err:
                            str = "Error loading json content for %s/%s : %s" % (
                                batch_files_path, file, err)
                            logger.log_or_print(str, lg, level='error')
                            continue
        else:
            logger.log_or_print('No batch processes pending.',
                                lg,
                                level='info')

        ret, err = lock.release_lock('gluster_commands')
        if err:
            raise Exception(err)

        ret, err = lock.release_lock('batch_process')
        if err:
            raise Exception(err)

    except Exception, e:
        str = "Error processing batch files : %s" % e
        logger.log_or_print(str, lg, level='critical')
        sys.exit(-1)