def on_merge(self, effective_changes): self.logger.debug("Saving security page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) ssh_keys = ["ssh.pwauth", "strongrng.num_bytes", "strongrng.disable_aesni"] txs = utils.Transaction("Updating security configuration") if changes.contains_any(ssh_keys): model = defaults.SSH() model.update(*effective_model.values_for(ssh_keys)) txs += model.transaction() if changes.contains_any(["passwd.admin.password"]): pw = effective_model["passwd.admin.password"] passwd = utils.security.Passwd() # Create a custom transaction element, because the password # is not handled/saved in the defaults file class SetAdminPasswd(utils.Transaction.Element): title = "Setting admin password" def commit(self): self.logger.debug("Setting admin password.") passwd.set_password("admin", pw) txs += [SetAdminPasswd()] progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run()
def on_merge(self, effective_changes): self.logger.debug("Saving remote storage page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) txs = utils.Transaction("make local storage path") iscsi_keys = ["iscsi.initiator_name"] if changes.contains_any(iscsi_keys): args = effective_model.values_for(iscsi_keys) #model = defaults.iSCSI() txs += [createPath(args[0])] #args += [None, None, None] # No target config #model.update(*args) #txs += model.transaction() #nfsv4_keys = ["nfsv4.domain"] #if changes.contains_any(nfsv4_keys): # model = defaults.NFSv4() # args = effective_model.values_for(nfsv4_keys) # model.update(*args) # txs += model.transaction() progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run()
def on_merge(self, effective_changes): self.logger.debug("Saving logging page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) txs = utils.Transaction(_("Updating logging related configuration")) # If any logrotate key changed ... logrotate_keys = ["logrotate.max_size"] if changes.contains_any(logrotate_keys): # Get all logrotate values fomr the effective model model = defaults.Logrotate() # And update the defaults model.update(*effective_model.values_for(logrotate_keys)) txs += model.transaction() rsyslog_keys = ["rsyslog.address", "rsyslog.port"] if changes.contains_any(rsyslog_keys): model = defaults.Syslog() model.update(*effective_model.values_for(rsyslog_keys)) txs += model.transaction() netconsole_keys = ["netconsole.address", "netconsole.port"] if changes.contains_any(netconsole_keys): model = defaults.Netconsole() model.update(*effective_model.values_for(netconsole_keys)) txs += model.transaction() progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run()
def on_merge(self, effective_changes): self.logger.info("Saving Puppet config") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) puppet_keys = ["puppet.enabled", "puppet.server", "puppet.certname"] if changes.contains_any(puppet_keys): Puppet().update(*effective_model.values_for(puppet_keys)) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) txs = utils.Transaction("Configuring Puppet") if effective_changes.contains_any(["action.register"]): self.logger.debug("Connecting to puppet") txs += [ActivatePuppet()] if len(txs) > 0: progress_dialog = ui.TransactionProgressDialog( "dialog.txs", txs, self) progress_dialog.run() # Acts like a page reload return self.ui_content()
def on_merge(self, effective_changes): self.logger.debug("Saving SNMP page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) snmp_keys = ["snmp.password", "snmp.enabled"] txs = utils.Transaction("Updating SNMP configuration") if changes.contains_any(snmp_keys): is_enabled = effective_model["snmp.enabled"] pw = effective_model["snmp.password"] if is_enabled and len(pw) == 0: txt = "Unable to configure SNMP without a password!" self._confirm_dialog = ui.InfoDialog("dialog.confirm", "SNMP Error", txt) return self._confirm_dialog else: model = snmp_model.SNMP() model.update(is_enabled) txs += model.transaction(snmp_password=pw) progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run() return self.ui_content()
def on_merge(self, effective_changes): self.logger.info("Saving Puppet config") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) puppet_keys = ["puppet.enabled", "puppet.server", "puppet.certname"] if changes.contains_any(puppet_keys): Puppet().update(*effective_model.values_for(puppet_keys)) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) txs = utils.Transaction("Configuring Puppet") if effective_changes.contains_any(["action.register"]): self.logger.debug("Connecting to puppet") txs += [ActivatePuppet()] if len(txs) > 0: progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run() # Acts like a page reload return self.ui_content()
def on_merge(self, effective_changes): """Applies the changes to the plugins model, will do all required logic Normally on_merge is called by pushing the SaveButton instance, in this case it is called by on_change """ self.logger.debug("Saving kdump page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) saved_model = self.model() effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) kdump_keys = ["kdump.type", "kdump.ssh_location", "kdump.ssh_key", "kdump.nfs_location"] txs = utils.Transaction(_("Updating kdump related configuration")) if changes.contains_any(kdump_keys): model = defaults.KDump() ktype, sshloc, sshkey, nfsloc = effective_model.values_for( kdump_keys) if ktype == "nfs": model.configure_nfs(nfsloc) elif ktype == "ssh": if "kdump.ssh_key" in changes: model.configure_ssh(sshloc, sshkey) else: model.configure_ssh(sshloc) elif ktype == "local": model.configure_local() else: model.configure_disable() txs += model.transaction() try: with self.application.ui.suspended(): console.reset() is_dry = self.application.args.dry progress_dialog = console.TransactionProgress(txs, is_dry) progress_dialog.run() console.writeln("\nPlease press any key to continue") console.wait_for_keypress() except KeyboardInterrupt: def _handler(signum, frame): console.writeln("\nWait for configuration to be restored\n") with self.application.ui.suspended(): _original_sigint = signal.getsignal(signal.SIGINT) signal.signal(signal.SIGINT, _handler) self.restore_config(saved_model) signal.signal(signal.SIGINT, _original_sigint) return InfoDialog("dialog.restore", "Restored the " "configuration on keyboard interrupt") except Exception as e: self.restore_config(saved_model) self.logger.exception("Exception while configuring kdump") self.application.show(self.ui_content()) return InfoDialog("dialog.info", "An error occurred", e.message) return self.ui_content()
def on_merge(self, effective_changes): self.logger.debug("Saving logging page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) txs = utils.Transaction(_("Updating logging related configuration")) # If any logrotate key changed ... logrotate_keys = ["logrotate.max_size", "logrotate.interval"] if changes.contains_any(logrotate_keys): # Get all logrotate values fomr the effective model model = defaults.Logrotate() # And update the defaults model.update(*effective_model.values_for(logrotate_keys)) txs += model.transaction() rsyslog_keys = ["rsyslog.address", "rsyslog.port"] if changes.contains_any(rsyslog_keys): model = defaults.Syslog() model.update(*effective_model.values_for(rsyslog_keys)) txs += model.transaction() netconsole_keys = ["netconsole.address", "netconsole.port"] if changes.contains_any(netconsole_keys): model = defaults.Netconsole() model.update(*effective_model.values_for(netconsole_keys)) txs += model.transaction() progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run()
def on_merge(self, effective_changes): self.logger.debug("Saving remote storage page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) txs = utils.Transaction(_("Updating remote storage configuration")) iscsi_keys = ["iscsi.initiator_name"] if changes.contains_any(iscsi_keys): model = defaults.iSCSI() args = effective_model.values_for(iscsi_keys) args += [None, None, None] # No target config model.update(*args) txs += model.transaction() nfsv4_keys = ["nfsv4.domain"] if changes.contains_any(nfsv4_keys): model = defaults.NFSv4() args = effective_model.values_for(nfsv4_keys) model.update(*args) txs += model.transaction() scsi_keys = ["scsi.dh_alua"] if changes.contains_any(scsi_keys): model = defaults.SCSIDhAlua() args = effective_model.values_for(scsi_keys) model.update(*args) txs += model.transaction() progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run()
def on_merge(self, effective_changes): self.logger.debug("Saving remote storage page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) txs = utils.Transaction("Updating remote storage configuration") iscsi_keys = ["iscsi.initiator_name"] if changes.contains_any(iscsi_keys): model = defaults.iSCSI() args = effective_model.values_for(iscsi_keys) args += [None, None, None] # No target config model.update(*args) txs += model.transaction() nfsv4_keys = ["nfsv4.domain"] if changes.contains_any(nfsv4_keys): model = defaults.NFSv4() args = effective_model.values_for(nfsv4_keys) model.update(*args) txs += model.transaction() progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run()
def on_merge(self, effective_changes): """Applies the changes to the plugins model, will do all required logic Normally on_merge is called by pushing the SaveButton instance, in this case it is called by on_change """ self.logger.debug("Saving kdump page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) kdump_keys = ["kdump.type", "kdump.ssh_location", "kdump.ssh_key", "kdump.nfs_location"] txs = utils.Transaction(_("Updating kdump related configuration")) if changes.contains_any(kdump_keys): model = defaults.KDump() ktype, sshloc, sshkey, nfsloc = effective_model.values_for( kdump_keys) if ktype == "nfs": model.update(nfsloc, None, None, None) elif ktype == "ssh": if "kdump.ssh_key" in changes: model.update(None, sshloc, sshkey, None) else: model.update(None, sshloc, None, None) elif ktype == "local": model.update(None, None, None, True) else: model.update(None, None, None, None) txs += model.transaction() try: with self.application.ui.suspended(): console.reset() is_dry = self.application.args.dry progress_dialog = console.TransactionProgress(txs, is_dry) progress_dialog.run() console.writeln("\nPlease press any key to continue") console.wait_for_keypress() except Exception as e: self.logger.exception("Exception while configuring kdump") return InfoDialog("dialog.info", _("An error occurred"), e.message)
def on_merge(self, effective_changes): self.logger.debug("Saving security page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) ssh_keys = [ "ssh.pwauth", "strongrng.num_bytes", "strongrng.disable_aesni" ] passwd_keys = [ "passwd.admin.password", "passwd.admin.password_confirmation" ] txs = utils.Transaction("Updating security configuration") if changes.contains_any(ssh_keys): model = defaults.SSH() model.update(*effective_model.values_for(ssh_keys)) txs += model.transaction() if changes.contains_any(passwd_keys): pw, pwc = effective_model.values_for(passwd_keys) if pw != pwc: raise exceptions.InvalidData("Passwords do not match") passwd = utils.security.Passwd() # Create a custom transaction element, because the password # is not handled/saved in the defaults file class SetAdminPasswd(utils.Transaction.Element): title = "Setting admin password" def commit(self): self.logger.debug("Setting admin password.") passwd.set_password("admin", pw) txs += [SetAdminPasswd()] progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run()
def on_merge(self, effective_changes): self.logger.debug("Saving monitoring page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) collectd_keys = ["collectd.address", "collectd.port"] txs = utils.Transaction(_("Updating monitoring configuration")) if changes.contains_any(collectd_keys): model = defaults.Collectd() model.update(*effective_model.values_for(collectd_keys)) txs += model.transaction() progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run()
def on_merge(self, effective_changes): self.logger.debug("Saving keyboard page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) layout_keys = ["keyboard.layout"] txs = utils.Transaction("Updating keyboard related configuration") if changes.contains_any(layout_keys): model = defaults.Keyboard() model.update(*effective_model.values_for(layout_keys)) txs += model.transaction() progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run()
def on_merge(self, effective_changes): """Applies the changes to the plugins model, will do all required logic Normally on_merge is called by pushing the SaveButton instance, in this case it is called by on_change """ self.logger.debug("Saving kdump page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) kdump_keys = ["kdump.type", "kdump.ssh_location", "kdump.nfs_location"] txs = utils.Transaction("Updating kdump related configuration") if changes.contains_any(kdump_keys): model = defaults.KDump() ktype, sshloc, nfsloc = effective_model.values_for(kdump_keys) if ktype == "nfs": model.update(nfsloc, None, None) elif ktype == "ssh": model.update(None, sshloc, None) elif ktype == "local": model.update(None, None, True) else: model.update(None, None, None) txs += model.transaction() try: with self.application.ui.suspended(): console.reset() is_dry = self.application.args.dry progress_dialog = console.TransactionProgress(txs, is_dry) progress_dialog.run() console.writeln("\nPlease press any key to continue") console.wait_for_keypress() except Exception as e: self.logger.exception("Exception while configuring kdump") return InfoDialog("dialog.info", "An error occurred", e.message)
def on_merge(self, effective_changes): self.logger.debug("Saving hostname page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) collectd_keys = ["collectd.ip", "collectd.hostname"] txs = utils.Transaction("Add Node hostname to the Engine") if changes.contains_any(collectd_keys): model = defaults.Hostname() model.update(*effective_model.values_for(collectd_keys)) args = effective_model.values_for(collectd_keys) txs += [Hostname(args[0],args[1])] txs += model.transaction() progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run()
def on_merge(self, effective_changes): self.logger.debug("Saving hostname page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) collectd_keys = ["collectd.ip", "collectd.hostname"] txs = utils.Transaction("Add Node hostname to the Engine") if changes.contains_any(collectd_keys): model = defaults.Hostname() model.update(*effective_model.values_for(collectd_keys)) args = effective_model.values_for(collectd_keys) txs += [Hostname(args[0], args[1])] txs += model.transaction() progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run()
def on_merge(self, effective_changes): model = NodeManagement() changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) txs = utils.Transaction("Configuring {engine_name}".format( engine_name=config.engine_name)) if changes.contains_any(["vdsm_cfg.password"]): txs += [SetRootPassword( password=effective_model["vdsm_cfg.password"] )] if effective_model["vdsm_cfg.address"]: if validate_server(effective_model["vdsm_cfg.address"]): self._server, self._port = \ effective_model["vdsm_cfg.address"].split(":") else: self._server = effective_model["vdsm_cfg.address"] self._port = config.ENGINE_PORT txs += [NodeRegister(self._server, self._port)] model.update(mserver=self._server, mport=self._port) if len(txs) > 0: progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run() # VDSM messes with logging, and we just reset it log.configure_logging() # Acts like a page reload return self.ui_content()
def on_merge(self, effective_changes): self.logger.debug("Saving CIM page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) cim_keys = ["cim.password_confirmation", "cim.enabled"] txs = utils.Transaction("Updating CIM configuration") if changes.contains_any(cim_keys): is_enabled = effective_model["cim.enabled"] pw = effective_model["cim.password_confirmation"] model = cim_model.CIM() model.update(is_enabled) txs += model.transaction(cim_password=pw) progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run()
def on_merge(self, effective_changes): model = NodeManagement() changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) txs = utils.Transaction( "Configuring {engine_name}".format(engine_name=config.engine_name)) if changes.contains_any(["vdsm_cfg.password"]): txs += [ SetRootPassword(password=effective_model["vdsm_cfg.password"]) ] if effective_model["vdsm_cfg.address"]: if validate_server(effective_model["vdsm_cfg.address"]): self._server, self._port = \ effective_model["vdsm_cfg.address"].split(":") else: self._server = effective_model["vdsm_cfg.address"] self._port = config.ENGINE_PORT txs += [NodeRegister(self._server, self._port)] model.update(mserver=self._server, mport=self._port) if len(txs) > 0: progress_dialog = ui.TransactionProgressDialog( "dialog.txs", txs, self) progress_dialog.run() # VDSM messes with logging, and we just reset it log.configure_logging() # Acts like a page reload return self.ui_content()
def on_merge(self, effective_changes): """Applies the changes to the plugins model, will do all required logic Normally on_merge is called by pushing the SaveButton instance, in this case it is called by on_change """ self.logger.debug("Saving kdump page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) kdump_keys = ["kdump.type", "kdump.ssh_location", "kdump.nfs_location"] txs = utils.Transaction("Updating kdump related configuration") if changes.contains_any(kdump_keys): model = defaults.KDump() ktype, sshloc, nfsloc = effective_model.values_for(kdump_keys) if ktype == "nfs": model.update(nfsloc, None, None) elif ktype == "ssh": model.update(None, sshloc, None) elif ktype == "local": model.update(None, None, True) else: model.update(None, None, None) txs += model.transaction() with self.application.ui.suspended(): utils.process.call("reset") progress_dialog = console.TransactionProgress(txs, self) progress_dialog.run() console.writeln("\nPlease press any key to continue") console.wait_for_keypress()
def on_merge(self, effective_changes): self.logger.debug("Saving SNMP page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) snmp_keys = ["snmp.password_confirmation", "snmp.enabled"] txs = utils.Transaction("Updating SNMP configuration") if changes.contains_any(snmp_keys): values = effective_model.values_for(snmp_keys) args = [values[0]] if values[1] is False: # If set to disabled, set password to None args[0] = None model = snmp_model.SNMP() model.update(*args) txs += model.transaction() progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run()
# You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. A copy of the GNU General Public License is # also available at http://www.gnu.org/copyleft/gpl.html. from ovirt.node.setup.puppet.puppet_page import * import ovirtnode.ovirtfunctions as _functions from ovirt.node.plugins import Changeset import re args = _functions.get_cmdline_args() keys = ["puppet_enabled", "puppet_server", "puppet_certname"] changes = dict( (re.sub(r'_', r'.', key), args[key]) for key in keys if key in args) cfg = Puppet().retrieve() effective_model = Changeset({ "puppet.enabled": True if cfg["enabled"] else False, "puppet.server": cfg["server"] or "puppet", "puppet.certname": cfg["certname"] or socket.gethostname() }) if changes: effective_model.update(changes) Puppet().update(*effective_model.values_for(keys)) if "puppet_enabled" in args and (re.compile(r'y', re.I).match( args["puppet_enabled"]) or args["puppet_enabled"] == "1"): ActivatePuppet()
def on_merge(self, effective_changes): self.logger.debug("Saving RHSM page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) rhn_keys = [ "rhn.username", "rhn.password", "rhn.profilename", "rhn.type", "rhn.url", "rhn.ca", "rhn.proxyhost", "rhn.proxyport", "rhn.proxyuser", "rhn.proxypassword", "rhn.org", "rhn.environment", "rhn.activation_key" ] if "button.proxy" in changes: description = ("Please enter the proxy details to use " + "for contacting the management server ") self._dialog = ProxyDialog("Input proxy information", description, self) self.widgets.add(self._dialog) return self._dialog if "rhn.activation_key" in changes and "rhn.username" in changes: return ui.InfoDialog( "dialog.error", "Conflicting Inputs", "Username and activationkey cannot be used " "simultaneously. Please clear one of the " "values") elif "rhn.activation_key" not in effective_model and \ ("rhn.username" not in effective_model and "rhn.password" not in effective_model): return ui.InfoDialog( "dialog.error", "Conflicting Inputs", "Username or activationkey must be set." "Please set one of the values.") txs = utils.Transaction("Updating RHSM configuration") if changes.contains_any(rhn_keys): def update_proxy(): vals = [ effective_model["rhn.proxyhost"], effective_model["rhn.proxyport"] ] proxy_str = "%s:%s" % (vals[0], vals[1]) if vals[1] else \ "%s" % vals[0] return proxy_str effective_model["rhn.proxy"] = proxy_str self.logger.debug(changes) self.logger.debug(effective_model) effective_model["rhn.type"] = effective_model["rhn.type"] or "rhn" effective_model["rhn.proxy"] = update_proxy() if \ effective_model["rhn.proxyhost"] else "" rhn_keys = [ "rhn.type", "rhn.url", "rhn.ca", "rhn.username", "rhn.profilename", "rhn.activation_key", "rhn.org", "rhn.environment", "rhn.proxy", "rhn.proxyuser" ] pw = effective_model["rhn.password"] proxypassword = effective_model["rhn.proxypassword"] warning_text = None rhn_type = effective_model["rhn.type"] if rhn_type == "sam" or rhn_type == "satellite": if not effective_model["rhn.url"] and not \ effective_model["rhn.ca"]: warning_text = "URL and CA path " elif not effective_model["rhn.ca"]: warning_text = "CA path " if warning_text: txt = "%s must not be empty!" % warning_text self._error_dialog = ui.InfoDialog("dialog.error", "RHSM Error", txt) return self._error_dialog else: model = rhn_model.RHN() model.clear() model.update(*effective_model.values_for(rhn_keys)) txs += model.transaction(password=pw, proxypass=proxypassword) progress_dialog = ui.TransactionProgressDialog( "dialog.txs", txs, self) progress_dialog.run() return self.ui_content()
def on_merge(self, effective_changes): model = VDSM() self.logger.info("Saving engine stuff") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) if changes.contains_any(["action.fetch_cert"]): buttons = [ui.Button("action.cert.accept", "Accept"), ui.Button("action.cert.reject", "Reject & Remove")] try: server = effective_model["vdsm_cfg.address"] port = findPort(server, effective_model["vdsm_cfg.port"]) self._cert_path, fingerprint = retrieveCetrificate(server, port) self._server, self._port = server, port title_msg = "\nPlease review the following SSL fingerprint" \ " from Engine:\n" except Exception as e: fingerprint = str(e) title_msg = "\n" buttons = [ui.Button("action.cert.reject", "Close")] self._fp_dialog = ui.Dialog("dialog.engine.fp", "{engine_name} " "Fingerprint".format(engine_name=config.engine_name), [ui.Label("dialog.label[0]", title_msg), ui.Label("dialog.fp", fingerprint)]) self._fp_dialog.buttons = buttons return self._fp_dialog elif changes.contains_any(["action.cert.accept"]): self._fp_dialog.close() model.update(self._server, self._port, self._cert_path) utils.fs.Config().persist(self._cert_path) self._server, self._port, self._cert_path = None, None, None elif changes.contains_any(["action.cert.reject"]): model.update(cert_path=None) utils.fs.Config().unpersist(self._cert_path) if self._cert_path is not None: os.unlink(self._cert_path) self._fp_dialog.close() self._server, self._port, self._cert_path = None, None, None txs = utils.Transaction("Configuring {engine_name}".format( engine_name=config.engine_name)) if changes.contains_any(["vdsm_cfg.password"]): self.logger.debug("Setting engine password") txs += [SetRootPassword( password=effective_model["vdsm_cfg.password"])] if effective_changes.contains_any(["action.register"]) and \ effective_model["vdsm_cfg.address"] != "": model.update(server=effective_model["vdsm_cfg.address"], port=effective_model["vdsm_cfg.port"]) self.logger.debug("Connecting to engine") txs += [ActivateVDSM(effective_model["vdsm_cfg.address"], effective_model["vdsm_cfg.port"])] if len(txs) > 0: progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run() # VDSM messes with logging, and we just reset it log.configure_logging() # Acts like a page reload return self.ui_content()
def on_merge(self, effective_changes): self.logger.info("Saving network stuff") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.info("Effective changes %s" % effective_changes) self.logger.debug("Effective Model: %s" % effective_model) # Special case: A NIC was selected, display that dialog! if "nics" in changes and len(changes) == 1: iface = changes["nics"] self.logger.debug("Opening NIC Details dialog for '%s'" % iface) self._nic_dialog = NicDetailsDialog(self, iface) return self._nic_dialog if "dialog.nic.close" in changes: self._nic_dialog.close() return if "button.ping" in changes: self.logger.debug("Opening ping page") plugin_type = ovirt.node.setup.ping.Plugin self.application.switch_to_plugin(plugin_type) return # This object will contain all transaction elements to be executed txs = utils.Transaction("DNS and NTP configuration") e_changes_h = plugins.Changeset(effective_changes) nameservers = [] dns_keys = ["dns[0]", "dns[1]"] if e_changes_h.contains_any(dns_keys): nameservers += effective_model.values_for(dns_keys) if nameservers: self.logger.info("Setting new nameservers: %s" % nameservers) model = defaults.Nameservers() model.update(nameservers) txs += model.transaction() timeservers = [] ntp_keys = ["ntp[0]", "ntp[1]"] if e_changes_h.contains_any(ntp_keys): timeservers += effective_model.values_for(ntp_keys) if timeservers: self.logger.info("Setting new timeservers: %s" % timeservers) model = defaults.Timeservers() model.update(timeservers) txs += model.transaction() hostname_keys = ["hostname"] if e_changes_h.contains_any(hostname_keys): value = effective_model.values_for(hostname_keys) self.logger.info("Setting new hostname: %s" % value) model = defaults.Hostname() model.update(*value) txs += model.transaction() # For the NIC details dialog: if e_changes_h.contains_any(self._nic_details_group): # If any networking related key was changed, reconfigure networking # Fetch the values for the nic keys, they are used as arguments args = effective_model.values_for(self._nic_details_group) txs += self._configure_nic(*args) progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run() if "dialog.nic.save" in changes: # Close the remaing details dialog self._nic_dialog.close() # Behaves like a page reload return self.ui_content()
def on_merge(self, effective_changes): self.logger.debug("Saving RHN page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) rhn_keys = [ "rhn.user", "rhn.password", "rhn.profilename", "rhn.type", "rhn.url", "rhn.ca", "rhn.proxyhost", "rhn.proxyport", "rhn.proxyuser", "rhn.proxypassword", "rhn.org", "rhn.activation_key" ] txs = utils.Transaction("Updating RHN configuration") if changes.contains_any(rhn_keys): self.logger.debug(changes) self.logger.debug(effective_model) user = effective_model["rhn.user"] pw = effective_model["rhn.password"] profilename = effective_model["rhn.profilename"] rhn_type = effective_model["rhn.type"] url = effective_model["rhn.url"] ca = effective_model["rhn.ca"] org = effective_model["rhn.org"] activationkey = effective_model["rhn.activation_key"] proxyhost = effective_model["rhn.proxyhost"] proxyport = effective_model["rhn.proxyport"] proxyuser = effective_model["rhn.proxyuser"] proxypassword = effective_model["rhn.proxypassword"] warning_text = "" if rhn_type == "sam" or rhn_type == "satellite": if url == "" or url is None: warning_text += "URL " if ca == "" or ca is None: if warning_text is "": warning_text += "CA path " else: warning_text += "and CA path " if warning_text is not "": txt = "%s must not be empty!" % warning_text self._error_dialog = ui.InfoDialog("dialog.error", "RHN Error", txt) return self._error_dialog else: model = rhn_model.RHN() # join proxy host/port self.logger.debug(proxyhost) self.logger.debug(proxyport) proxy = None if len(proxyhost) > 0 and len(proxyport) > 0: proxy = "%s:%s" % (proxyhost, proxyport) self.logger.debug(proxy) model.update(rhn_type, url, ca, user, profilename, activationkey, org, proxy, proxyuser) txs += model.transaction(password=pw, proxypass=proxypassword) progress_dialog = ui.TransactionProgressDialog( "dialog.txs", txs, self) progress_dialog.run() return self.ui_content()
def on_merge(self, effective_changes): """Applies the changes to the plugins model, will do all required logic Normally on_merge is called by pushing the SaveButton instance, in this case it is called by on_change """ self.logger.debug("Saving kdump page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) saved_model = self.model() effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) kdump_keys = [ "kdump.type", "kdump.ssh_location", "kdump.ssh_key", "kdump.nfs_location" ] txs = utils.Transaction(_("Updating kdump related configuration")) if changes.contains_any(kdump_keys): model = defaults.KDump() ktype, sshloc, sshkey, nfsloc = effective_model.values_for( kdump_keys) if ktype == "nfs": model.configure_nfs(nfsloc) elif ktype == "ssh": if "kdump.ssh_key" in changes: model.configure_ssh(sshloc, sshkey) else: model.configure_ssh(sshloc) elif ktype == "local": model.configure_local() else: model.configure_disable() txs += model.transaction() try: with self.application.ui.suspended(): console.reset() is_dry = self.application.args.dry progress_dialog = console.TransactionProgress(txs, is_dry) progress_dialog.run() console.writeln("\nPlease press any key to continue") console.wait_for_keypress() except KeyboardInterrupt: def _handler(signum, frame): console.writeln("\nWait for configuration to be restored\n") with self.application.ui.suspended(): _original_sigint = signal.getsignal(signal.SIGINT) signal.signal(signal.SIGINT, _handler) self.restore_config(saved_model) signal.signal(signal.SIGINT, _original_sigint) return InfoDialog( "dialog.restore", "Restored the " "configuration on keyboard interrupt") except Exception as e: self.restore_config(saved_model) self.logger.exception("Exception while configuring kdump") self.application.show(self.ui_content()) return InfoDialog("dialog.info", "An error occurred", e.message) return self.ui_content()
def on_merge(self, effective_changes): self.logger.info("Saving engine stuff") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) if changes.contains_any(["action.fetch_options"]): http_port = effective_model.values_for(["engine_cfg.httpPORT"])[0] https_port = effective_model.values_for(["engine_cfg.httpsPORT" ])[0] auth_pass = effective_model.values_for(["engine_cfg.authPASS"])[0] org_license = effective_model.values_for(["engine_cfg.license"])[0] host_fqdn = effective_model.values_for(["engine_cfg.hostFQDN"])[0] db_local_pass = effective_model.values_for( ["engine_cfg.adminPASS"])[0] org_name = effective_model.values_for(["engine_cfg.orgNAME"])[0] nfs_mp = effective_model.values_for(["engine_cfg.isoPATH"])[0] pieces={"OVESETUP_CONFIG/httpPort":http_port,'OVESETUP_CONFIG/httpsPort':\ https_port,"OVESETUP_CONFIG/adminPassword":auth_pass,\ "ORG_LICENSE":org_license,'OVESETUP_DB/password':db_local_pass,\ "OVESETUP_PKI/organization":org_name,'OVESETUP_CONFIG/isoDomainMountPoint':nfs_mp} if not auth_pass: pieces.update({'TUI_change_admin': False}) self.engine_config.update(**pieces) self._fp_dialog = AdvanceOptionsDialog( self, 'Engine Advance Options:', app_mode=self.cfg["OVESETUP_CONFIG/applicationMode"], db_type=self.cfg["OVESETUP_CONFIG/storageIsLocal"], config_nfs=self.cfg["OVESETUP_SYSTEM/nfsConfigEnabled"], firewall=self.cfg["OVESETUP_CONFIG/firewallManager"], dc_type=self.cfg["OVESETUP_CONFIG/storageType"]) return self._fp_dialog elif changes.contains_any(["action.reset"]): _functions.system_closefds( "rm -rf /etc/ovirt-engine/engine-setup.conf &> /dev/null") _functions.system_closefds( "engine-setup --gen-answer-file=/etc/ovirt-engine/engine-setup.conf &> /dev/null" ) _functions.system_closefds( "sed -i 1d /etc/ovirt-engine/engine-setup.conf &> /dev/null") elif changes.contains_any(["dialog.options.save"]): #LOGGER.debug("dialog.options.save................................!!!!") args = effective_model.values_for(self._options_details_group) self._advance_configure(*args) self._fp_dialog.close() if effective_changes.contains_any(["action.register"]): self.logger.debug("engine setup") #txs += [ActivateVDSM()] http_port = effective_model.values_for(["engine_cfg.httpPORT"])[0] https_port = effective_model.values_for(["engine_cfg.httpsPORT" ])[0] auth_pass = effective_model.values_for(["engine_cfg.authPASS"])[0] org_license = effective_model.values_for(["engine_cfg.license"])[0] host_fqdn = effective_model.values_for(["engine_cfg.hostFQDN"])[0] db_local_pass = effective_model.values_for( ["engine_cfg.adminPASS"])[0] org_name = effective_model.values_for(["engine_cfg.orgNAME"])[0] nfs_mp = effective_model.values_for(["engine_cfg.isoPATH"])[0] self.cfg = self.engine_config.retrieve() if self.cfg['OVESETUP_SYSTEM/nfsConfigEnabled']: if not nfs_mp: return pieces={"OVESETUP_CONFIG/httpPort":http_port,'OVESETUP_CONFIG/httpsPort':\ https_port,"OVESETUP_CONFIG/adminPassword":auth_pass,\ "ORG_LICENSE":org_license,'OVESETUP_DB/password':db_local_pass,\ "OVESETUP_PKI/organization":org_name,'OVESETUP_CONFIG/isoDomainMountPoint':nfs_mp} if not auth_pass: pieces.update({"TUI_change_admin": False}) self.engine_config.update(**pieces) #args = effective_model.values_for(self._options_details_group) #self._advance_configure(*args) plugin_type = setup.Plugin self.cfg = self.engine_config.retrieve() plugin_type.environment = self.cfg plugin_type.filename = self.fn self.application.switch_to_plugin(plugin_type) return #if len(txs) > 0: # progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, # self) # progress_dialog.run() # VDSM messes with logging, and we just reset it # app.configure_logging() # Acts like a page reload return self.ui_content()
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. A copy of the GNU General Public License is # also available at http://www.gnu.org/copyleft/gpl.html. from ovirt.node.setup.puppet.puppet_page import * import ovirtnode.ovirtfunctions as _functions from ovirt.node.plugins import Changeset import re args = _functions.get_cmdline_args() keys = ["puppet_enabled", "puppet_server", "puppet_certname"] changes = dict((re.sub(r"_", r".", key), args[key]) for key in keys if key in args) cfg = Puppet().retrieve() effective_model = Changeset( { "puppet.enabled": True if cfg["enabled"] else False, "puppet.server": cfg["server"] or "puppet", "puppet.certname": cfg["certname"] or socket.gethostname(), } ) if changes: effective_model.update(changes) real_keys = [re.sub(r"_", r".", key) for key in keys] Puppet().update(*effective_model.values_for(real_keys)) if "puppet_enabled" in args and (re.compile(r"y", re.I).match(args["puppet_enabled"]) or args["puppet_enabled"] == "1"): ActivatePuppet().enable_puppet()
def on_merge(self, effective_changes): self.logger.debug("Saving RHN page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) rhn_keys = ["rhn.user", "rhn.password", "rhn.profilename", "rhn.type", "rhn.url", "rhn.ca", "rhn.proxyhost", "rhn.proxyport", "rhn.proxyuser", "rhn.proxypassword", "rhn.org", "rhn.activation_key"] txs = utils.Transaction("Updating RHN configuration") if changes.contains_any(rhn_keys): self.logger.debug(changes) self.logger.debug(effective_model) user = effective_model["rhn.user"] pw = effective_model["rhn.password"] profilename = effective_model["rhn.profilename"] rhn_type = effective_model["rhn.type"] url = effective_model["rhn.url"] ca = effective_model["rhn.ca"] org = effective_model["rhn.org"] activationkey = effective_model["rhn.activation_key"] proxyhost = effective_model["rhn.proxyhost"] proxyport = effective_model["rhn.proxyport"] proxyuser = effective_model["rhn.proxyuser"] proxypassword = effective_model["rhn.proxypassword"] warning_text = "" if rhn_type == "sam" or rhn_type == "satellite": if url == "" or url is None: warning_text += "URL " if ca == "" or ca is None: if warning_text is "": warning_text += "CA path " else: warning_text += "and CA path " if warning_text is not "": txt = "%s must not be empty!" % warning_text self._error_dialog = ui.InfoDialog("dialog.error", "RHN Error", txt) return self._error_dialog else: model = rhn_model.RHN() # join proxy host/port self.logger.debug(proxyhost) self.logger.debug(proxyport) proxy = None if len(proxyhost) > 0 and len(proxyport) > 0: proxy = "%s:%s" % (proxyhost, proxyport) self.logger.debug(proxy) model.update(rhn_type, url, ca, user, profilename, activationkey, org, proxy, proxyuser) txs += model.transaction(password=pw, proxypass=proxypassword) progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run() return self.ui_content()
def on_merge(self, effective_changes): self.logger.info("Saving network stuff") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.info("Effective changes %s" % effective_changes) self.logger.debug("Effective Model: %s" % effective_model) # This object will contain all transaction elements to be executed txs = utils.Transaction("Network Interface Configuration") # Special case: A NIC was selected, display that dialog! if "nics" in changes and len(changes) == 1: iface = changes["nics"] self.logger.debug("Opening NIC Details dialog for '%s'" % iface) self._model_extra["dialog.nic.ifname"] = iface self._nic_dialog = NicDetailsDialog(self, iface) return self._nic_dialog if "dialog.nic.close" in changes: self._nic_dialog.close() return if "button.toggle_bond" in changes: m_bond = defaults.NicBonding() mnet = defaults.Network() if m_bond.retrieve()["slaves"]: if mnet.retrieve()["iface"] == m_bond.retrieve()["name"]: # Remove network config if primary devce was this # bond mnet.configure_no_networking() m_bond.configure_no_bond() txs += m_bond.transaction() txs += mnet.transaction() else: self._bond_dialog = CreateBondDialog("dialog.bond") self.widgets.add(self._bond_dialog) return self._bond_dialog if "button.ping" in changes: self.logger.debug("Opening ping page") self.application.switch_to_plugin(ping.Plugin) return if "dialog.nic.identify" in changes: ifname = self._model_extra["dialog.nic.ifname"] utils.network.NIC(ifname).identify() self.application.notice("Flashing lights now") return nameservers = [] dns_keys = ["dns[0]", "dns[1]"] if effective_changes.contains_any(dns_keys): nameservers += effective_model.values_for(dns_keys) if nameservers: self.logger.info("Setting new nameservers: %s" % nameservers) model = defaults.Nameservers() model.update(nameservers) txs += model.transaction() timeservers = [] ntp_keys = ["ntp[0]", "ntp[1]"] if effective_changes.contains_any(ntp_keys): timeservers += effective_model.values_for(ntp_keys) if timeservers: self.logger.info("Setting new timeservers: %s" % timeservers) model = defaults.Timeservers() model.update(timeservers) txs += model.transaction() hostname_keys = ["hostname"] if effective_changes.contains_any(hostname_keys): value = effective_model.values_for(hostname_keys) self.logger.info("Setting new hostname: %s" % value) model = defaults.Hostname() model.update(*value) txs += model.transaction() # For the NIC details dialog: if effective_changes.contains_any(self._nic_details_group): # If any networking related key was changed, reconfigure networking # Fetch the values for the nic keys, they are used as arguments args = effective_model.values_for(self._nic_details_group) txs += self._configure_nic(*args) if effective_changes.contains_any(self._bond_group): mb = defaults.NicBonding() mnet = defaults.Network() args = effective_model.values_for( ["bond.name", "bond.slaves.selected", "bond.options"]) self.logger.debug("args: %s" % args) mb.update(*args) txs += mb.transaction() txs += mnet.transaction() self._bond_dialog.close() progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run() if "dialog.nic.save" in changes: # Close the remaing details dialog self._nic_dialog.close() # Behaves like a page reload return self.ui_content()
def on_merge(self, effective_changes): self.logger.debug("Saving RHSM page") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) rhn_keys = ["rhn.username", "rhn.password", "rhn.profilename", "rhn.type", "rhn.url", "rhn.ca", "rhn.proxyhost", "rhn.proxyport", "rhn.proxyuser", "rhn.proxypassword", "rhn.org", "rhn.environment", "rhn.activation_key"] if "button.proxy" in changes: description = ("Please enter the proxy details to use " + "for contacting the management server ") self._dialog = ProxyDialog("Input proxy information", description, self) self.widgets.add(self._dialog) return self._dialog if "rhn.activation_key" in changes and "rhn.username" in changes: return ui.InfoDialog("dialog.error", "Conflicting Inputs", "Username and activationkey cannot be used " "simultaneously. Please clear one of the " "values") elif "rhn.activation_key" not in effective_model and \ ("rhn.username" not in effective_model and "rhn.password" not in effective_model): return ui.InfoDialog("dialog.error", "Conflicting Inputs", "Username or activationkey must be set." "Please set one of the values.") txs = utils.Transaction("Updating RHSM configuration") if changes.contains_any(rhn_keys): def update_proxy(): vals = [effective_model["rhn.proxyhost"], effective_model["rhn.proxyport"]] proxy_str = "%s:%s" % (vals[0], vals[1]) if vals[1] else \ "%s" % vals[0] return proxy_str effective_model["rhn.proxy"] = proxy_str self.logger.debug(changes) self.logger.debug(effective_model) effective_model["rhn.type"] = effective_model["rhn.type"] or "rhn" effective_model["rhn.proxy"] = update_proxy() if \ effective_model["rhn.proxyhost"] else "" rhn_keys = ["rhn.type", "rhn.url", "rhn.ca", "rhn.username", "rhn.profilename", "rhn.activation_key", "rhn.org", "rhn.environment", "rhn.proxy", "rhn.proxyuser"] pw = effective_model["rhn.password"] proxypassword = effective_model["rhn.proxypassword"] warning_text = None rhn_type = effective_model["rhn.type"] if rhn_type == "sam" or rhn_type == "satellite": if not effective_model["rhn.url"] and not \ effective_model["rhn.ca"]: warning_text = "URL and CA path " elif not effective_model["rhn.ca"]: warning_text = "CA path " if warning_text: txt = "%s must not be empty!" % warning_text self._error_dialog = ui.InfoDialog("dialog.error", "RHSM Error", txt) return self._error_dialog else: model = rhn_model.RHN() model.clear() model.update(*effective_model.values_for(rhn_keys)) txs += model.transaction(password=pw, proxypass=proxypassword) progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run() return self.ui_content()
def on_merge(self, effective_changes): self.logger.info("Saving network stuff") changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.info("Effective changes %s" % effective_changes) self.logger.debug("Effective Model: %s" % effective_model) # This object will contain all transaction elements to be executed txs = utils.Transaction(_("Network Interface Configuration")) # Special case: A NIC was selected, display that dialog! if "nics" in changes and len(changes) == 1: iface = changes["nics"] self.logger.debug("Opening NIC Details dialog for '%s'" % iface) self._model_extra["dialog.nic.ifname"] = iface self._nic_dialog = NicDetailsDialog(self, iface) if network.NodeNetwork().is_configured(): txt = "Network Configuration detected an already configured " txt += "NIC. The configuration for that NIC is " txt += "going to be removed if changes are made. Proceed?" self._confirm_dialog = ui.ConfirmationDialog("dialog.confirm", "Confirm Network " "Settings", txt, ) return self._confirm_dialog else: return self._nic_dialog if "dialog.confirm.yes" in changes: self._confirm_dialog.close() return self._nic_dialog if "dialog.nic.close" in changes: self._nic_dialog.close() return if "button.toggle_bond" in changes: m_bond = defaults.NicBonding() mnet = defaults.Network() if m_bond.retrieve()["slaves"]: if mnet.retrieve()["iface"] == m_bond.retrieve()["name"]: # Remove network config if primary devce was this # bond mnet.configure_no_networking() m_bond.configure_no_bond() txs += m_bond.transaction() txs += mnet.transaction() else: self._bond_dialog = CreateBondDialog("dialog.bond") self.widgets.add(self._bond_dialog) return self._bond_dialog if "button.ping" in changes: self.logger.debug("Opening ping page") self.application.switch_to_plugin( ping.Plugin) return if "dialog.nic.identify" in changes: ifname = self._model_extra["dialog.nic.ifname"] nic = utils.network.NodeNetwork().build_nic_model(ifname) nic.identify() self.application.notice("Flashing lights of '%s'" % nic.ifname) return nameservers = [] dns_keys = ["dns[0]", "dns[1]"] if effective_changes.contains_any(dns_keys): nameservers += effective_model.values_for(dns_keys) if nameservers: self.logger.info("Setting new nameservers: %s" % nameservers) model = defaults.Nameservers() model.update(nameservers) txs += model.transaction() timeservers = [] ntp_keys = ["ntp[0]", "ntp[1]"] if effective_changes.contains_any(ntp_keys): timeservers += effective_model.values_for(ntp_keys) if timeservers: self.logger.info("Setting new timeservers: %s" % timeservers) model = defaults.Timeservers() model.update(timeservers) txs += model.transaction() hostname_keys = ["hostname"] if effective_changes.contains_any(hostname_keys): value = effective_model.values_for(hostname_keys) self.logger.info("Setting new hostname: %s" % value) model = defaults.Hostname() model.update(*value) txs += model.transaction() # For the NIC details dialog: if effective_changes.contains_any(self._nic_details_group): # If any networking related key was changed, reconfigure networking # Fetch the values for the nic keys, they are used as arguments args = effective_model.values_for(self._nic_details_group) txs += self._configure_nic(*args) if effective_changes.contains_any(self._bond_group): mb = defaults.NicBonding() mnet = defaults.Network() args = effective_model.values_for(["bond.name", "bond.slaves.selected", "bond.options"]) self.logger.debug("args: %s" % args) if effective_model["bond.name"] and \ effective_model["bond.slaves.selected"]: mb.update(*args) txs += mb.transaction() txs += mnet.transaction() self._bond_dialog.close() progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run() if "dialog.nic.save" in changes: # Close the remaing details dialog self._nic_dialog.close() # Behaves like a page reload return self.ui_content()
def on_merge(self, effective_changes): def close_dialog(): if self._dialog: self._dialog.close() self._dialog = None self._install_ready = False self._invalid_download = False self.temp_cfg_file = False effective_changes = Changeset(effective_changes) changes = Changeset(self.pending_changes(False)) effective_model = Changeset(self.model()) effective_model.update(effective_changes) self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) if "button.dialog" in effective_changes: self._dialog = DeployDialog("Deploy Hosted Engine", self) self.widgets.add(self._dialog) return self._dialog if "button.status" in effective_changes: try: contents = utils.process.check_output( ["hosted-engine", "--vm-status"], stderr=utils.process.STDOUT ) except utils.process.CalledProcessError: contents = "\nFailed to collect hosted engine vm status, " \ "check ovirt-ha-broker logs." self.application.show(self.ui_content()) return ui.TextViewDialog("output.dialog", "Hosted Engine VM " "Status", contents) if "button.maintenance" in effective_changes: self._dialog = MaintenanceDialog("Hosted Engine Maintenance", self) self.widgets.add(self._dialog) return self._dialog if "maintenance.confirm" in effective_changes: close_dialog() if "maintenance.level" in effective_changes: level = effective_changes["maintenance.level"] try: utils.process.check_call(["hosted-engine", "--set-maintenance", "--mode=%s" % level]) except: self.logger.exception("Couldn't set maintenance level " "to %s" % level, exc_info=True) return ui.InfoDialog("dialog.error", "An error occurred", "Couldn't set maintenance level to " "%s. Check the logs" % level) if "deploy.additional" in effective_changes: close_dialog() def run_additional(*args): with self.application.ui.suspended(): try: utils.process.call( "reset; screen hosted-engine --deploy", shell=True) sys.stdout.write("Press <Return> to return to the TUI") console.wait_for_keypress() self.__persist_configs() except: self.logger.exception("hosted-engine failed to " "deploy!", exc_info=True) txt = ("Please set a password on the RHEV-M page of a host " "which has previously deployed hosted engine before " "continuing. This is required to retrieve the setup " "answer file") dialog = ui.ConfirmationDialog("dialog.add", "Prepare remote host", txt) yes_btn, cncl_btn = dialog.buttons yes_btn.label("Proceed") yes_btn.on_activate.connect(run_additional) return dialog if effective_changes.contains_any(["deploy.confirm"]): close_dialog() def make_tempfile(): if not os.path.exists(config.HOSTED_ENGINE_SETUP_DIR): os.makedirs(config.HOSTED_ENGINE_SETUP_DIR) if not os.path.exists(config.HOSTED_ENGINE_TEMPDIR): os.makedirs(config.HOSTED_ENGINE_TEMPDIR) temp_fd, temp_cfg_file = tempfile.mkstemp() os.close(temp_fd) return temp_cfg_file imagepath = effective_model["hosted_engine.diskpath"] pxe = effective_model["hosted_engine.pxe"] localpath = None # FIXME: dynamically enable the fields so we can't get into # this kind of situation. Selection should be ui.Options, not # a checkbox and a blank entry field # # Check whether we have unclear conditions if not imagepath and not pxe: self._model['display_message'] = "\n\nYou must enter a URL" \ " or choose PXE to install the Engine VM" return self.show_dialog() elif imagepath and pxe: self._model['display_message'] = "\n\nPlease choose either " \ "PXE or an image to " \ "retrieve, not both" return self.show_dialog() self.temp_cfg_file = make_tempfile() engine_keys = ["hosted_engine.diskpath", "hosted_engine.pxe"] txs = utils.Transaction("Setting up hosted engine") # FIXME: The "None" is for force_enable # Why are we setting force_enable? It clutters the code. We should # move force enabling it to checking for --dry instead model = HostedEngine() args = tuple(effective_model.values_for(engine_keys)) + (None,) model.update(*args) if "file://" in imagepath: localpath = imagepath[7:] elif imagepath: localpath = os.path.join(config.HOSTED_ENGINE_SETUP_DIR, os.path.basename(imagepath)) # Check whether we have enough conditions to run it right now if pxe or os.path.exists(localpath): def console_wait(event): event.wait() self._install_ready = True self.show_dialog() txs += model.transaction(self.temp_cfg_file) progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) t = threading.Thread(target=console_wait, args=(progress_dialog.event,)) t.start() progress_dialog.run() # The application doesn't wait until the progressdialog is # done, and it ends up being called asynchronously. Calling # in a thread and waiting to set threading.Event # time.sleep(5) # Otherwise start an async download else: path_parsed = urlparse(imagepath) if not path_parsed.scheme: self._model['display_message'] = ("\nCouldn't parse " "URL. please check " "it manually.") elif path_parsed.scheme == 'http' or \ path_parsed.scheme == 'https': self._show_progressbar = True self.application.show(self.ui_content()) self._image_retrieve(imagepath, config.HOSTED_ENGINE_SETUP_DIR) return self.ui_content()