[node-patches] Change in ovirt-node[master]: move snmp page to a plugin

jboggs at redhat.com jboggs at redhat.com
Wed Sep 5 20:37:35 UTC 2012


Joey Boggs has uploaded a new change for review.

Change subject: move snmp page to a plugin
......................................................................

move snmp page to a plugin

This moves the snmp page out into a separate plugin to eventually help in saving some
space as well as providing an example plugin for edit-node in the future. core snmp
packages are still there and will be removed in the next revision, this only hides the
page within the setup for now unless ovirt-node-plugin-snmp is installed

Change-Id: Id5c4930b7dbd9ce718f706337a2f6a93f58d1922
Signed-off-by: Joey Boggs <jboggs at redhat.com>
---
M ovirt-node.spec.in
M scripts/Makefile.am
M scripts/ovirt-config-setup.py
A scripts/ovirt_config_setup/snmp.py
D scripts/ovirtnode/snmp.py
5 files changed, 165 insertions(+), 134 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/82/7782/1

diff --git a/ovirt-node.spec.in b/ovirt-node.spec.in
index 3345a81..b3b8dd5 100644
--- a/ovirt-node.spec.in
+++ b/ovirt-node.spec.in
@@ -103,6 +103,14 @@
 This package is not to be installed on the %{product_family},
 however on a development machine to work with the image.
 
+%package plugin-snmp
+Summary:        SNMP plugin for %{product_family} image
+Group:          Applications/System
+
+%define snmp_root %{_datadir}/%{name}
+
+%description plugin-snmp
+This package provides an snmp plugin tools for use with%{product_family} image.
 
 %prep
 %setup -q
@@ -230,6 +238,8 @@
 %{_sbindir}/edit-node
 %{_mandir}/man8/edit-node.8.gz
 
+%files plugin-snmp
+%{python_sitelib}/ovirt_config_setup/snmp.py
 
 %files
 %defattr(-,root,root)
@@ -289,6 +299,7 @@
 %{_sbindir}/persist
 %{_sbindir}/unpersist
 %{python_sitelib}/ovirt_config_setup
+%exclude %{python_sitelib}/ovirt_config_setup/snmp.py*
 %{python_sitelib}/ovirtnode
 %{python_sitelib}/augeas*
 %{_sysconfdir}/ovirt-early.d
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 341379f..0c88bbd 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -69,7 +69,8 @@
 pyovirtconfigsetup_PYTHON = \
   ovirt_config_setup/__init__.py \
   ovirt_config_setup/cim.py \
-  ovirt_config_setup/plugins.py
+  ovirt_config_setup/plugins.py \
+  ovirt_config_setup/snmp.py
 
 if TARGET_FEDORA
 pyovirtconfigsetup_PYTHON += \
@@ -96,7 +97,6 @@
   ovirtnode/network.py \
   ovirtnode/ovirtfunctions.py \
   ovirtnode/password.py \
-  ovirtnode/snmp.py \
   ovirtnode/storage.py
 
 EXTRA_DIST = \
diff --git a/scripts/ovirt-config-setup.py b/scripts/ovirt-config-setup.py
index 017e5bf..cc49914 100755
--- a/scripts/ovirt-config-setup.py
+++ b/scripts/ovirt-config-setup.py
@@ -35,7 +35,6 @@
 from ovirtnode.network import *
 from ovirtnode.kdump import *
 from ovirtnode.iscsi import *
-from ovirtnode.snmp import *
 
 OK_BUTTON = "OK"
 BACK_BUTTON = "Back"
@@ -55,12 +54,11 @@
 NETWORK_PAGE = 2
 AUTHENTICATION_PAGE = 3
 KEYBOARD_PAGE = 4
-SNMP_PAGE = 5
-LOGGING_PAGE = 6
-KDUMP_PAGE = 7
-LAST_OPTION = REMOTE_STORAGE_PAGE = 8
+LOGGING_PAGE = 5
+KDUMP_PAGE = 6
+LAST_OPTION = REMOTE_STORAGE_PAGE = 7
 # max. 3 plugin menu options/pages: 13,15,17
-FIRST_PLUGIN_PAGE = 9
+FIRST_PLUGIN_PAGE = 8
 LAST_PLUGIN_PAGE = 13
 #
 NETWORK_DETAILS_PAGE = 19
