From c2be25325ce1e9b3c753b8dd5131d4eabc236864 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Mon, 17 Oct 2011 12:04:18 +0100
Subject: [PATCH] xen: abstract instance config file naming

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/hypervisor/hv_xen.py | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py
index 290409470..33491854d 100644
--- a/lib/hypervisor/hv_xen.py
+++ b/lib/hypervisor/hv_xen.py
@@ -50,6 +50,18 @@ class XenHypervisor(hv_base.BaseHypervisor):
     "/etc/xen/scripts/vif-bridge",
     ]
 
+  @staticmethod
+  def _ConfigFileName(instance_name):
+    """Get the config file name for an instance.
+
+    @param instance_name: instance name
+    @type instance_name: str
+    @return: fully qualified path to instance config file
+    @rtype: str
+
+    """
+    return "/etc/xen/%s" % instance_name
+
   @classmethod
   def _WriteConfigFile(cls, instance, block_devices):
     """Write the Xen config file for the instance.
@@ -64,7 +76,7 @@ class XenHypervisor(hv_base.BaseHypervisor):
     This version of the function just writes the config file from static data.
 
     """
-    utils.WriteFile("/etc/xen/%s" % instance_name, data=data)
+    utils.WriteFile(XenHypervisor._ConfigFileName(instance_name), data=data)
 
   @staticmethod
   def _ReadConfigFile(instance_name):
@@ -72,7 +84,8 @@ class XenHypervisor(hv_base.BaseHypervisor):
 
     """
     try:
-      file_content = utils.ReadFile("/etc/xen/%s" % instance_name)
+      file_content = utils.ReadFile(
+                       XenHypervisor._ConfigFileName(instance_name))
     except EnvironmentError, err:
       raise errors.HypervisorError("Failed to load Xen config file: %s" % err)
     return file_content
@@ -82,7 +95,7 @@ class XenHypervisor(hv_base.BaseHypervisor):
     """Remove the xen configuration file.
 
     """
-    utils.RemoveFile("/etc/xen/%s" % instance_name)
+    utils.RemoveFile(XenHypervisor._ConfigFileName(instance_name))
 
   @staticmethod
   def _RunXmList(xmlist_errors):
@@ -549,11 +562,12 @@ class XenPvmHypervisor(XenHypervisor):
     # just in case it exists
     utils.RemoveFile("/etc/xen/auto/%s" % instance.name)
     try:
-      utils.WriteFile("/etc/xen/%s" % instance.name, data=config.getvalue())
+      utils.WriteFile(cls._ConfigFileName(instance.name),
+                      data=config.getvalue())
     except EnvironmentError, err:
       raise errors.HypervisorError("Cannot write Xen instance confile"
-                                   " file /etc/xen/%s: %s" %
-                                   (instance.name, err))
+                                   " file %s: %s" %
+                                   (cls._ConfigFileName(instance.name), err))
 
     return True
 
@@ -690,11 +704,11 @@ class XenHvmHypervisor(XenHypervisor):
     # just in case it exists
     utils.RemoveFile("/etc/xen/auto/%s" % instance.name)
     try:
-      utils.WriteFile("/etc/xen/%s" % instance.name,
+      utils.WriteFile(cls._ConfigFileName(instance.name),
                       data=config.getvalue())
     except EnvironmentError, err:
       raise errors.HypervisorError("Cannot write Xen instance confile"
-                                   " file /etc/xen/%s: %s" %
-                                   (instance.name, err))
+                                   " file %s: %s" %
+                                   (cls._ConfigFileName(instance.name), err))
 
     return True
-- 
GitLab