diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 8fad4a1869807185e3121d9bb3ff6d9eac519a24..6d9386faf04eb3edfb8e7bc8cf2472ac16556454 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -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 diff --git a/lib/opcodes.py b/lib/opcodes.py index d99d7bd981f40b62330cf09a931121676d4ecf0b..457d4422155b7694ff4d26866562ce6fc3560750 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -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", ] diff --git a/scripts/gnt-instance b/scripts/gnt-instance index 3dd7baa6e5ebc20a7ea508d6f178ee1a6ce0c700..7d72dfd090dec503537adc51e7b221a6e9345eb5 100755 --- a/scripts/gnt-instance +++ b/scripts/gnt-instance @@ -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