[node-patches] Change in ovirt-node[master]: abstract "/etc/sysconfig/network-scripts" to a path const va...

boh.ricky at gmail.com boh.ricky at gmail.com
Mon Oct 21 16:00:43 UTC 2013


hai bo has uploaded a new change for review.

Change subject: abstract "/etc/sysconfig/network-scripts" to a path const value.
......................................................................

abstract "/etc/sysconfig/network-scripts" to a path const value.

On some platform, the network configuration's path  is different from
fedora platform. Easy to port to another platform, it's better
to abstract "/etc/sysconfig/network-scripts" to a path const value.

Change-Id: I4304f5eabcc1f8b547cdb076b836607a6009468f
Signed-off-by: boh.ricky <boh.ricky at gmail.com>
---
M src/ovirt/node/config/defaults.py
M src/ovirt/node/config/network.py
A src/ovirt/node/utils/const.py
M src/ovirtnode/network.py
M src/ovirtnode/ovirtfunctions.py
5 files changed, 44 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/69/20369/1

diff --git a/src/ovirt/node/config/defaults.py b/src/ovirt/node/config/defaults.py
index 26afabe..bdeb8b2 100644
--- a/src/ovirt/node/config/defaults.py
+++ b/src/ovirt/node/config/defaults.py
@@ -24,6 +24,7 @@
 from ovirt.node.utils import storage, process, fs, AugeasWrapper, console, \
     system
 from ovirt.node.utils.fs import ShellVarFile, File
+from ovirt.node.utils.const import NetworkConst
 from ovirt.node.utils.network import NIC, Bridges, Bonds
 import glob
 import os
@@ -812,7 +813,8 @@
 
             def commit(self):
                 # Set or remove PEERDNS for all ifcfg-*
-                for nic in glob.glob("/etc/sysconfig/network-scripts/ifcfg-*"):
+                for nic in glob.glob("%s/ifcfg-*" %
+                                     NetworkConst.NETWORK_SCRIPTS_PATH):
                     if "ifcfg-lo" in nic:
                         continue
                     path = "/files%s/PEERDNS" % nic
diff --git a/src/ovirt/node/config/network.py b/src/ovirt/node/config/network.py
index a9c329f..4485e66 100644
--- a/src/ovirt/node/config/network.py
+++ b/src/ovirt/node/config/network.py
@@ -21,6 +21,7 @@
 from ovirt.node import utils, base, log
 from ovirt.node.utils import AugeasWrapper as Augeas, fs, is_fileobj
 from ovirt.node.utils.fs import ShellVarFile
+from ovirt.node.utils.const import NetworkConst
 import glob
 import os
 
@@ -112,7 +113,7 @@
         return NicConfig._backend_type.list()
 
     class IfcfgBackend(ShellVarFile):
-        filename_tpl = "/etc/sysconfig/network-scripts/ifcfg-%s"
+        filename_tpl = "%s/ifcfg-%s" % NetworkConst.NETWORK_SCRIPTS_PATH
         filename = None
 
         def __init__(self, cfg, ifname):
@@ -265,7 +266,7 @@
     """Returns all configured ifaces
     """
     ifaces = []
-    filepath = "/etc/sysconfig/network-scripts/ifcfg-"
+    filepath = "%s/ifcfg-" % NetworkConst.NETWORK_SCRIPTS_PATH
     for fn in glob.glob("%s*" % filepath):
         iface = fn[len(filepath):]
         ifaces.append(iface)
diff --git a/src/ovirt/node/utils/const.py b/src/ovirt/node/utils/const.py
new file mode 100644
index 0000000..8685196
--- /dev/null
+++ b/src/ovirt/node/utils/const.py
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# const.py - Copyright (C) 2013 Huawei Technologies co.,Ltd.
+# Written by boh.ricky<bohai at huawei.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.
+
+"""
+Some const value related to ovirt-node
+"""
+from ovirt.node import base
+
+
+class NetworkConst(base.Base):
+    """const value related to network
+    """
+    NETWORK_SCRIPTS_PATH = "/etc/sysconfig/network-scripts"
diff --git a/src/ovirtnode/network.py b/src/ovirtnode/network.py
index 82761ed..36278b8 100644
--- a/src/ovirtnode/network.py
+++ b/src/ovirtnode/network.py
@@ -19,6 +19,7 @@
 
 from glob import glob
 from ovirt.node.utils import Transaction
+from ovirt.node.utils.const import NetworkConst
 from ovirtnode.ovirtfunctions import OVIRT_VARS
 from pipes import quote
 import logging
@@ -34,7 +35,7 @@
     def __init__(self):
         OVIRT_VARS = _functions.parse_defaults()
         self.WORKDIR = tempfile.mkdtemp()
-        self.IFSCRIPTS_PATH = "/etc/sysconfig/network-scripts/ifcfg-"
+        self.IFSCRIPTS_PATH = "%s/ifcfg-" % NetworkConst.NETWORK_SCRIPTS_PATH
         self.IFCONFIG_FILE_ROOT = "/files%s" % self.IFSCRIPTS_PATH
         self.NTP_CONFIG_FILE = "/etc/ntp.conf"
         self.NTPSERVERS = ""
@@ -79,7 +80,7 @@
                     mac = line.split()[2]
                     nics[mac.upper()] = nic
         logger.debug(nics)
-        scripts_path = "/etc/sysconfig/network-scripts"
+        scripts_path = NetworkConst.NETWORK_SCRIPTS_PATH
         logger.debug(glob(scripts_path + "/ifcfg-*"))
         for file in glob(scripts_path + "/ifcfg-*"):
             logger.debug("Processing %s" % file)
diff --git a/src/ovirtnode/ovirtfunctions.py b/src/ovirtnode/ovirtfunctions.py
index a81d642..df34938 100644
--- a/src/ovirtnode/ovirtfunctions.py
+++ b/src/ovirtnode/ovirtfunctions.py
@@ -39,6 +39,7 @@
 import pwd
 from ovirt.node.config import defaults
 from ovirt.node.utils import process
+from ovirt.node.utils.const import NetworkConst
 import ovirt.node.utils.system as osystem
 
 OVIRT_CONFIG="/config"
@@ -1636,7 +1637,9 @@
         try:
             dev_interface = device.get_property("INTERFACE")
             dev_address = get_mac_address(dev_interface)
-            bridge_cmd = "/files/etc/sysconfig/network-scripts/ifcfg-%s/BRIDGE" % str(dev_interface)
+            bridge_cmd = "/files%s/ifcfg-%s/BRIDGE" %\
+                         (NetworkConst.NETWORK_SCRIPTS_PATH,
+                          str(dev_interface))
             dev_bridge = augtool_get(bridge_cmd)
         except:
             pass


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4304f5eabcc1f8b547cdb076b836607a6009468f
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: hai bo <boh.ricky at gmail.com>



More information about the node-patches mailing list