Commit 59ef0f15 authored by Helga Velroyen's avatar Helga Velroyen

Utility functions for storage

This patch add a couple of utility functions dealing with
storage types and disk templates.
Signed-off-by: default avatarHelga Velroyen <helgav@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 89ff748d
......@@ -379,6 +379,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
......
......@@ -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 *
......
#
#
# 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
def LvmGetsEnabled(enabled_disk_templates, new_enabled_disk_templates):
"""Checks whether lvm was not enabled before, but will be enabled after
the operation.
"""
if IsLvmEnabled(enabled_disk_templates):
return False
return set(GetLvmDiskTemplates()).intersection(
set(new_enabled_disk_templates))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment