Douglas Schilling Landgraf has uploaded a new change for review. Change subject: engine_page: rewrite register ......................................................................
engine_page: rewrite register Remove vdsm-reg dependency Change-Id: I38f3b800c445f8dbb0fa0e89d128cea1e3407798 Signed-off-by: Douglas Schilling Landgraf <[email protected]> --- M src/engine_page.py A src/misc.py A src/network.py 3 files changed, 217 insertions(+), 13 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-node-plugin-vdsm refs/changes/82/17682/1 diff --git a/src/engine_page.py b/src/engine_page.py index f437661..e1f3df0 100644 --- a/src/engine_page.py +++ b/src/engine_page.py @@ -41,6 +41,7 @@ _server = None _port = None _model = None + _newreg = None def __init__(self, app): super(Plugin, self).__init__(app) @@ -60,6 +61,7 @@ "vdsm_cfg.cert": "Verified" if utils.fs.Config().exists(cfg["cert_path"]) else "N/A", "vdsm_cfg.password": "", + "engine.newreg": True, } return model @@ -76,6 +78,7 @@ engine_name=config.engine_name)), ui.Entry("vdsm_cfg.address", "Management Server:"), ui.Entry("vdsm_cfg.port", "Management Server Port:"), + ui.Checkbox("engine.newreg", "Engine version >= 3.2", True), ui.Divider("divider[0]"), ui.SaveButton("action.fetch_cert", "Retrieve Certificate"), ui.KeywordLabel("vdsm_cfg.cert", "Certificate Status: "), @@ -110,6 +113,8 @@ self.logger.debug("Changes: %s" % changes) self.logger.debug("Effective Model: %s" % effective_model) + + self._newreg = effective_model["engine.newreg"] if changes.contains_any(["action.fetch_cert"]): buttons = [ui.Button("action.cert.accept", "Accept"), @@ -336,19 +341,23 @@ cfg = VDSM().retrieve() - # Stopping vdsm-reg may fail but its ok - its in the case when the - # menus are run after installation - self.logger.info("Stopping vdsm-reg service") - deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'stop']) - if write_vdsm_config(cfg["server"], cfg["port"]): - self.logger.info("Starting vdsm-reg service") - deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'start']) + if self._newreg == False: + self.logger.info("VDSM-reg registering..") + # Stopping vdsm-reg may fail but its ok - its in the case when the + # menus are run after installation + self.logger.info("Stopping vdsm-reg service") + deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'stop']) + if write_vdsm_config(cfg["server"], cfg["port"]): + self.logger.info("Starting vdsm-reg service") + deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'start']) - msgConf = "{engine_name} Configuration Successfully " \ - " Updated".format( + msgConf = "{engine_name} Configuration Successfully " \ + " Updated".format( + engine_name=config.engine_name) + self.logger.debug(msgConf) + else: + msgConf = "{engine_name} Configuration Failed".format( engine_name=config.engine_name) - self.logger.debug(msgConf) + raise RuntimeError(msgConf) else: - msgConf = "{engine_name} Configuration Failed".format( - engine_name=config.engine_name) - raise RuntimeError(msgConf) + print "new" diff --git a/src/misc.py b/src/misc.py new file mode 100644 index 0000000..4ab6e28 --- /dev/null +++ b/src/misc.py @@ -0,0 +1,126 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# network.py - Copyright (C) 2013 Red Hat, Inc. +# +# 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 os +import os.path +import platform +import logging +import traceback +import subprocess + +EX_DMIDECODE = '/usr/sbin/dmidecode' +P_VDSM_NODE_ID = '/etc/vdsm/vdsm.id' + +class Misc: + + def isOvirt(): + """ + This function checks if current machine runs ovirt platform. + """ + if os.path.exists('/etc/rhev-hypervisor-release'): + return True + elif not len(glob.glob('/etc/ovirt-node-*-release')) == 0: + return True + else: + return False + + def _logExec(argv, input=None): + """ + This function executes a given shell command while logging it. + """ + out = None + err = None + rc = None + + try: + logging.debug(argv) + stdin = None + if input is not None: + logging.debug(input) + stdin = subprocess.PIPE + p = subprocess.Popen(argv, stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = p.communicate(input) + rc = p.returncode + logging.debug(out) + logging.debug(err) + except: + print traceback.format_exc() + + return (out, err, rc) + + def getMachineUUID(self): + """ + This function parses the DMI data for the host's UUID. If not found, + returns "None". + """ + arch = platform.machine() + if arch == 'x86_64': + out, err, ret = self._logExec([EX_DMIDECODE, "-s", "system-uuid"]) + print "=====" + print out + print err + print ret + print "=====" + out = '\n'.join(line for line in out.splitlines() + if not line.startswith('#')) + + # Avoid error string- 'Not Settable' or 'Not Present' + if ret == 0 and "Not" not in out: + return out.replace("\n", "") + elif arch == "ppc64": + if os.path.exists('/proc/device-tree/system-id'): + #eg. output IBM,03061C14A + return file('/proc/device-tree/system-id').readline().\ + replace(",", "") + + logging.error("getMachineUUID: Could not find machine's UUID.") + + return "None" + + def getHostID(self): + """ + This function concatenate the first serted mac address to the machine's + UUID. + """ + strReturn = "None" + + if os.path.exists(P_VDSM_NODE_ID): + if self.isOvirt(): + ovirtfunctions.ovirt_store_config(P_VDSM_NODE_ID) + strReturn = open(P_VDSM_NODE_ID).readline().replace("\n", "") + else: + strReturn = self.getMachineUUID() + + macs = getMacs() + + if len(macs) > 0: + strMAC = sorted(macs)[0] + else: + strMAC = "" + logging.warning("getHostID: Could not find machine's MAC, returning UUID only.") + + if strReturn != "None": + strReturn += "_" + strMAC + else: + strReturn = "_" + strMAC + + logging.debug("getHostID: " + str(strReturn)) + return strReturn + diff --git a/src/network.py b/src/network.py new file mode 100644 index 0000000..8fa9b76 --- /dev/null +++ b/src/network.py @@ -0,0 +1,69 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# network.py - Copyright (C) 2013 Red Hat, Inc. +# +# 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 socket +import struct +from vdsm import netinfo + +class Network: + + def _getIfaceByIP(self, addr): + remote = struct.unpack('I', socket.inet_aton(addr))[0] + for line in file('/proc/net/route').readlines()[1:]: + iface, dest, gateway, flags, refcnt, use, metric, \ + mask, mtu, window, irtt = line.split() + dest = int(dest, 16) + mask = int(mask, 16) + if remote & mask == dest & mask: + return iface + + return None # Should never get here w/ default gw + + def _getMGTIface(self, vdcHostName): + strVDCIP = "None" + strReturn = None + strVDCName = vdcHostName + + try: + if vdcHostName != "None": + print "_getMGTIface: read host name: " + strVDCName + strVDCIP = socket.gethostbyname(strVDCName) + except: + strVDCIP = "None" + print "_getMGTIface: error trying to figure out IP" + + print "_getMGTIface: using host name " + strVDCName + " strIP= " + strVDCIP + + if strVDCIP != "None": + strReturn = self._getIfaceByIP(strVDCIP) + + print "_getMGTIface IP=" + str(strVDCIP) + " strIface=" + str(strReturn) + + return strReturn + + def getMGTIP(self, vdcHostName): + + strReturn = None + strIface = self._getMGTIface(vdcHostName) + + if strIface is not None: + strReturn = netinfo.getaddr(strIface) + + return strReturn -- To view, visit http://gerrit.ovirt.org/17682 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I38f3b800c445f8dbb0fa0e89d128cea1e3407798 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-node-plugin-vdsm Gerrit-Branch: master Gerrit-Owner: Douglas Schilling Landgraf <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
