Utility functions to check if a disk template is enabed
authorHelga Velroyen <helgav@google.com>
Tue, 9 Jul 2013 10:52:20 +0000 (12:52 +0200)
committerHelga Velroyen <helgav@google.com>
Mon, 15 Jul 2013 09:34:18 +0000 (11:34 +0200)
This patch adds some helper functions to the config and
storage utils which check whether a disk template is
enabled or not. The functions themselves are quite small
but they will be used quite often and therefore should
have a designated place.

Signed-off-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

lib/objects.py
lib/utils/storage.py

index 08d6916..fdd2dbd 100644 (file)
@@ -1899,6 +1899,26 @@ class Cluster(TaggableObject):
     """
     return FillIPolicy(self.ipolicy, ipolicy)
 
+  def IsDiskTemplateEnabled(self, disk_template):
+    """Checks if a particular disk template is enabled.
+
+    """
+    return utils.storage.IsDiskTemplateEnabled(
+        disk_template, self.enabled_disk_templates)
+
+  def IsFileStorageEnabled(self):
+    """Checks if file storage is enabled.
+
+    """
+    return utils.storage.IsFileStorageEnabled(self.enabled_disk_templates)
+
+  def IsSharedFileStorageEnabled(self):
+    """Checks if shared file storage is enabled.
+
+    """
+    return utils.storage.IsSharedFileStorageEnabled(
+        self.enabled_disk_templates)
+
 
 class BlockDevStatus(ConfigObject):
   """Config object representing the status of a block device."""
index 02fec19..21b5d7d 100644 (file)
@@ -40,6 +40,27 @@ def GetLvmDiskTemplates():
   return GetDiskTemplatesOfStorageType(constants.ST_LVM_VG)
 
 
+def IsDiskTemplateEnabled(disk_template, enabled_disk_templates):
+  """Checks if a particular disk template is enabled.
+
+  """
+  return disk_template in enabled_disk_templates
+
+
+def IsFileStorageEnabled(enabled_disk_templates):
+  """Checks if file storage is enabled.
+
+  """
+  return IsDiskTemplateEnabled(constants.DT_FILE, enabled_disk_templates)
+
+
+def IsSharedFileStorageEnabled(enabled_disk_templates):
+  """Checks if shared file storage is enabled.
+
+  """
+  return IsDiskTemplateEnabled(constants.DT_SHARED_FILE, enabled_disk_templates)
+
+
 def IsLvmEnabled(enabled_disk_templates):
   """Check whether or not any lvm-based disk templates are enabled."""
   return len(set(GetLvmDiskTemplates())