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 model(self):
     cfg = snmp_model.SNMP().retrieve()
     self.logger.debug(cfg)
     model = {"snmp.enabled": cfg["enabled"] or False,
              "snmp.password": "",
              }
     return model
Exemplo n.º 3
0
 def model(self):
     cfg = snmp_model.SNMP().retrieve()
     self.logger.debug(cfg)
     model = {
         "snmp.enabled": True if cfg["password"] else False,
         "snmp.password": "",
         "snmp.password_confirmation": "",
     }
     return model
Exemplo n.º 4
0
    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()