Revision 9bf56d77 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
6103 | 6103 |
self.adopt_disks = has_adopt |
6104 | 6104 |
|
6105 | 6105 |
# verify creation mode |
6106 |
if self.op.mode not in (constants.INSTANCE_CREATE, |
|
6107 |
constants.INSTANCE_IMPORT): |
|
6106 |
if self.op.mode not in constants.INSTANCE_CREATE_MODES: |
|
6108 | 6107 |
raise errors.OpPrereqError("Invalid instance creation mode '%s'" % |
6109 | 6108 |
self.op.mode, errors.ECODE_INVAL) |
6110 | 6109 |
|
... | ... | |
6114 | 6113 |
self.op.instance_name = self.hostname1.name |
6115 | 6114 |
# used in CheckPrereq for ip ping check |
6116 | 6115 |
self.check_ip = self.hostname1.ip |
6116 |
elif self.op.mode == constants.INSTANCE_REMOTE_IMPORT: |
|
6117 |
raise errors.OpPrereqError("Remote imports require names to be checked" % |
|
6118 |
errors.ECODE_INVAL) |
|
6117 | 6119 |
else: |
6118 | 6120 |
self.check_ip = None |
6119 | 6121 |
|
... | ... | |
6133 | 6135 |
" node must be given", |
6134 | 6136 |
errors.ECODE_INVAL) |
6135 | 6137 |
|
6138 |
self._cds = _GetClusterDomainSecret() |
|
6139 |
|
|
6136 | 6140 |
if self.op.mode == constants.INSTANCE_IMPORT: |
6137 | 6141 |
# On import force_variant must be True, because if we forced it at |
6138 | 6142 |
# initial install, our only chance when importing it back is that it |
... | ... | |
6142 | 6146 |
if self.op.no_install: |
6143 | 6147 |
self.LogInfo("No-installation mode has no effect during import") |
6144 | 6148 |
|
6145 |
else: # INSTANCE_CREATE
|
|
6149 |
elif self.op.mode == constants.INSTANCE_CREATE:
|
|
6146 | 6150 |
if getattr(self.op, "os_type", None) is None: |
6147 | 6151 |
raise errors.OpPrereqError("No guest OS specified", |
6148 | 6152 |
errors.ECODE_INVAL) |
... | ... | |
6151 | 6155 |
raise errors.OpPrereqError("No disk template specified", |
6152 | 6156 |
errors.ECODE_INVAL) |
6153 | 6157 |
|
6158 |
elif self.op.mode == constants.INSTANCE_REMOTE_IMPORT: |
|
6159 |
# Check handshake to ensure both clusters have the same domain secret |
|
6160 |
src_handshake = getattr(self.op, "source_handshake", None) |
|
6161 |
if not src_handshake: |
|
6162 |
raise errors.OpPrereqError("Missing source handshake", |
|
6163 |
errors.ECODE_INVAL) |
|
6164 |
|
|
6165 |
errmsg = masterd.instance.CheckRemoteExportHandshake(self._cds, |
|
6166 |
src_handshake) |
|
6167 |
if errmsg: |
|
6168 |
raise errors.OpPrereqError("Invalid handshake: %s" % errmsg, |
|
6169 |
errors.ECODE_INVAL) |
|
6170 |
|
|
6171 |
# Load and check source CA |
|
6172 |
self.source_x509_ca_pem = getattr(self.op, "source_x509_ca", None) |
|
6173 |
if not self.source_x509_ca_pem: |
|
6174 |
raise errors.OpPrereqError("Missing source X509 CA", |
|
6175 |
errors.ECODE_INVAL) |
|
6176 |
|
|
6177 |
try: |
|
6178 |
(cert, _) = utils.LoadSignedX509Certificate(self.source_x509_ca_pem, |
|
6179 |
self._cds) |
|
6180 |
except OpenSSL.crypto.Error, err: |
|
6181 |
raise errors.OpPrereqError("Unable to load source X509 CA (%s)" % |
|
6182 |
(err, ), errors.ECODE_INVAL) |
|
6183 |
|
|
6184 |
(errcode, msg) = utils.VerifyX509Certificate(cert, None, None) |
|
6185 |
if errcode is not None: |
|
6186 |
raise errors.OpPrereqError("Invalid source X509 CA (%s)" % (msg, ), |
|
6187 |
errors.ECODE_INVAL) |
|
6188 |
|
|
6189 |
self.source_x509_ca = cert |
|
6190 |
|
|
6191 |
src_instance_name = getattr(self.op, "source_instance_name", None) |
|
6192 |
if not src_instance_name: |
|
6193 |
raise errors.OpPrereqError("Missing source instance name", |
|
6194 |
errors.ECODE_INVAL) |
|
6195 |
|
|
6196 |
self.source_instance_name = \ |
|
6197 |
utils.GetHostInfo(utils.HostInfo.NormalizeName(src_instance_name)).name |
|
6198 |
|
|
6199 |
else: |
|
6200 |
raise errors.OpPrereqError("Invalid instance creation mode %r" % |
|
6201 |
self.op.mode, errors.ECODE_INVAL) |
|
6202 |
|
|
6154 | 6203 |
def ExpandNames(self): |
6155 | 6204 |
"""ExpandNames for CreateInstance. |
6156 | 6205 |
|
... | ... | |
6829 | 6878 |
self.LogWarning("Some disks for instance %s on node %s were not" |
6830 | 6879 |
" imported successfully" % (instance, pnode_name)) |
6831 | 6880 |
|
6881 |
elif self.op.mode == constants.INSTANCE_REMOTE_IMPORT: |
|
6882 |
feedback_fn("* preparing remote import...") |
|
6883 |
connect_timeout = constants.RIE_CONNECT_TIMEOUT |
|
6884 |
timeouts = masterd.instance.ImportExportTimeouts(connect_timeout) |
|
6885 |
|
|
6886 |
disk_results = masterd.instance.RemoteImport(self, feedback_fn, iobj, |
|
6887 |
self.source_x509_ca, |
|
6888 |
self._cds, timeouts) |
|
6889 |
if not compat.all(disk_results): |
|
6890 |
# TODO: Should the instance still be started, even if some disks |
|
6891 |
# failed to import (valid for local imports, too)? |
|
6892 |
self.LogWarning("Some disks for instance %s on node %s were not" |
|
6893 |
" imported successfully" % (instance, pnode_name)) |
|
6894 |
|
|
6895 |
# Run rename script on newly imported instance |
|
6896 |
assert iobj.name == instance |
|
6897 |
feedback_fn("Running rename script for %s" % instance) |
|
6898 |
result = self.rpc.call_instance_run_rename(pnode_name, iobj, |
|
6899 |
self.source_instance_name, |
|
6900 |
self.op.debug_level) |
|
6901 |
if result.fail_msg: |
|
6902 |
self.LogWarning("Failed to run rename script for %s on node" |
|
6903 |
" %s: %s" % (instance, pnode_name, result.fail_msg)) |
|
6904 |
|
|
6832 | 6905 |
else: |
6833 | 6906 |
# also checked in the prereq part |
6834 | 6907 |
raise errors.ProgrammerError("Unknown OS initialization mode '%s'" |
Also available in: Unified diff