Revision f9518d38 lib/config.py
b/lib/config.py | ||
---|---|---|
126 | 126 |
all_macs = self._AllMACs() |
127 | 127 |
return mac in all_macs |
128 | 128 |
|
129 |
@locking.ssynchronized(_config_lock, shared=1) |
|
130 |
def GenerateDRBDSecret(self): |
|
131 |
"""Generate a DRBD secret. |
|
132 |
|
|
133 |
This checks the current disks for duplicates. |
|
134 |
|
|
135 |
""" |
|
136 |
self._OpenConfig() |
|
137 |
all_secrets = self._AllDRBDSecrets() |
|
138 |
retries = 64 |
|
139 |
while retries > 0: |
|
140 |
secret = utils.GenerateSecret() |
|
141 |
if secret not in all_secrets: |
|
142 |
break |
|
143 |
retries -= 1 |
|
144 |
else: |
|
145 |
raise errors.ConfigurationError("Can't generate unique DRBD secret") |
|
146 |
return secret |
|
147 |
|
|
129 | 148 |
def _ComputeAllLVs(self): |
130 | 149 |
"""Compute the list of all LVs. |
131 | 150 |
|
... | ... | |
185 | 204 |
|
186 | 205 |
return result |
187 | 206 |
|
207 |
def _AllDRBDSecrets(self): |
|
208 |
"""Return all DRBD secrets present in the config. |
|
209 |
|
|
210 |
""" |
|
211 |
def helper(disk, result): |
|
212 |
"""Recursively gather secrets from this disk.""" |
|
213 |
if disk.dev_type == constants.DT_DRBD8: |
|
214 |
result.append(disk.logical_id[5]) |
|
215 |
if disk.children: |
|
216 |
for child in disk.children: |
|
217 |
helper(child, result) |
|
218 |
|
|
219 |
result = [] |
|
220 |
for instance in self._config_data.instances.values(): |
|
221 |
for disk in instance.disks: |
|
222 |
helper(disk, result) |
|
223 |
|
|
224 |
return result |
|
225 |
|
|
188 | 226 |
@locking.ssynchronized(_config_lock, shared=1) |
189 | 227 |
def VerifyConfig(self): |
190 | 228 |
"""Stub verify function. |
... | ... | |
268 | 306 |
if disk.logical_id is None and disk.physical_id is not None: |
269 | 307 |
return |
270 | 308 |
if disk.dev_type == constants.LD_DRBD8: |
271 |
pnode, snode, port, pminor, sminor = disk.logical_id |
|
309 |
pnode, snode, port, pminor, sminor, secret = disk.logical_id
|
|
272 | 310 |
if node_name not in (pnode, snode): |
273 | 311 |
raise errors.ConfigurationError("DRBD device not knowing node %s" % |
274 | 312 |
node_name) |
... | ... | |
280 | 318 |
p_data = (pnode_info.secondary_ip, port) |
281 | 319 |
s_data = (snode_info.secondary_ip, port) |
282 | 320 |
if pnode == node_name: |
283 |
disk.physical_id = p_data + s_data + (pminor,) |
|
321 |
disk.physical_id = p_data + s_data + (pminor, secret)
|
|
284 | 322 |
else: # it must be secondary, we tested above |
285 |
disk.physical_id = s_data + p_data + (sminor,) |
|
323 |
disk.physical_id = s_data + p_data + (sminor, secret)
|
|
286 | 324 |
else: |
287 | 325 |
disk.physical_id = disk.logical_id |
288 | 326 |
return |
... | ... | |
354 | 392 |
|
355 | 393 |
""" |
356 | 394 |
def _AppendUsedPorts(instance_name, disk, used): |
357 |
if disk.dev_type == constants.LD_DRBD8 and len(disk.logical_id) == 5:
|
|
358 |
nodeA, nodeB, dummy, minorA, minorB = disk.logical_id |
|
395 |
if disk.dev_type == constants.LD_DRBD8 and len(disk.logical_id) >= 5:
|
|
396 |
nodeA, nodeB, dummy, minorA, minorB = disk.logical_id[:5]
|
|
359 | 397 |
for node, port in ((nodeA, minorA), (nodeB, minorB)): |
360 | 398 |
assert node in used, "Instance node not found in node list" |
361 | 399 |
if port in used[node]: |
Also available in: Unified diff