From cb2037a26555bf6bb5d1ca17275e7b75e2b12cb3 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 11 Dec 2007 16:25:02 +0000
Subject: [PATCH] Return more data in rpc.call_volume_list
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Currently, the volume_list call returns only the volume size. However,
it is useful to also have two other things: the 'inactive' state of the
volume (which might trigger a β€˜vgchange -a y’ on the volume group) and
the online state (which shows if the volume is in use or not).

Since this modifies an RPC call, we also bump the protocol version,
although the single user of the call didn't care about the dictionary
values, only about the keys.

Reviewed-by: imsnah
---
 lib/backend.py   | 28 ++++++++++++++++++++--------
 lib/constants.py |  2 +-
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/lib/backend.py b/lib/backend.py
index f54c04191..a3ec5666a 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -210,19 +210,31 @@ def GetVolumeList(vg_name):
   """Compute list of logical volumes and their size.
 
   Returns:
-    dictionary of all partions (key) with their size:
-    test1: 20.06MiB
+    dictionary of all partions (key) with their size (in MiB), inactive
+    and online status:
+    {'test1': ('20.06', True, True)}
 
   """
-  result = utils.RunCmd(["lvs", "--noheadings", "--units=m",
-                         "-oname,size", vg_name])
+  lvs = {}
+  sep = '|'
+  result = utils.RunCmd(["lvs", "--noheadings", "--units=m", "--nosuffix",
+                         "--separator=%s" % sep,
+                         "-olv_name,lv_size,lv_attr", vg_name])
   if result.failed:
     logger.Error("Failed to list logical volumes, lvs output: %s" %
                  result.output)
-    return {}
-
-  lvlist = [line.split() for line in result.stdout.splitlines()]
-  return dict(lvlist)
+    return lvs
+
+  for line in result.stdout.splitlines():
+    line = line.strip().rstrip(sep)
+    name, size, attr = line.split(sep)
+    if len(attr) != 6:
+      attr = '------'
+    inactive = attr[4] == '-'
+    online = attr[5] == 'o'
+    lvs[name] = (size, inactive, online)
+
+  return lvs
 
 
 def ListVolumeGroups():
diff --git a/lib/constants.py b/lib/constants.py
index ecc6182f8..fc5b88596 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -25,7 +25,7 @@ from ganeti import _autoconf
 
 # various versions
 CONFIG_VERSION = 3
-PROTOCOL_VERSION = 7
+PROTOCOL_VERSION = 8
 RELEASE_VERSION = _autoconf.PACKAGE_VERSION
 OS_API_VERSION = 5
 EXPORT_VERSION = 0
-- 
GitLab