LUQueryInstances: fix querying for nic data
authorGuido Trotter <ultrotter@google.com>
Tue, 16 Jun 2009 14:47:25 +0000 (15:47 +0100)
committerGuido Trotter <ultrotter@google.com>
Tue, 16 Jun 2009 15:03:01 +0000 (16:03 +0100)
Currently we support querying for "mac" "ip" or "bridge", meaning "the
one of the first nic. We are not checking that there is a first nic,
though, and thus could incur in errors. This patch fixes it by returning
"None" should there be no such nic, as it's done when explicitely asking
for a nic via nic.<field>/<N>

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/cmdlib.py

index 46c7810..096ee71 100644 (file)
@@ -3413,11 +3413,20 @@ class LUQueryInstances(NoHooksLU):
         elif field == "disk_template":
           val = instance.disk_template
         elif field == "ip":
-          val = instance.nics[0].ip
+          if instance.nics:
+            val = instance.nics[0].ip
+          else:
+            val = None
         elif field == "bridge":
-          val = instance.nics[0].bridge
+          if instance.nics:
+            val = instance.nics[0].bridge
+          else:
+            val = None
         elif field == "mac":
-          val = instance.nics[0].mac
+          if instance.nics:
+            val = instance.nics[0].mac
+          else:
+            val = None
         elif field == "sda_size" or field == "sdb_size":
           idx = ord(field[2]) - ord('a')
           try: