From 69ab2e123e51590a754d9a04c15137eeb7ea9329 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Tue, 18 Oct 2011 16:43:44 +0100
Subject: [PATCH] Add hypervisors ancillary files list

These lists will be used to declare some of the files not necessarily
needed on all nodes. The files selected are files without which the
various hypervisors can still work, but that when they are present
should be synchronized across the cluster (or node group).

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/backend.py            |  2 +-
 lib/cmdlib.py             |  2 +-
 lib/hypervisor/hv_base.py | 10 +++++++---
 lib/hypervisor/hv_kvm.py  |  3 +++
 lib/hypervisor/hv_xen.py  |  6 ++++++
 5 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/lib/backend.py b/lib/backend.py
index 98d61ef10..57b31a9ca 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -203,7 +203,7 @@ def _BuildUploadFileList():
 
   for hv_name in constants.HYPER_TYPES:
     hv_class = hypervisor.GetHypervisorClass(hv_name)
-    allowed_files.update(hv_class.GetAncillaryFiles())
+    allowed_files.update(hv_class.GetAncillaryFiles()[0])
 
   return frozenset(allowed_files)
 
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 7d126899d..6151ddb62 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -3760,7 +3760,7 @@ def _ComputeAncillaryFiles(cluster, redist):
   # Files which should only be on VM-capable nodes
   files_vm = set(filename
     for hv_name in cluster.enabled_hypervisors
-    for filename in hypervisor.GetHypervisor(hv_name).GetAncillaryFiles())
+    for filename in hypervisor.GetHypervisor(hv_name).GetAncillaryFiles()[0])
 
   # Filenames must be unique
   assert (len(files_all | files_all_opt | files_mc | files_vm) ==
diff --git a/lib/hypervisor/hv_base.py b/lib/hypervisor/hv_base.py
index 7c4b1b59d..5fe197837 100644
--- a/lib/hypervisor/hv_base.py
+++ b/lib/hypervisor/hv_base.py
@@ -133,6 +133,7 @@ class BaseHypervisor(object):
   """
   PARAMETERS = {}
   ANCILLARY_FILES = []
+  ANCILLARY_FILES_OPT = []
   CAN_MIGRATE = False
 
   def __init__(self):
@@ -221,13 +222,16 @@ class BaseHypervisor(object):
     """Return a list of ancillary files to be copied to all nodes as ancillary
     configuration files.
 
-    @rtype: list of strings
-    @return: list of absolute paths of files to ship cluster-wide
+    @rtype: (list of absolute paths, list of absolute paths)
+    @return: (all files, optional files)
 
     """
     # By default we return a member variable, so that if an hypervisor has just
     # a static list of files it doesn't have to override this function.
-    return cls.ANCILLARY_FILES
+    assert set(cls.ANCILLARY_FILES).issuperset(cls.ANCILLARY_FILES_OPT), \
+      "Optional ancillary files must be a subset of ancillary files"
+
+    return (cls.ANCILLARY_FILES, cls.ANCILLARY_FILES_OPT)
 
   def Verify(self):
     """Verify the hypervisor.
diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index c4b05b117..ccf9f7d85 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -475,6 +475,9 @@ class KVMHypervisor(hv_base.BaseHypervisor):
   ANCILLARY_FILES = [
     _KVM_NETWORK_SCRIPT,
     ]
+  ANCILLARY_FILES_OPT = [
+    _KVM_NETWORK_SCRIPT,
+    ]
 
   def __init__(self):
     hv_base.BaseHypervisor.__init__(self)
diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py
index 3468fbe09..ffeb01768 100644
--- a/lib/hypervisor/hv_xen.py
+++ b/lib/hypervisor/hv_xen.py
@@ -55,6 +55,9 @@ class XenHypervisor(hv_base.BaseHypervisor):
     XL_CONFIG_FILE,
     VIF_BRIDGE_SCRIPT,
     ]
+  ANCILLARY_FILES_OPT = [
+    XL_CONFIG_FILE,
+    ]
 
   @staticmethod
   def _ConfigFileName(instance_name):
@@ -589,6 +592,9 @@ class XenHvmHypervisor(XenHypervisor):
   ANCILLARY_FILES = XenHypervisor.ANCILLARY_FILES + [
     constants.VNC_PASSWORD_FILE,
     ]
+  ANCILLARY_FILES_OPT = XenHypervisor.ANCILLARY_FILES_OPT + [
+    constants.VNC_PASSWORD_FILE,
+    ]
 
   PARAMETERS = {
     constants.HV_ACPI: hv_base.NO_CHECK,
-- 
GitLab