From 0af0f6412550a3aec9e3ee9c6e2bca23ad98d9ab Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 9 Apr 2010 17:55:40 +0200 Subject: [PATCH] Reuse NIC information from export MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the user doesn't pass any nics in import, do not use a default one-nic, but instead read the nics from the export file as is. Fortunately the export and the way nics are read from the command line are compatible⦠Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/cli.py | 5 ++++- lib/cmdlib.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/cli.py b/lib/cli.py index 591926d53..08827061a 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -1536,9 +1536,12 @@ def GenericInstanceCreate(mode, opts, args): elif opts.no_nics: # no nics nics = [] - else: + elif mode == constants.INSTANCE_CREATE: # default of one nic, all auto nics = [{}] + else: + # mode == import + nics = [] if opts.disk_template == constants.DT_DISKLESS: if opts.disks or opts.sd_size is not None: diff --git a/lib/cmdlib.py b/lib/cmdlib.py index ea404a7f7..bb6a190e8 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -6278,6 +6278,17 @@ class LUCreateInstance(LogicalUnit): " is missing the disk information", errors.ECODE_INVAL) + if (not self.op.nics and + einfo.has_option(constants.INISECT_INS, "nic_count")): + nics = [] + for idx in range(einfo.getint(constants.INISECT_INS, "nic_count")): + ndict = {} + for name in list(constants.NICS_PARAMETERS) + ["ip", "mac"]: + v = einfo.get(constants.INISECT_INS, "nic%d_%s" % (idx, name)) + ndict[name] = v + nics.append(ndict) + self.op.nics = nics + if (self.op.hypervisor is None and einfo.has_option(constants.INISECT_INS, "hypervisor")): self.op.hypervisor = einfo.get(constants.INISECT_INS, "hypervisor") -- GitLab