def model(self): model = { "hostname": "", "dns[0]": "", "dns[1]": "", "ntp[0]": "", "ntp[1]": "", "bond.name": "", "bond.slaves.selected": "", "bond.options": "mode=balance-rr miimon=100" } model["hostname"] = defaults.Hostname().retrieve()["hostname"] or \ network.hostname() # Pull name-/timeservers from config files (not defaults) nameservers = config.network.nameservers() if nameservers: for idx, nameserver in enumerate(nameservers): model["dns[%d]" % idx] = nameserver timeservers = config.network.timeservers() if timeservers: for idx, timeserver in enumerate(timeservers): model["ntp[%d]" % idx] = timeserver model.update(self._model_extra) return model
def model(self): model = { "hostname": "", "dns[0]": "", "dns[1]": "", "ntp[0]": "", "ntp[1]": "", } model["hostname"] = defaults.Hostname().retrieve()["hostname"] or \ network.hostname() # Pull name-/timeservers from config files (not defaults) nameservers = config.network.nameservers() if nameservers: for idx, nameserver in enumerate(nameservers): model["dns[%d]" % idx] = nameserver timeservers = config.network.timeservers() if timeservers: for idx, timeserver in enumerate(timeservers): model["ntp[%d]" % idx] = timeserver model.update(self._model_extra) return model
def model(self): #cfg = defaults.Collectd().retrieve() #fn = "/home/mujun/ovirt_config/20141230183208-setup.conf" #cfgfile = ConfigFile(fn) #cfg = defaults.Hostname(cfgfile).retrieve() cfg = defaults.Hostname().retrieve() model = { "collectd.ip": cfg['ip'] or '', "collectd.hostname": cfg['hostname'] or '', } return model
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.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.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()