Revision e78a6817
b/lib/cmdlib.py | ||
---|---|---|
9657 | 9657 |
if self.op.mode == constants.INSTANCE_IMPORT: |
9658 | 9658 |
export_info = self._ReadExportInfo() |
9659 | 9659 |
self._ReadExportParams(export_info) |
9660 |
self._old_instance_name = export_info.get(constants.INISECT_INS, "name") |
|
9661 |
else: |
|
9662 |
self._old_instance_name = None |
|
9660 | 9663 |
|
9661 | 9664 |
if (not self.cfg.GetVGName() and |
9662 | 9665 |
self.op.disk_template not in constants.DTS_NOT_LVM): |
... | ... | |
9810 | 9813 |
|
9811 | 9814 |
self.src_images = disk_images |
9812 | 9815 |
|
9813 |
old_name = export_info.get(constants.INISECT_INS, "name") |
|
9814 |
if self.op.instance_name == old_name: |
|
9816 |
if self.op.instance_name == self._old_instance_name: |
|
9815 | 9817 |
for idx, nic in enumerate(self.nics): |
9816 | 9818 |
if nic.mac == constants.VALUE_AUTO: |
9817 | 9819 |
nic_mac_ini = "nic%d_mac" % idx |
... | ... | |
10162 | 10164 |
os_add_result.Raise("Could not add os for instance %s" |
10163 | 10165 |
" on node %s" % (instance, pnode_name)) |
10164 | 10166 |
|
10165 |
elif self.op.mode == constants.INSTANCE_IMPORT: |
|
10166 |
feedback_fn("* running the instance OS import scripts...") |
|
10167 |
else: |
|
10168 |
if self.op.mode == constants.INSTANCE_IMPORT: |
|
10169 |
feedback_fn("* running the instance OS import scripts...") |
|
10170 |
|
|
10171 |
transfers = [] |
|
10172 |
|
|
10173 |
for idx, image in enumerate(self.src_images): |
|
10174 |
if not image: |
|
10175 |
continue |
|
10176 |
|
|
10177 |
# FIXME: pass debug option from opcode to backend |
|
10178 |
dt = masterd.instance.DiskTransfer("disk/%s" % idx, |
|
10179 |
constants.IEIO_FILE, (image, ), |
|
10180 |
constants.IEIO_SCRIPT, |
|
10181 |
(iobj.disks[idx], idx), |
|
10182 |
None) |
|
10183 |
transfers.append(dt) |
|
10184 |
|
|
10185 |
import_result = \ |
|
10186 |
masterd.instance.TransferInstanceData(self, feedback_fn, |
|
10187 |
self.op.src_node, pnode_name, |
|
10188 |
self.pnode.secondary_ip, |
|
10189 |
iobj, transfers) |
|
10190 |
if not compat.all(import_result): |
|
10191 |
self.LogWarning("Some disks for instance %s on node %s were not" |
|
10192 |
" imported successfully" % (instance, pnode_name)) |
|
10193 |
|
|
10194 |
rename_from = self._old_instance_name |
|
10195 |
|
|
10196 |
elif self.op.mode == constants.INSTANCE_REMOTE_IMPORT: |
|
10197 |
feedback_fn("* preparing remote import...") |
|
10198 |
# The source cluster will stop the instance before attempting to make |
|
10199 |
# a connection. In some cases stopping an instance can take a long |
|
10200 |
# time, hence the shutdown timeout is added to the connection |
|
10201 |
# timeout. |
|
10202 |
connect_timeout = (constants.RIE_CONNECT_TIMEOUT + |
|
10203 |
self.op.source_shutdown_timeout) |
|
10204 |
timeouts = masterd.instance.ImportExportTimeouts(connect_timeout) |
|
10167 | 10205 |
|
10168 |
transfers = [] |
|
10206 |
assert iobj.primary_node == self.pnode.name |
|
10207 |
disk_results = \ |
|
10208 |
masterd.instance.RemoteImport(self, feedback_fn, iobj, self.pnode, |
|
10209 |
self.source_x509_ca, |
|
10210 |
self._cds, timeouts) |
|
10211 |
if not compat.all(disk_results): |
|
10212 |
# TODO: Should the instance still be started, even if some disks |
|
10213 |
# failed to import (valid for local imports, too)? |
|
10214 |
self.LogWarning("Some disks for instance %s on node %s were not" |
|
10215 |
" imported successfully" % (instance, pnode_name)) |
|
10169 | 10216 |
|
10170 |
for idx, image in enumerate(self.src_images): |
|
10171 |
if not image: |
|
10172 |
continue |
|
10217 |
rename_from = self.source_instance_name |
|
10173 | 10218 |
|
10174 |
# FIXME: pass debug option from opcode to backend |
|
10175 |
dt = masterd.instance.DiskTransfer("disk/%s" % idx, |
|
10176 |
constants.IEIO_FILE, (image, ), |
|
10177 |
constants.IEIO_SCRIPT, |
|
10178 |
(iobj.disks[idx], idx), |
|
10179 |
None) |
|
10180 |
transfers.append(dt) |
|
10181 |
|
|
10182 |
import_result = \ |
|
10183 |
masterd.instance.TransferInstanceData(self, feedback_fn, |
|
10184 |
self.op.src_node, pnode_name, |
|
10185 |
self.pnode.secondary_ip, |
|
10186 |
iobj, transfers) |
|
10187 |
if not compat.all(import_result): |
|
10188 |
self.LogWarning("Some disks for instance %s on node %s were not" |
|
10189 |
" imported successfully" % (instance, pnode_name)) |
|
10190 |
|
|
10191 |
elif self.op.mode == constants.INSTANCE_REMOTE_IMPORT: |
|
10192 |
feedback_fn("* preparing remote import...") |
|
10193 |
# The source cluster will stop the instance before attempting to make a |
|
10194 |
# connection. In some cases stopping an instance can take a long time, |
|
10195 |
# hence the shutdown timeout is added to the connection timeout. |
|
10196 |
connect_timeout = (constants.RIE_CONNECT_TIMEOUT + |
|
10197 |
self.op.source_shutdown_timeout) |
|
10198 |
timeouts = masterd.instance.ImportExportTimeouts(connect_timeout) |
|
10199 |
|
|
10200 |
assert iobj.primary_node == self.pnode.name |
|
10201 |
disk_results = \ |
|
10202 |
masterd.instance.RemoteImport(self, feedback_fn, iobj, self.pnode, |
|
10203 |
self.source_x509_ca, |
|
10204 |
self._cds, timeouts) |
|
10205 |
if not compat.all(disk_results): |
|
10206 |
# TODO: Should the instance still be started, even if some disks |
|
10207 |
# failed to import (valid for local imports, too)? |
|
10208 |
self.LogWarning("Some disks for instance %s on node %s were not" |
|
10209 |
" imported successfully" % (instance, pnode_name)) |
|
10219 |
else: |
|
10220 |
# also checked in the prereq part |
|
10221 |
raise errors.ProgrammerError("Unknown OS initialization mode '%s'" |
|
10222 |
% self.op.mode) |
|
10210 | 10223 |
|
10211 | 10224 |
# Run rename script on newly imported instance |
10212 | 10225 |
assert iobj.name == instance |
10213 | 10226 |
feedback_fn("Running rename script for %s" % instance) |
10214 | 10227 |
result = self.rpc.call_instance_run_rename(pnode_name, iobj, |
10215 |
self.source_instance_name,
|
|
10228 |
rename_from,
|
|
10216 | 10229 |
self.op.debug_level) |
10217 | 10230 |
if result.fail_msg: |
10218 | 10231 |
self.LogWarning("Failed to run rename script for %s on node" |
10219 | 10232 |
" %s: %s" % (instance, pnode_name, result.fail_msg)) |
10220 | 10233 |
|
10221 |
else: |
|
10222 |
# also checked in the prereq part |
|
10223 |
raise errors.ProgrammerError("Unknown OS initialization mode '%s'" |
|
10224 |
% self.op.mode) |
|
10225 |
|
|
10226 | 10234 |
assert not self.owned_locks(locking.LEVEL_NODE_RES) |
10227 | 10235 |
|
10228 | 10236 |
if self.op.start: |
Also available in: Unified diff