def page(self) -> None: host_names = get_hostnames_from_checkboxes() hosts = { host_name: Folder.current().host(host_name) for host_name in host_names } current_host_hash = sha256(repr(hosts).encode()).hexdigest() # When bulk edit has been made with some hosts, then other hosts have been selected # and then another bulk edit has made, the attributes need to be reset before # rendering the form. Otherwise the second edit will have the attributes of the # first set. host_hash = request.var("host_hash") if not host_hash or host_hash != current_host_hash: request.del_vars(prefix="attr_") request.del_vars(prefix="bulk_change_") html.p("%s%s %s" % ( _("You have selected <b>%d</b> hosts for bulk edit. You can now change " "host attributes for all selected hosts at once. ") % len(hosts), _("If a select is set to <i>don't change</i> then currenty not all selected " "hosts share the same setting for this attribute. " "If you leave that selection, all hosts will keep their individual settings." ), _("In case you want to <i>unset</i> attributes on multiple hosts, you need to " "use the <i>bulk cleanup</i> action instead of bulk edit."), )) html.begin_form("edit_host", method="POST") html.prevent_password_auto_completion() html.hidden_field("host_hash", current_host_hash) configure_attributes(False, hosts, "bulk", parent=Folder.current()) forms.end() html.hidden_fields() html.end_form()
def page(self): # Show search form html.begin_form("edit_host", method="POST") html.prevent_password_auto_completion() basic_attributes = [ ( "host_search_host", TextInput( title=_( "Hostname", ) ), "", ), ] html.set_focus("host_search_host") # Attributes configure_attributes( new=False, hosts={}, for_what="host_search", parent=None, varprefix="host_search_", basic_attributes=basic_attributes, ) forms.end() html.hidden_field("host_search", "1") html.hidden_fields() html.end_form()
def page(self): self._folder.show_breadcrump() # Show search form html.begin_form("edit_host", method="POST") html.prevent_password_auto_completion() basic_attributes = [ ("host_search_host", TextAscii(title=_("Hostname",)), ""), ] html.set_focus("host_search_host") # Attributes configure_attributes( new=False, hosts={}, for_what="host_search", parent=None, varprefix="host_search_", basic_attributes=basic_attributes, ) # Button forms.end() html.button("_local", _("Search in %s") % self._folder.title(), "submit") html.hidden_field("host_search", "1") html.hidden_fields() html.end_form()
def page(self): new = self._folder.name() is None watolib.Folder.current().show_breadcrump() watolib.Folder.current().need_permission("read") if new and watolib.Folder.current().locked(): watolib.Folder.current().show_locking_information() html.begin_form("edit_host", method="POST") # title basic_attributes: List[Tuple[str, ValueSpec, str]] = [ ("title", TextUnicode(title=_("Title")), "" if new else self._folder.title()), ] html.set_focus("title") # folder name (omit this for root folder) if new or not watolib.Folder.current().is_root(): if not config.wato_hide_filenames: basic_attributes += [ ("name", TextAscii( title=_("Internal directory name"), help= _("This is the name of subdirectory where the files and " "other folders will be created. You cannot change this later." ), ), self._folder.name()), ] # Attributes inherited to hosts if new: parent = watolib.Folder.current() myself = None else: parent = watolib.Folder.current().parent() myself = watolib.Folder.current() configure_attributes(new=new, hosts={"folder": myself}, for_what="folder", parent=parent, myself=myself, basic_attributes=basic_attributes) forms.end() if new or not watolib.Folder.current().locked(): html.button("save", _("Save & Finish"), "submit") html.hidden_fields() html.end_form()
def page(self): new = self._folder.name() is None watolib.Folder.current().show_breadcrump() watolib.Folder.current().need_permission("read") if new and watolib.Folder.current().locked(): watolib.Folder.current().show_locking_information() html.begin_form("edit_host", method="POST") # title forms.header(_("Title")) forms.section(_("Title")) TextUnicode().render_input("title", self._folder.title()) html.set_focus("title") # folder name (omit this for root folder) if new or not watolib.Folder.current().is_root(): if not config.wato_hide_filenames: forms.section(_("Internal directory name")) if new: html.text_input("name") else: html.write_text(self._folder.name()) html.help( _("This is the name of subdirectory where the files and " "other folders will be created. You cannot change this later." )) # Attributes inherited to hosts if new: parent = watolib.Folder.current() myself = None else: parent = watolib.Folder.current().parent() myself = watolib.Folder.current() configure_attributes(new, {"folder": myself}, "folder", parent, myself) forms.end() if new or not watolib.Folder.current().locked(): html.button("save", _("Save & Finish"), "submit") html.hidden_fields() html.end_form()
def page(self): self._folder.show_breadcrump() # Show search form html.begin_form("edit_host", method="GET") html.prevent_password_auto_completion() forms.header(_("General Properties")) forms.section(_("Hostname")) html.text_input("host_search_host") html.set_focus("host_search_host") # Attributes configure_attributes(False, {}, "host_search", parent=None, varprefix="host_search_") # Button forms.end() html.button("_local", _("Search in %s") % self._folder.title(), "submit") html.hidden_field("host_search", "1") html.hidden_fields() html.end_form()
def page(self): # Show outcome of host validation. Do not validate new hosts errors = None if self._mode == "edit": errors = (watolib.validate_all_hosts([self._host.name()]).get( self._host.name(), []) + self._host.validation_errors()) if errors: html.open_div(class_="info") html.open_table(class_="validationerror", boder="0", cellspacing="0", cellpadding="0") html.open_tr() html.open_td(class_="img") html.icon("validation_error") html.close_td() html.open_td() html.open_p() html.h3(_("Warning: This host has an invalid configuration!")) html.open_ul() for error in errors: html.li(error) html.close_ul() html.close_p() if html.form_submitted(): html.br() html.b(_("Your changes have been saved nevertheless.")) html.close_td() html.close_tr() html.close_table() html.close_div() lock_message = "" locked_hosts = watolib.Folder.current().locked_hosts() if locked_hosts: if locked_hosts is True: lock_message = _( "Host attributes locked (You cannot edit this host)") elif isinstance(locked_hosts, str): lock_message = locked_hosts if lock_message: html.div(lock_message, class_="info") html.begin_form("edit_host", method="POST") html.prevent_password_auto_completion() basic_attributes = [ # attribute name, valuepec, default value ("host", self._vs_host_name(), self._host.name()), ] if self._is_cluster(): basic_attributes += [ # attribute name, valuepec, default value ( "nodes", self._vs_cluster_nodes(), self._host.cluster_nodes() if self._host else [], ), ] configure_attributes( new=self._mode != "edit", hosts={self._host.name(): self._host} if self._mode != "new" else {}, for_what="host" if not self._is_cluster() else "cluster", parent=watolib.Folder.current(), basic_attributes=basic_attributes, ) if self._mode != "edit": html.set_focus("host") forms.end() html.hidden_fields() html.end_form()
def page(self): # Show outcome of host validation. Do not validate new hosts errors = None if self._mode != "edit": watolib.Folder.current().show_breadcrump() else: errors = watolib.validate_all_hosts([self._host.name()]).get( self._host.name(), []) + self._host.validation_errors() if errors: html.open_div(class_="info") html.open_table(class_="validationerror", boder=0, cellspacing=0, cellpadding=0) html.open_tr() html.open_td(class_="img") html.icon(title=None, icon="validation_error") html.close_td() html.open_td() html.open_p() html.h3(_("Warning: This host has an invalid configuration!")) html.open_ul() for error in errors: html.li(error) html.close_ul() html.close_p() if html.form_submitted(): html.br() html.b(_("Your changes have been saved nevertheless.")) html.close_td() html.close_tr() html.close_table() html.close_div() lock_message = "" if watolib.Folder.current().locked_hosts(): if watolib.Folder.current().locked_hosts() is True: lock_message = _( "Host attributes locked (You cannot edit this host)") else: lock_message = watolib.Folder.current().locked_hosts() if len(lock_message) > 0: html.div(lock_message, class_="info") html.begin_form("edit_host", method="POST") html.prevent_password_auto_completion() forms.header(_("General Properties")) self._show_host_name() # Cluster: nodes if self._is_cluster(): forms.section(_("Nodes")) self._vs_cluster_nodes().render_input( "nodes", self._host.cluster_nodes() if self._host else []) html.help( _('Enter the host names of the cluster nodes. These ' 'hosts must be present in WATO. ')) configure_attributes( new=self._mode != "edit", hosts={self._host.name(): self._host} if self._mode != "new" else {}, for_what="host" if not self._is_cluster() else "cluster", parent=watolib.Folder.current()) forms.end() if not watolib.Folder.current().locked_hosts(): html.button("services", _("Save & go to Services"), "submit") html.button("save", _("Save & Finish"), "submit") if not self._is_cluster(): html.button("diag_host", _("Save & Test"), "submit") html.hidden_fields() html.end_form()