@@ -238,8 +236,6 @@
             return self.authentication_configuration_page(screen)
         if page == KEYBOARD_PAGE:
             return self.keyboard_configuration_page(screen)
-        if page == SNMP_PAGE:
-            return self.snmp_configuration_page(screen)
         if page == LOGGING_PAGE:
             return self.logging_configuration_page(screen)
         if page == KDUMP_PAGE:
@@ -1285,41 +1281,6 @@
         return [Label(""),
                 grid]
 
-    def snmp_configuration_page(self, screen):
-        elements = Grid(2, 9)
-        heading = Label("SNMP")
-        if is_console():
-            heading.setColors(customColorset(1))
-        elements.setField(heading, 0, 0, anchorLeft=1)
-        pw_elements = Grid(3, 3)
-        self.current_snmp_status = 0
-        if os.path.exists("/etc/snmp/snmpd.conf"):
-            f = open("/etc/snmp/snmpd.conf")
-            for line in f:
-                if "createUser" in line:
-                    self.current_snmp_status = 1
-            f.close()
-        self.snmp_status = Checkbox("Enable SNMP",
-                                    isOn=self.current_snmp_status)
-        elements.setField(self.snmp_status, 0, 1, anchorLeft=1)
-        local_heading = Label("SNMP Password")
-        if is_console():
-            local_heading.setColors(customColorset(1))
-        elements.setField(local_heading, 0, 3, anchorLeft=1,
-                          padding=(0, 2, 0, 0))
-        elements.setField(Label(" "), 0, 6)
-        pw_elements.setField(Label("Password: "), 0, 1, anchorLeft=1)
-        pw_elements.setField(Label("Confirm Password: "), 0, 2, anchorLeft=1)
-        self.root_password_1 = Entry(15, password=1)
-        self.root_password_1.setCallback(self.password_check_callback)
-        self.root_password_2 = Entry(15, password=1)
-        self.root_password_2.setCallback(self.password_check_callback)
-        pw_elements.setField(self.root_password_1, 1, 1)
-        pw_elements.setField(self.root_password_2, 1, 2)
-        self.pw_msg = Textbox(60, 6, "", wrap=1)
-        elements.setField(pw_elements, 0, 7, anchorLeft=1)
-        elements.setField(self.pw_msg, 0, 8, padding=(0, 1, 0, 0))
-        return [Label(""), elements]
 
     def keyboard_configuration_page(self, screen):
         # placeholder for system-config-keyboard-base, will remove move later
@@ -1805,8 +1766,6 @@
             ret = self.process_nic_config()
         if self.__current_page == KEYBOARD_PAGE:
             ret = self.process_keyboard_config()
-        if self.__current_page == SNMP_PAGE:
-            ret = self.process_snmp_config()
         if self.__current_page == KDUMP_PAGE:
             ret = self.process_kdump_config()
         if self.__current_page == REMOTE_STORAGE_PAGE:
@@ -1824,28 +1783,6 @@
                 # should not happen
                 break
         return
-
-    def process_snmp_config(self):
-        if self.snmp_status.value() == 1:
-            if len(self.root_password_1.value()) > 0:
-                if (self.root_password_1.value() != "" or
-                    self.root_password_2.value() != ""):
-                    if (self.root_password_1.value() !=
-                        self.root_password_2.value()):
-                        self._create_warn_screen()
-                        ButtonChoiceWindow(self.screen, "SNMP", "SNMP was " +
-                                           "not enabled because passwords " +
-                                           "do not match", buttons=['Ok'])
-                        return
-                enable_snmpd(self.root_password_1.value())
-            else:
-                self._create_warn_screen()
-                ButtonChoiceWindow(self.screen, "SNMP Error",
-                              "Unable to configure SNMP without a password!",
-                              buttons=['Ok'])
-                self.reset_screen_colors()
-        elif self.snmp_status.value() == 0:
-            disable_snmpd()
 
     def process_kdump_config(self):
         if self.kdump_nfs_type.value() == 1:
@@ -1926,7 +1863,6 @@
             self.menu_list.append(" Network", 2)
             self.menu_list.append(" Security", 3)
             self.menu_list.append(" Keyboard", 4)
