From bef9c750c91346bc70ac6899f1e15e451add60ea Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Wed, 10 Jun 2009 16:28:36 +0100
Subject: [PATCH] KVM: NIC parameters

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/hypervisor/hv_kvm.py | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index e2114751a..56925bca7 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -150,17 +150,28 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     script.write("# this is autogenerated by Ganeti, please do not edit\n#\n")
     script.write("export INSTANCE=%s\n" % instance.name)
     script.write("export MAC=%s\n" % nic.mac)
-    script.write("export IP=%s\n" % nic.ip)
-    script.write("export BRIDGE=%s\n" % nic.bridge)
+    if nic.ip:
+      script.write("export IP=%s\n" % nic.ip)
+    script.write("export MODE=%s\n" % nic.nicparams[constants.NIC_MODE])
+    if nic.nicparams[constants.NIC_LINK]:
+      script.write("export LINK=%s\n" % nic.nicparams[constants.NIC_LINK])
+    if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED:
+      script.write("export BRIDGE=%s\n" % nic.nicparams[constants.NIC_LINK])
     script.write("export INTERFACE=$1\n")
     # TODO: make this configurable at ./configure time
     script.write("if [ -x '%s' ]; then\n" % self._KVM_NETWORK_SCRIPT)
     script.write("  # Execute the user-specific vif file\n")
     script.write("  %s\n" % self._KVM_NETWORK_SCRIPT)
     script.write("else\n")
-    script.write("  # Connect the interface to the bridge\n")
     script.write("  /sbin/ifconfig $INTERFACE 0.0.0.0 up\n")
-    script.write("  /usr/sbin/brctl addif $BRIDGE $INTERFACE\n")
+    if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED:
+      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:
+      script.write("  # Route traffic targeted at the IP to the interface\n")
+      script.write("  /sbin/ip route add $IP/32 dev $INTERFACE\n")
+      interface_proxy_arp = "/proc/sys/net/ipv4/conf/$INTERFACE/proxy_arp"
+      script.write("  /bin/echo 1 > %s\n" % interface_proxy_arp)
     script.write("fi\n\n")
     # As much as we'd like to put this in our _ROOT_DIR, that will happen to be
     # mounted noexec sometimes, so we'll have to find another place.
-- 
GitLab