1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 """Utility functions for storage.
31
32 """
33
34 import logging
35
36 from ganeti import constants
37
38
44
45
47 """Checks if a particular disk template is enabled.
48
49 """
50 return disk_template in enabled_disk_templates
51
52
58
59
65
66
68 """Check whether or not any lvm-based disk templates are enabled."""
69 return len(constants.DTS_LVM & set(enabled_disk_templates)) != 0
70
71
72 -def LvmGetsEnabled(enabled_disk_templates, new_enabled_disk_templates):
73 """Checks whether lvm was not enabled before, but will be enabled after
74 the operation.
75
76 """
77 if IsLvmEnabled(enabled_disk_templates):
78 return False
79 return len(constants.DTS_LVM & set(new_enabled_disk_templates)) != 0
80
81
83 """Retrieves the identifier of the default storage entity for the given
84 storage type.
85
86 @type cfg: C{objects.ConfigData}
87 @param cfg: the configuration data
88 @type disk_template: string
89 @param disk_template: a disk template, for example 'drbd'
90 @rtype: string
91 @return: identifier for a storage unit, for example the vg_name for lvm
92 storage
93
94 """
95 storage_type = constants.MAP_DISK_TEMPLATE_STORAGE_TYPE[disk_template]
96 cluster = cfg.GetClusterInfo()
97 if disk_template in constants.DTS_LVM:
98 return (storage_type, cfg.GetVGName())
99 elif disk_template == constants.DT_FILE:
100 return (storage_type, cluster.file_storage_dir)
101 elif disk_template == constants.DT_SHARED_FILE:
102 return (storage_type, cluster.shared_file_storage_dir)
103 else:
104 return (storage_type, None)
105
106
111
112
114 """Get the cluster's storage units for the given disk templates.
115
116 If any lvm-based disk template is requested, spindle information
117 is added to the request.
118
119 @type cfg: L{config.ConfigWriter}
120 @param cfg: Cluster configuration
121 @type disk_templates: list of string
122 @param disk_templates: list of disk templates for which the storage
123 units will be computed
124 @rtype: list of tuples (string, string)
125 @return: list of storage units, each storage unit being a tuple of
126 (storage_type, storage_key); storage_type is in
127 C{constants.STORAGE_TYPES} and the storage_key a string to
128 identify an entity of that storage type, for example a volume group
129 name for LVM storage or a file for file storage.
130
131 """
132 storage_units = []
133 for disk_template in disk_templates:
134 if DiskTemplateSupportsSpaceReporting(disk_template):
135 storage_units.append(
136 _GetDefaultStorageUnitForDiskTemplate(cfg, disk_template))
137 return storage_units
138
139
141 """Looks up the storage space info for a given disk template.
142
143 @type storage_space_info: list of dicts
144 @param storage_space_info: result of C{GetNodeInfo}
145 @type disk_template: string
146 @param disk_template: disk template to get storage space info
147 @rtype: tuple
148 @return: returns the element of storage_space_info that matches the given
149 disk template
150
151 """
152 storage_type = constants.MAP_DISK_TEMPLATE_STORAGE_TYPE[disk_template]
153 return LookupSpaceInfoByStorageType(storage_space_info, storage_type)
154
155
157 """Looks up the storage space info for a given storage type.
158
159 Note that this lookup can be ambiguous if storage space reporting for several
160 units of the same storage type was requested. This function is only supposed
161 to be used for legacy code in situations where it actually is unambiguous.
162
163 @type storage_space_info: list of dicts
164 @param storage_space_info: result of C{GetNodeInfo}
165 @type storage_type: string
166 @param storage_type: a storage type, which is included in the storage_units
167 list
168 @rtype: tuple
169 @return: returns the element of storage_space_info that matches the given
170 storage type
171
172 """
173 result = None
174 for unit_info in storage_space_info:
175 if unit_info["type"] == storage_type:
176 if result is None:
177 result = unit_info
178 else:
179
180 logging.warning("Storage space information requested for"
181 " ambiguous storage type '%s'.", storage_type)
182 return result
183
184
186 """Return the device minor number from a raw device number.
187
188 This is a replacement for os.minor working around the issue that
189 Python's os.minor still has the old definition. See Ganeti issue
190 1058 for more details.
191 """
192 return (dev & 0xff) | ((dev >> 12) & ~0xff)
193