def _getConfSubnets(): subnetTemplate = """ subnet %(subnet)s netmask %(netmask)s { option routers %(routers)s; } """ subnet = '' # All net types are defined together with NATing. Assuming NATing for # Local net type. Need to create a shared network. if Util.isTrueConfVal(self.nat) and _isAllDhcpGroupsDefined(dhcpGroups): subnet = """ shared-network StratusLab-LAN { """ for _type in self.NET_TYPES_DHCP: subnet += subnetTemplate % { 'subnet' : getattr(self, self._assembleDhcpAttributeName('%sSubnet' % _type)), 'netmask' : getattr(self, self._assembleDhcpAttributeName('%sNetmask' % _type)), 'routers' : getattr(self, self._assembleDhcpAttributeName('%sRouters' % _type))} subnet += "}\n" elif Util.isTrueConfVal(self.nat) and dhcpGroups['OneLocalNetwork']: subnet = """ shared-network StratusLab-LAN { """ # main interface subnet += """ subnet %(subnet)s netmask %(netmask)s { } """ % {'subnet' : self.dhcpSubnet, 'netmask' : self.dhcpNetmask} # virtual interface natGateway = getattr(self, 'natGateway', '') if not natGateway: natGateway = Util.gatewayIpFromNetAddress(self.natNetwork) subnet += subnetTemplate % {'subnet' : self.natNetwork, 'netmask' : self.natNetmask, 'routers' : natGateway} subnet += "}\n" elif dhcpGroups['OnePublicNetwork']: # main interface subnet += """ subnet %(subnet)s netmask %(netmask)s { } """ % {'subnet' : self.dhcpSubnet, 'netmask' : self.dhcpNetmask} elif dhcpGroups['OneLocalNetwork']: # virtual interface subnet = subnetTemplate % { 'subnet' : self.dhcpOneLocalNetworkSubnet, 'netmask' : self.dhcpOneLocalNetworkNetmask, 'routers' : self.dhcpOneLocalNetworkRouters} else: Util.printWarning('Invalid parameters combination to configure DHCP.') return subnet
def _configureFirewallNatNetworking(self): self._enableIpForwarding() device = self.natNetworkInterface ip = getattr(self, "natGateway", "") if not ip: ip = Util.gatewayIpFromNetAddress(self.natNetwork) self._configureVirtualNetInterface(device, ip, self.natNetmask)
def testGatewayIpFromNetAddress(self): self.assertEqual(Util.gatewayIpFromNetAddress('0.0.0.0'), '0.0.0.1')