Revision f7b0366c
b/lib/cmdlib/backup.py | ||
---|---|---|
32 | 32 |
from ganeti import locking |
33 | 33 |
from ganeti import masterd |
34 | 34 |
from ganeti import utils |
35 |
from ganeti.utils import retry |
|
35 | 36 |
|
36 | 37 |
from ganeti.cmdlib.base import NoHooksLU, LogicalUnit |
37 |
from ganeti.cmdlib.common import CheckNodeOnline, ExpandNodeUuidAndName |
|
38 |
from ganeti.cmdlib.common import CheckNodeOnline, ExpandNodeUuidAndName, \ |
|
39 |
IsInstanceRunning |
|
38 | 40 |
from ganeti.cmdlib.instance_storage import StartInstanceDisks, \ |
39 |
ShutdownInstanceDisks, TemporaryDisk |
|
41 |
ShutdownInstanceDisks, TemporaryDisk, ImageDisks
|
|
40 | 42 |
from ganeti.cmdlib.instance_utils import GetClusterDomainSecret, \ |
41 | 43 |
BuildInstanceHookEnvByObject, CheckNodeNotDrained, RemoveInstance |
42 | 44 |
|
... | ... | |
387 | 389 |
# Finally, the conversion |
388 | 390 |
return math.ceil(byte_size / 1024. / 1024.) |
389 | 391 |
|
392 |
def _InstanceDiskSizeSum(self): |
|
393 |
"""Calculates the size of all the disks of the instance used in this LU. |
|
394 |
|
|
395 |
@rtype: int |
|
396 |
@return: Size of the disks in MiB |
|
397 |
|
|
398 |
""" |
|
399 |
return sum([d.size for d in self.instance.disks]) |
|
400 |
|
|
390 | 401 |
def ZeroFreeSpace(self, feedback_fn): |
391 | 402 |
"""Zeroes the free space on a shutdown instance. |
392 | 403 |
|
... | ... | |
401 | 412 |
src_node_uuid = self.instance.primary_node |
402 | 413 |
disk_size = self._DetermineImageSize(zeroing_image, src_node_uuid) |
403 | 414 |
|
404 |
with TemporaryDisk(self, self.instance, disk_size, feedback_fn) as _disk: |
|
405 |
pass |
|
415 |
# Calculate the sum prior to adding the temporary disk |
|
416 |
instance_disks_size_sum = self._InstanceDiskSizeSum() |
|
417 |
|
|
418 |
with TemporaryDisk(self, self.instance, disk_size, feedback_fn): |
|
419 |
feedback_fn("Activating instance disks") |
|
420 |
StartInstanceDisks(self, self.instance, False) |
|
421 |
|
|
422 |
feedback_fn("Imaging disk with zeroing image") |
|
423 |
ImageDisks(self, self.instance, zeroing_image) |
|
424 |
|
|
425 |
feedback_fn("Starting instance with zeroing image") |
|
426 |
result = self.rpc.call_instance_start(src_node_uuid, |
|
427 |
(self.instance, [], []), |
|
428 |
False, self.op.reason) |
|
429 |
result.Raise("Could not start instance %s when using the zeroing image " |
|
430 |
"%s" % (self.instance.name, zeroing_image)) |
|
431 |
|
|
432 |
# First wait for the instance to start up |
|
433 |
running_check = lambda: IsInstanceRunning(self, self.instance, |
|
434 |
check_user_shutdown=True) |
|
435 |
instance_up = retry.SimpleRetry(True, running_check, 5.0, |
|
436 |
self.op.shutdown_timeout) |
|
437 |
if not instance_up: |
|
438 |
raise errors.OpExecError("Could not boot instance when using the " |
|
439 |
"zeroing image %s" % zeroing_image) |
|
440 |
|
|
441 |
feedback_fn("Instance is up, now awaiting shutdown") |
|
442 |
|
|
443 |
# Then for it to be finished, detected by its shutdown |
|
444 |
timeout = self.op.zeroing_timeout_fixed + \ |
|
445 |
self.op.zeroing_timeout_per_mib * instance_disks_size_sum |
|
446 |
instance_up = retry.SimpleRetry(False, running_check, 20.0, timeout) |
|
447 |
if instance_up: |
|
448 |
self.LogWarning("Zeroing not completed prior to timeout; instance will" |
|
449 |
"be shut down forcibly") |
|
450 |
|
|
451 |
feedback_fn("Zeroing completed!") |
|
406 | 452 |
|
407 | 453 |
def Exec(self, feedback_fn): |
408 | 454 |
"""Export an instance to an image in the cluster. |
Also available in: Unified diff