This adds a new opcode parameter ‘name_check’ (similar to ip_check) that
is not required to be present (to easy backwards compatibility for
tools).
It also adds a CheckArguments to LUCreateInstance and changes the
workflow related to instance IP checks and NIC initialisation based on
it.
---
lib/cmdlib.py | 30 +++++++++++++++++++++++++-----
lib/opcodes.py | 2 +-
2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 9bbc196..0fa8bdc 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -5619,6 +5619,19 @@ class LUCreateInstance(LogicalUnit):
"hvparams", "beparams"]
REQ_BGL = False
+ def CheckArguments(self):
+ """Check arguments.
+
+ """
+ # do not require name_check to ease forward/backward compatibility
+ # for tools
+ if not hasattr(self.op, "name_check"):
+ self.op.name_check = True
+ if self.op.ip_check and not self.op.name_check:
+ # TODO: make the ip check more flexible and not depend on the name check
+ raise errors.OpPrereqError("Cannot do ip checks without a name check",
+ errors.ECODE_INVAL)
+
def _ExpandNode(self, node):
"""Expands and checks one node name.
@@ -5683,8 +5696,14 @@ class LUCreateInstance(LogicalUnit):
#### instance parameters check
# instance name verification
- hostname1 = utils.GetHostInfo(self.op.instance_name)
- self.op.instance_name = instance_name = hostname1.name
+ if self.op.name_check:
+ hostname1 = utils.GetHostInfo(self.op.instance_name)
+ self.op.instance_name = instance_name = hostname1.name
+ # used in CheckPrereq for ip ping check
+ self.check_ip = hostname1.ip
+ else:
+ instance_name = self.op.instance_name
+ self.check_ip = None
# this is just a preventive check, but someone might still add this
# instance in the meantime, and creation will fail at lock-add time
@@ -5713,6 +5732,10 @@ class LUCreateInstance(LogicalUnit):
if ip is None or ip.lower() == constants.VALUE_NONE:
nic_ip = None
elif ip.lower() == constants.VALUE_AUTO:
+ if not self.op.name_check:
+ raise errors.OpPrereqError("IP address set to auto but name checks"
+ " have been skipped. Aborting.",
+ errors.ECODE_INVAL)
nic_ip = hostname1.ip
else:
if not utils.IsValidIP(ip):
@@ -5780,9 +5803,6 @@ class LUCreateInstance(LogicalUnit):
errors.ECODE_INVAL)
self.disks.append({"size": size, "mode": mode})
- # used in CheckPrereq for ip ping check
- self.check_ip = hostname1.ip
-
# file storage checks
if (self.op.file_driver and
not self.op.file_driver in constants.FILE_DRIVER):
diff --git a/lib/opcodes.py b/lib/opcodes.py
index 0244144..80c802d 100644
--- a/lib/opcodes.py
+++ b/lib/opcodes.py
@@ -447,7 +447,7 @@ class OpCreateInstance(OpCode):
"pnode", "disk_template", "snode", "mode",
"disks", "nics",
"src_node", "src_path", "start",
- "wait_for_sync", "ip_check",
+ "wait_for_sync", "ip_check", "name_check",
"file_storage_dir", "file_driver",
"iallocator",
"hypervisor", "hvparams", "beparams",
--
1.6.5.4