Revision c1c31426
b/lib/cmdlib.py | ||
---|---|---|
6201 | 6201 |
self.secondaries) |
6202 | 6202 |
return env, nl, nl |
6203 | 6203 |
|
6204 |
def _ReadExportInfo(self): |
|
6205 |
"""Reads the export information from disk. |
|
6206 |
|
|
6207 |
It will override the opcode source node and path with the actual |
|
6208 |
information, if these two were not specified before. |
|
6209 |
|
|
6210 |
@return: the export information |
|
6211 |
|
|
6212 |
""" |
|
6213 |
assert self.op.mode == constants.INSTANCE_IMPORT |
|
6214 |
|
|
6215 |
src_node = self.op.src_node |
|
6216 |
src_path = self.op.src_path |
|
6217 |
|
|
6218 |
if src_node is None: |
|
6219 |
locked_nodes = self.acquired_locks[locking.LEVEL_NODE] |
|
6220 |
exp_list = self.rpc.call_export_list(locked_nodes) |
|
6221 |
found = False |
|
6222 |
for node in exp_list: |
|
6223 |
if exp_list[node].fail_msg: |
|
6224 |
continue |
|
6225 |
if src_path in exp_list[node].payload: |
|
6226 |
found = True |
|
6227 |
self.op.src_node = src_node = node |
|
6228 |
self.op.src_path = src_path = utils.PathJoin(constants.EXPORT_DIR, |
|
6229 |
src_path) |
|
6230 |
break |
|
6231 |
if not found: |
|
6232 |
raise errors.OpPrereqError("No export found for relative path %s" % |
|
6233 |
src_path, errors.ECODE_INVAL) |
|
6234 |
|
|
6235 |
_CheckNodeOnline(self, src_node) |
|
6236 |
result = self.rpc.call_export_info(src_node, src_path) |
|
6237 |
result.Raise("No export or invalid export found in dir %s" % src_path) |
|
6238 |
|
|
6239 |
export_info = objects.SerializableConfigParser.Loads(str(result.payload)) |
|
6240 |
if not export_info.has_section(constants.INISECT_EXP): |
|
6241 |
raise errors.ProgrammerError("Corrupted export config", |
|
6242 |
errors.ECODE_ENVIRON) |
|
6243 |
|
|
6244 |
ei_version = export_info.get(constants.INISECT_EXP, "version") |
|
6245 |
if (int(ei_version) != constants.EXPORT_VERSION): |
|
6246 |
raise errors.OpPrereqError("Wrong export version %s (wanted %d)" % |
|
6247 |
(ei_version, constants.EXPORT_VERSION), |
|
6248 |
errors.ECODE_ENVIRON) |
|
6249 |
return export_info |
|
6204 | 6250 |
|
6205 | 6251 |
def CheckPrereq(self): |
6206 | 6252 |
"""Check prerequisites. |
6207 | 6253 |
|
6208 | 6254 |
""" |
6255 |
if self.op.mode == constants.INSTANCE_IMPORT: |
|
6256 |
export_info = self._ReadExportInfo() |
|
6257 |
|
|
6209 | 6258 |
if (not self.cfg.GetVGName() and |
6210 | 6259 |
self.op.disk_template not in constants.DTS_NOT_LVM): |
6211 | 6260 |
raise errors.OpPrereqError("Cluster does not support lvm-based" |
... | ... | |
6329 | 6378 |
self.disks.append(new_disk) |
6330 | 6379 |
|
6331 | 6380 |
if self.op.mode == constants.INSTANCE_IMPORT: |
6332 |
src_node = self.op.src_node |
|
6333 |
src_path = self.op.src_path |
|
6334 |
|
|
6335 |
if src_node is None: |
|
6336 |
locked_nodes = self.acquired_locks[locking.LEVEL_NODE] |
|
6337 |
exp_list = self.rpc.call_export_list(locked_nodes) |
|
6338 |
found = False |
|
6339 |
for node in exp_list: |
|
6340 |
if exp_list[node].fail_msg: |
|
6341 |
continue |
|
6342 |
if src_path in exp_list[node].payload: |
|
6343 |
found = True |
|
6344 |
self.op.src_node = src_node = node |
|
6345 |
self.op.src_path = src_path = utils.PathJoin(constants.EXPORT_DIR, |
|
6346 |
src_path) |
|
6347 |
break |
|
6348 |
if not found: |
|
6349 |
raise errors.OpPrereqError("No export found for relative path %s" % |
|
6350 |
src_path, errors.ECODE_INVAL) |
|
6351 |
|
|
6352 |
_CheckNodeOnline(self, src_node) |
|
6353 |
result = self.rpc.call_export_info(src_node, src_path) |
|
6354 |
result.Raise("No export or invalid export found in dir %s" % src_path) |
|
6355 |
|
|
6356 |
export_info = objects.SerializableConfigParser.Loads(str(result.payload)) |
|
6357 |
if not export_info.has_section(constants.INISECT_EXP): |
|
6358 |
raise errors.ProgrammerError("Corrupted export config", |
|
6359 |
errors.ECODE_ENVIRON) |
|
6360 |
|
|
6361 |
ei_version = export_info.get(constants.INISECT_EXP, 'version') |
|
6362 |
if (int(ei_version) != constants.EXPORT_VERSION): |
|
6363 |
raise errors.OpPrereqError("Wrong export version %s (wanted %d)" % |
|
6364 |
(ei_version, constants.EXPORT_VERSION), |
|
6365 |
errors.ECODE_ENVIRON) |
|
6366 | 6381 |
|
6367 | 6382 |
# Check that the new instance doesn't have less disks than the export |
6368 | 6383 |
instance_disks = len(self.disks) |
... | ... | |
6380 | 6395 |
if export_info.has_option(constants.INISECT_INS, option): |
6381 | 6396 |
# FIXME: are the old os-es, disk sizes, etc. useful? |
6382 | 6397 |
export_name = export_info.get(constants.INISECT_INS, option) |
6383 |
image = utils.PathJoin(src_path, export_name) |
|
6398 |
image = utils.PathJoin(self.op.src_path, export_name)
|
|
6384 | 6399 |
disk_images.append(image) |
6385 | 6400 |
else: |
6386 | 6401 |
disk_images.append(False) |
Also available in: Unified diff