Skip to content
Snippets Groups Projects
Commit c2be2532 authored by Guido Trotter's avatar Guido Trotter
Browse files

xen: abstract instance config file naming


Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 2876c2d6
No related branches found
No related tags found
No related merge requests found
...@@ -50,6 +50,18 @@ class XenHypervisor(hv_base.BaseHypervisor): ...@@ -50,6 +50,18 @@ class XenHypervisor(hv_base.BaseHypervisor):
"/etc/xen/scripts/vif-bridge", "/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 @classmethod
def _WriteConfigFile(cls, instance, block_devices): def _WriteConfigFile(cls, instance, block_devices):
"""Write the Xen config file for the instance. """Write the Xen config file for the instance.
...@@ -64,7 +76,7 @@ class XenHypervisor(hv_base.BaseHypervisor): ...@@ -64,7 +76,7 @@ class XenHypervisor(hv_base.BaseHypervisor):
This version of the function just writes the config file from static data. 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 @staticmethod
def _ReadConfigFile(instance_name): def _ReadConfigFile(instance_name):
...@@ -72,7 +84,8 @@ class XenHypervisor(hv_base.BaseHypervisor): ...@@ -72,7 +84,8 @@ class XenHypervisor(hv_base.BaseHypervisor):
""" """
try: try:
file_content = utils.ReadFile("/etc/xen/%s" % instance_name) file_content = utils.ReadFile(
XenHypervisor._ConfigFileName(instance_name))
except EnvironmentError, err: except EnvironmentError, err:
raise errors.HypervisorError("Failed to load Xen config file: %s" % err) raise errors.HypervisorError("Failed to load Xen config file: %s" % err)
return file_content return file_content
...@@ -82,7 +95,7 @@ class XenHypervisor(hv_base.BaseHypervisor): ...@@ -82,7 +95,7 @@ class XenHypervisor(hv_base.BaseHypervisor):
"""Remove the xen configuration file. """Remove the xen configuration file.
""" """
utils.RemoveFile("/etc/xen/%s" % instance_name) utils.RemoveFile(XenHypervisor._ConfigFileName(instance_name))
@staticmethod @staticmethod
def _RunXmList(xmlist_errors): def _RunXmList(xmlist_errors):
...@@ -549,11 +562,12 @@ class XenPvmHypervisor(XenHypervisor): ...@@ -549,11 +562,12 @@ class XenPvmHypervisor(XenHypervisor):
# just in case it exists # just in case it exists
utils.RemoveFile("/etc/xen/auto/%s" % instance.name) utils.RemoveFile("/etc/xen/auto/%s" % instance.name)
try: try:
utils.WriteFile("/etc/xen/%s" % instance.name, data=config.getvalue()) utils.WriteFile(cls._ConfigFileName(instance.name),
data=config.getvalue())
except EnvironmentError, err: except EnvironmentError, err:
raise errors.HypervisorError("Cannot write Xen instance confile" raise errors.HypervisorError("Cannot write Xen instance confile"
" file /etc/xen/%s: %s" % " file %s: %s" %
(instance.name, err)) (cls._ConfigFileName(instance.name), err))
return True return True
...@@ -690,11 +704,11 @@ class XenHvmHypervisor(XenHypervisor): ...@@ -690,11 +704,11 @@ class XenHvmHypervisor(XenHypervisor):
# just in case it exists # just in case it exists
utils.RemoveFile("/etc/xen/auto/%s" % instance.name) utils.RemoveFile("/etc/xen/auto/%s" % instance.name)
try: try:
utils.WriteFile("/etc/xen/%s" % instance.name, utils.WriteFile(cls._ConfigFileName(instance.name),
data=config.getvalue()) data=config.getvalue())
except EnvironmentError, err: except EnvironmentError, err:
raise errors.HypervisorError("Cannot write Xen instance confile" raise errors.HypervisorError("Cannot write Xen instance confile"
" file /etc/xen/%s: %s" % " file %s: %s" %
(instance.name, err)) (cls._ConfigFileName(instance.name), err))
return True return True
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment