Commit 5f23e043 authored by Iustin Pop's avatar Iustin Pop
Browse files

Op/LUCreateInstance support for (no) name checks



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.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 8b2df5f6
...@@ -5619,6 +5619,19 @@ class LUCreateInstance(LogicalUnit): ...@@ -5619,6 +5619,19 @@ class LUCreateInstance(LogicalUnit):
"hvparams", "beparams"] "hvparams", "beparams"]
REQ_BGL = False 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): def _ExpandNode(self, node):
"""Expands and checks one node name. """Expands and checks one node name.
...@@ -5683,8 +5696,14 @@ class LUCreateInstance(LogicalUnit): ...@@ -5683,8 +5696,14 @@ class LUCreateInstance(LogicalUnit):
#### instance parameters check #### instance parameters check
# instance name verification # instance name verification
hostname1 = utils.GetHostInfo(self.op.instance_name) if self.op.name_check:
self.op.instance_name = instance_name = hostname1.name 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 # this is just a preventive check, but someone might still add this
# instance in the meantime, and creation will fail at lock-add time # instance in the meantime, and creation will fail at lock-add time
...@@ -5713,6 +5732,10 @@ class LUCreateInstance(LogicalUnit): ...@@ -5713,6 +5732,10 @@ class LUCreateInstance(LogicalUnit):
if ip is None or ip.lower() == constants.VALUE_NONE: if ip is None or ip.lower() == constants.VALUE_NONE:
nic_ip = None nic_ip = None
elif ip.lower() == constants.VALUE_AUTO: 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 nic_ip = hostname1.ip
else: else:
if not utils.IsValidIP(ip): if not utils.IsValidIP(ip):
...@@ -5780,9 +5803,6 @@ class LUCreateInstance(LogicalUnit): ...@@ -5780,9 +5803,6 @@ class LUCreateInstance(LogicalUnit):
errors.ECODE_INVAL) errors.ECODE_INVAL)
self.disks.append({"size": size, "mode": mode}) self.disks.append({"size": size, "mode": mode})
# used in CheckPrereq for ip ping check
self.check_ip = hostname1.ip
# file storage checks # file storage checks
if (self.op.file_driver and if (self.op.file_driver and
not self.op.file_driver in constants.FILE_DRIVER): not self.op.file_driver in constants.FILE_DRIVER):
......
...@@ -447,7 +447,7 @@ class OpCreateInstance(OpCode): ...@@ -447,7 +447,7 @@ class OpCreateInstance(OpCode):
"pnode", "disk_template", "snode", "mode", "pnode", "disk_template", "snode", "mode",
"disks", "nics", "disks", "nics",
"src_node", "src_path", "start", "src_node", "src_path", "start",
"wait_for_sync", "ip_check", "wait_for_sync", "ip_check", "name_check",
"file_storage_dir", "file_driver", "file_storage_dir", "file_driver",
"iallocator", "iallocator",
"hypervisor", "hvparams", "beparams", "hypervisor", "hvparams", "beparams",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment