Revision a03fcb26 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
6287 | 6287 |
return "originstname+%s" % instance.name |
6288 | 6288 |
|
6289 | 6289 |
|
6290 |
def _CalcEta(time_taken, written, total_size): |
|
6291 |
"""Calculates the ETA based on size written and total size. |
|
6292 |
|
|
6293 |
@param time_taken: The time taken so far |
|
6294 |
@param written: amount written so far |
|
6295 |
@param total_size: The total size of data to be written |
|
6296 |
@return: The remaining time in seconds |
|
6297 |
|
|
6298 |
""" |
|
6299 |
avg_time = time_taken / float(written) |
|
6300 |
return (total_size - written) * avg_time |
|
6301 |
|
|
6302 |
|
|
6303 |
def _WipeDisks(lu, instance): |
|
6304 |
"""Wipes instance disks. |
|
6305 |
|
|
6306 |
@type lu: L{LogicalUnit} |
|
6307 |
@param lu: the logical unit on whose behalf we execute |
|
6308 |
@type instance: L{objects.Instance} |
|
6309 |
@param instance: the instance whose disks we should create |
|
6310 |
@return: the success of the wipe |
|
6311 |
|
|
6312 |
""" |
|
6313 |
node = instance.primary_node |
|
6314 |
for idx, device in enumerate(instance.disks): |
|
6315 |
lu.LogInfo("* Wiping disk %d", idx) |
|
6316 |
logging.info("Wiping disk %d for instance %s", idx, instance.name) |
|
6317 |
|
|
6318 |
# The wipe size is MIN_WIPE_CHUNK_PERCENT % of the instance disk but |
|
6319 |
# MAX_WIPE_CHUNK at max |
|
6320 |
wipe_chunk_size = min(constants.MAX_WIPE_CHUNK, device.size / 100.0 * |
|
6321 |
constants.MIN_WIPE_CHUNK_PERCENT) |
|
6322 |
|
|
6323 |
offset = 0 |
|
6324 |
size = device.size |
|
6325 |
last_output = 0 |
|
6326 |
start_time = time.time() |
|
6327 |
|
|
6328 |
while offset < size: |
|
6329 |
wipe_size = min(wipe_chunk_size, size - offset) |
|
6330 |
result = lu.rpc.call_blockdev_wipe(node, device, offset, wipe_size) |
|
6331 |
result.Raise("Could not wipe disk %d at offset %d for size %d" % |
|
6332 |
(idx, offset, wipe_size)) |
|
6333 |
now = time.time() |
|
6334 |
offset += wipe_size |
|
6335 |
if now - last_output >= 60: |
|
6336 |
eta = _CalcEta(now - start_time, offset, size) |
|
6337 |
lu.LogInfo(" - done: %.1f%% ETA: %s" % |
|
6338 |
(offset / float(size) * 100, utils.FormatSeconds(eta))) |
|
6339 |
last_output = now |
|
6340 |
|
|
6341 |
|
|
6290 | 6342 |
def _CreateDisks(lu, instance, to_skip=None, target_node=None): |
6291 | 6343 |
"""Create all disks for an instance. |
6292 | 6344 |
|
... | ... | |
7261 | 7313 |
self.cfg.ReleaseDRBDMinors(instance) |
7262 | 7314 |
raise |
7263 | 7315 |
|
7316 |
if self.cfg.GetClusterInfo().prealloc_wipe_disks: |
|
7317 |
feedback_fn("* wiping instance disks...") |
|
7318 |
try: |
|
7319 |
_WipeDisks(self, iobj) |
|
7320 |
except errors.OpExecError: |
|
7321 |
self.LogWarning("Device wiping failed, reverting...") |
|
7322 |
try: |
|
7323 |
_RemoveDisks(self, iobj) |
|
7324 |
finally: |
|
7325 |
self.cfg.ReleaseDRBDMinors(instance) |
|
7326 |
raise |
|
7327 |
|
|
7264 | 7328 |
feedback_fn("adding instance %s to cluster config" % instance) |
7265 | 7329 |
|
7266 | 7330 |
self.cfg.AddInstance(iobj, self.proc.GetECId()) |
Also available in: Unified diff