From a379d9bdbe151c49fb9f04e26527f5ad0fd3eaf0 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Tue, 16 Jun 2009 17:57:21 +0100
Subject: [PATCH] Update gnt-instance batch-create for NIC params

This is compatible with the previous version, but also allows specifying
more than one nic, by giving a "nics" list of dicts. The two methods
(individual fields for the first nic, and list of all nics) are
incompatible with each other.

The default remains one nick with no parameters specified.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 scripts/gnt-instance | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/scripts/gnt-instance b/scripts/gnt-instance
index 903654d30..3ac16d7b1 100755
--- a/scripts/gnt-instance
+++ b/scripts/gnt-instance
@@ -396,9 +396,7 @@ def BatchCreate(opts, args):
                     "iallocator": None,
                     "primary_node": None,
                     "secondary_node": None,
-                    "ip": 'none',
-                    "mac": 'auto',
-                    "bridge": None,
+                    "nics": None,
                     "start": True,
                     "ip_check": True,
                     "hypervisor": None,
@@ -466,11 +464,24 @@ def BatchCreate(opts, args):
                                    (elem, name, err))
       disks.append({"size": size})
 
-    nic0 = {'ip': specs['ip'], 'bridge': specs['bridge'], 'mac': specs['mac']}
-
     utils.ForceDictType(specs['backend'], constants.BES_PARAMETER_TYPES)
     utils.ForceDictType(hvparams, constants.HVS_PARAMETER_TYPES)
 
+    tmp_nics = []
+    for field in ('ip', 'mac', 'mode', 'link', 'bridge'):
+      if field in specs:
+        if not tmp_nics:
+          tmp_nics.append({})
+        tmp_nics[0][field] = specs[field]
+
+    if specs['nics'] is not None and tmp_nics:
+      raise errors.OpPrereqError("'nics' list incompatible with using"
+                                 " individual nic fields as well")
+    elif specs['nics'] is not None:
+      tmp_nics = specs['nics']
+    elif not tmp_nics:
+      tmp_nics = [{}]
+
     op = opcodes.OpCreateInstance(instance_name=name,
                                   disks=disks,
                                   disk_template=specs['template'],
@@ -478,7 +489,7 @@ def BatchCreate(opts, args):
                                   os_type=specs['os'],
                                   pnode=specs['primary_node'],
                                   snode=specs['secondary_node'],
-                                  nics=[nic0],
+                                  nics=tmp_nics,
                                   start=specs['start'],
                                   ip_check=specs['ip_check'],
                                   wait_for_sync=True,
-- 
GitLab