diff options
-rw-r--r-- | os_net_config/impl_eni.py | 37 | ||||
-rw-r--r-- | os_net_config/tests/test_impl_eni.py | 30 |
2 files changed, 60 insertions, 7 deletions
diff --git a/os_net_config/impl_eni.py b/os_net_config/impl_eni.py index 53d540c..6b88e85 100644 --- a/os_net_config/impl_eni.py +++ b/os_net_config/impl_eni.py @@ -57,7 +57,10 @@ class ENINetConfig(os_net_config.NetConfig): if data: return data - _iface = "iface %s " % interface.name + if isinstance(interface, objects.Vlan): + _iface = "iface vlan%i " % interface.vlan_id + else: + _iface = "iface %s " % interface.name if static_addr and static_addr.version == 6: _iface += "inet6 " else: @@ -81,12 +84,29 @@ class ENINetConfig(os_net_config.NetConfig): for i in interface.members: data += " pre-up ip addr flush dev %s\n" % i.name elif interface.ovs_port: - data += "auto %s\n" % interface.name - data += "allow-%s %s\n" % (interface.bridge_name, interface.name) + if isinstance(interface, objects.Vlan): + data += "auto vlan%i\n" % interface.vlan_id + data += "allow-%s vlan%i\n" % (interface.bridge_name, + interface.vlan_id) + data += _iface + data += address_data + data += " ovs_bridge %s\n" % interface.bridge_name + data += " ovs_type OVSIntPort\n" + data += " ovs_options tag=%s\n" % interface.vlan_id + + else: + data += "auto %s\n" % interface.name + data += "allow-%s %s\n" % (interface.bridge_name, + interface.name) + data += _iface + data += address_data + data += " ovs_bridge %s\n" % interface.bridge_name + data += " ovs_type OVSPort\n" + elif isinstance(interface, objects.Vlan): + data += "auto vlan%i\n" % interface.vlan_id data += _iface data += address_data - data += " ovs_bridge %s\n" % interface.bridge_name - data += " ovs_type OVSPort\n" + data += " vlan-raw-device %s\n" % interface.device else: data += "auto %s\n" % interface.name data += _iface @@ -107,6 +127,13 @@ class ENINetConfig(os_net_config.NetConfig): if bridge.routes: self._addRoutes(bridge.name, bridge.routes) + def addVlan(self, vlan): + data = self._addCommon(vlan) + + self.interfaces[vlan.name] = data + if vlan.routes: + self._addRoutes(vlan.name, vlan.routes) + def _addRoutes(self, interface_name, routes=[]): data = "" for route in routes: diff --git a/os_net_config/tests/test_impl_eni.py b/os_net_config/tests/test_impl_eni.py index 8bd25d7..5a20093 100644 --- a/os_net_config/tests/test_impl_eni.py +++ b/os_net_config/tests/test_impl_eni.py @@ -51,6 +51,19 @@ iface br0 inet dhcp pre-up ip addr flush dev eth0 """ +_VLAN_NO_IP = """auto vlan5 +iface vlan5 inet manual + vlan-raw-device eth0 +""" + +_VLAN_OVS_PORT = """auto vlan5 +allow-br0 vlan5 +iface vlan5 inet manual + ovs_bridge br0 + ovs_type OVSIntPort + ovs_options tag=5 +""" + _RTS = """up route add -net 172.19.0.0 netmask 255.255.255.0 gw 192.168.1.1 down route del -net 172.19.0.0 netmask 255.255.255.0 gw 192.168.1.1 """ @@ -67,8 +80,8 @@ class TestENINetConfig(base.TestCase): def tearDown(self): super(TestENINetConfig, self).tearDown() - def get_interface_config(self): - return self.provider.interfaces[self.if_name] + def get_interface_config(self, name="eth0"): + return self.provider.interfaces[name] def get_route_config(self): return self.provider.routes[self.if_name] @@ -131,6 +144,19 @@ class TestENINetConfig(base.TestCase): self.assertEqual(_OVS_PORT_IFACE, self.get_interface_config()) self.assertEqual(_OVS_BRIDGE_DHCP, self.provider.bridges['br0']) + def test_vlan(self): + vlan = objects.Vlan('eth0', 5) + self.provider.addVlan(vlan) + self.assertEqual(_VLAN_NO_IP, self.get_interface_config('vlan5')) + + def test_vlan_ovs_bridge_int_port(self): + vlan = objects.Vlan('eth0', 5) + bridge = objects.OvsBridge('br0', use_dhcp=True, + members=[vlan]) + self.provider.addBridge(bridge) + self.provider.addVlan(vlan) + self.assertEqual(_VLAN_OVS_PORT, self.get_interface_config('vlan5')) + class TestENINetConfigApply(base.TestCase): |