-            self.menu_list.append(" SNMP", 5)
             self.menu_list.append(" Logging", 6)
             self.menu_list.append(" Kernel Dump", 7)
             self.menu_list.append(" Remote Storage", 8)
diff --git a/scripts/ovirt_config_setup/snmp.py b/scripts/ovirt_config_setup/snmp.py
new file mode 100755
index 0000000..e4ba28e
--- /dev/null
+++ b/scripts/ovirt_config_setup/snmp.py
@@ -0,0 +1,148 @@
+# snmp.py - Copyright (C) 2012 Red Hat, Inc.
+# Written by Joey Boggs <jboggs at redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# 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.
+
+import ovirtnode.ovirtfunctions as _functions
+from ovirtnode.ovirtfunctions import PluginBase
+import os
+from subprocess import Popen, PIPE, STDOUT
+from snack import *
+import subprocess
+
+snmp_conf = "/etc/snmp/snmpd.conf"
+
+
+def enable_snmpd(password):
+    _functions.system("service snmpd stop")
+    # get old password #
+    if os.path.exists("/tmp/snmpd.conf"):
+        conf = "/tmp/snmpd.conf"
+    else:
+        conf = snmp_conf
+    cmd = "cat %s|grep createUser|awk '{print $4}'" % conf
+    oldpwd = _functions.subprocess_closefds(cmd, shell=True,
+                                            stdout=subprocess.PIPE,
+                                            stderr=subprocess.STDOUT)
+    oldpwd = oldpwd.stdout.read().strip()
+    _functions.system("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)
+    f.close()
+    _functions.system("service snmpd start")
+    # change existing password
+    if len(oldpwd) > 0:
+        pwd_change_cmd = ("snmpusm -v 3 -u root -n \"\" -l authNoPriv -a " +
+        "SHA -A %s localhost passwd %s %s -x AES") % (oldpwd, oldpwd, password)
+        if _functions.system(pwd_change_cmd):
+            _functions.system("rm -rf /tmp/snmpd.conf")
+    _functions.ovirt_store_config(snmp_conf)
+
+
+def disable_snmpd():
+    _functions.system("service snmpd stop")
+    # copy to /tmp for enable/disable toggles w/o reboot
+    _functions.system("cp /etc/snmp/snmpd.conf /tmp")
+    _functions.system("sed -c -ie '/^createUser root/d' %s" % snmp_conf)
+    _functions.remove_config(snmp_conf)
+
+
+class Plugin(PluginBase):
+    """Plugin for SNMP Configuration
+    """
+
+    def __init__(self, ncs):
+        PluginBase.__init__(self, "SNMP", ncs)
+
+    def password_check_callback(self):
+        resp, msg = _functions.password_check(self.root_password_1.value(),
+                                              self.root_password_2.value())
+        if len(self.root_password_1.value()) < 8:
+            self.root_password_1.set("")
+            msg = "Password must be at least 8 characters"
+        if len(self.root_password_2.value()) < 8:
+            self.root_password_2.set("")
+            msg = "Password must be at least 8 characters"
+        self.pw_msg.setText(msg)
+        return
+
+    def form(self):
+        elements = Grid(2, 9)
+        heading = Label("SNMP")
+        if _functions.is_console():
+            heading.setColors(customColorset(1))
+        elements.setField(heading, 0, 0, anchorLeft=1)
+        pw_elements = Grid(3, 3)
+        self.current_snmp_status = 0
+        if os.path.exists("/etc/snmp/snmpd.conf"):
+            f = open("/etc/snmp/snmpd.conf")
+            for line in f:
+                if "createUser" in line:
+                    self.current_snmp_status = 1
+            f.close()
+        self.snmp_status = Checkbox("Enable SNMP",
+                                    isOn=self.current_snmp_status)
+        elements.setField(self.snmp_status, 0, 1, anchorLeft=1)
+
+        local_heading = Label("SNMP Password")
+        if _functions.is_console():
+            local_heading.setColors(customColorset(1))
+        elements.setField(local_heading, 0, 3, anchorLeft=1,
+                          padding=(0, 2, 0, 0))
+        elements.setField(Label(" "), 0, 6)
+        pw_elements.setField(Label("Password: "), 0, 1, anchorLeft=1)
+        pw_elements.setField(Label("Confirm Password: "), 0, 2, anchorLeft=1)
+        self.root_password_1 = Entry(15, password=1)
+        self.root_password_1.setCallback(self.password_check_callback)
+        self.root_password_2 = Entry(15, password=1)
+        self.root_password_2.setCallback(self.password_check_callback)
+        pw_elements.setField(self.root_password_1, 1, 1)
+        pw_elements.setField(self.root_password_2, 1, 2)
+        self.pw_msg = Textbox(60, 6, "", wrap=1)
+        elements.setField(pw_elements, 0, 7, anchorLeft=1)
+        elements.setField(self.pw_msg, 0, 8, padding=(0, 1, 0, 0))
+        return [Label(""), elements]
+
+    def action(self):
+        if self.snmp_status.value() == 1:
+            if len(self.root_password_1.value()) > 0:
+                if (self.root_password_1.value() != "" or
+                    self.root_password_2.value() != ""):
+                    if (self.root_password_1.value() !=
+                        self.root_password_2.value()):
+                        self.ncs._create_warn_screen()
+                        ButtonChoiceWindow(self.ncs.screen, "SNMP", "SNMP was " +
+                                           "not enabled because passwords " +
+                                           "do not match", buttons=['Ok'])
+                        return
+                enable_snmpd(self.root_password_1.value())
+            else:
+                self.ncs._create_warn_screen()
+                ButtonChoiceWindow(self.ncs.screen, "SNMP Error",
+                              "Unable to configure SNMP without a password!",
+                              buttons=['Ok'])
+                self.ncs.reset_screen_colors()
+        elif self.snmp_status.value() == 0:
+            disable_snmpd()
+
+def snmp_auto():
+    if "OVIRT_SNMP_PASSWORD" in _functions.OVIRT_VARS:
+        enable_snmpd(_functions.OVIRT_VARS["OVIRT_SNMP_PASSWORD"])
+
+
+def get_plugin(ncs):
+    return Plugin(ncs)
diff --git a/scripts/ovirtnode/snmp.py b/scripts/ovirtnode/snmp.py
deleted file mode 100755
index a447f91..0000000
--- a/scripts/ovirtnode/snmp.py
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/usr/bin/python
-# snmp.py - Copyright (C) 2012 Red Hat, Inc.
-# Written by Joey Boggs <jboggs at redhat.com>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 2 of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# 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.
-
-import ovirtnode.ovirtfunctions as _functions
-import os
-import subprocess
-
-snmp_conf = "/etc/snmp/snmpd.conf"
-
-
-def enable_snmpd(password):
-    _functions.system("service snmpd stop")
-    # get old password #
-    if os.path.exists("/tmp/snmpd.conf"):
-        conf = "/tmp/snmpd.conf"
-    else:
-        conf = snmp_conf
-    cmd = "cat %s|grep createUser|awk '{print $4}'" % conf
-    oldpwd = _functions.subprocess_closefds(cmd, shell=True,
-                                            stdout=subprocess.PIPE,
-                                            stderr=subprocess.STDOUT)
-    oldpwd = oldpwd.stdout.read().strip()
-    _functions.system("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)
-    f.close()
-    _functions.system("service snmpd start")
-    # change existing password
-    if len(oldpwd) > 0:
-        pwd_change_cmd = ("snmpusm -v 3 -u root -n \"\" -l authNoPriv -a " +
-        "SHA -A %s localhost passwd %s %s -x AES") % (oldpwd, oldpwd, password)
-        if _functions.system(pwd_change_cmd):
-            _functions.system("rm -rf /tmp/snmpd.conf")
-    _functions.ovirt_store_config(snmp_conf)
-
-
-def disable_snmpd():
-    _functions.system("service snmpd stop")
-    # copy to /tmp for enable/disable toggles w/o reboot
-    _functions.system("cp /etc/snmp/snmpd.conf /tmp")
-    _functions.system("sed -c -ie '/^createUser root/d' %s" % snmp_conf)
-    _functions.remove_config(snmp_conf)
-
-
-def snmp_auto():
-    if "OVIRT_SNMP_PASSWORD" in _functions.OVIRT_VARS:
-        enable_snmpd(_functions.OVIRT_VARS["OVIRT_SNMP_PASSWORD"])


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id5c4930b7dbd9ce718f706337a2f6a93f58d1922
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Joey Boggs <jboggs at redhat.com>



More information about the node-patches mailing list