Commit 3fe11ba3 authored by Manuel Franceschini's avatar Manuel Franceschini
Browse files

gnt-instance rename: Fix bug and rename params



This patch fixes a bug when gnt-instance rename was invoked with
--no-name-check. It renames the internal variables to be consistent with
the ones in equivalent instance add code. Furthermore it checks whether
and instance rename is invoked with --no-name-check but without
--no-ip-check and throws an exception if so.
Signed-off-by: default avatarManuel Franceschini <livewire@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 452913ed
......@@ -4870,10 +4870,19 @@ class LURenameInstance(LogicalUnit):
_OP_PARAMS = [
_PInstanceName,
("new_name", _NoDefault, _TNonEmptyString),
("ignore_ip", False, _TBool),
("check_name", True, _TBool),
("ip_check", False, _TBool),
("name_check", True, _TBool),
]
def CheckArguments(self):
"""Check arguments.
"""
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 check without a name check",
errors.ECODE_INVAL)
def BuildHooksEnv(self):
"""Build hooks env.
......@@ -4899,23 +4908,21 @@ class LURenameInstance(LogicalUnit):
_CheckInstanceDown(self, instance, "cannot rename")
self.instance = instance
# new name verification
if self.op.check_name:
name_info = netutils.GetHostInfo(self.op.new_name)
self.op.new_name = name_info.name
new_name = self.op.new_name
if self.op.name_check:
hostinfo = netutils.HostInfo(netutils.HostInfo.NormalizeName(new_name))
new_name = hostinfo.name
if (self.op.ip_check and
netutils.TcpPing(hostinfo.ip, constants.DEFAULT_NODED_PORT)):
raise errors.OpPrereqError("IP %s of instance %s already in use" %
(hostinfo.ip, new_name),
errors.ECODE_NOTUNIQUE)
instance_list = self.cfg.GetInstanceList()
if new_name in instance_list:
raise errors.OpPrereqError("Instance '%s' is already in the cluster" %
new_name, errors.ECODE_EXISTS)
if not self.op.ignore_ip:
if netutils.TcpPing(name_info.ip, constants.DEFAULT_NODED_PORT):
raise errors.OpPrereqError("IP %s of instance %s already in use" %
(name_info.ip, new_name),
errors.ECODE_NOTUNIQUE)
def Exec(self, feedback_fn):
"""Reinstall the instance.
......@@ -6527,7 +6534,7 @@ class LUCreateInstance(LogicalUnit):
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",
raise errors.OpPrereqError("Cannot do ip check without a name check",
errors.ECODE_INVAL)
# check nics' parameter names
......
......@@ -505,7 +505,7 @@ class OpRenameInstance(OpCode):
"""Rename an instance."""
OP_ID = "OP_INSTANCE_RENAME"
__slots__ = [
"instance_name", "ignore_ip", "new_name", "check_name",
"instance_name", "ip_check", "new_name", "name_check",
]
......
......@@ -634,8 +634,8 @@ def RenameInstance(opts, args):
op = opcodes.OpRenameInstance(instance_name=args[0],
new_name=args[1],
ignore_ip=not opts.ip_check,
check_name=opts.name_check)
ip_check=opts.ip_check,
name_check=opts.name_check)
SubmitOrSend(op, opts)
return 0
......
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