root / lib / utils / storage.py @ 59ef0f15
History | View | Annotate | Download (1.7 kB)
1 |
#
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2013 Google Inc.
|
5 |
#
|
6 |
# This program is free software; you can redistribute it and/or modify
|
7 |
# it under the terms of the GNU General Public License as published by
|
8 |
# the Free Software Foundation; either version 2 of the License, or
|
9 |
# (at your option) any later version.
|
10 |
#
|
11 |
# This program is distributed in the hope that it will be useful, but
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
# General Public License for more details.
|
15 |
#
|
16 |
# You should have received a copy of the GNU General Public License
|
17 |
# along with this program; if not, write to the Free Software
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
# 02110-1301, USA.
|
20 |
|
21 |
"""Utility functions for storage.
|
22 |
|
23 |
"""
|
24 |
|
25 |
from ganeti import constants |
26 |
|
27 |
|
28 |
def GetDiskTemplatesOfStorageType(storage_type): |
29 |
"""Given the storage type, returns a list of disk templates based on that
|
30 |
storage type."""
|
31 |
return [dt for dt in constants.DISK_TEMPLATES |
32 |
if constants.DISK_TEMPLATES_STORAGE_TYPE[dt] == storage_type]
|
33 |
|
34 |
|
35 |
def GetLvmDiskTemplates(): |
36 |
"""Returns all disk templates that use LVM."""
|
37 |
return GetDiskTemplatesOfStorageType(constants.ST_LVM_VG)
|
38 |
|
39 |
|
40 |
def IsLvmEnabled(enabled_disk_templates): |
41 |
"""Check whether or not any lvm-based disk templates are enabled."""
|
42 |
return len(set(GetLvmDiskTemplates()) |
43 |
.intersection(set(enabled_disk_templates))) != 0 |
44 |
|
45 |
|
46 |
def LvmGetsEnabled(enabled_disk_templates, new_enabled_disk_templates): |
47 |
"""Checks whether lvm was not enabled before, but will be enabled after
|
48 |
the operation.
|
49 |
|
50 |
"""
|
51 |
if IsLvmEnabled(enabled_disk_templates):
|
52 |
return False |
53 |
return set(GetLvmDiskTemplates()).intersection( |
54 |
set(new_enabled_disk_templates))
|