Commit 39a02558 authored by Guido Trotter's avatar Guido Trotter
Browse files

LUQueryInstances: fix querying for nic data



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: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent a2a24f4c
......@@ -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:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment