Revision 0247d20f lib/cmdlib/instance_storage.py
b/lib/cmdlib/instance_storage.py | ||
---|---|---|
1 | 1 |
# |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc. |
|
4 |
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
1095 | 1095 |
" failed", idx, instance.name) |
1096 | 1096 |
|
1097 | 1097 |
|
1098 |
def ImageDisks(lu, instance, image, disks=None): |
|
1099 |
"""Dumps an image onto an instance disk. |
|
1100 |
|
|
1101 |
@type lu: L{LogicalUnit} |
|
1102 |
@param lu: the logical unit on whose behalf we execute |
|
1103 |
@type instance: L{objects.Instance} |
|
1104 |
@param instance: the instance whose disks we should create |
|
1105 |
@type image: string |
|
1106 |
@param image: the image whose disks we should create |
|
1107 |
@type disks: None or list of ints |
|
1108 |
@param disks: disk indices |
|
1109 |
|
|
1110 |
""" |
|
1111 |
node_uuid = instance.primary_node |
|
1112 |
node_name = lu.cfg.GetNodeName(node_uuid) |
|
1113 |
|
|
1114 |
if disks is None: |
|
1115 |
disks = [(0, instance.disks[0])] |
|
1116 |
else: |
|
1117 |
disks = map(lambda idx: instance.disks[idx], disks) |
|
1118 |
|
|
1119 |
logging.info("Pausing synchronization of disks of instance '%s'", |
|
1120 |
instance.name) |
|
1121 |
result = lu.rpc.call_blockdev_pause_resume_sync(node_uuid, |
|
1122 |
(map(compat.snd, disks), |
|
1123 |
instance), |
|
1124 |
True) |
|
1125 |
result.Raise("Failed to pause disk synchronization on node '%s'" % node_name) |
|
1126 |
|
|
1127 |
for idx, success in enumerate(result.payload): |
|
1128 |
if not success: |
|
1129 |
logging.warn("Pausing synchronization of disk %s of instance '%s'" |
|
1130 |
" failed", idx, instance.name) |
|
1131 |
|
|
1132 |
try: |
|
1133 |
for (idx, device) in disks: |
|
1134 |
lu.LogInfo("Imaging disk '%d' for instance '%s' on node '%s'", |
|
1135 |
idx, instance.name, node_name) |
|
1136 |
|
|
1137 |
result = lu.rpc.call_blockdev_image(node_uuid, (device, instance), |
|
1138 |
image, device.size) |
|
1139 |
result.Raise("Could not image disk '%d' for instance '%s' on node '%s'" % |
|
1140 |
(idx, instance.name, node_name)) |
|
1141 |
finally: |
|
1142 |
logging.info("Resuming synchronization of disks for instance '%s'", |
|
1143 |
instance.name) |
|
1144 |
|
|
1145 |
result = lu.rpc.call_blockdev_pause_resume_sync(node_uuid, |
|
1146 |
(map(compat.snd, disks), |
|
1147 |
instance), |
|
1148 |
False) |
|
1149 |
|
|
1150 |
if result.fail_msg: |
|
1151 |
lu.LogWarning("Failed to resume disk synchronization for instance '%s' on" |
|
1152 |
" node '%s'", node_name, result.fail_msg) |
|
1153 |
else: |
|
1154 |
for idx, success in enumerate(result.payload): |
|
1155 |
if not success: |
|
1156 |
lu.LogWarning("Failed to resume synchronization of disk '%d' of" |
|
1157 |
" instance '%s'", idx, instance.name) |
|
1158 |
|
|
1159 |
|
|
1098 | 1160 |
def WipeOrCleanupDisks(lu, instance, disks=None, cleanup=None): |
1099 | 1161 |
"""Wrapper for L{WipeDisks} that handles errors. |
1100 | 1162 |
|
Also available in: Unified diff