From 8b3fd458f3b6c2639365ff3f43edef4be7ac0da5 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 14 Oct 2008 11:29:36 +0000
Subject: [PATCH] Change hypervisors to use the beparams

This patch changes the hypervisor functions to use the beparams dict
instead of the instance attributes.

Reviewed-by: ultrotter
---
 lib/hypervisor/hv_fake.py | 4 +++-
 lib/hypervisor/hv_kvm.py  | 5 ++---
 lib/hypervisor/hv_xen.py  | 8 ++++----
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/lib/hypervisor/hv_fake.py b/lib/hypervisor/hv_fake.py
index fdfbdef21..e688099b8 100644
--- a/lib/hypervisor/hv_fake.py
+++ b/lib/hypervisor/hv_fake.py
@@ -122,7 +122,9 @@ class FakeHypervisor(hv_base.BaseHypervisor):
     try:
       fh = file(file_name, "w")
       try:
-        fh.write("0\n%d\n%d\n" % (instance.memory, instance.vcpus))
+        fh.write("0\n%d\n%d\n" %
+                 (instance.beparams[constants.BE_MEMORY],
+                  instance.beparams[constants.BE_VCPUS]))
       finally:
         fh.close()
     except IOError, err:
diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index b3b8940fd..dd78e0032 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -176,8 +176,8 @@ class KVMHypervisor(hv_base.BaseHypervisor):
 
     kvm = constants.KVM_PATH
     kvm_cmd = [kvm]
-    kvm_cmd.extend(['-m', instance.memory])
-    kvm_cmd.extend(['-smp', instance.vcpus])
+    kvm_cmd.extend(['-m', instance.beparams[constants.BE_MEMORY]])
+    kvm_cmd.extend(['-smp', instance.beparams[constants.BE_VCPUS]])
     kvm_cmd.extend(['-pidfile', pidfile])
     # used just by the vnc server, if enabled
     kvm_cmd.extend(['-name', instance.name])
@@ -372,4 +372,3 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     """
     if not os.path.exists(constants.KVM_PATH):
       return "The kvm binary ('%s') does not exist." % constants.KVM_PATH
-
diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py
index cea3fa8ce..0ee8911fd 100644
--- a/lib/hypervisor/hv_xen.py
+++ b/lib/hypervisor/hv_xen.py
@@ -353,8 +353,8 @@ class XenPvmHypervisor(XenHypervisor):
       config.write("ramdisk = '%s'\n" % initrd_path)
 
     # rest of the settings
-    config.write("memory = %d\n" % instance.memory)
-    config.write("vcpus = %d\n" % instance.vcpus)
+    config.write("memory = %d\n" % instance.beparams[constants.BE_MEMORY])
+    config.write("vcpus = %d\n" % instance.beparams[constants.BE_VCPUS])
     config.write("name = '%s'\n" % instance.name)
 
     vif_data = []
@@ -467,8 +467,8 @@ class XenHvmHypervisor(XenHypervisor):
     config.write("# this is autogenerated by Ganeti, please do not edit\n#\n")
     config.write("kernel = '/usr/lib/xen/boot/hvmloader'\n")
     config.write("builder = 'hvm'\n")
-    config.write("memory = %d\n" % instance.memory)
-    config.write("vcpus = %d\n" % instance.vcpus)
+    config.write("memory = %d\n" % instance.beparams[constants.BE_MEMORY])
+    config.write("vcpus = %d\n" % instance.beparams[constants.BE_VCPUS])
     config.write("name = '%s'\n" % instance.name)
     if instance.hvparams[constants.HV_PAE]:
       config.write("pae = 1\n")
-- 
GitLab