Revision 683335b3 lib/utils/storage.py
b/lib/utils/storage.py | ||
---|---|---|
22 | 22 |
|
23 | 23 |
""" |
24 | 24 |
|
25 |
import logging |
|
26 |
|
|
25 | 27 |
from ganeti import constants |
28 |
from ganeti import pathutils |
|
26 | 29 |
|
27 | 30 |
|
28 | 31 |
def GetDiskTemplatesOfStorageType(storage_type): |
... | ... | |
52 | 55 |
return False |
53 | 56 |
return set(GetLvmDiskTemplates()).intersection( |
54 | 57 |
set(new_enabled_disk_templates)) |
58 |
|
|
59 |
|
|
60 |
def _GetDefaultStorageUnitForDiskTemplate(cfg, disk_template): |
|
61 |
"""Retrieves the identifier of the default storage entity for the given |
|
62 |
storage type. |
|
63 |
|
|
64 |
@type disk_template: string |
|
65 |
@param disk_template: a disk template, for example 'drbd' |
|
66 |
@rtype: string |
|
67 |
@return: identifier for a storage unit, for example the vg_name for lvm |
|
68 |
storage |
|
69 |
|
|
70 |
""" |
|
71 |
storage_type = constants.DISK_TEMPLATES_STORAGE_TYPE[disk_template] |
|
72 |
if disk_template in GetLvmDiskTemplates(): |
|
73 |
return (storage_type, cfg.GetVGName()) |
|
74 |
# FIXME: Adjust this, once FILE_STORAGE_DIR and SHARED_FILE_STORAGE_DIR |
|
75 |
# are not in autoconf anymore. |
|
76 |
elif disk_template == constants.DT_FILE: |
|
77 |
return (storage_type, pathutils.DEFAULT_FILE_STORAGE_DIR) |
|
78 |
elif disk_template == constants.DT_SHARED_FILE: |
|
79 |
return (storage_type, pathutils.DEFAULT_SHARED_FILE_STORAGE_DIR) |
|
80 |
else: |
|
81 |
return (storage_type, None) |
|
82 |
|
|
83 |
|
|
84 |
def _GetDefaultStorageUnitForSpindles(cfg): |
|
85 |
"""Creates a 'spindle' storage unit, by retrieving the volume group |
|
86 |
name and associating it to the lvm-pv storage type. |
|
87 |
|
|
88 |
@rtype: (string, string) |
|
89 |
@return: tuple (storage_type, storage_key), where storage type is |
|
90 |
'lvm-pv' and storage_key the name of the default volume group |
|
91 |
|
|
92 |
""" |
|
93 |
return (constants.ST_LVM_PV, cfg.GetVGName()) |
|
94 |
|
|
95 |
|
|
96 |
# List of storage type for which space reporting is implemented. |
|
97 |
# FIXME: Remove this, once the backend is capable to do this for all |
|
98 |
# storage types. |
|
99 |
_DISK_TEMPLATES_SPACE_QUERYABLE = GetLvmDiskTemplates() \ |
|
100 |
+ GetDiskTemplatesOfStorageType(constants.ST_FILE) |
|
101 |
|
|
102 |
|
|
103 |
def GetStorageUnitsOfCluster(cfg, include_spindles=False): |
|
104 |
"""Examines the cluster's configuration and returns a list of storage |
|
105 |
units and their storage keys, ordered by the order in which they |
|
106 |
are enabled. |
|
107 |
|
|
108 |
@type cfg: L{config.ConfigWriter} |
|
109 |
@param cfg: Cluster configuration |
|
110 |
@type include_spindles: boolean |
|
111 |
@param include_spindles: flag to include an extra storage unit for physical |
|
112 |
volumes |
|
113 |
@rtype: list of tuples (string, string) |
|
114 |
@return: list of storage units, each storage unit being a tuple of |
|
115 |
(storage_type, storage_key); storage_type is in |
|
116 |
C{constants.VALID_STORAGE_TYPES} and the storage_key a string to |
|
117 |
identify an entity of that storage type, for example a volume group |
|
118 |
name for LVM storage or a file for file storage. |
|
119 |
|
|
120 |
""" |
|
121 |
cluster_config = cfg.GetClusterInfo() |
|
122 |
storage_units = [] |
|
123 |
for disk_template in cluster_config.enabled_disk_templates: |
|
124 |
if disk_template in _DISK_TEMPLATES_SPACE_QUERYABLE: |
|
125 |
storage_units.append( |
|
126 |
_GetDefaultStorageUnitForDiskTemplate(cfg, disk_template)) |
|
127 |
if include_spindles: |
|
128 |
included_storage_types = set([st for (st, _) in storage_units]) |
|
129 |
if not constants.ST_LVM_PV in included_storage_types: |
|
130 |
storage_units.append( |
|
131 |
_GetDefaultStorageUnitForSpindles(cfg)) |
|
132 |
|
|
133 |
return storage_units |
|
134 |
|
|
135 |
|
|
136 |
def LookupSpaceInfoByStorageType(storage_space_info, storage_type): |
|
137 |
"""Looks up the storage space info for a given storage type. |
|
138 |
|
|
139 |
Note that this lookup can be ambiguous if storage space reporting for several |
|
140 |
units of the same storage type was requested. This function is only supposed |
|
141 |
to be used for legacy code in situations where it actually is unambiguous. |
|
142 |
|
|
143 |
@type storage_space_info: list of dicts |
|
144 |
@param storage_space_info: result of C{GetNodeInfo} |
|
145 |
@type storage_type: string |
|
146 |
@param storage_type: a storage type, which is included in the storage_units |
|
147 |
list |
|
148 |
@rtype: tuple |
|
149 |
@return: returns the element of storage_space_info that matches the given |
|
150 |
storage type |
|
151 |
|
|
152 |
""" |
|
153 |
result = None |
|
154 |
for unit_info in storage_space_info: |
|
155 |
if unit_info["type"] == storage_type: |
|
156 |
if result is None: |
|
157 |
result = unit_info |
|
158 |
else: |
|
159 |
# There is more than one storage type in the query, log a warning |
|
160 |
logging.warning("Storage space information requested for" |
|
161 |
" ambiguous storage type '%s'.", storage_type) |
|
162 |
return result |
Also available in: Unified diff