Пример #1
0
        fw = open(tmpfile, 'w')
        readline = fr.readline()
        while len(readline) > 0:
            fw.write(readline.replace(keyword_auto, str(resource_identifier)))
            readline = fr.readline()
        fw.close()
        fr.close()
    except Exception, err:

        msg += \
            'Failed to apply hostidentifier to configfile. Failure: %s'\
             % err
        return (False, msg)

    unique_resource_name = resource_name + '.' + str(resource_identifier)
    (status, run_msg) = run(configuration, tmpfile, unique_resource_name)
    msg += '\n' + run_msg
    if not status:
        return (False, msg)

    # truncate old conf with new accepted file

    try:
        move(tmpfile, new_configfile)
    except Exception, err:
        msg += '\nAccepted config, but failed to save it! Failed: %s'\
             % err
        return (False, msg)

    mark_resource_modified(configuration, unique_resource_name)
    mark_vgrid_modified(configuration, unique_resource_name)
Пример #2
0
    # write the conf string to a conf file

    conf_file_src = os.path.join(configuration.resource_home,
                                 unique_resource_name, 'config.MiG')
    try:
        fd = open(conf_file_src, 'w')
        fd.write(res_conf_string)
        fd.close()
    except Exception, e:
        o.out(e)
        o.reply_and_exit(o.ERROR)

    # parse and pickle the conf file

    (status, msg) = confparser.run(conf_file_src, resource_name + '.'
                                    + str(resource_identifier))
    if not status:
        o.out(msg, conf_file_src)
        o.reply_and_exit(o.ERROR)

    # Create PGID file in resource_home, this is needed for timeout/kill of jobs

    exe_pgid_file = os.path.join(configuration.resource_home,
                                 unique_resource_name,
                                 'EXE_%s.PGID' % exe_name)
    try:
        fd = open(exe_pgid_file, 'w')
        fd.write('stopped')
        fd.close()
    except Exception, e:
        o.out(e)
Пример #3
0
        readline = fr.readline()
        while len(readline) > 0:
            fw.write(readline.replace('$HOSTIDENTIFIER',
                     str(resource_identifier)))
            readline = fr.readline()
        fw.close()
        fr.close()
    except Exception, err:

        msg += \
            'Failed to apply hostidentifier to configfile. Failure: %s'\
             % err
        return (False, msg)

    unique_resource_name = resource_name + '.' + str(resource_identifier)
    (status, run_msg) = run(tmpfile, unique_resource_name)
    msg += '\n' + run_msg
    if not status:
        return (False, msg)

    # truncate old conf with new accepted file

    try:
        move(tmpfile, new_configfile)
    except Exception, err:
        msg += '\nAccepted config, but failed to save it! Failed: %s'\
             % err
        return (False, msg)

    mark_resource_modified(configuration, unique_resource_name)
    mark_vgrid_modified(configuration, unique_resource_name)
Пример #4
0
#
# -- END_HEADER ---
#

import os
import sys

import shared.confparser as confparser
from shared.conf import get_configuration_object

if os.getenv('HTTP_METHOD'):
    print 'CGI access disabled because of security implications'
    sys.exit(1)

resource_home = '/home/mig/resource_home'

configuration = get_configuration_object()
for (root, dirs, files) in os.walk(resource_home):
    for file in files:
        if file.startswith('config.MiG'):
            unique_resource_name = root.replace(resource_home, '')
            print unique_resource_name
            (status, msg) = confparser.run(configuration, root + '/' + file,
                                           unique_resource_name)
            print file
            print msg
            if status:
                print 'ok'
            else:
                print 'error'
Пример #5
0
        logger.info('Auto creating resource %s from %s' %
                    (resource_id, pending_file))
        (create_status, msg) = create_resource(configuration, client_id,
                                               resource_name, pending_file)
        if not create_status:
            output_objects.append({
                'object_type': 'error_text',
                'text': 'Resource creation failed:'
            })
            output_objects.append({'object_type': 'html_form', 'text': msg})
            return False
        output += '''Your resource was added as %s.%s
<hr />''' % (resource_name, msg)
    else:
        logger.info('Parsing conf %s for %s' % (pending_file, resource_id))
        (run_status, msg) = confparser.run(configuration, pending_file,
                                           resource_id, '')
        if not run_status:
            logger.error(msg)
            output_objects.append({
                'object_type': 'error_text',
                'text': 'Failed to parse new configuration:'
            })
            output_objects.append({'object_type': 'html_form', 'text': msg})
            try:
                os.remove(pending_file)
            except:
                pass
            return False

        logger.info('Sending create request for %s to admins' % resource_id)
        (send_status, msg) = send_resource_create_request_mail(
Пример #6
0
    # write the conf string to a conf file

    conf_file_src = os.path.join(configuration.resource_home,
                                 unique_resource_name, 'config.MiG')
    try:
        fd = open(conf_file_src, 'w')
        fd.write(res_conf_string)
        fd.close()
    except Exception, e:
        o.out(e)
        o.reply_and_exit(o.ERROR)

    # parse and pickle the conf file

    (status, msg) = confparser.run(configuration, conf_file_src, resource_name \
                                   + '.' + str(resource_identifier))
    if not status:
        o.out(msg, conf_file_src)
        o.reply_and_exit(o.ERROR)

    # Create PGID file in resource_home, this is needed for timeout/kill of jobs

    exe_pgid_file = os.path.join(configuration.resource_home,
                                 unique_resource_name,
                                 'EXE_%s.PGID' % exe_name)
    try:
        fd = open(exe_pgid_file, 'w')
        fd.write('stopped')
        fd.close()
    except Exception, e:
        o.out(e)
Пример #7
0
        return True
    elif configuration.auto_add_resource:
        resource_name = user_vars['HOSTURL']
        logger.info('Auto creating resource %s from %s' % (resource_id,
                                                           pending_file))
        (create_status, msg) = create_resource(configuration, client_id,
                                               resource_name, pending_file)
        if not create_status:
            output_objects.append({'object_type': 'text', 'error_text':
                               'Resource creation failed: %s' % msg})
            return False
        output += '''Your resource was added as %s.%s
<hr />''' % (resource_name, msg)
    else:
        logger.info('Parsing conf %s for %s' % (pending_file, resource_id))
        (status, msg) = confparser.run(pending_file, resource_id, '')
        if not status:
            logger.error(msg)
            output_objects.append({'object_type': 'error_text', 'text':
                               'Failed to parse new configuration: %s' % msg})
            try:
                os.remove(pending_file)
            except:
                pass
            return False

        logger.info('Sending create request for %s to admins' % resource_id)
        (status, msg) = send_resource_create_request_mail(client_id,
                                                          user_vars['HOSTURL'],
                                                          pending_file, logger,
                                                          configuration)