# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1242829650 -3600
# Node ID 23f9857f642f0b511553a2b7507a972465cc8930
# Parent 070f456143d3f8c82436a2c774b09e57f848133a
tools: get rid of hardcoded config dirs
Remove *all* hardcoded "/etc/xen" strings in python code.
Additionally, it removes pygrub_path from osdep.py. Its use has been
replaced with auxbin.pathTo("pygrub").
Signed-off-by: Christoph Egger <Christoph.Egger@xxxxxxx>
---
config/StdGNU.mk | 8 ++++++++
config/SunOS.mk | 8 ++++++++
tools/Makefile | 2 ++
tools/Rules.mk | 4 ----
tools/python/Makefile | 2 ++
tools/python/xen/util/auxbin.py | 7 +++++++
tools/python/xen/util/xsm/acm/acm.py | 4 ++--
tools/python/xen/xend/XendConstants.py | 3 ++-
tools/python/xen/xend/XendDomainInfo.py | 6 +++---
tools/python/xen/xend/XendOptions.py | 11 ++++++-----
tools/python/xen/xend/XendPIF.py | 1 +
tools/python/xen/xend/osdep.py | 11 -----------
tools/python/xen/xend/server/blkif.py | 4 ++--
tools/python/xen/xend/server/pciquirk.py | 5 +++--
tools/python/xen/xm/addlabel.py | 4 ++--
tools/python/xen/xm/create.py | 7 +++----
tools/python/xen/xm/getlabel.py | 4 ++--
tools/python/xen/xm/main.py | 3 ++-
tools/python/xen/xm/rmlabel.py | 4 ++--
tools/python/xen/xm/tests/test_create.py | 9 +++++----
20 files changed, 62 insertions(+), 45 deletions(-)
diff -r 070f456143d3 -r 23f9857f642f config/StdGNU.mk
--- a/config/StdGNU.mk Wed May 20 15:13:36 2009 +0100
+++ b/config/StdGNU.mk Wed May 20 15:27:30 2009 +0100
@@ -40,6 +40,14 @@ PRIVATE_PREFIX = $(LIBDIR)/xen
PRIVATE_PREFIX = $(LIBDIR)/xen
PRIVATE_BINDIR = $(PRIVATE_PREFIX)/bin
+ifeq ($(PREFIX),/usr)
+CONFIG_DIR = /etc
+else
+CONFIG_DIR = $(PREFIX)/etc
+endif
+XEN_CONFIG_DIR = $(CONFIG_DIR)/xen
+XEN_SCRIPT_DIR = $(XEN_CONFIG_DIR)/scripts
+
SOCKET_LIBS =
CURSES_LIBS = -lncurses
PTHREAD_LIBS = -lpthread
diff -r 070f456143d3 -r 23f9857f642f config/SunOS.mk
--- a/config/SunOS.mk Wed May 20 15:13:36 2009 +0100
+++ b/config/SunOS.mk Wed May 20 15:27:30 2009 +0100
@@ -34,6 +34,14 @@ PRIVATE_PREFIX = $(LIBDIR)/xen
PRIVATE_PREFIX = $(LIBDIR)/xen
PRIVATE_BINDIR = $(PRIVATE_PREFIX)/bin
+ifeq ($(PREFIX),/usr)
+CONFIG_DIR = /etc
+else
+CONFIG_DIR = $(PREFIX)/etc
+endif
+XEN_CONFIG_DIR = $(CONFIG_DIR)/xen
+XEN_SCRIPT_DIR = $(PRIVATE_PREFIX)/scripts
+
SunOS_LIBDIR = /usr/sfw/lib
SunOS_LIBDIR_x86_64 = /usr/sfw/lib/amd64
diff -r 070f456143d3 -r 23f9857f642f tools/Makefile
--- a/tools/Makefile Wed May 20 15:13:36 2009 +0100
+++ b/tools/Makefile Wed May 20 15:27:30 2009 +0100
@@ -94,7 +94,9 @@ ioemu-dir-find:
set -e; \
$(absolutify_xen_root); \
PREFIX=$(PREFIX); \
+ XEN_SCRIPT_DIR=$(XEN_SCRIPT_DIR); \
export PREFIX; \
+ export XEN_SCRIPT_DIR; \
cd ioemu-dir; \
./xen-setup $(IOEMU_CONFIGURE_CROSS)
diff -r 070f456143d3 -r 23f9857f642f tools/Rules.mk
--- a/tools/Rules.mk Wed May 20 15:13:36 2009 +0100
+++ b/tools/Rules.mk Wed May 20 15:27:30 2009 +0100
@@ -7,10 +7,6 @@ include $(XEN_ROOT)/Config.mk
export _INSTALL := $(INSTALL)
INSTALL = $(XEN_ROOT)/tools/cross-install
-
-CONFIG_DIR = /etc
-XEN_CONFIG_DIR = $(CONFIG_DIR)/xen
-XEN_SCRIPT_DIR = $(XEN_CONFIG_DIR)/scripts
XEN_INCLUDE = $(XEN_ROOT)/tools/include
XEN_XC = $(XEN_ROOT)/tools/python/xen/lowlevel/xc
diff -r 070f456143d3 -r 23f9857f642f tools/python/Makefile
--- a/tools/python/Makefile Wed May 20 15:13:36 2009 +0100
+++ b/tools/python/Makefile Wed May 20 15:27:30 2009 +0100
@@ -23,6 +23,8 @@ genpath:
echo "LIBEXEC=\"$(LIBEXEC)\"" >> ${xenpath}
echo "LIBDIR=\"$(LIBDIR)\"" >> ${xenpath}
echo "PRIVATE_BINDIR=\"$(PRIVATE_BINDIR)\"" >> ${xenpath}
+ echo "XEN_CONFIG_DIR=\"$(XEN_CONFIG_DIR)\"" >> ${xenpath}
+ echo "XEN_SCRIPT_DIR=\"$(XEN_SCRIPT_DIR)\"" >> ${xenpath}
buildpy: genpath
CC="$(CC)" CFLAGS="$(CFLAGS)" $(PYTHON) setup.py build
diff -r 070f456143d3 -r 23f9857f642f tools/python/xen/util/auxbin.py
--- a/tools/python/xen/util/auxbin.py Wed May 20 15:13:36 2009 +0100
+++ b/tools/python/xen/util/auxbin.py Wed May 20 15:27:30 2009 +0100
@@ -20,6 +20,7 @@ import os.path
import os.path
import sys
from xen.util.path import SBINDIR,BINDIR,LIBEXEC,LIBDIR,PRIVATE_BINDIR
+from xen.util.path import XEN_CONFIG_DIR, XEN_SCRIPT_DIR
def execute(exe, args = None):
exepath = pathTo(exe)
@@ -45,3 +46,9 @@ def path():
def libpath():
return LIBDIR
+
+def xen_configdir():
+ return XEN_CONFIG_DIR
+
+def scripts_dir():
+ return XEN_SCRIPT_DIR
diff -r 070f456143d3 -r 23f9857f642f tools/python/xen/util/xsm/acm/acm.py
--- a/tools/python/xen/util/xsm/acm/acm.py Wed May 20 15:13:36 2009 +0100
+++ b/tools/python/xen/util/xsm/acm/acm.py Wed May 20 15:27:30 2009 +0100
@@ -31,11 +31,11 @@ from xen.xend import XendOptions
from xen.xend import XendOptions
from xen.xend.XendLogging import log
from xen.xend.XendError import VmError
-from xen.util import dictio, xsconstants
+from xen.util import dictio, xsconstants, auxbin
from xen.xend.XendConstants import *
#global directories and tools for security management
-install_policy_dir_prefix = "/etc/xen/acm-security/policies"
+install_policy_dir_prefix = auxbin.xen_configdir() + "/acm-security/policies"
security_dir_prefix = XendOptions.instance().get_xend_security_path()
policy_dir_prefix = security_dir_prefix + "/policies"
res_label_filename = policy_dir_prefix + "/resource_labels"
diff -r 070f456143d3 -r 23f9857f642f tools/python/xen/xend/XendConstants.py
--- a/tools/python/xen/xend/XendConstants.py Wed May 20 15:13:36 2009 +0100
+++ b/tools/python/xen/xend/XendConstants.py Wed May 20 15:27:30 2009 +0100
@@ -16,6 +16,7 @@
#============================================================================
from xen.xend.XendAPIConstants import *
+from xen.util import auxbin
#
# Shutdown codes and reasons.
@@ -129,7 +130,7 @@ DEV_MIGRATE_STEP3 = 3
# VTPM-related constants
#
-VTPM_DELETE_SCRIPT = '/etc/xen/scripts/vtpm-delete'
+VTPM_DELETE_SCRIPT = auxbin.scripts_dir() + '/vtpm-delete'
#
# Xenstore Constants
diff -r 070f456143d3 -r 23f9857f642f tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py Wed May 20 15:13:36 2009 +0100
+++ b/tools/python/xen/xend/XendDomainInfo.py Wed May 20 15:27:30 2009 +0100
@@ -34,12 +34,12 @@ from types import StringTypes
from types import StringTypes
import xen.lowlevel.xc
-from xen.util import asserts
+from xen.util import asserts, auxbin
from xen.util.blkif import blkdev_uname_to_file, blkdev_uname_to_taptype
import xen.util.xsm.xsm as security
from xen.util import xsconstants
-from xen.xend import balloon, sxp, uuid, image, arch, osdep
+from xen.xend import balloon, sxp, uuid, image, arch
from xen.xend import XendOptions, XendNode, XendConfig
from xen.xend.XendConfig import scrub_password
@@ -2914,7 +2914,7 @@ class XendDomainInfo:
else:
# Boot using bootloader
if not blexec or blexec == 'pygrub':
- blexec = osdep.pygrub_path
+ blexec = auxbin.pathTo('pygrub')
blcfg = None
disks = [x for x in self.info['vbd_refs']
diff -r 070f456143d3 -r 23f9857f642f tools/python/xen/xend/XendOptions.py
--- a/tools/python/xen/xend/XendOptions.py Wed May 20 15:13:36 2009 +0100
+++ b/tools/python/xen/xend/XendOptions.py Wed May 20 15:27:30 2009 +0100
@@ -32,6 +32,7 @@ import sys
from xen.xend import sxp, osdep, XendLogging
from xen.xend.XendError import XendError
+from xen.util import auxbin
if os.uname()[0] == 'SunOS':
from xen.lowlevel import scf
@@ -40,10 +41,10 @@ class XendOptions:
"""Configuration options."""
"""Where network control scripts live."""
- network_script_dir = osdep.scripts_dir
+ network_script_dir = auxbin.scripts_dir()
"""Where block control scripts live."""
- block_script_dir = osdep.scripts_dir
+ block_script_dir = auxbin.scripts_dir()
"""Default path to the log file. """
logfile_default = "/var/log/xen/xend.log"
@@ -115,7 +116,7 @@ class XendOptions:
xend_vnc_tls = 0
"""x509 certificate directory for QEMU VNC server"""
- xend_vnc_x509_cert_dir = "/etc/xen/vnc"
+ xend_vnc_x509_cert_dir = auxbin.xen_configdir() + "/vnc"
"""Verify incoming client x509 certs"""
xend_vnc_x509_verify = 0
@@ -355,7 +356,7 @@ class XendOptions:
s = self.get_config_string('resource-label-change-script')
if s:
result = s.split(" ")
- result[0] = os.path.join(osdep.scripts_dir, result[0])
+ result[0] = os.path.join(auxbin.scripts_dir(), result[0])
return result
else:
return None
@@ -386,7 +387,7 @@ class XendOptionsFile(XendOptions):
class XendOptionsFile(XendOptions):
"""Default path to the config file."""
- config_default = "/etc/xen/xend-config.sxp"
+ config_default = auxbin.xen_configdir() + "/xend-config.sxp"
"""Environment variable used to override config_default."""
config_var = "XEND_CONFIG"
diff -r 070f456143d3 -r 23f9857f642f tools/python/xen/xend/XendPIF.py
--- a/tools/python/xen/xend/XendPIF.py Wed May 20 15:13:36 2009 +0100
+++ b/tools/python/xen/xend/XendPIF.py Wed May 20 15:27:30 2009 +0100
@@ -25,6 +25,7 @@ from xen.xend.XendPIFMetrics import Xend
from xen.xend.XendPIFMetrics import XendPIFMetrics
from xen.xend.XendError import *
from xen.xend import Vifctl
+from xen.util import auxbin
log = logging.getLogger("xend.XendPIF")
log.setLevel(logging.TRACE)
diff -r 070f456143d3 -r 23f9857f642f tools/python/xen/xend/osdep.py
--- a/tools/python/xen/xend/osdep.py Wed May 20 15:13:36 2009 +0100
+++ b/tools/python/xen/xend/osdep.py Wed May 20 15:27:30 2009 +0100
@@ -20,19 +20,10 @@ import os
import os
import commands
-_scripts_dir = {
- "Linux": "/etc/xen/scripts",
- "SunOS": "/usr/lib/xen/scripts",
-}
-
_xend_autorestart = {
"NetBSD": True,
"Linux": True,
"SunOS": False,
-}
-
-_pygrub_path = {
- "SunOS": "/usr/lib/xen/bin/pygrub"
}
_vif_script = {
@@ -221,9 +212,7 @@ def _get(var, default=None):
def _get(var, default=None):
return var.get(os.uname()[0], default)
-scripts_dir = _get(_scripts_dir, "/etc/xen/scripts")
xend_autorestart = _get(_xend_autorestart)
-pygrub_path = _get(_pygrub_path, "/usr/bin/pygrub")
vif_script = _get(_vif_script, "vif-bridge")
lookup_balloon_stat = _get(_balloon_stat, _linux_balloon_stat)
get_cpuinfo = _get(_get_cpuinfo, _linux_get_cpuinfo)
diff -r 070f456143d3 -r 23f9857f642f tools/python/xen/xend/server/blkif.py
--- a/tools/python/xen/xend/server/blkif.py Wed May 20 15:13:36 2009 +0100
+++ b/tools/python/xen/xend/server/blkif.py Wed May 20 15:27:30 2009 +0100
@@ -24,7 +24,7 @@ import xen.util.xsm.xsm as security
import xen.util.xsm.xsm as security
from xen.xend.XendError import VmError
from xen.xend.server.DevController import DevController
-from xen.util import xsconstants
+from xen.util import xsconstants, auxbin
class BlkifController(DevController):
"""Block device interface controller. Handles all block devices
@@ -40,7 +40,7 @@ class BlkifController(DevController):
if protocol in ('phy', 'file', 'tap'):
return True
- return os.access('/etc/xen/scripts/block-%s' % protocol, os.X_OK)
+ return os.access(auxbin.scripts_dir() + '/block-%s' % protocol,
os.X_OK)
def getDeviceDetails(self, config):
diff -r 070f456143d3 -r 23f9857f642f tools/python/xen/xend/server/pciquirk.py
--- a/tools/python/xen/xend/server/pciquirk.py Wed May 20 15:13:36 2009 +0100
+++ b/tools/python/xen/xend/server/pciquirk.py Wed May 20 15:27:30 2009 +0100
@@ -3,10 +3,11 @@ import sys
import sys
import os.path
from xen.xend.sxp import *
+from xen.util import auxbin
QUIRK_SYSFS_NODE = "/sys/bus/pci/drivers/pciback/quirks"
-QUIRK_CONFIG_FILE = "/etc/xen/xend-pci-quirks.sxp"
-PERMISSIVE_CONFIG_FILE = "/etc/xen/xend-pci-permissive.sxp"
+QUIRK_CONFIG_FILE = auxbin.xen_configdir() + "/xend-pci-quirks.sxp"
+PERMISSIVE_CONFIG_FILE = auxbin.xen_configdir() + "/xend-pci-permissive.sxp"
PERMISSIVE_SYSFS_NODE = "/sys/bus/pci/drivers/pciback/permissive"
class PCIQuirk:
diff -r 070f456143d3 -r 23f9857f642f tools/python/xen/xm/addlabel.py
--- a/tools/python/xen/xm/addlabel.py Wed May 20 15:13:36 2009 +0100
+++ b/tools/python/xen/xm/addlabel.py Wed May 20 15:27:30 2009 +0100
@@ -24,7 +24,7 @@ import sys
import xen.util.xsm.xsm as security
from xen.xm.opts import OptionError
-from xen.util import xsconstants
+from xen.util import xsconstants, auxbin
from xen.xm import main as xm_main
from xen.xm.main import server
@@ -221,7 +221,7 @@ def main(argv):
if argv[2].lower() == "dom":
configfile = argv[3]
if configfile[0] != '/':
- for prefix in [os.path.realpath(os.path.curdir), "/etc/xen"]:
+ for prefix in [os.path.realpath(os.path.curdir),
auxbin.xen_configdir()]:
configfile = prefix + "/" + configfile
if os.path.isfile(configfile):
break
diff -r 070f456143d3 -r 23f9857f642f tools/python/xen/xm/create.py
--- a/tools/python/xen/xm/create.py Wed May 20 15:13:36 2009 +0100
+++ b/tools/python/xen/xm/create.py Wed May 20 15:27:30 2009 +0100
@@ -29,7 +29,6 @@ import xmlrpclib
from xen.xend import sxp
from xen.xend import PrettyPrint as SXPPrettyPrint
-from xen.xend import osdep
import xen.xend.XendClient
from xen.xend.XendBootloader import bootloader
from xen.xend.XendConstants import *
@@ -38,7 +37,7 @@ from xen.util import vscsi_util
from xen.util import vscsi_util
import xen.util.xsm.xsm as security
from xen.xm.main import serverType, SERVER_XEN_API, get_single_vm
-from xen.util import utils
+from xen.util import utils, auxbin
from xen.xm.opts import *
@@ -72,7 +71,7 @@ gopts.opt('quiet', short='q',
use="Quiet.")
gopts.opt('path', val='PATH',
- fn=set_value, default='.:/etc/xen',
+ fn=set_value, default='.:' + auxbin.xen_configdir(),
use="Search path for configuration scripts. "
"The value of PATH is a colon-separated directory list.")
@@ -981,7 +980,7 @@ def make_config(vals):
config_image = configure_image(vals)
if vals.bootloader:
if vals.bootloader == "pygrub":
- vals.bootloader = osdep.pygrub_path
+ vals.bootloader = auxbin.pathTo(vals.bootloader)
config.append(['bootloader', vals.bootloader])
if vals.bootargs:
diff -r 070f456143d3 -r 23f9857f642f tools/python/xen/xm/getlabel.py
--- a/tools/python/xen/xm/getlabel.py Wed May 20 15:13:36 2009 +0100
+++ b/tools/python/xen/xm/getlabel.py Wed May 20 15:27:30 2009 +0100
@@ -20,7 +20,7 @@
"""
import sys, os, re
import xen.util.xsm.xsm as security
-from xen.util import xsconstants
+from xen.util import xsconstants, auxbin
from xen.xm.opts import OptionError
from xen.xm import main as xm_main
from xen.xm.main import server
@@ -59,7 +59,7 @@ def get_domain_label(configfile):
if configfile[0] == '/':
fd = open(configfile, "rb")
else:
- for prefix in [".", "/etc/xen"]:
+ for prefix in [".", auxbin.xen_configdir() ]:
abs_file = prefix + "/" + configfile
if os.path.isfile(abs_file):
fd = open(abs_file, "rb")
diff -r 070f456143d3 -r 23f9857f642f tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py Wed May 20 15:13:36 2009 +0100
+++ b/tools/python/xen/xm/main.py Wed May 20 15:27:30 2009 +0100
@@ -55,6 +55,7 @@ import xen.util.xsm.xsm as security
import xen.util.xsm.xsm as security
from xen.util.xsm.xsm import XSMError
from xen.util.acmpolicy import ACM_LABEL_UNLABELED_DISPLAY
+from xen.util import auxbin
import XenAPI
@@ -72,7 +73,7 @@ if not hasattr(getopt, 'gnu_getopt'):
getopt.gnu_getopt = getopt.getopt
XM_CONFIG_FILE_ENVVAR = 'XM_CONFIG_FILE'
-XM_CONFIG_FILE_DEFAULT = '/etc/xen/xm-config.xml'
+XM_CONFIG_FILE_DEFAULT = auxbin.xen_configdir + '/xm-config.xml'
# Supported types of server
SERVER_LEGACY_XMLRPC = 'LegacyXMLRPC'
diff -r 070f456143d3 -r 23f9857f642f tools/python/xen/xm/rmlabel.py
--- a/tools/python/xen/xm/rmlabel.py Wed May 20 15:13:36 2009 +0100
+++ b/tools/python/xen/xm/rmlabel.py Wed May 20 15:27:30 2009 +0100
@@ -22,7 +22,7 @@ import re
import re
import sys
import xen.util.xsm.xsm as security
-from xen.util import xsconstants
+from xen.util import xsconstants, auxbin
from xen.util.acmpolicy import ACM_LABEL_UNLABELED
from xen.xm.opts import OptionError
from xen.xm import main as xm_main
@@ -81,7 +81,7 @@ def rm_domain_label(configfile):
fil = configfile
fd = open(fil, "rb")
else:
- for prefix in [".", "/etc/xen"]:
+ for prefix in [".", auxbin.xen_configdir() ]:
fil = prefix + "/" + configfile
if os.path.isfile(fil):
fd = open(fil, "rb")
diff -r 070f456143d3 -r 23f9857f642f tools/python/xen/xm/tests/test_create.py
--- a/tools/python/xen/xm/tests/test_create.py Wed May 20 15:13:36 2009 +0100
+++ b/tools/python/xen/xm/tests/test_create.py Wed May 20 15:27:30 2009 +0100
@@ -8,6 +8,7 @@ xen.xend.XendOptions.XendOptions.config_
xen.xend.XendOptions.XendOptions.config_default = '/dev/null'
import xen.xm.create
+from xen.util import auxbin
class test_create(unittest.TestCase):
@@ -48,7 +49,7 @@ class test_create(unittest.TestCase):
'boot' : 'c',
'dhcp' : 'off',
'interface' : 'eth0',
- 'path' : '.:/etc/xen',
+ 'path' : '.:' + auxbin.xen_configdir(),
'builder' : 'linux',
'nics' : -1,
'vncunused' : 1,
@@ -99,7 +100,7 @@ on_crash = 'destroy'
'boot' : 'c',
'dhcp' : 'off',
'interface' : 'eth0',
- 'path' : '.:/etc/xen',
+ 'path' : '.:' + auxbin.xen_configdir(),
'builder' : 'linux',
'vncunused' : 1,
@@ -138,7 +139,7 @@ cpu_weight = 0.75
'boot' : 'c',
'dhcp' : 'off',
'interface' : 'eth0',
- 'path' : '.:/etc/xen',
+ 'path' : '.:' + auxbin.xen_configdir(),
'builder' : 'linux',
'nics' : -1,
@@ -195,7 +196,7 @@ ne2000=0
'boot' : 'c',
'dhcp' : 'off',
'interface' : 'eth0',
- 'path' : '.:/etc/xen',
+ 'path' : '.:' + auxbin.xen_configdir(),
'xauthority' : xen.xm.create.get_xauthority(),
})
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|