This patch add a couple of utility functions dealing with
storage types and disk templates.

Signed-off-by: Helga Velroyen <[email protected]>
---
 Makefile.am           |  1 +
 lib/utils/__init__.py |  1 +
 lib/utils/storage.py  | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+)
 create mode 100644 lib/utils/storage.py

diff --git a/Makefile.am b/Makefile.am
index b43c187..ecc0357 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -368,6 +368,7 @@ utils_PYTHON = \
        lib/utils/nodesetup.py \
        lib/utils/process.py \
        lib/utils/retry.py \
+       lib/utils/storage.py \
        lib/utils/text.py \
        lib/utils/wrapper.py \
        lib/utils/x509.py
diff --git a/lib/utils/__init__.py b/lib/utils/__init__.py
index d3319c1..c5940c3 100644
--- a/lib/utils/__init__.py
+++ b/lib/utils/__init__.py
@@ -53,6 +53,7 @@ from ganeti.utils.mlock import *
 from ganeti.utils.nodesetup import *
 from ganeti.utils.process import *
 from ganeti.utils.retry import *
+from ganeti.utils.storage import *
 from ganeti.utils.text import *
 from ganeti.utils.wrapper import *
 from ganeti.utils.x509 import *
diff --git a/lib/utils/storage.py b/lib/utils/storage.py
new file mode 100644
index 0000000..ed8851b
--- /dev/null
+++ b/lib/utils/storage.py
@@ -0,0 +1,43 @@
+#
+#
+
+# Copyright (C) 2013 Google Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+"""Utility functions for storage.
+
+"""
+
+from ganeti import constants
+
+
+def GetDiskTemplatesOfStorageType(storage_type):
+  """Given the storage type, returns a list of disk templates based on that
+     storage type."""
+  return [dt for dt in constants.DISK_TEMPLATES
+          if constants.DISK_TEMPLATES_STORAGE_TYPE[dt] == storage_type]
+
+
+def GetLvmDiskTemplates():
+  """Returns all disk templates that use LVM."""
+  return GetDiskTemplatesOfStorageType(constants.ST_LVM_VG)
+
+
+def IsLvmEnabled(enabled_disk_templates):
+  """Check whether or not any lvm-based disk templates are enabled."""
+  return len(set(GetLvmDiskTemplates())
+             .intersection(set(enabled_disk_templates))) != 0
-- 
1.8.1.3

Reply via email to