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) title_entry = find_entry(output_objects, 'title') title_entry['text'] = 'Resource details' output_objects.append({'object_type': 'header', 'text' : 'Show resource details'}) defaults = signature()[1] (validate_status, accepted) = validate_input_and_cert( user_arguments_dict, defaults, output_objects, client_id, configuration, allow_rejects=False, ) if not validate_status: return (accepted, returnvalues.CLIENT_ERROR) resource_list = accepted['unique_resource_name'] status = returnvalues.OK visible_res = user_visible_res_confs(configuration, client_id) allowed_vgrids = user_allowed_vgrids(configuration, client_id) for visible_res_name in resource_list: if not visible_res_name in visible_res.keys(): logger.warning('User %s not allowed to view %s (%s)' % \ (client_id, visible_res_name, visible_res.keys())) output_objects.append({'object_type': 'error_text', 'text': 'invalid resource %s' % \ visible_res_name}) continue res_dict = visible_res[visible_res_name] res_item = build_resitem_object_from_res_dict(configuration, visible_res_name, res_dict, allowed_vgrids) output_objects.append(res_item) return (output_objects, status)
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) title_entry = find_entry(output_objects, 'title') title_entry['text'] = 'Runtime env support' output_objects.append({ 'object_type': 'header', 'text': 'Test runtime environment support' }) client_dir = client_id_dir(client_id) defaults = signature()[1] (validate_status, accepted) = validate_input_and_cert( user_arguments_dict, defaults, output_objects, client_id, configuration, allow_rejects=False, ) if not validate_status: logger.warning('%s invalid input: %s' % (op_name, accepted)) return (accepted, returnvalues.CLIENT_ERROR) resource_list = accepted['unique_resource_name'] re_name = accepted['re_name'][-1] status = returnvalues.OK visible_res = user_visible_res_confs(configuration, client_id) if not safe_handler(configuration, 'post', op_name, client_id, get_csrf_limit(configuration), accepted): output_objects.append({ 'object_type': 'error_text', 'text': '''Only accepting CSRF-filtered POST requests to prevent unintended updates''' }) return (output_objects, returnvalues.CLIENT_ERROR) if not re_name: output_objects.append({ 'object_type': 'error_text', 'text': 'Please specify the name of the runtime environment!' }) return (output_objects, returnvalues.CLIENT_ERROR) if not valid_dir_input(configuration.re_home, re_name): logger.warning( "possible illegal directory traversal attempt re_name '%s'" % re_name) output_objects.append({ 'object_type': 'error_text', 'text': 'Illegal runtime environment name: "%s"' % re_name }) return (output_objects, returnvalues.CLIENT_ERROR) # Please note that base_dir must end in slash to avoid access to other # user dirs when own name is a prefix of another user name base_dir = os.path.abspath( os.path.join(configuration.user_home, client_dir)) + os.sep for visible_res_name in resource_list: if not visible_res_name in visible_res.keys(): logger.warning('User %s not allowed to view %s (%s)' % \ (client_id, visible_res_name, visible_res.keys())) output_objects.append({'object_type': 'error_text', 'text': 'invalid resource %s' % \ visible_res_name}) status = returnvalues.CLIENT_ERROR continue if not is_owner(client_id, visible_res_name, configuration.resource_home, logger): output_objects.append({ 'object_type': 'error_text', 'text': 'You must be an owner of the resource to validate runtime ' 'environment support. (resource %s)' % visible_res_name }) status = returnvalues.CLIENT_ERROR continue (re_dict, re_msg) = get_re_dict(re_name, configuration) if not re_dict: output_objects.append({ 'object_type': 'error_text', 'text': 'Could not get re_dict %s' % re_msg }) status = returnvalues.SYSTEM_ERROR continue if not testresource_has_re_specified(visible_res_name, re_name, configuration): output_objects.append({ 'object_type': 'error_text', 'text': 'You must specify the runtime environment in the resource' 'configuration before verifying if it is supported!' }) status = returnvalues.CLIENT_ERROR continue base64string = '' for stringpart in re_dict['TESTPROCEDURE']: base64string += stringpart mrslfile_content = base64.decodestring(base64string) try: (filehandle, mrslfile) = tempfile.mkstemp(text=True) os.write(filehandle, mrslfile_content) os.close(filehandle) create_verify_files(['status', 'stdout', 'stderr'], re_name, re_dict, base_dir, logger) except Exception, exc: output_objects.append({ 'object_type': 'error_text', 'text': 'Could not write test job for %s: %s' % (visible_res_name, exc) }) status = returnvalues.SYSTEM_ERROR continue forceddestination_dict = { 'UNIQUE_RESOURCE_NAME': visible_res_name, 'RE_NAME': re_name } (success, msg) = new_job(mrslfile, client_id, configuration, forceddestination_dict) if not success: output_objects.append({ 'object_type': 'error_text', 'text': 'Submit test job failed %s: %s' % (visible_res_name, msg) }) status = returnvalues.SYSTEM_ERROR try: os.remove(mrslfile) except: pass output_objects.append( {'object_type': 'text', 'text': 'Runtime environment test job for %s successfuly submitted! %s' \ % (visible_res_name, msg)})
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) status = returnvalues.OK defaults = signature()[1] title_entry = find_entry(output_objects, 'title') title_entry['text'] = 'Resource management' (validate_status, accepted) = validate_input_and_cert( user_arguments_dict, defaults, output_objects, client_id, configuration, allow_rejects=False, ) if not validate_status: return (accepted, returnvalues.CLIENT_ERROR) show_sandboxes = (accepted['show_sandboxes'][-1] != 'false') operation = accepted['operation'][-1] caching = (accepted['caching'][-1].lower() in ('true', 'yes')) if not configuration.site_enable_resources: output_objects.append({ 'object_type': 'error_text', 'text': '''Resources are not enabled on this system''' }) return (output_objects, returnvalues.SYSTEM_ERROR) if not operation in allowed_operations: output_objects.append({ 'object_type': 'text', 'text': '''Operation must be one of %s.''' % ', '.join(allowed_operations) }) return (output_objects, returnvalues.OK) logger.info("%s %s begin for %s" % (op_name, operation, client_id)) pending_updates = False if operation in show_operations: # jquery support for tablesorter and confirmation on delete # table initially sorted by col. 1 (admin), then 0 (name) # NOTE: We distinguish between caching on page load and forced refresh refresh_call = 'ajax_resman(%s)' table_spec = { 'table_id': 'resourcetable', 'sort_order': '[[1,0],[0,0]]', 'refresh_call': refresh_call % 'false' } (add_import, add_init, add_ready) = man_base_js(configuration, [table_spec]) if operation == "show": add_ready += '%s;' % refresh_call % 'true' title_entry['script']['advanced'] += add_import title_entry['script']['init'] += add_init title_entry['script']['ready'] += add_ready output_objects.append({ 'object_type': 'html_form', 'text': man_base_html(configuration) }) output_objects.append({ 'object_type': 'header', 'text': 'Available Resources' }) output_objects.append({ 'object_type': 'sectionheader', 'text': 'Resources available on this server' }) output_objects.append({ 'object_type': 'text', 'text': ''' All available resources are listed below with overall hardware specifications. Any resources that you own will have a administration icon that you can click to open resource management. ''' }) # Helper forms for requests and removes form_method = 'post' csrf_limit = get_csrf_limit(configuration) target_op = 'sendrequestaction' csrf_token = make_csrf_token(configuration, form_method, target_op, client_id, csrf_limit) helper = html_post_helper( 'reqresowner', '%s.py' % target_op, { 'unique_resource_name': '__DYNAMIC__', 'request_type': 'resourceowner', 'request_text': '', csrf_field: csrf_token }) output_objects.append({'object_type': 'html_form', 'text': helper}) target_op = 'rmresowner' csrf_token = make_csrf_token(configuration, form_method, target_op, client_id, csrf_limit) helper = html_post_helper( 'rmresowner', '%s.py' % target_op, { 'unique_resource_name': '__DYNAMIC__', 'cert_id': client_id, csrf_field: csrf_token }) output_objects.append({'object_type': 'html_form', 'text': helper}) output_objects.append({ 'object_type': 'table_pager', 'entry_name': 'resources', 'default_entries': default_pager_entries }) resources = [] if operation in list_operations: logger.info("get vgrid and resource map with caching %s" % caching) visible_res_confs = user_visible_res_confs(configuration, client_id, caching) res_map = get_resource_map(configuration, caching) anon_map = anon_to_real_res_map(configuration.resource_home) if caching: modified_resources, _ = check_resources_modified(configuration) modified_vgrids, _ = check_vgrids_modified(configuration) if modified_resources: logger.info("pending resource cache updates: %s" % modified_resources) pending_updates = True elif modified_vgrids: logger.info("pending vgrid cache updates: %s" % modified_vgrids) pending_updates = True else: logger.info("no pending cache updates") # Iterate through resources and show management for each one requested fields = [ 'PUBLICNAME', 'NODECOUNT', 'CPUCOUNT', 'MEMORY', 'DISK', 'ARCHITECTURE', 'SANDBOX', 'RUNTIMEENVIRONMENT' ] # NOTE: only resources that user is allowed to access are listed. # Resource with neither exes nor stores are not shown to anyone # but the owners. Similarly resources are not shown if all # resource units solely participate in VGrids, which the user # can't access. for visible_res_name in visible_res_confs.keys(): unique_resource_name = visible_res_name if visible_res_name in anon_map.keys(): unique_resource_name = anon_map[visible_res_name] if not show_sandboxes and sandbox_resource(unique_resource_name): continue res_obj = {'object_type': 'resource', 'name': visible_res_name} if client_id in res_map[unique_resource_name][OWNERS]: # Admin of resource when owner res_obj['resownerlink'] = { 'object_type': 'link', 'destination': "javascript: confirmDialog(%s, '%s', %s, %s);" % ('rmresowner', 'Really leave %s owners?' % unique_resource_name, 'undefined', "{unique_resource_name: '%s'}" % unique_resource_name), 'class': 'removelink iconspace', 'title': 'Leave %s owners' % unique_resource_name, 'text': '' } res_obj['resdetailslink'] = { 'object_type': 'link', 'destination': 'resadmin.py?unique_resource_name=%s' % unique_resource_name, 'class': 'adminlink iconspace', 'title': 'Administrate %s' % unique_resource_name, 'text': '' } else: # link to become owner res_obj['resownerlink'] = { 'object_type': 'link', 'destination': "javascript: confirmDialog(%s, '%s', '%s', %s);" % ('reqresowner', "Request ownership of " + visible_res_name + ":<br/>" + "\nPlease write a message to the owners (field below).", 'request_text', "{unique_resource_name: '%s'}" % visible_res_name), 'class': 'addlink iconspace', 'title': 'Request ownership of %s' % visible_res_name, 'text': '' } res_obj['resdetailslink'] = { 'object_type': 'link', 'destination': 'viewres.py?unique_resource_name=%s' % visible_res_name, 'class': 'infolink iconspace', 'title': 'View detailed %s specs' % visible_res_name, 'text': '' } # fields for everyone: public status for name in fields: res_obj[name] = res_map[unique_resource_name][CONF].get( name, '') # Use runtimeenvironment names instead of actual definitions res_obj['RUNTIMEENVIRONMENT'] = [ i[0] for i in res_obj['RUNTIMEENVIRONMENT'] ] res_obj['RUNTIMEENVIRONMENT'].sort() resources.append(res_obj) if operation == "show": # insert dummy placeholder to build table res_obj = {'object_type': 'resource', 'name': ''} resources.append(res_obj) output_objects.append({ 'object_type': 'resource_list', 'pending_updates': pending_updates, 'resources': resources }) if operation in show_operations: if configuration.site_enable_sandboxes: if show_sandboxes: output_objects.append({ 'object_type': 'link', 'destination': '?show_sandboxes=false', 'class': 'removeitemlink iconspace', 'title': 'Hide sandbox resources', 'text': 'Exclude sandbox resources', }) else: output_objects.append({ 'object_type': 'link', 'destination': '?show_sandboxes=true', 'class': 'additemlink iconspace', 'title': 'Show sandbox resources', 'text': 'Include sandbox resources', }) output_objects.append({ 'object_type': 'sectionheader', 'text': 'Resource Status' }) output_objects.append({ 'object_type': 'text', 'text': ''' Live resource status is available in the resource monitor page with all %s/resources you can access ''' % configuration.site_vgrid_label }) output_objects.append({ 'object_type': 'link', 'destination': 'showvgridmonitor.py?vgrid_name=ALL', 'class': 'monitorlink iconspace', 'title': 'Show monitor with all resources you can access', 'text': 'Global resource monitor', }) output_objects.append({ 'object_type': 'sectionheader', 'text': 'Additional Resources' }) output_objects.append({ 'object_type': 'text', 'text': 'You can sign up spare or dedicated resources to the grid below.' }) output_objects.append({ 'object_type': 'link', 'destination': 'resedit.py', 'class': 'addlink iconspace', 'title': 'Show sandbox resources', 'text': 'Create a new %s resource' % configuration.short_title, }) output_objects.append({'object_type': 'sectionheader', 'text': ''}) if configuration.site_enable_sandboxes: output_objects.append({ 'object_type': 'link', 'destination': 'ssslogin.py', 'class': 'adminlink iconspace', 'title': 'Administrate and monitor your sandbox resources', 'text': 'Administrate %s sandbox resources' % configuration.short_title }) output_objects.append({'object_type': 'sectionheader', 'text': ''}) output_objects.append({ 'object_type': 'link', 'destination': 'oneclick.py', 'class': 'sandboxlink iconspace', 'title': 'Run a One-click resource in your browser', 'text': 'Use this computer as One-click %s resource' % configuration.short_title }) logger.info("%s %s end for %s" % (op_name, operation, client_id)) return (output_objects, status)
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) title_entry = find_entry(output_objects, 'title') title_entry['text'] = 'Runtime env support' output_objects.append({'object_type': 'header', 'text' : 'Test runtime environment support'}) client_dir = client_id_dir(client_id) defaults = signature()[1] (validate_status, accepted) = validate_input_and_cert( user_arguments_dict, defaults, output_objects, client_id, configuration, allow_rejects=False, ) if not validate_status: logger.warning('%s invalid input: %s' % (op_name, accepted)) return (accepted, returnvalues.CLIENT_ERROR) resource_list = accepted['unique_resource_name'] re_name = accepted['re_name'][-1] status = returnvalues.OK visible_res = user_visible_res_confs(configuration, client_id) if not re_name: output_objects.append( {'object_type': 'error_text', 'text' : 'Please specify the name of the runtime environment!'}) return (output_objects, returnvalues.CLIENT_ERROR) if not valid_dir_input(configuration.re_home, re_name): logger.warning( "possible illegal directory traversal attempt re_name '%s'" % re_name) output_objects.append({'object_type': 'error_text', 'text' : 'Illegal runtime environment name: "%s"' % re_name}) return (output_objects, returnvalues.CLIENT_ERROR) # Please note that base_dir must end in slash to avoid access to other # user dirs when own name is a prefix of another user name base_dir = os.path.abspath(os.path.join(configuration.user_home, client_dir)) + os.sep for visible_res_name in resource_list: if not visible_res_name in visible_res.keys(): logger.warning('User %s not allowed to view %s (%s)' % \ (client_id, visible_res_name, visible_res.keys())) output_objects.append({'object_type': 'error_text', 'text': 'invalid resource %s' % \ visible_res_name}) status = returnvalues.CLIENT_ERROR continue if not is_owner(client_id, visible_res_name, configuration.resource_home, logger): output_objects.append( {'object_type': 'error_text', 'text': 'You must be an owner of the resource to validate runtime ' 'environment support. (resource %s)' % visible_res_name}) status = returnvalues.CLIENT_ERROR continue (re_dict, re_msg) = get_re_dict(re_name, configuration) if not re_dict: output_objects.append( {'object_type': 'error_text', 'text': 'Could not get re_dict %s' % re_msg}) status = returnvalues.SYSTEM_ERROR continue if not testresource_has_re_specified(visible_res_name, re_name, configuration): output_objects.append( {'object_type': 'error_text', 'text': 'You must specify the runtime environment in the resource' 'configuration before verifying if it is supported!'}) status = returnvalues.CLIENT_ERROR continue base64string = '' for stringpart in re_dict['TESTPROCEDURE']: base64string += stringpart mrslfile_content = base64.decodestring(base64string) try: (filehandle, mrslfile) = tempfile.mkstemp(text=True) os.write(filehandle, mrslfile_content) os.close(filehandle) create_verify_files(['status', 'stdout', 'stderr'], re_name, re_dict, base_dir, logger) except Exception, exc: output_objects.append( {'object_type': 'error_text', 'text': 'Could not write test job for %s: %s' % (visible_res_name, exc)}) status = returnvalues.SYSTEM_ERROR continue forceddestination_dict = {'UNIQUE_RESOURCE_NAME': visible_res_name, 'RE_NAME': re_name} (success, msg) = new_job(mrslfile, client_id, configuration, forceddestination_dict) if not success: output_objects.append( {'object_type': 'error_text', 'text': 'Submit test job failed %s: %s' % (visible_res_name, msg)}) status = returnvalues.SYSTEM_ERROR try: os.remove(mrslfile) except: pass output_objects.append( {'object_type': 'text', 'text': 'Runtime environment test job for %s successfuly submitted! %s' \ % (visible_res_name, msg)})
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) title_entry = find_entry(output_objects, 'title') title_entry['text'] = 'Resource details' output_objects.append({'object_type': 'header', 'text' : 'Show resource details'}) defaults = signature()[1] (validate_status, accepted) = validate_input_and_cert( user_arguments_dict, defaults, output_objects, client_id, configuration, allow_rejects=False, ) if not validate_status: return (accepted, returnvalues.CLIENT_ERROR) resource_list = accepted['unique_resource_name'] status = returnvalues.OK visible_res = user_visible_res_confs(configuration, client_id) vgrid_access = user_vgrid_access(configuration, client_id) res_map = get_resource_map(configuration) anon_map = anon_to_real_res_map(configuration.resource_home) for visible_res_name in resource_list: unique_resource_name = visible_res_name if visible_res_name in anon_map.keys(): unique_resource_name = anon_map[visible_res_name] if not visible_res_name in visible_res.keys(): logger.warning('User %s not allowed to view %s (%s)' % \ (client_id, visible_res_name, visible_res.keys())) output_objects.append({'object_type': 'error_text', 'text': 'invalid resource %s' % \ visible_res_name}) continue res_dict = visible_res[visible_res_name] res_item = build_resitem_object_from_res_dict(configuration, visible_res_name, res_dict, vgrid_access) output_objects.append(res_item) if client_id in res_map[unique_resource_name][OWNERS]: output_objects.append({'object_type': 'sectionheader', 'text': 'Administrate'}) output_objects.append({'object_type': 'link', 'destination': 'resadmin.py?unique_resource_name=%s'\ % unique_resource_name, 'class': 'adminlink iconspace', 'title': 'Administrate %s' % unique_resource_name, 'text': 'Administrate %s' % unique_resource_name, }) return (output_objects, status)