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] (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) hosturl = accepted['hosturl'][-1] hostidentifier = accepted['hostidentifier'][-1] resource_id = '%s.%s' % (hosturl, hostidentifier) extra_selects = 3 # Find allowed VGrids and Runtimeenvironments and add them to # configuration object for automated choice handling allowed_vgrids = [''] + res_allowed_vgrids(configuration, resource_id) allowed_vgrids.sort() configuration.vgrids = allowed_vgrids (re_status, allowed_run_envs) = list_runtime_environments(configuration) allowed_run_envs.sort() area_cols = 80 area_rows = 5 status = returnvalues.OK logger.info('Starting Resource edit GUI.') title_entry = find_entry(output_objects, 'title') title_entry['text'] = 'Resource Editor' output_objects.append({'object_type': 'header', 'text': 'Resource Editor' }) output_objects.append({'object_type': 'sectionheader', 'text' : '%s Resource Editor' % configuration.short_title}) output_objects.append({'object_type': 'text', 'text' : ''' Please fill in or edit the fields below to fit your %s resource reservation. Most fields will work with their default values. So if you are still in doubt after reading the help description, you can likely just leave the field alone.''' % configuration.short_title }) if hosturl and hostidentifier: conf = init_conf(configuration, hosturl, hostidentifier) if not conf: status = returnvalues.CLIENT_ERROR output_objects.append({'object_type': 'error_text', 'text' : '''No such resource! (%s.%s)''' % (hosturl, hostidentifier)}) return (output_objects, status) else: conf = empty_resource_config(configuration) res_fields = resconfkeywords.get_resource_specs(configuration) exe_fields = resconfkeywords.get_exenode_specs(configuration) store_fields = resconfkeywords.get_storenode_specs(configuration) output_objects.append({'object_type': 'html_form', 'text': """ <form method='post' action='reseditaction.py'> """ }) # Resource overall fields output_objects.append({'object_type': 'sectionheader', 'text' : "Main Resource Settings"}) output_objects.append({'object_type': 'text', 'text' : """This section configures general options for the resource.""" }) (title, field) = ('Host FQDN', 'HOSTURL') if hosturl: try: hostip = conf.get('HOSTIP', socket.gethostbyname(hosturl)) except: hostip = '<unknown>' output_objects.append({'object_type': 'html_form', 'text' : """<br /> <b>%s:</b> <a class='infolink' href='resedithelp.py#res-%s'>help</a><br /> <input type='hidden' name='%s' value='%s' /> <input type='hidden' name='hostip' value='%s' /> %s <br /> <br />""" % (title, field, field, conf[field], hostip, conf[field]) }) else: output_objects.append({'object_type': 'html_form', 'text' : """<br /> <b>%s:</b> <a class='infolink' href='resedithelp.py#res-%s'>help</a><br /> <input type='text' name='%s' size='%d' value='%s' /> <br /> <br />""" % (title, field, field, field_size(conf[field]), conf[field]) }) (title, field) = ('Host identifier', 'HOSTIDENTIFIER') if hostidentifier: output_objects.append({'object_type': 'html_form', 'text' : """<br /> <b>%s:</b> <a class='infolink' href='resedithelp.py#res-%s'>help</a><br /> <input type='hidden' name='%s' value='%s' /> %s <br /> <br />""" % (title, field, field, conf[field], conf[field]) }) (field, title) = 'frontendhome', 'Frontend Home Path' output_objects.append({'object_type': 'html_form', 'text' : """<br /> <b>%s:</b> <a class='infolink' href='resedithelp.py#%s'>help</a><br /> <input type='text' name='%s' size='%d' value='%s' /> <br /> <br />""" % (title, field, field, field_size(conf[field]), conf[field]) }) for (field, spec) in res_fields: title = spec['Title'] field_type = spec['Type'] if 'invisible' == spec['Editor']: continue elif 'input' == spec['Editor']: output_objects.append({'object_type': 'html_form', 'text' : """<br /> <b>%s:</b> <a class='infolink' href='resedithelp.py#res-%s'>help</a><br /> <input type='text' name='%s' size='%d' value='%s' /> <br /> <br />""" % (title, field, field, field_size(conf[field]), conf[field]) }) elif 'select' == spec['Editor']: choices = available_choices(configuration, client_id, resource_id, field, spec) res_value = conf[field] value_select = '' if field_type.startswith('multiple'): select_count = len(res_value) + extra_selects else: select_count = 1 res_value = [res_value] for i in range(select_count): value_select += "<select name='%s'>\n" % field for name in choices: selected = '' if i < len(res_value) and res_value[i] == name: selected = 'selected' display = "%s" % name if display == '': display = ' ' value_select += """<option %s value='%s'>%s</option>\n""" \ % (selected, name, display) value_select += """</select><br />\n""" output_objects.append({'object_type': 'html_form', 'text' : """<br /> <b>%s:</b> <a class='infolink' href='resedithelp.py#res-%s'>help</a><br /> %s <br />""" % (title, field, value_select) }) # Not all resource fields here map directly to keywords/specs input field (title, field) = ('Runtime Environments', 'RUNTIMEENVIRONMENT') re_list = conf[field] show = re_list + [('', []) for i in range(extra_selects)] re_select = "<input type='hidden' name='runtime_env_fields' value='%s'/>\n" \ % len(show) i = 0 for active in show: re_select += "<select name='runtimeenvironment%d'>\n" % i for name in allowed_run_envs + ['']: selected = '' if active[0] == name: selected = 'selected' display = "%s" % name if display == '': display = ' ' re_select += """<option %s value='%s'>%s</option>\n""" % \ (selected, name, display) re_select += """</select><br />\n""" values = '\n'.join(['%s=%s' % pair for pair in active[1]]) re_select += "<textarea cols='%d' rows='%d' name='re_values%d'>%s</textarea><br />\n" % \ (area_cols, area_rows, i, values) i += 1 output_objects.append({'object_type': 'html_form', 'text' : """<br /> <b>%s:</b> <a class='infolink' href='resedithelp.py#res-%s'>help</a><br /> Please enter any required environment variable settings on the form NAME=VALUE in the box below each selected runtimeenvironment.<br /> %s <br />""" % (title, field, re_select) }) # Execution node fields output_objects.append({'object_type': 'sectionheader', 'text' : "Execution nodes"}) output_objects.append({'object_type': 'text', 'text' : """This section configures execution nodes on the resource.""" }) (field, title) = 'executionnodes', 'Execution Node(s)' output_objects.append({'object_type': 'html_form', 'text' : """<br /> <b>%s:</b> <a class='infolink' href='resedithelp.py#exe-%s'>help</a><br /> <input type='text' name='exe-%s' size='%d' value='%s' /> <br /> <br />""" % (title, field, field, field_size(conf['all_exes'][field]), conf['all_exes'][field]) }) (field, title) = 'executionhome', 'Execution Home Path' output_objects.append({'object_type': 'html_form', 'text' : """<br /> <b>%s:</b> <a class='infolink' href='resedithelp.py#exe-%s'>help</a><br /> <input type='text' name='exe-%s' size='%d' value='%s' /> <br /> <br />""" % (title, field, field, field_size(conf['all_exes'][field]), conf['all_exes'][field]) }) for (field, spec) in exe_fields: title = spec['Title'] field_type = spec['Type'] if 'invisible' == spec['Editor']: continue elif 'input' == spec['Editor']: output_objects.append({'object_type': 'html_form', 'text' : """<br /> <b>%s:</b> <a class='infolink' href='resedithelp.py#exe-%s'>help</a><br /> <input type='text' name='exe-%s' size='%d' value='%s' /> <br /> <br />""" % (title, field, field, field_size(conf['all_exes'][field]), conf['all_exes'][field]) }) elif 'select' == spec['Editor']: choices = available_choices(configuration, client_id, resource_id, field, spec) exe_value = conf['all_exes'][field] value_select = '' if field_type.startswith('multiple'): select_count = len(exe_value) + extra_selects else: select_count = 1 exe_value = [exe_value] for i in range(select_count): value_select += "<select name='exe-%s'>\n" % field for name in choices: selected = '' if i < len(exe_value) and exe_value[i] == name: selected = 'selected' display = "%s" % name if display == '': display = ' ' value_select += """<option %s value='%s'>%s</option>\n""" \ % (selected, name, display) value_select += """</select><br />\n""" output_objects.append({'object_type': 'html_form', 'text' : """<br /> <b>%s:</b> <a class='infolink' href='resedithelp.py#exe-%s'>help</a><br /> %s <br />""" % (title, field, value_select) }) # Storage node fields output_objects.append({'object_type': 'sectionheader', 'text' : "Storage nodes"}) output_objects.append({'object_type': 'text', 'text' : """This section configures storage nodes on the resource.""" }) (field, title) = 'storagenodes', 'Storage Node(s)' output_objects.append({'object_type': 'html_form', 'text' : """<br /> <b>%s:</b> <a class='infolink' href='resedithelp.py#store-%s'>help</a><br /> <input type='text' name='store-%s' size='%d' value='%s' /> <br /> <br />""" % (title, field, field, field_size(conf['all_stores'][field]), conf['all_stores'][field]) }) (field, title) = 'storagehome', 'Storage Home Path' output_objects.append({'object_type': 'html_form', 'text' : """<br /> <b>%s:</b> <a class='infolink' href='resedithelp.py#store-%s'>help</a><br /> <input type='text' name='store-%s' size='%d' value='%s' /> <br /> <br />""" % (title, field, field, field_size(conf['all_stores'][field]), conf['all_stores'][field]) }) for (field, spec) in store_fields: title = spec['Title'] field_type = spec['Type'] if 'invisible' == spec['Editor']: continue elif 'input' == spec['Editor']: output_objects.append({'object_type': 'html_form', 'text' : """<br /> <b>%s:</b> <a class='infolink' href='resedithelp.py#store-%s'>help</a><br /> <input type='text' name='store-%s' size='%d' value='%s' /> <br /> <br />""" % (title, field, field, field_size(conf['all_stores'][field]), conf['all_stores'][field]) }) elif 'select' == spec['Editor']: choices = available_choices(configuration, client_id, resource_id, field, spec) store_value = conf['all_stores'][field] value_select = '' if field_type.startswith('multiple'): select_count = len(store_value) + extra_selects else: select_count = 1 store_value = [store_value] for i in range(select_count): value_select += "<select name='store-%s'>\n" % field for name in choices: selected = '' if i < len(store_value) and store_value[i] == name: selected = 'selected' display = "%s" % name if display == '': display = ' ' value_select += """<option %s value='%s'>%s</option>\n""" \ % (selected, name, display) value_select += """</select><br />\n""" output_objects.append({'object_type': 'html_form', 'text' : """<br /> <b>%s:</b> <a class='infolink' href='resedithelp.py#store-%s'>help</a><br /> %s <br />""" % (title, field, value_select) }) output_objects.append({'object_type': 'html_form', 'text': """ <input type='submit' value='Save' /> </form> """ }) return (output_objects, status)