diff --git a/lago/providers/libvirt/network.py b/lago/providers/libvirt/network.py index 66e024c5..4087d897 100644 --- a/lago/providers/libvirt/network.py +++ b/lago/providers/libvirt/network.py @@ -52,6 +52,9 @@ def name(self): def gw(self): return self._spec.get('gw') + def subnet(self): + return self._spec.get('subnet') + def mtu(self): if self.libvirt_con.getLibVersion() > 3001001: return self._spec.get('mtu', '1500') @@ -180,7 +183,10 @@ def _ipv6_prefix(self, subnet, const='fd8f:1391:3a82:'): def _libvirt_xml(self): net_raw_xml = libvirt_utils.get_template('net_nat_template.xml') - subnet = self.gw().split('.')[2] + subnet = self.subnet() + if not subnet: + subnet = self.gw().split('.')[2] + ipv6_prefix = self._ipv6_prefix(subnet=subnet) mtu = self.mtu() diff --git a/tests/functional-sdk/test_sdk_sanity.py b/tests/functional-sdk/test_sdk_sanity.py index 10c26a31..7b956099 100644 --- a/tests/functional-sdk/test_sdk_sanity.py +++ b/tests/functional-sdk/test_sdk_sanity.py @@ -62,6 +62,10 @@ def init_str(images): dhcp: start: 100 end: 254 + + net-03: + type: nat + subnet: 250 """ ) template = Environment(loader=BaseLoader()).from_string(init_template) @@ -110,6 +114,12 @@ def test_custom_gateway(vms, nets, init_dict): assert nets[net_name].gw() == net['gw'] +def test_custom_subnet(vms, nets, init_dict): + for net_name, net in init_dict['nets'].iteritems(): + if 'subnet' in net: + assert nets[net_name].subnet() == net['subnet'] + + def test_vm_is_running(vms, vm_name): vm = vms[vm_name] assert vm.running()