예제 #1
0
def main(client_id, user_arguments_dict):
    """Main function used by front end"""

    (configuration, logger, output_objects, op_name) = \
        initialize_main_variables(client_id, op_header=False, op_title=False,
                                  op_menu=client_id)
    defaults = signature()[1]
    (validate_status, accepted) = validate_input(user_arguments_dict,
            defaults, output_objects, allow_rejects=False)
    if not validate_status:
        return (accepted, returnvalues.CLIENT_ERROR)

    action = accepted['action'][-1]
    sandboxkey = accepted['sandboxkey'][-1]
    exe_name = accepted['exe_name'][-1]

    status = returnvalues.OK

    # Web format for cert access and no header for SID access
    if client_id:
        output_objects.append({'object_type': 'title', 'text'
                               : 'SSS script download'})
        output_objects.append({'object_type': 'header', 'text'
                               : 'SSS script download'})
    else:
        output_objects.append({'object_type': 'start'})

    if not configuration.site_enable_sandboxes:
        output_objects.append({'object_type': 'text', 'text':
                               '''Sandbox resources are disabled on this site.
Please contact the Grid admins %s if you think they should be enabled.
''' % configuration.admin_email})
        return (output_objects, returnvalues.OK)

    (result, unique_resource_name) = get_resource_name(sandboxkey, logger)
    if not result:
        msg = unique_resource_name
    elif action == 'get_frontend_script':
        (result, msg) = get_frontend_script(unique_resource_name, logger)
    elif action == 'get_master_node_script':
        (result, msg) = get_master_node_script(unique_resource_name,
                                               exe_name, logger)
    else:
        result = False
        msg = 'Unknown action: %s' % action

    if not result:
        status = returnvalues.ERROR

    # Status code line followed by raw output
    if not client_id:
        output_objects.append({'object_type': 'script_status', 'text': ''})
        output_objects.append({'object_type': 'binary', 'data': '%s' % status[0]})
    output_objects.append({'object_type': 'binary', 'data': msg})
    return (output_objects, status)
예제 #2
0
파일: ps3live.py 프로젝트: heromod/migrid
def get_ps3_resource():
    log_msg = 'ps3live'

    # Identify sandboxkey

    sandboxkey = fieldstorage.getfirst('sandboxkey', None)
    if not sandboxkey:

        # No sandboxkey provided,

        log_msg = log_msg + ', Remote IP: %s, provided no sandboxkey.'\
             % os.getenv('REMOTE_ADDR')

        return (False, log_msg)

    if not os.path.exists(configuration.sandbox_home + sandboxkey):

        # Create resource

        unique_resource_name = create_ps3_resource(sandboxkey)
        log_msg = log_msg + ' Created resource: %s'\
             % unique_resource_name

        # Make symbolic link from
    # sandbox_home/sandboxkey to resource_home/resource_name

        sandbox_link = configuration.sandbox_home + sandboxkey
        resource_path = os.path.abspath(os.path.join(configuration.resource_home,
                                                     unique_resource_name))

        make_symlink(resource_path, sandbox_link, logger)
    else:
        (status, unique_resource_name) = get_resource_name(sandboxkey,
                logger)
        if not status:
            return (False, unique_resource_name)

    # If resource has a jobrequest pending, remove it.

    job_pending_file = os.path.join(configuration.resource_home,
                                    unique_resource_name,
                                    'jobrequest_pending.ps3')

    if os.path.exists(job_pending_file):
        os.remove(job_pending_file)

    log_msg = log_msg + ', Remote IP: %s, Key: %s'\
         % (os.getenv('REMOTE_ADDR'), sandboxkey)

    o.internal('''
%s
''' % log_msg)

    return (True, unique_resource_name)
예제 #3
0
def get_ps3_resource(configuration):
    log_msg = 'ps3live'

    # Identify sandboxkey

    sandboxkey = fieldstorage.getfirst('sandboxkey', None)
    if not sandboxkey:

        # No sandboxkey provided,

        log_msg = log_msg + ', Remote IP: %s, provided no sandboxkey.'\
             % os.getenv('REMOTE_ADDR')

        return (False, log_msg)

    if not os.path.exists(configuration.sandbox_home + sandboxkey):

        # Create resource

        unique_resource_name = create_ps3_resource(configuration, sandboxkey)
        log_msg = log_msg + ' Created resource: %s'\
             % unique_resource_name

        # Make symbolic link from
        # sandbox_home/sandboxkey to resource_home/resource_name

        sandbox_link = configuration.sandbox_home + sandboxkey
        resource_path = os.path.abspath(
            os.path.join(configuration.resource_home, unique_resource_name))

        make_symlink(resource_path, sandbox_link, logger)
    else:
        (status, unique_resource_name) = get_resource_name(sandboxkey, logger)
        if not status:
            return (False, unique_resource_name)

    # If resource has a jobrequest pending, remove it.

    job_pending_file = os.path.join(configuration.resource_home,
                                    unique_resource_name,
                                    'jobrequest_pending.ps3')

    if os.path.exists(job_pending_file):
        os.remove(job_pending_file)

    log_msg = log_msg + ', Remote IP: %s, Key: %s'\
         % (os.getenv('REMOTE_ADDR'), sandboxkey)

    o.internal('''
%s
''' % log_msg)

    return (True, unique_resource_name)
예제 #4
0
def main(client_id, user_arguments_dict):
    """Main function used by front end"""

    (configuration, logger, output_objects, op_name) = \
        initialize_main_variables(client_id, op_header=False, op_title=False,
                                  op_menu=client_id)
    defaults = signature()[1]
    (validate_status, accepted) = validate_input(user_arguments_dict,
                                                 defaults,
                                                 output_objects,
                                                 allow_rejects=False)
    if not validate_status:
        return (accepted, returnvalues.CLIENT_ERROR)

    action = accepted['action'][-1]
    sandboxkey = accepted['sandboxkey'][-1]
    exe_name = accepted['exe_name'][-1]

    status = returnvalues.OK

    # Web format for cert access and no header for SID access
    if client_id:
        output_objects.append({
            'object_type': 'title',
            'text': 'SSS script download'
        })
        output_objects.append({
            'object_type': 'header',
            'text': 'SSS script download'
        })
    else:
        output_objects.append({'object_type': 'start'})

    if not configuration.site_enable_sandboxes:
        output_objects.append({
            'object_type':
            'text',
            'text':
            '''Sandbox resources are disabled on this site.
Please contact the site admins %s if you think they should be enabled.
''' % configuration.admin_email
        })
        return (output_objects, returnvalues.OK)

    (result, unique_resource_name) = get_resource_name(sandboxkey, logger)
    if not result:
        msg = unique_resource_name
    elif action == 'get_frontend_script':
        (result, msg) = get_frontend_script(unique_resource_name, logger)
    elif action == 'get_master_node_script':
        (result, msg) = get_master_node_script(unique_resource_name, exe_name,
                                               logger)
    else:
        result = False
        msg = 'Unknown action: %s' % action

    if not result:
        status = returnvalues.ERROR

    # Status code line followed by raw output
    if not client_id:
        output_objects.append({'object_type': 'script_status', 'text': ''})
        output_objects.append({
            'object_type': 'binary',
            'data': '%s' % status[0]
        })
    output_objects.append({'object_type': 'binary', 'data': msg})
    return (output_objects, status)