def commit(self): try: model = defaults.KDump() if "OVIRT_KDUMP_SSH" in OVIRT_VARS and \ "OVIRT_KDUMP_SSH_KEY" in OVIRT_VARS: model.configure_ssh(OVIRT_VARS["OVIRT_KDUMP_SSH"], OVIRT_VARS["OVIRT_KDUMP_SSH_KEY"]) elif "OVIRT_KDUMP_NFS" in OVIRT_VARS: model.configure_nfs(OVIRT_VARS["OVIRT_KDUMP_NFS"]) elif "OVIRT_DISABLE_KDUMP" in OVIRT_VARS: model.configure_disable() else: model.configure_local() tx = model.transaction() tx() except: kdump_args = [ "OVIRT_KDUMP_SSH", "OVIRT_KDUMP_SSH_KEY", "OVIRT_KDUMP_NFS", "OVIRT_KDUMP_LOCAL" ] logger.warning("Unknown kdump configuration: %s" % " ".join([x for x in kdump_args if x in OVIRT_VARS]))
def commit(self): try: model = defaults.KDump() model.configure_local() tx = model.transaction() tx() except: self.logger.info("Could not configure local kdump!")
def restore_config(self, saved_model): model = defaults.KDump() if saved_model["kdump.type"] == "nfs": model.configure_nfs(saved_model["kdump.nfs_location"]) elif saved_model["kdump.type"] == "kdump.ssh_location": if self.model()["kdump.ssh_key"]: model.configure_ssh(saved_model['kdump.ssh_location'], saved_model['kdump.ssh_key']) else: model.configure_ssh(saved_model['kdump.ssh_location']) elif saved_model["kdump.type"] == "local": model.configure_local() else: model.configure_disable()
def model(self): """Returns the model of this plugin This is expected to parse files and all stuff to build up the model. """ cfg = defaults.KDump().retrieve() ktype = "disabled" for k in ["local", "ssh", "nfs"]: if cfg[k]: ktype = k break model = { # The target address "kdump.type": ktype, "kdump.ssh_location": cfg["ssh"] or "", "kdump.nfs_location": cfg["nfs"] or "", } self.logger.debug(model) return model
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): """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()