[node-patches] Change in ovirt-node[master]: Similar as CIM, using "OVIRT_SNMP_ENABLED" instead of "OVIRT...

hadong0720 at gmail.com hadong0720 at gmail.com
Tue Jul 16 11:23:54 UTC 2013


hadong has uploaded a new change for review.

Change subject: Similar as CIM, using "OVIRT_SNMP_ENABLED" instead of "OVIRT_SNMP_PASSWORD" for SNMP to save in /etc/default/ovirt
......................................................................

Similar as CIM, using "OVIRT_SNMP_ENABLED" instead of
"OVIRT_SNMP_PASSWORD" for SNMP to save in /etc/default/ovirt

Change-Id: I534d8beb371c94aace17ead025a196dd50ae6214
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=984917
Signed-off-by: hadong <hadong0720 at gmail.com>
---
M src/ovirt/node/setup/snmp/snmp_model.py
M src/ovirt/node/setup/snmp/snmp_page.py
2 files changed, 37 insertions(+), 31 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/15/16915/1

diff --git a/src/ovirt/node/setup/snmp/snmp_model.py b/src/ovirt/node/setup/snmp/snmp_model.py
index 032997c..c64e850 100644
--- a/src/ovirt/node/setup/snmp/snmp_model.py
+++ b/src/ovirt/node/setup/snmp/snmp_model.py
@@ -38,9 +38,9 @@
     else:
         conf = snmp_conf
     cmd = "cat %s|grep createUser|awk '{print $4}'" % conf
-    oldpwd, stderr = process.pipe(cmd, shell=True)
+    oldpwd, stderr = process.pipe(cmd)
     oldpwd = oldpwd.stdout.read().strip()
-    process.call("sed -c -ie '/^createUser root/d' %s" % snmp_conf, shell=True)
+    process.call("sed -c -ie '/^createUser root/d' %s" % snmp_conf)
     f = open(snmp_conf, "a")
     # create user account
     f.write("createUser root SHA %s AES\n" % password)
@@ -51,9 +51,9 @@
         pwd_change_cmd = (("snmpusm -v 3 -u root -n \"\" -l authNoPriv -a " +
                            "SHA -A %s localhost passwd %s %s -x AES") %
                           (oldpwd, oldpwd, password))
-        process.check_call(pwd_change_cmd, shell=True)
+        process.check_call(pwd_change_cmd)
         # Only reached when no excepion occurs
-        process.call(["rm", "-rf", "/tmp/snmpd.conf"])
+        process.call("rm -rf /tmp/snmpd.conf")
     ovirt_store_config(snmp_conf)
 
 
@@ -62,9 +62,8 @@
 
     system.service("snmpd", "stop")
     # copy to /tmp for enable/disable toggles w/o reboot
-    process.check_call(["cp", "/etc/snmp/snmpd.conf", "/tmp"])
-    process.check_call("sed -c -ie '/^createUser root/d' %s" % snmp_conf,
-                       shell=True)
+    process.check_call("cp /etc/snmp/snmpd.conf /tmp")
+    process.check_call("sed -c -ie '/^createUser root/d' %s" % snmp_conf)
     remove_config(snmp_conf)
 
 
@@ -73,34 +72,42 @@
 
     >>> from ovirt.node.utils import fs
     >>> n = SNMP(fs.FakeFs.File("dst"))
-    >>> n.update("secret")
-    >>> n.retrieve().items()
-    [('password', 'secret')]
+    >>> n.update(True)
+    >>> n.retrieve()
+    {'enabled': True}
     """
-    keys = ("OVIRT_SNMP_PASSWORD",)
+    keys = ("OVIRT_SNMP_ENABLED",)
 
     @NodeConfigFileSection.map_and_update_defaults_decorator
-    def update(self, password):
-        # FIXME add validation
-        pass
+    def update(self, enabled):
+        return {"OVIRT_SNMP_ENABLED":
+                "1" if utils.parse_bool(enabled) else None}
 
-    def transaction(self):
-        cfg = dict(self.retrieve())
-        password = cfg["password"]
+    def retrieve(self):
+        cfg = dict(NodeConfigFileSection.retrieve(self))
+        cfg.update({"enabled":
+                    True if cfg["enabled"] == "1" else None})
+        return cfg
+
+    def transaction(self, snmp_password):
+        cfg = self.retrieve()
+        enabled = cfg["enabled"]
+
+        tx = utils.Transaction("Configuring SNMP")
 
         class ConfigureSNMP(utils.Transaction.Element):
-            title = "Enabling/Disabling SNMP and setting the password"
+            state = ("Enabling" if enabled else "Disabling")
+            title = "%s SNMP and setting the password" % state
 
             def commit(self):
                 # FIXME snmp plugin needs to be placed somewhere else (in src)
                 # pylint: disable-msg=E0611
                 from ovirt_config_setup import snmp  # @UnresolvedImport
                 # pylint: enable-msg=E0611
-                if password:
-                    snmp.enable_snmpd(password)
+                if enabled and snmp_password:
+                    snmp.enable_snmpd(snmp_password)
                 else:
                     snmp.disable_snmpd()
 
-        tx = utils.Transaction("Configuring SNMP")
         tx.append(ConfigureSNMP())
         return tx
diff --git a/src/ovirt/node/setup/snmp/snmp_page.py b/src/ovirt/node/setup/snmp/snmp_page.py
index fd8ecbd..d1e1c34 100644
--- a/src/ovirt/node/setup/snmp/snmp_page.py
+++ b/src/ovirt/node/setup/snmp/snmp_page.py
@@ -66,14 +66,13 @@
     def model(self):
         cfg = snmp_model.SNMP().retrieve()
         self.logger.debug(cfg)
-        model = {"snmp.enabled": True if cfg["password"] else False,
+        model = {"snmp.enabled": cfg["enabled"] or False,
                  "snmp.password": "",
                  }
-        model.update(self._model)
         return model
 
     def validators(self):
-        return {"snmp.password": valid.Text()
+        return {"snmp.password": SnmpPassword()
                 }
 
     def ui_content(self):
@@ -101,18 +100,18 @@
         self.logger.debug("Changes: %s" % changes)
         self.logger.debug("Effective Model: %s" % effective_model)
 
-        snmp_keys = ["snmp.password_confirmation", "snmp.enabled"]
+        snmp_keys = ["snmp.password", "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
+            is_enabled = effective_model["snmp.enabled"]
+            pw = effective_model["snmp.password"]
+
             model = snmp_model.SNMP()
-            model.update(*args)
-            txs += model.transaction()
+            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()


-- 
To view, visit http://gerrit.ovirt.org/16915
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I534d8beb371c94aace17ead025a196dd50ae6214
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: hadong <hadong0720 at gmail.com>



More information about the node-patches mailing list