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…
---
 lib/cli.py    |    5 ++++-
 lib/cmdlib.py |   11 +++++++++++
 2 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/lib/cli.py b/lib/cli.py
index 591926d..0882706 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 d8f1ea5..c372c05 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -6279,6 +6279,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")
-- 
1.7.0.1



-- 
To unsubscribe, reply using "remove me" as the subject.

Reply via email to