This shouldn't happen, but if it does it's better to fail at this level,
rather than create a broken NIC script, which is hard to debug.

Signed-off-by: Guido Trotter <[email protected]>
---
 lib/hypervisor/hv_kvm.py |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index a153d36..a478a53 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -183,6 +183,8 @@ class KVMHypervisor(hv_base.BaseHypervisor):
       script.write("  # Connect the interface to the bridge\n")
       script.write("  /usr/sbin/brctl addif $BRIDGE $INTERFACE\n")
     elif nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_ROUTED:
+      if not nic.ip:
+        raise errors.HypervisorError("nic/%d is routed, but has no ip." % seq)
       script.write("  # Route traffic targeted at the IP to the interface\n")
       if nic.nicparams[constants.NIC_LINK]:
         script.write("  while /sbin/ip rule del dev $INTERFACE; do :; done\n")
-- 
1.6.5

Reply via email to