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) defaults = signature()[1] output_objects.append({'object_type': 'header', 'text' : 'Show runtime environment details'}) (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) re_name = accepted['re_name'][-1] 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) if not is_runtime_environment(re_name, configuration): output_objects.append({'object_type': 'error_text', 'text' : "'%s' is not an existing runtime environment!" % re_name}) return (output_objects, returnvalues.CLIENT_ERROR) title_entry = find_entry(output_objects, 'title') title_entry['text'] = 'Runtime environment details' (re_dict, msg) = get_re_dict(re_name, configuration) if not re_dict: output_objects.append({'object_type': 'error_text', 'text' : 'Could not read details for "%s"' % msg}) return (output_objects, returnvalues.SYSTEM_ERROR) output_objects.append(build_reitem_object(configuration, re_dict)) return (output_objects, returnvalues.OK)
def run(configuration, localfile_spaces, unique_resource_name, outfile='AUTOMATIC'): """Parse configuration in localfile_spaces and write results to outfile if non-empty. The keyword AUTOMATIC is replaced by the expected resource configuration path. """ if not configuration: configuration = get_configuration_object() (status, msg, conf) = get_resource_config_dict(configuration, localfile_spaces) if not status: return (False, msg) # verify runtime environments are specified correctly if conf.has_key('RUNTIMEENVIRONMENT'): for re in conf['RUNTIMEENVIRONMENT']: try: (name, value) = re except Exception, err: return (False, 'Runtime environment error: %s' % err) if not refunctions.is_runtime_environment(name, configuration): return ( False, "Non existing runtime environment specified ('%s'), please create the runtime environment before specifying it in resource configurations." % name) (re_dict, msg) = refunctions.get_re_dict(name, configuration) if not re_dict: return (False, 'Runtime environment error, could not open (%s) %s' % (name, msg)) if not re_dict.has_key('ENVIRONMENTVARIABLE'): if value: # res conf has envs, but according to the template it should not return ( False, "%s should not have any environments and you specified '%s'. Details about the runtime environment <a href=showre.py?re_name=%s>here</a>" % (re, value, name)) else: continue re_dict_environments = re_dict['ENVIRONMENTVARIABLE'] re_dict_environment_names = [] for re_environment in re_dict_environments: re_dict_environment_names.append(re_environment['name']) if not len(value) == len(re_dict_environments): return ( False, "You have specified %s environments, but the runtime environment '%s' requires %s. Details about the runtime environment <a href='showre.py?re_name=%s'>here.</a>" % (len(value), name, len(re_dict_environments), name)) # we now know that the number of environments are # correct, verify that there are no name duplicates used_envnames = [] for env in value: try: (envname, _) = env if envname in used_envnames: # same envname used twice return ( False, "You have specified the environment '%s' more than once for the '%s' runtime environment." % (envname, name)) used_envnames.append(envname) except Exception, err: return ( False, 'Runtimeenvironment error: Name and value not found in env: %s' % err) # verify environment names are correct according to the # runtime environment definition do this by comparing # list of names specified for runtime environment and # res. conf. # re_dict_environment_names and used_envnames should # have the same entries! for n in re_dict_environment_names: # any build-in list comparison functionality? if not n in used_envnames: return ( False, "You have not specified an environment named '%s' which is required by the '%s' runtime environment. Details about the runtime environment <a href=showre.py?re_name=%s>here.</a>" % (n, name, name))
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'] = 'Delete runtime environment' output_objects.append({'object_type': 'header', 'text' : 'Delete runtime environment'}) 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) if not correct_handler('POST'): output_objects.append( {'object_type': 'error_text', 'text' : 'Only accepting POST requests to prevent unintended updates'}) return (output_objects, returnvalues.CLIENT_ERROR) re_name = accepted['re_name'][-1] 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) # Check whether re_name represents a runtime environment if not is_runtime_environment(re_name, configuration): output_objects.append({'object_type': 'error_text', 'text': "No such runtime environment: '%s'" % re_name}) return (output_objects, returnvalues.CLIENT_ERROR) re_dict = get_re_dict(re_name, configuration) if not re_dict[0]: output_objects.append( {'object_type': 'error_text', 'text': 'Could not read runtime environment details for %s' % re_name}) return (output_objects, returnvalues.SYSTEM_ERROR) # Make sure the runtime environment belongs to the user trying to delete it if client_id != re_dict[0]['CREATOR']: output_objects.append({'object_type': 'error_text', 'text': \ 'You are not the owner of runtime environment "%s"' % re_name}) return (output_objects, returnvalues.CLIENT_ERROR) # Prevent delete if the runtime environment is used by any resources actives = resources_using_re(configuration, re_name) # If the runtime environment is active, an error message is printed, along # with a list of the resources using the runtime environment if actives: output_objects.append( {'object_type': 'error_text', 'text': "Can't delete runtime environment '%s' in use by resources:" % re_name}) output_objects.append({'object_type': 'list', 'list' : actives}) output_objects.append({'object_type': 'link', 'destination': 'redb.py', 'class': 'infolink', 'title': 'Show runtime environments', 'text': 'Show runtime environments'}) return (output_objects, returnvalues.CLIENT_ERROR) # Delete the runtime environment (status, msg) = delete_runtimeenv(re_name, configuration) # If something goes wrong when trying to delete runtime environment # re_name, an error is displayed. if not status: output_objects.append({'object_type': 'error_text', 'text' : 'Could not remove %s runtime environment: %s' % (re_name, msg)}) return (output_objects, returnvalues.SYSTEM_ERROR) # If deletion of runtime environment re_name is successful, we just # return OK else: output_objects.append( {'object_type': 'text', 'text' : 'Successfully deleted runtime environment: "%s"' % re_name}) output_objects.append({'object_type': 'link', 'destination': 'redb.py', 'class': 'infolink', 'title': 'Show runtime environments', 'text': 'Show runtime environments'}) return (output_objects, returnvalues.OK)
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) defaults = signature()[1] output_objects.append({ 'object_type': 'header', 'text': 'Create runtime environment' }) (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) re_template = accepted['re_template'][-1].upper().strip() software_entries = int(accepted['software_entries'][-1]) environment_entries = int(accepted['environment_entries'][-1]) testprocedure_entry = int(accepted['testprocedure_entry'][-1]) template = {} if re_template: if not is_runtime_environment(re_template, configuration): output_objects.append({ 'object_type': 'error_text', 'text': "re_template ('%s') is not a valid existing runtime env!" % re_template }) return (output_objects, returnvalues.CLIENT_ERROR) (template, msg) = get_re_dict(re_template, configuration) if not template: output_objects.append({ 'object_type': 'error_text', 'text': 'Could not read re_template %s. %s' % (re_template, msg) }) return (output_objects, returnvalues.SYSTEM_ERROR) # Override template fields if user loaded a template and modified the # required entries and chose update. # Use default of 1 sw, 1 env and 0 test or template setting otherwise if software_entries < 0: software_entries = len(template.get('SOFTWARE', [None])) if environment_entries < 0: environment_entries = len(template.get('ENVIRONMENTVARIABLE', [None])) if testprocedure_entry < 0: testprocedure_entry = len(template.get('TESTPROCEDURE', [])) if template.has_key('SOFTWARE'): new_sw = template['SOFTWARE'][:software_entries] template['SOFTWARE'] = new_sw if template.has_key('ENVIRONMENTVARIABLE'): new_env = template['ENVIRONMENTVARIABLE'][:environment_entries] template['ENVIRONMENTVARIABLE'] = new_env if template.has_key('TESTPROCEDURE'): new_test = template['TESTPROCEDURE'][:testprocedure_entry] template['TESTPROCEDURE'] = new_test # Avoid DoS, limit number of software_entries if software_entries > max_software_entries: output_objects.append( {'object_type': 'error_text', 'text' : 'Maximum number of software_entries %s exceeded (%s)' % \ (max_software_entries, software_entries)}) return (output_objects, returnvalues.CLIENT_ERROR) # Avoid DoS, limit number of environment_entries if environment_entries > max_environment_entries: output_objects.append( {'object_type': 'error_text', 'text' : 'Maximum number of environment_entries %s exceeded (%s)' % \ (max_environment_entries, environment_entries)}) return (output_objects, returnvalues.CLIENT_ERROR) rekeywords_dict = get_keywords_dict() (list_status, ret) = list_runtime_environments(configuration) if not list_status: output_objects.append({'object_type': 'error_text', 'text': ret}) return (output_objects, returnvalues.SYSTEM_ERROR) output_objects.append({ 'object_type': 'text', 'text': 'Use existing Runtime Environment as template' }) html_form = \ """<form method='get' action='adminre.py'> <select name='re_template'> <option value=''>None</option> """ for existing_re in ret: html_form += " <option value='%s'>%s</option>\n" % \ (existing_re, existing_re) html_form += """ </select> <input type='submit' value='Get' /> </form>""" output_objects.append({'object_type': 'html_form', 'text': html_form}) output_objects.append({ 'object_type': 'text', 'text': '''Note that a runtime environment can not be changed after creation and it can only be removed if not in use by any resources, so please be careful when filling in the details''' }) output_objects.append({ 'object_type': 'text', 'text': '''Changing the number of software and environment entries removes all data in the form, so please enter the correct values before entering any information.''' }) html_form = \ """<form method='get' action='adminre.py'> <table> """ html_form += """ <tr> <td>Number of needed software entries</td> <td><input type='number' name='software_entries' min=0 max=99 minlength=1 maxlength=2 value='%s' required pattern='[0-9]{1,2}' title='number of software entries needed in runtime environment' /></td> </tr>""" % software_entries html_form += """ <tr> <td>Number of environment entries</td> <td> <input type='number' name='environment_entries' min=0 max=99 minlength=1 maxlength=2 value='%s' required pattern='[0-9]{1,2}' title='number of environment variables provided by runtime environment' /> </td> </tr>""" % environment_entries output_objects.append({'object_type': 'html_form', 'text': html_form}) if testprocedure_entry == 0: select_string = """<option value='0' selected>No</option> <option value=1>Yes</option>""" elif testprocedure_entry == 1: select_string = """<option value='0'>No</option> <option value='1' selected>Yes</option>""" else: output_objects.append({ 'object_type': 'error_text', 'text': 'testprocedure_entry should be 0 or 1, you specified %s' % testprocedure_entry }) return (output_objects, returnvalues.CLIENT_ERROR) html_form = """ <tr> <td>Runtime environment has a testprocedure</td> <td><select name='testprocedure_entry'>%s</select></td> </tr> <tr> <td colspan=2> <input type='hidden' name='re_template' value='%s' /> <input type='submit' value='Update fields' /> </td> </tr> </table> </form><br /> """ % (select_string, re_template) form_method = 'post' csrf_limit = get_csrf_limit(configuration) fill_helpers = { 'short_title': configuration.short_title, 'form_method': form_method, 'csrf_field': csrf_field, 'csrf_limit': csrf_limit } target_op = 'createre' csrf_token = make_csrf_token(configuration, form_method, target_op, client_id, csrf_limit) fill_helpers.update({'target_op': target_op, 'csrf_token': csrf_token}) html_form += """ <form method='%(form_method)s' action='%(target_op)s.py'> <input type='hidden' name='%(csrf_field)s' value='%(csrf_token)s' /> <b>Runtime Environment Name</b><br /> <small>(eg. BASH-2.X-1, must be unique):</small><br /> <input class='p80width' type='text' name='re_name' required pattern='[a-zA-Z0-9_.-]+' title='unique name of ASCII letters and digits separated only by underscores, periods and hyphens' /> <br /> <br /><b>Description:</b><br /> <textarea class='p80width' rows='4' name='redescription'> """ if template: html_form += template['DESCRIPTION'].replace('<br />', '\n') html_form += '</textarea><br />' soft_list = [] if software_entries > 0: html_form += '<br /><b>Needed Software:</b><br />' if template: if template.has_key('SOFTWARE'): soft_list = template['SOFTWARE'] for soft in soft_list: html_form += """ <textarea class='p80width' rows='6' name='software'>""" for keyname in soft.keys(): if keyname != '': html_form += '%s=%s\n' % (keyname, soft[keyname]) html_form += '</textarea><br />' # loop and create textareas for any missing software entries software = rekeywords_dict['SOFTWARE'] sublevel_required = [] sublevel_optional = [] if software.has_key('Sublevel') and software['Sublevel']: sublevel_required = software['Sublevel_required'] sublevel_optional = software['Sublevel_optional'] for _ in range(len(soft_list), software_entries): html_form += """ <textarea class='p80width' rows='6' name='software'>""" for sub_req in sublevel_required: html_form += '%s= # required\n' % sub_req for sub_opt in sublevel_optional: html_form += '%s= # optional\n' % sub_opt html_form += '</textarea><br />' if template and testprocedure_entry == 1: if template.has_key('TESTPROCEDURE'): html_form += """ <br /><b>Testprocedure</b> (in mRSL format):<br /> <textarea class='p80width' rows='15' name='testprocedure'>""" base64string = '' for stringpart in template['TESTPROCEDURE']: base64string += stringpart decodedstring = base64.decodestring(base64string) html_form += decodedstring html_form += '</textarea>' output_objects.append({ 'object_type': 'html_form', 'text': html_form }) html_form = """ <br /><b>Expected .stdout file if testprocedure is executed</b><br /> <textarea class='p80width' rows='10' name='verifystdout'>""" if template.has_key('VERIFYSTDOUT'): for line in template['VERIFYSTDOUT']: html_form += line html_form += '</textarea>' html_form += """ <br /><b>Expected .stderr file if testprocedure is executed</b><br /> <textarea cols='50' rows='10' name='verifystderr'>""" if template.has_key('VERIFYSTDERR'): for line in template['VERIFYSTDERR']: html_form += line html_form += '</textarea>' html_form += """ <br /><b>Expected .status file if testprocedure is executed</b><br /> <textarea cols='50' rows='10' name='verifystatus'>""" if template.has_key('VERIFYSTATUS'): for line in template['VERIFYSTATUS']: html_form += line html_form += '</textarea>' elif testprocedure_entry == 1: html_form += """ <br /><b>Testprocedure</b> (in mRSL format):<br /> <textarea class='p80width' rows='15' name='testprocedure'>""" html_form += \ """::EXECUTE:: ls </textarea> <br /><b>Expected .stdout file if testprocedure is executed</b><br /> <textarea class='p80width' rows='10' name='verifystdout'></textarea> <br /><b>Expected .stderr file if testprocedure is executed</b><br /> <textarea class='p80width' rows='10' name='verifystderr'></textarea> <br /><b>Expected .status file if testprocedure is executed</b><br /> <textarea class='p80width' rows='10' name='verifystatus'></textarea> """ environmentvariable = rekeywords_dict['ENVIRONMENTVARIABLE'] sublevel_required = [] sublevel_optional = [] if environmentvariable.has_key('Sublevel')\ and environmentvariable['Sublevel']: sublevel_required = environmentvariable['Sublevel_required'] sublevel_optional = environmentvariable['Sublevel_optional'] env_list = [] if environment_entries > 0: html_form += '<br /><b>Environments:</b><br />' if template: if template.has_key('ENVIRONMENTVARIABLE'): env_list = template['ENVIRONMENTVARIABLE'] for env in env_list: html_form += """ <textarea class='p80width' rows='4' name='environment'>""" for keyname in env.keys(): if keyname != '': html_form += '%s=%s\n' % (keyname, env[keyname]) html_form += '</textarea><br />' # loop and create textareas for any missing environment entries for _ in range(len(env_list), environment_entries): html_form += """ <textarea class='p80width' rows='4' name='environment'>""" for sub_req in sublevel_required: html_form += '%s= # required\n' % sub_req for sub_opt in sublevel_optional: html_form += '%s= # optional\n' % sub_opt html_form += '</textarea><br />' html_form += """<br /><br /><input type='submit' value='Create' /> </form> """ output_objects.append({ 'object_type': 'html_form', 'text': html_form % fill_helpers }) return (output_objects, returnvalues.OK)
def display_resource(resourcename, raw_conf, resource_config, owners, re_list, configuration): """Format and print the information and actions for a given resource. """ exe_units = [] store_units = [] frontend = None hosturl = None html = "" row_name = ("even_row", "odd_row") if resource_config: if resource_config.has_key("EXECONFIG"): for exe in resource_config["EXECONFIG"]: exe_units.append(exe["name"]) if resource_config.has_key("STORECONFIG"): for store in resource_config["STORECONFIG"]: store_units.append(store["name"]) if resource_config.has_key("FRONTENDNODE"): frontend = resource_config["FRONTENDNODE"] if resource_config.has_key("HOSTURL"): hosturl = resource_config["HOSTURL"] # Try to split resourcename first to support resources where name # doesn't match hosturl. sep = "." index = resourcename.rfind(sep) if index: hosturl = resourcename[:index] identifier = resourcename[index + 1 :] elif hosturl: identifier = resourcename.replace(hosturl + sep, "") else: configuration.logger.warning("failed to find host identifier from unique resource name!") (hosturl, identifier) = (None, 0) html += '<a id="%s"></a>' % resourcename html += "<h1>%s</h1>\n" % resourcename html += "<h3>Configuration</h3>" html += """ Use the <a class="editlink" href="resedit.py?hosturl=%s;hostidentifier=%s"> editing interface </a> or make any changes manually in the text box below.<br /> <a class="infolink" href="docs.py?show=Resource"> Resource configuration docs </a> """ % ( hosturl, identifier, ) html += "" html += """ <form method="post" action="updateresconfig.py"> <table class=resources> <tr> <td class=centertext> <textarea cols="100" rows="25" name="resconfig">""" for line in raw_conf: html += "%s\n" % line.strip() html += ( """</textarea> <br /> <input type="hidden" name="unique_resource_name" value="%s" /> <input type="submit" value="Save" /> ---------- <input type="reset" value="Forget changes" /> """ % resourcename ) html += """ </td></tr> </table> </form> <p> <table class=resources> <tr class=title><td colspan="5">Front End</td></tr> """ if not frontend: html += "<tr><td colspan=5>Not specified</td></tr>\n" else: html += "<tr><td>%s</td>" % frontend for action in ["restart", "status", "stop", "clean"]: if action == "restart": action_str = "(Re)Start" else: action_str = action.capitalize() html += """<td> <form method="post" action="%sfe.py"> <input type="hidden" name="unique_resource_name" value="%s" /> <input type="submit" value="%s" /> </form> </td> """ % ( action, resourcename, action_str, ) html += "</tr>" html += "<tr class=title><td colspan=5>Execution Units</td></tr>\n" if not exe_units: html += "<tr><td colspan=5>None specified</td></tr>\n" else: html += "<tr><td>ALL UNITS</td>" for action in ["restart", "status", "stop", "clean"]: html += """<td> <form method="post" action="%sexe.py"> <input type="hidden" name="unique_resource_name" value="%s" /> <input type="hidden" name="all" value="true" /> <input type="hidden" name="parallel" value="true" />""" % ( action, resourcename, ) if action == "restart": action_str = "(Re)Start" else: action_str = action.capitalize() html += ( """ <input type="submit" value="%s" /> </form> </td> """ % action_str ) html += "</tr>" row_number = 1 for unit in exe_units: row_class = row_name[row_number % 2] html += "<tr class=%s><td>%s</td>" % (row_class, unit) for action in ["restart", "status", "stop", "clean"]: if action == "restart": action_str = "(Re)Start" else: action_str = action.capitalize() html += """<td> <form method="post" action="%sexe.py"> <input type="hidden" name="unique_resource_name" value="%s" /> <input type="hidden" name="exe_name" value="%s" /> <input type="submit" value="%s" /> </form> </td> """ % ( action, resourcename, unit, action_str, ) html += "</tr>" row_number += 1 html += "<tr class=title><td colspan=5>Storage Units</td></tr>\n" if not store_units: html += "<tr><td colspan=5>None specified</td></tr>\n" else: html += "<tr><td>ALL UNITS</td>" for action in ["restart", "status", "stop", "clean"]: html += """<td> <form method="post" action="%sstore.py"> <input type="hidden" name="unique_resource_name" value="%s" /> <input type="hidden" name="all" value="true" /> <input type="hidden" name="parallel" value="true" />""" % ( action, resourcename, ) if action == "restart": action_str = "(Re)Start" else: action_str = action.capitalize() html += ( """ <input type="submit" value="%s" /> </form> </td> """ % action_str ) html += "</tr>" row_number = 1 for unit in store_units: row_class = row_name[row_number % 2] html += "<tr class=%s><td>%s</td>" % (row_class, unit) for action in ["restart", "status", "stop", "clean"]: if action == "restart": action_str = "(Re)Start" else: action_str = action.capitalize() html += """<td> <form method="post" action="%sstore.py"> <input type="hidden" name="unique_resource_name" value="%s" /> <input type="hidden" name="store_name" value="%s" /> <input type="submit" value="%s" /> </form> </td> """ % ( action, resourcename, unit, action_str, ) html += "</tr>" row_number += 1 html += "</table><p>" html += "<h3>Owners</h3>" html += """ Owners are specified with the Distinguished Name (DN) from the certificate.<br /> <table class=resources> """ html += ( """<tr><td> <form method="post" action="addresowner.py"> <input type="hidden" name="unique_resource_name" value="%s" /> <input type="hidden" name="output_format" value="html" /> <input type="text" name="cert_id" size="72" /> <input type="submit" value=" Add " /> </form> </td></tr></table><br /> <table class=resources> """ % resourcename ) for owner_id in owners: html += """<tr><td> <form method="post" action="rmresowner.py"> <input type="hidden" name="unique_resource_name" value="%s" /> <input type="hidden" name="cert_id" value="%s" /> <input type="hidden" name="output_format" value="html" /> <input type="submit" value="Remove" /> </form> </td> """ % ( resourcename, owner_id, ) html += "<td>" + owner_id + "</td></tr>" html += "</table>" # create html to request vgrid resource access html += "<h3>%s access</h3>" % configuration.site_vgrid_label html += """Request resource access to additional %ss. <table class=resources> <tr><td> <form method="post" action="sendrequestaction.py"> <input type="hidden" name="unique_resource_name" value="%s" /> <input type="hidden" name="request_type" value="vgridresource" /> <select name="vgrid_name">""" % ( configuration.site_vgrid_label, resourcename, ) # list all vgrids without access allowed_vgrids = res_allowed_vgrids(configuration, resourcename) (vgrid_status, vgrid_list) = vgrid_list_vgrids(configuration) if not vgrid_status: vgrid_list = [] for vgrid_name in vgrid_list: if not vgrid_name in allowed_vgrids: html += "<option value=%s>%s" % (vgrid_name, vgrid_name) html += """</select>""" html += """ Message to owners: <input type="text" name="request_text" size=50 value="" /> <input type="submit" value="send" /> """ html += "</form></tr></table><p>" # create html to select and execute a runtime environment testprocedure html += "<h3>Runtime environments</h3>" html += ( """Verify that resource supports the selected runtime environment. <table class=resources> <tr><td> <form method="post" action="testresupport.py"> <input type="hidden" name="unique_resource_name" value="%s" /> <select name="re_name">""" % resourcename ) # list runtime environments that have a testprocedure for env in re_list: (re_dict, re_msg) = get_re_dict(env, configuration) if re_dict: if re_dict.has_key("TESTPROCEDURE"): if re_dict["TESTPROCEDURE"] != []: html += "<option value=%s>%s" % (env, env) html += """</select>""" html += '<input type="submit" value="verify" />' html += "</form></tr></table><p>" # create html to select and call script to display testprocedure history verify_history = ( """ Show testprocedure history for the selected runtime environment and the resource with its current configuration. <table class=resources> <tr><td> <form method="post" action="showresupport.py"> <input type="hidden" name="unique_resource_name" value="%s" /> <select name="re_name">""" % resourcename ) # list runtime environments that have a testprocedure for env in re_list: (re_dict, re_msg) = get_re_dict(env, configuration) if re_dict: if re_dict.has_key("TESTPROCEDURE"): if re_dict["TESTPROCEDURE"] != []: verify_history += "<option value=%s>%s" % (env, env) verify_history += """</select>""" verify_history += '<input type="submit" value="Show" />' verify_history += "</form></tr></table><p>" # TODO: reimplement showresupporthistory in new style and re-enable here # html += verify_history return html
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) defaults = signature()[1] title_entry = find_entry(output_objects, 'title') title_entry['text'] = 'Show Runtime Environment Details' (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) re_name = accepted['re_name'][-1] output_objects.append({ 'object_type': 'header', 'text': 'Show runtime environment details' }) 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) if not is_runtime_environment(re_name, configuration): output_objects.append({ 'object_type': 'error_text', 'text': "'%s' is not an existing runtime environment!" % re_name }) return (output_objects, returnvalues.CLIENT_ERROR) title_entry = find_entry(output_objects, 'title') title_entry['text'] = 'Runtime environment details' (re_dict, msg) = get_re_dict(re_name, configuration) if not re_dict: output_objects.append({ 'object_type': 'error_text', 'text': 'Could not read details for "%s"' % msg }) return (output_objects, returnvalues.SYSTEM_ERROR) # Set providers explicitly after build_reitem_object to avoid import loop re_item = build_reitem_object(configuration, re_dict) re_name = re_item['name'] re_item['providers'] = resources_using_re(configuration, re_name) re_item['resource_count'] = len(re_item['providers']) output_objects.append(re_item) return (output_objects, returnvalues.OK)
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) defaults = signature()[1] output_objects.append({"object_type": "header", "text": "Create runtime environment"}) (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) re_template = accepted["re_template"][-1].upper().strip() software_entries = int(accepted["software_entries"][-1]) environment_entries = int(accepted["environment_entries"][-1]) testprocedure_entry = int(accepted["testprocedure_entry"][-1]) template = {} if re_template: if not is_runtime_environment(re_template, configuration): output_objects.append( { "object_type": "error_text", "text": "re_template ('%s') is not a valid existing runtime env!" % re_template, } ) return (output_objects, returnvalues.CLIENT_ERROR) (template, msg) = get_re_dict(re_template, configuration) if not template: output_objects.append( {"object_type": "error_text", "text": "Could not read re_template %s. %s" % (re_template, msg)} ) return (output_objects, returnvalues.SYSTEM_ERROR) # Override template fields if user loaded a template and modified the # required entries and chose update. # Use default of 1 sw, 1 env and 0 test or template setting otherwise if software_entries < 0: software_entries = len(template.get("SOFTWARE", [None])) if environment_entries < 0: environment_entries = len(template.get("ENVIRONMENTVARIABLE", [None])) if testprocedure_entry < 0: testprocedure_entry = len(template.get("TESTPROCEDURE", [])) if template.has_key("SOFTWARE"): new_sw = template["SOFTWARE"][:software_entries] template["SOFTWARE"] = new_sw if template.has_key("ENVIRONMENTVARIABLE"): new_env = template["ENVIRONMENTVARIABLE"][:environment_entries] template["ENVIRONMENTVARIABLE"] = new_env if template.has_key("TESTPROCEDURE"): new_test = template["TESTPROCEDURE"][:testprocedure_entry] template["TESTPROCEDURE"] = new_test # Avoid DoS, limit number of software_entries if software_entries > max_software_entries: output_objects.append( { "object_type": "error_text", "text": "Maximum number of software_entries %s exceeded (%s)" % (max_software_entries, software_entries), } ) return (output_objects, returnvalues.CLIENT_ERROR) # Avoid DoS, limit number of environment_entries if environment_entries > max_environment_entries: output_objects.append( { "object_type": "error_text", "text": "Maximum number of environment_entries %s exceeded (%s)" % (max_environment_entries, environment_entries), } ) return (output_objects, returnvalues.CLIENT_ERROR) rekeywords_dict = get_keywords_dict() (status, ret) = list_runtime_environments(configuration) if not status: output_objects.append({"object_type": "error_text", "text": ret}) return (output_objects, returnvalues.SYSTEM_ERROR) output_objects.append({"object_type": "text", "text": "Use existing RE as template"}) html_form = """<form method='get' action='adminre.py'> <select name='re_template'> <option value=''>None</option> """ for existing_re in ret: html_form += " <option value='%s'>%s</option>\n" % (existing_re, existing_re) html_form += """ </select> <input type='submit' value='Get' /> </form>""" output_objects.append({"object_type": "html_form", "text": html_form}) output_objects.append( { "object_type": "text", "text": """Note that a runtime environment can not be changed after creation and it can only be removed if not in use by any resources, so please be careful when filling in the details""", } ) output_objects.append( { "object_type": "text", "text": """Changing the number of software and environment entries removes all data in the form, so please enter the correct values before entering any information.""", } ) html_form = """<form method='get' action='adminre.py'> <table> """ html_form += ( """ <tr> <td>Number of needed software entries</td> <td><input type='text' size='2' name='software_entries' value='%s' /></td> </tr>""" % software_entries ) html_form += ( """ <tr> <td>Number of environment entries</td> <td> <input type='text' size='2' name='environment_entries' value='%s' /> </td> </tr>""" % environment_entries ) output_objects.append({"object_type": "html_form", "text": html_form}) if testprocedure_entry == 0: select_string = """<option value='0' selected>No</option> <option value=1>Yes</option>""" elif testprocedure_entry == 1: select_string = """<option value='0'>No</option> <option value='1' selected>Yes</option>""" else: output_objects.append( { "object_type": "error_text", "text": "testprocedure_entry should be 0 or 1, you specified %s" % testprocedure_entry, } ) return (output_objects, returnvalues.CLIENT_ERROR) html_form = """ <tr> <td>Runtime environment has a testprocedure</td> <td><select name='testprocedure_entry'>%s</select></td> </tr> <tr> <td colspan=2> <input type='hidden' name='re_template' value='%s' /> <input type='submit' value='Update fields' /> </td> </tr> </table> </form><br /> """ % ( select_string, re_template, ) html_form += """ <form method='post' action='createre.py'> <b>RE Name</b><br /> <small>(eg. BASH-2.X-1, must be unique):</small><br /> <input type='text' size='40' name='re_name' /><br /> <br /><b>Description:</b><br /> <textarea cols='50' rows='2' name='redescription'> """ if template: html_form += template["DESCRIPTION"].replace("<br />", "\n") html_form += "</textarea><br />" soft_list = [] if software_entries > 0: html_form += "<br /><b>Needed Software:</b><br />" if template: if template.has_key("SOFTWARE"): soft_list = template["SOFTWARE"] for soft in soft_list: html_form += """ <textarea cols='50' rows='5' name='software'>""" for keyname in soft.keys(): if keyname != "": html_form += "%s=%s\n" % (keyname, soft[keyname]) html_form += "</textarea><br />" # loop and create textareas for any missing software entries software = rekeywords_dict["SOFTWARE"] sublevel_required = [] sublevel_optional = [] if software.has_key("Sublevel") and software["Sublevel"]: sublevel_required = software["Sublevel_required"] sublevel_optional = software["Sublevel_optional"] for _ in range(len(soft_list), software_entries): html_form += """ <textarea cols='50' rows='5' name='software'>""" for sub_req in sublevel_required: html_form += "%s= # required\n" % sub_req for sub_opt in sublevel_optional: html_form += "%s= # optional\n" % sub_opt html_form += "</textarea><br />" if template and testprocedure_entry == 1: if template.has_key("TESTPROCEDURE"): html_form += """ <br /><b>Testprocedure</b> (in mRSL format):<br /> <textarea cols='50' rows='15' name='testprocedure'>""" base64string = "" for stringpart in template["TESTPROCEDURE"]: base64string += stringpart decodedstring = base64.decodestring(base64string) html_form += decodedstring html_form += "</textarea>" output_objects.append({"object_type": "html_form", "text": html_form}) html_form = """ <br /><b>Expected .stdout file if testprocedure is executed</b><br /> <textarea cols='50' rows='10' name='verifystdout'>""" if template.has_key("VERIFYSTDOUT"): for line in template["VERIFYSTDOUT"]: html_form += line html_form += "</textarea>" html_form += """ <br /><b>Expected .stderr file if testprocedure is executed</b><br /> <textarea cols='50' rows='10' name='verifystderr'>""" if template.has_key("VERIFYSTDERR"): for line in template["VERIFYSTDERR"]: html_form += line html_form += "</textarea>" html_form += """ <br /><b>Expected .status file if testprocedure is executed</b><br /> <textarea cols='50' rows='10' name='verifystatus'>""" if template.has_key("VERIFYSTATUS"): for line in template["VERIFYSTATUS"]: html_form += line html_form += "</textarea>" elif testprocedure_entry == 1: html_form += """ <br /><b>Testprocedure</b> (in mRSL format):<br /> <textarea cols='50' rows='15' name='testprocedure'>""" html_form += """::EXECUTE:: ls </textarea> <br /><b>Expected .stdout file if testprocedure is executed</b><br /> <textarea cols='50' rows='10' name='verifystdout'></textarea> <br /><b>Expected .stderr file if testprocedure is executed</b><br /> <textarea cols='50' rows='10' name='verifystderr'></textarea> <br /><b>Expected .status file if testprocedure is executed</b><br /> <textarea cols='50' rows='10' name='verifystatus'></textarea> """ environmentvariable = rekeywords_dict["ENVIRONMENTVARIABLE"] sublevel_required = [] sublevel_optional = [] if environmentvariable.has_key("Sublevel") and environmentvariable["Sublevel"]: sublevel_required = environmentvariable["Sublevel_required"] sublevel_optional = environmentvariable["Sublevel_optional"] env_list = [] if environment_entries > 0: html_form += "<br /><b>Environments:</b><br />" if template: if template.has_key("ENVIRONMENTVARIABLE"): env_list = template["ENVIRONMENTVARIABLE"] for env in env_list: html_form += """ <textarea cols='50' rows='3' name='environment'>""" for keyname in env.keys(): if keyname != "": html_form += "%s=%s\n" % (keyname, env[keyname]) html_form += "</textarea><br />" # loop and create textareas for any missing environment entries for _ in range(len(env_list), environment_entries): html_form += """ <textarea cols='50' rows='3' name='environment'>""" for sub_req in sublevel_required: html_form += "%s= # required\n" % sub_req for sub_opt in sublevel_optional: html_form += "%s= # optional\n" % sub_opt html_form += "</textarea><br />" html_form += """<br /><br /><input type='submit' value='Create' /> </form> """ output_objects.append({"object_type": "html_form", "text": html_form}) return (output_objects, returnvalues.OK)
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'] = 'Delete runtime environment' output_objects.append({ 'object_type': 'header', 'text': 'Delete runtime environment' }) 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) re_name = accepted['re_name'][-1] 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 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) # Check whether re_name represents a runtime environment if not is_runtime_environment(re_name, configuration): output_objects.append({ 'object_type': 'error_text', 'text': "No such runtime environment: '%s'" % re_name }) return (output_objects, returnvalues.CLIENT_ERROR) (re_dict, load_msg) = get_re_dict(re_name, configuration) if not re_dict: output_objects.append({ 'object_type': 'error_text', 'text': 'Could not read runtime environment details for %s: %s' % (re_name, load_msg) }) return (output_objects, returnvalues.SYSTEM_ERROR) # Make sure the runtime environment belongs to the user trying to delete it if client_id != re_dict['CREATOR']: output_objects.append({'object_type': 'error_text', 'text': \ 'You are not the owner of runtime environment "%s"' % re_name}) return (output_objects, returnvalues.CLIENT_ERROR) # Prevent delete if the runtime environment is used by any resources actives = resources_using_re(configuration, re_name) # If the runtime environment is active, an error message is printed, along # with a list of the resources using the runtime environment if actives: output_objects.append({ 'object_type': 'error_text', 'text': "Can't delete runtime environment '%s' in use by resources:" % re_name }) output_objects.append({'object_type': 'list', 'list': actives}) output_objects.append({ 'object_type': 'link', 'destination': 'redb.py', 'class': 'infolink iconspace', 'title': 'Show runtime environments', 'text': 'Show runtime environments' }) return (output_objects, returnvalues.CLIENT_ERROR) # Delete the runtime environment (del_status, msg) = delete_runtimeenv(re_name, configuration) # If something goes wrong when trying to delete runtime environment # re_name, an error is displayed. if not del_status: output_objects.append({ 'object_type': 'error_text', 'text': 'Could not remove %s runtime environment: %s' % (re_name, msg) }) return (output_objects, returnvalues.SYSTEM_ERROR) # If deletion of runtime environment re_name is successful, we just # return OK else: output_objects.append({ 'object_type': 'text', 'text': 'Successfully deleted runtime environment: "%s"' % re_name }) output_objects.append({ 'object_type': 'link', 'destination': 'redb.py', 'class': 'infolink iconspace', 'title': 'Show runtime environments', 'text': 'Show runtime environments' }) return (output_objects, returnvalues.OK)
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) defaults = signature()[1] title_entry = find_entry(output_objects, 'title') title_entry['text'] = 'Runtime Environments' (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) # jquery support for tablesorter and confirmation on "leave": title_entry['style'] = themed_styles(configuration) title_entry['javascript'] = ''' <script type="text/javascript" src="/images/js/jquery.js"></script> <script type="text/javascript" src="/images/js/jquery.tablesorter.js"></script> <script type="text/javascript" src="/images/js/jquery.tablesorter.pager.js"></script> <script type="text/javascript" src="/images/js/jquery.tablesorter.widgets.js"></script> <script type="text/javascript" src="/images/js/jquery-ui.js"></script> <script type="text/javascript" src="/images/js/jquery.confirm.js"></script> <script type="text/javascript" > $(document).ready(function() { // init confirmation dialog $( "#confirm_dialog" ).dialog( // see http://jqueryui.com/docs/dialog/ for options { autoOpen: false, modal: true, closeOnEscape: true, width: 500, buttons: { "Cancel": function() { $( "#" + name ).dialog("close"); } } }); // table initially sorted by col. 2 (admin), then 0 (name) var sortOrder = [[2,1],[0,0]]; // use image path for sorting if there is any inside var imgTitle = function(contents) { var key = $(contents).find("a").attr("class"); if (key == null) { key = $(contents).html(); } return key; } $("#runtimeenvtable").tablesorter({widgets: ["zebra", "saveSort"], sortList:sortOrder, textExtraction: imgTitle }) .tablesorterPager({ container: $("#pager"), size: %s }); } ); </script> ''' % default_pager_entries output_objects.append({'object_type': 'html_form', 'text':''' <div id="confirm_dialog" title="Confirm" style="background:#fff;"> <div id="confirm_text"><!-- filled by js --></div> <textarea cols="40" rows="4" id="confirm_input" style="display:none;"></textarea> </div> ''' }) output_objects.append({'object_type': 'header', 'text' : 'Runtime Environments'}) output_objects.append( {'object_type': 'text', 'text' : 'Runtime environments specify software/data available on resources.' }) output_objects.append( {'object_type': 'link', 'destination': 'docs.py?show=Runtime+Environments', 'class': 'infolink', 'title': 'Show information about runtime environment', 'text': 'Documentation on runtime environments'}) output_objects.append({'object_type': 'sectionheader', 'text' : 'Existing runtime environments'}) (status, ret) = list_runtime_environments(configuration) if not status: output_objects.append({'object_type': 'error_text', 'text' : ret}) return (output_objects, returnvalues.SYSTEM_ERROR) runtimeenvironments = [] for single_re in ret: (re_dict, msg) = get_re_dict(single_re, configuration) if not re_dict: output_objects.append({'object_type': 'error_text', 'text' : msg}) return (output_objects, returnvalues.SYSTEM_ERROR) re_item = build_reitem_object(configuration, re_dict) re_name = re_item['name'] re_item['viewruntimeenvlink'] = {'object_type': 'link', 'destination': "showre.py?re_name=%s" % re_name, 'class': 'infolink', 'title': 'View %s runtime environment' % re_name, 'text': ''} if client_id == re_item['creator']: js_name = 'delete%s' % hexlify(re_name) helper = html_post_helper(js_name, 'deletere.py', {'re_name': re_name}) output_objects.append({'object_type': 'html_form', 'text': helper}) re_item['ownerlink'] = {'object_type': 'link', 'destination': "javascript: confirmDialog(%s, '%s');"\ % (js_name, 'Really delete %s?' % re_name), 'class': 'removelink', 'title': 'Delete %s runtime environment' % re_name, 'text': ''} runtimeenvironments.append(re_item) output_objects.append({'object_type': 'table_pager', 'entry_name': 'runtime envs', 'default_entries': default_pager_entries}) output_objects.append({'object_type': 'runtimeenvironments', 'runtimeenvironments': runtimeenvironments}) if configuration.site_swrepo_url: output_objects.append({'object_type': 'sectionheader', 'text': 'Software Packages'}) output_objects.append({'object_type': 'link', 'destination': configuration.site_swrepo_url, 'class': 'swrepolink', 'title': 'Browse available software packages', 'text': 'Open software catalogue for %s' % \ configuration.short_title, }) output_objects.append({'object_type': 'sectionheader', 'text': 'Additional Runtime Environments'}) output_objects.append({'object_type': 'link', 'destination': 'adminre.py', 'class': 'addlink', 'title': 'Specify a new runtime environment', 'text': 'Create a new runtime environment'}) return (output_objects, returnvalues.OK)
def display_resource(client_id, resourcename, raw_conf, resource_config, owners, re_list, configuration, fill_helpers): """Format and print the information and actions for a given resource. """ exe_units = [] store_units = [] frontend = None hosturl = None html = '' row_name = ('even', 'odd') if resource_config: if resource_config.has_key('EXECONFIG'): for exe in resource_config['EXECONFIG']: exe_units.append(exe['name']) if resource_config.has_key('STORECONFIG'): for store in resource_config['STORECONFIG']: store_units.append(store['name']) if resource_config.has_key('FRONTENDNODE'): frontend = resource_config['FRONTENDNODE'] if resource_config.has_key('HOSTURL'): hosturl = resource_config['HOSTURL'] # Try to split resourcename first to support resources where name # doesn't match hosturl. sep = '.' index = resourcename.rfind(sep) if index: hosturl = resourcename[:index] identifier = resourcename[index + 1:] elif hosturl: identifier = resourcename.replace(hosturl + sep, '') else: configuration.logger.warning( 'failed to find host identifier from unique resource name!') (hosturl, identifier) = (None, 0) form_method = fill_helpers['form_method'] csrf_limit = fill_helpers['csrf_limit'] fill_helpers.update({ 'res_id': resourcename, 'hosturl': hosturl, 'identifier': identifier }) html += '''<a id="%(res_id)s"></a> <h1>%(res_id)s</h1> <h3>Configuration</h3> Use the <a class="editlink iconspace" href="resedit.py?hosturl=%(hosturl)s;hostidentifier=%(identifier)s"> editing interface </a> or make any changes manually in the text box below.<br /> <a class="infolink iconspace" href="docs.py?show=Resource"> Resource configuration docs </a> ''' target_op = 'updateresconfig' csrf_token = make_csrf_token(configuration, form_method, target_op, client_id, csrf_limit) fill_helpers.update({'target_op': target_op, 'csrf_token': csrf_token}) html += ''' <form method="%(form_method)s" action="%(target_op)s.py"> <input type="hidden" name="%(csrf_field)s" value="%(csrf_token)s" /> <table class=resources> <tr> <td class=centertext> <textarea class="fillwidth padspace" rows="25" name="resconfig">''' % \ fill_helpers for line in raw_conf: html += '%s\n' % line.strip() html += \ '''</textarea> <br /> <input type="hidden" name="unique_resource_name" value="%(res_id)s" /> <input type="submit" value="Save" /> ---------- <input type="reset" value="Forget changes" /> ''' html += ''' </td></tr> </table> </form> <p> <h3>Control Resource Units</h3> <table class=resources> <tr class=title><td colspan="5">Front End</td></tr> ''' if not frontend: html += '<tr><td colspan=5>Not specified</td></tr>\n' else: html += '<tr><td>%s</td>' % frontend for action in ['restart', 'status', 'stop', 'clean']: if action == 'restart': action_str = '(Re)Start' else: action_str = action.capitalize() target_op = "%sfe" % action csrf_token = make_csrf_token(configuration, form_method, target_op, client_id, csrf_limit) fill_helpers.update({ 'action_str': action_str, 'target_op': target_op, 'csrf_token': csrf_token }) html += '''<td> <form method="%(form_method)s" action="%(target_op)s.py"> <input type="hidden" name="%(csrf_field)s" value="%(csrf_token)s" /> <input type="hidden" name="unique_resource_name" value="%(res_id)s" /> <input type="submit" value="%(action_str)s" /> </form> </td> ''' % fill_helpers html += '</tr>' html += '<tr class=title><td colspan=5>Execution Units</td></tr>\n' if not exe_units: html += '<tr><td colspan=5>None specified</td></tr>\n' else: html += '<tr><td>ALL UNITS</td>' for action in ['restart', 'status', 'stop', 'clean']: if action == 'restart': action_str = '(Re)Start' else: action_str = action.capitalize() target_op = "%sexe" % action csrf_token = make_csrf_token(configuration, form_method, target_op, client_id, csrf_limit) fill_helpers.update({ 'action_str': action_str, 'target_op': target_op, 'csrf_token': csrf_token }) html += '''<td> <form method="%(form_method)s" action="%(target_op)s.py"> <input type="hidden" name="%(csrf_field)s" value="%(csrf_token)s" /> <input type="hidden" name="unique_resource_name" value="%(res_id)s" /> <input type="hidden" name="all" value="true" /> <input type="hidden" name="parallel" value="true" /> <input type="submit" value="%(action_str)s" /> </form> </td> ''' % fill_helpers html += '</tr>' row_number = 1 for unit in exe_units: row_class = row_name[row_number % 2] html += '<tr class=%s><td>%s</td>' % (row_class, unit) for action in ['restart', 'status', 'stop', 'clean']: if action == 'restart': action_str = '(Re)Start' else: action_str = action.capitalize() target_op = "%sexe" % action csrf_token = make_csrf_token(configuration, form_method, target_op, client_id, csrf_limit) fill_helpers.update({ 'unit': unit, 'action_str': action_str, 'target_op': target_op, 'csrf_token': csrf_token }) html += '''<td> <form method="%(form_method)s" action="%(target_op)s.py"> <input type="hidden" name="%(csrf_field)s" value="%(csrf_token)s" /> <input type="hidden" name="unique_resource_name" value="%(res_id)s" /> <input type="hidden" name="exe_name" value="%(unit)s" /> <input type="submit" value="%(action_str)s" /> </form> </td> ''' % fill_helpers html += '</tr>' row_number += 1 html += '<tr class=title><td colspan=5>Storage Units</td></tr>\n' if not store_units: html += '<tr><td colspan=5>None specified</td></tr>\n' else: html += '<tr><td>ALL UNITS</td>' for action in ['restart', 'status', 'stop', 'clean']: if action == 'restart': action_str = '(Re)Start' else: action_str = action.capitalize() target_op = "%sstore" % action csrf_token = make_csrf_token(configuration, form_method, target_op, client_id, csrf_limit) fill_helpers.update({ 'action_str': action_str, 'target_op': target_op, 'csrf_token': csrf_token }) html += '''<td> <form method="%(form_method)s" action="%(target_op)s.py"> <input type="hidden" name="%(csrf_field)s" value="%(csrf_token)s" /> <input type="hidden" name="unique_resource_name" value="%(res_id)s" /> <input type="hidden" name="all" value="true" /> <input type="hidden" name="parallel" value="true" /> <input type="submit" value="%(action_str)s" /> </form> </td> ''' % fill_helpers html += '</tr>' row_number = 1 for unit in store_units: row_class = row_name[row_number % 2] html += '<tr class=%s><td>%s</td>' % (row_class, unit) for action in ['restart', 'status', 'stop', 'clean']: if action == 'restart': action_str = '(Re)Start' else: action_str = action.capitalize() target_op = "%sstore" % action csrf_token = make_csrf_token(configuration, form_method, target_op, client_id, csrf_limit) fill_helpers.update({ 'unit': unit, 'action_str': action_str, 'target_op': target_op, 'csrf_token': csrf_token }) html += '''<td> <form method="%(form_method)s" action="%(target_op)s.py"> <input type="hidden" name="%(csrf_field)s" value="%(csrf_token)s" /> <input type="hidden" name="unique_resource_name" value="%(res_id)s" /> <input type="hidden" name="store_name" value="%(unit)s" /> <input type="submit" value="%(action_str)s" /> </form> </td> ''' % fill_helpers html += '</tr>' row_number += 1 html += '</table><p>' html += '<h3>Owners</h3>' html += \ ''' Current owners of %(res_id)s.<br /> <table class=resources> ''' target_op = "rmresowner" csrf_token = make_csrf_token(configuration, form_method, target_op, client_id, csrf_limit) fill_helpers.update({'target_op': target_op, 'csrf_token': csrf_token}) for owner_id in owners: fill_helpers['cert_id'] = owner_id html += '''<tr><td> <form method="%(form_method)s" action="%(target_op)s.py"> <input type="hidden" name="%(csrf_field)s" value="%(csrf_token)s" /> <input type="hidden" name="unique_resource_name" value="%(res_id)s" /> <input type="hidden" name="cert_id" value="%(cert_id)s" /> <input type="hidden" name="output_format" value="html" /> <input type="submit" value="Remove" /> </form> </td> ''' % fill_helpers html += '<td>' + owner_id + '</td></tr>' html += '</table>' openid_add = "" if configuration.user_openid_providers: openid_add = "either the OpenID alias or " target_op = "addresowner" csrf_token = make_csrf_token(configuration, form_method, target_op, client_id, csrf_limit) fill_helpers.update({ 'openid_add': openid_add, 'target_op': target_op, 'csrf_token': csrf_token }) html += ''' <table class=resources> <tr><td> <form method="%(form_method)s" action="%(target_op)s.py"> <input type="hidden" name="%(csrf_field)s" value="%(csrf_token)s" /> <fieldset> <legend>Add resource owner(s)</legend> Note: owners are specified with %(openid_add)s the Distinguished Name (DN) of the user. If in doubt, just let the user request access and accept it with the <span class="addlink"></span>-icon in the Pending Requests table. <br /> <input type="hidden" name="unique_resource_name" value="%(res_id)s" /> <input type="hidden" name="output_format" value="html" /> <div id="dynownerspares"> <!-- placeholder for dynamic add owner fields --> </div> <input type="submit" value=" Add " /> </fieldset> </form> </td></tr> </table> <br /> ''' % fill_helpers # create html to request vgrid resource access html += '<h3>%(vgrid_label)s access</h3>' target_op = "sendrequestaction" csrf_token = make_csrf_token(configuration, form_method, target_op, client_id, csrf_limit) fill_helpers.update({'target_op': target_op, 'csrf_token': csrf_token}) html += ''' <table class=resources> <tr><td> <form method="%(form_method)s" action="%(target_op)s.py"> <input type="hidden" name="%(csrf_field)s" value="%(csrf_token)s" /> <fieldset> <legend>Request resource access to additional %(vgrid_label)ss</legend> <input type="hidden" name="unique_resource_name" value="%(res_id)s" /> <input type="hidden" name="request_type" value="vgridresource" /> <select name="vgrid_name">''' % fill_helpers # list all vgrids without access allowed_vgrids = res_vgrid_access(configuration, resourcename) vgrid_list = get_vgrid_map_vgrids(configuration) for vgrid_name in vgrid_list: if not vgrid_name in allowed_vgrids: html += '<option value=%s>%s' % (vgrid_name, vgrid_name) html += """</select>""" html += ''' Message to owners: <input type="text" name="request_text" size=50 value="" /> <input type="submit" value="send" /> </fieldset> </form> </td></tr></table><br /> ''' # create html to select and execute a runtime environment testprocedure html += '<h3>Runtime environments</h3>' target_op = "testresupport" csrf_token = make_csrf_token(configuration, form_method, target_op, client_id, csrf_limit) fill_helpers.update({'target_op': target_op, 'csrf_token': csrf_token}) html += ''' <table class=resources> <tr><td> <form method="%(form_method)s" action="%(target_op)s.py"> <input type="hidden" name="%(csrf_field)s" value="%(csrf_token)s" /> <fieldset> <legend>Verify that resource supports the selected runtime environment </legend> <input type="hidden" name="unique_resource_name" value="%(res_id)s" /> <select name="re_name">''' % fill_helpers # list runtime environments that have a testprocedure for env in re_list: (re_dict, re_msg) = get_re_dict(env, configuration) if re_dict: if re_dict.has_key('TESTPROCEDURE'): if re_dict['TESTPROCEDURE'] != []: html += '<option value=%s>%s' % (env, env) html += """</select>""" html += '<input type="submit" value="verify" /></fieldset>' html += ''' </form> </td></tr></table><br/> ''' # create html to select and call script to display testprocedure history target_op = "showresupport" csrf_token = make_csrf_token(configuration, form_method, target_op, client_id, csrf_limit) fill_helpers.update({'target_op': target_op, 'csrf_token': csrf_token}) verify_history = ''' Show testprocedure history for the selected runtime environment and the resource with its current configuration. <table class=resources> <tr><td> <form method="%(form_method)s" action="%(target_op)s.py"> <input type="hidden" name="%(csrf_field)s" value="%(csrf_token)s" /> <input type="hidden" name="unique_resource_name" value="%(res_id)s" /> <select name="re_name">''' % fill_helpers # list runtime environments that have a testprocedure for env in re_list: (re_dict, re_msg) = get_re_dict(env, configuration) if re_dict: if re_dict.has_key('TESTPROCEDURE'): if re_dict['TESTPROCEDURE'] != []: verify_history += '<option value=%s>%s' % (env, env) verify_history += """</select>""" verify_history += '<input type="submit" value="Show" />' verify_history += ''' </form> </td></tr></table><br /> ''' # TODO: reimplement showresupporthistory in new style and re-enable here #html += verify_history return html % fill_helpers
def run(localfile_spaces, unique_resource_name, outfile='AUTOMATIC' ): """Parse configuration in localfile_spaces and write results to outfile if non-empty. The keyword AUTOMATIC is replaced by the expected resource configuration path. """ (status, msg, conf) = get_resource_config_dict(localfile_spaces) if not status: return (False, msg) # verify runtime environments are specified correctly if conf.has_key('RUNTIMEENVIRONMENT'): for re in conf['RUNTIMEENVIRONMENT']: try: (name, value) = re except Exception, err: return (False, 'Runtime environment error: %s' % err) if not refunctions.is_runtime_environment(name, configuration): return (False, "Non existing runtime environment specified ('%s'), please create the runtime environment before specifying it in resource configurations." % name) (re_dict, msg) = refunctions.get_re_dict(name, configuration) if not re_dict: return (False, 'Runtime environment error, could not open (%s) %s' % (name, msg)) if not re_dict.has_key('ENVIRONMENTVARIABLE'): if value: # res conf has envs, but according to the template it should not return (False, "%s should not have any environments and you specified '%s'. Details about the runtime environment <a href=showre.py?re_name=%s>here</a>" % (re, value, name)) else: continue re_dict_environments = re_dict['ENVIRONMENTVARIABLE'] re_dict_environment_names = [] for re_environment in re_dict_environments: re_dict_environment_names.append(re_environment['name']) if not len(value) == len(re_dict_environments): return (False, "You have specified %s environments, but the runtime environment '%s' requires %s. Details about the runtime environment <a href='showre.py?re_name=%s'>here.</a>" % (len(value), name, len(re_dict_environments), name)) # we now know that the number of environments are # correct, verify that there are no name duplicates used_envnames = [] for env in value: try: (envname, _) = env if envname in used_envnames: # same envname used twice return (False, "You have specified the environment '%s' more than once for the '%s' runtime environment." % (envname, name)) used_envnames.append(envname) except Exception, err: return (False, 'Runtimeenvironment error: Name and value not found in env: %s' % err) # verify environment names are correct according to the # runtime environment definition do this by comparing # list of names specified for runtime environment and # res. conf. # re_dict_environment_names and used_envnames should # have the same entries! for n in re_dict_environment_names: # any build-in list comparison functionality? if not n in used_envnames: return (False, "You have not specified an environment named '%s' which is required by the '%s' runtime environment. Details about the runtime environment <a href=showre.py?re_name=%s>here.</a>" % (n, name, name))