From b4364a6bf0348ed6a49204401e2294b8da79f686 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Mon, 24 Nov 2008 09:48:11 +0000 Subject: [PATCH] LUCreateInstance: Fix import mac AUTO mode Previously on import LUCreateInstance used to recycle the mac if the instance name was the same than the one used at export time. Now we do the same, but apply the setting separately for each nic. Reviewed-by: iustinp --- lib/cmdlib.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 54f632a76..b696efcb9 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -3610,16 +3610,16 @@ class LUCreateInstance(LogicalUnit): self.src_images = disk_images - if self.op.mac == constants.VALUE_AUTO: - old_name = export_info.get(constants.INISECT_INS, 'name') - if self.op.instance_name == old_name: - # FIXME: adjust every nic, when we'll be able to create instances - # with more than one - if int(export_info.get(constants.INISECT_INS, 'nic_count')) >= 1: - self.op.mac = export_info.get(constants.INISECT_INS, 'nic_0_mac') + old_name = export_info.get(constants.INISECT_INS, 'name') + # FIXME: int() here could throw a ValueError on broken exports + exp_nic_count = int(export_info.get(constants.INISECT_INS, 'nic_count')) + if self.op.instance_name == old_name: + for idx, nic in enumerate(self.nics): + if nic.mac == constants.VALUE_AUTO and exp_nic_count >= idx: + nic_mac_ini = 'nic%d_mac' % idx + nic.mac = export_info.get(constants.INISECT_INS, nic_mac_ini) # ip ping checks (we use the same ip that was resolved in ExpandNames) - if self.op.start and not self.op.ip_check: raise errors.OpPrereqError("Cannot ignore IP address conflicts when" " adding an instance in start mode") -- GitLab