From dfa96ded38527e009bb5d068e9fdf54a2ddc3ab7 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Mon, 5 Nov 2007 00:43:55 +0000
Subject: [PATCH] Convert os_get to use OS rather than InvalidOS

In order to do this for simplicity we leave the OSFromDisk function as-is and
we convert the eventual exception to an OS object in ganeti-noded. The
unmangling gets simplified and so does the code for checking whether the OS is
valid.

Reviewed-By: iustinp
---
 daemons/ganeti-noded | 6 +++---
 lib/cmdlib.py        | 4 ++--
 lib/rpc.py           | 9 ++-------
 3 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded
index e11e27c27..30f3b54b9 100755
--- a/daemons/ganeti-noded
+++ b/daemons/ganeti-noded
@@ -460,10 +460,10 @@ class ServerObject(pb.Avatar):
     """
     name = params[0]
     try:
-      os_obj = backend.OSFromDisk(name).ToDict()
+      os_obj = backend.OSFromDisk(name)
     except errors.InvalidOS, err:
-      os_obj = err.args
-    return os_obj
+      os_obj = objects.OS.FromInvalidOS(err)
+    return os_obj.ToDict()
 
   # hooks -----------------------
 
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index fb3b84ec3..cb403383e 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -2159,7 +2159,7 @@ class LUReinstallInstance(LogicalUnit):
         raise errors.OpPrereqError("Primary node '%s' is unknown" %
                                    self.op.pnode)
       os_obj = rpc.call_os_get(pnode.name, self.op.os_type)
-      if not isinstance(os_obj, objects.OS):
+      if not os_obj:
         raise errors.OpPrereqError("OS '%s' not in supported OS list for"
                                    " primary node"  % self.op.os_type)
 
@@ -2950,7 +2950,7 @@ class LUCreateInstance(LogicalUnit):
 
     # os verification
     os_obj = rpc.call_os_get(pnode.name, self.op.os_type)
-    if not isinstance(os_obj, objects.OS):
+    if not os_obj:
       raise errors.OpPrereqError("OS '%s' not in supported os list for"
                                  " primary node"  % self.op.os_type)
 
diff --git a/lib/rpc.py b/lib/rpc.py
index c0a1eca53..e3e5a7389 100644
--- a/lib/rpc.py
+++ b/lib/rpc.py
@@ -656,15 +656,10 @@ def call_os_get(node, name):
   c.connect(node)
   c.run()
   result = c.getresult().get(node, False)
-
   if isinstance(result, dict):
-    new_result = objects.OS.FromDict(result)
-  elif isinstance(result, tuple) and len(data) == 3:
-    new_result = errors.InvalidOS(result[0], result[1], result[2])
+    return objects.OS.FromDict(result)
   else:
-    new_result = result
-
-  return new_result
+    return result
 
 
 def call_hooks_runner(node_list, hpath, phase, env):
-- 
GitLab