diff --git a/pym/cl_fill_install.py b/pym/cl_fill_install.py index e454a7c..2144f20 100644 --- a/pym/cl_fill_install.py +++ b/pym/cl_fill_install.py @@ -114,7 +114,7 @@ class fillVars(object, glob_attr): 'name':_("vendor")}) mapInterface = {} mapInterface["ip"] = ipaddr - mapInterface["mask"] = mask + mapInterface["cidr"] = str(ip.maskToCidr(mask)) if mask else "" mapInterface["dhcp"] = "on" if dhcp else "off" mapInterface["mac"] = mac mapInterface["name"] = "{vendor} {name}".format(**pciInfo) @@ -142,27 +142,58 @@ class fillVars(object, glob_attr): param['dev'] = routeParam.get('dev','') route_hash[network] = param return route_hash - - def get_os_install_net_route(self): - """Route info for conf.d/net""" + + def performRouteData(self,performFunc): routeMatrix = zip(self.Get('os_install_net_route_network'), self.Get('os_install_net_route_gw'), self.Get('os_install_net_route_dev'), self.Get('os_install_net_route_src')) - return map(lambda x:"\n".join( - # build string for route from net,gateway,dev and src - map(lambda z:"{net}{gateway}{src}".format( - net=z[0], - gateway=" via %s"%z[1] if z[1] else "", - src=" src %s"%z[3] if z[3] else ""), - # filter by interface and discard direct routes - # example: for 192.168.1.5/24 discard 192.168.1.0/24 net - filter(lambda z:x[0]==z[2] and x[1]!=z[0],routeMatrix))), + DEV,IP,CIDR,NET = 0,1,2,1 + return map(lambda x:performFunc(x[DEV],x[NET],routeMatrix), # union ip and mask to ip/net - map(lambda x:(x[0],ip.getIpNet(x[1],x[2])), + map(lambda x:(x[DEV],ip.getIpNet(x[IP],cidr=x[CIDR])), + filter(lambda x:x[IP] and x[CIDR], zip(self.Get('os_install_net_interfaces'), self.Get('os_install_net_ip'), - self.Get('os_install_net_mask')))) + self.Get('os_install_net_cidr'))))) + + def get_os_install_net_nmroute(self): + """Route info for system-connections of NetworkManager""" + def getRouteForInterfaceNM(interface,net,routeMatrix): + NET,GW,DEV,SRC = 0,1,2,3 + defaultGw = map(lambda x:"%s;"%x[GW], + filter(lambda x:interface==x[DEV] and \ + x[NET]=="default", + routeMatrix)) + return "{0}\n".format(defaultGw[0] if defaultGw else "") + \ + "\n".join( + # build string for route from net,gateway,dev and src + map(lambda x:"routes{num}={ip};{cidr};{gateway};0;".format( + num=x[0]+1, + ip=x[1][NET].partition('/')[0], + cidr=x[1][NET].partition('/')[2], + gateway=x[1][GW] if x[1][GW] else "0.0.0.0"), + # filter by interface and discard direct routes + # example: for 192.168.1.5/24 discard 192.168.1.0/24 net + enumerate( + filter(lambda x:interface==x[DEV] and net!=x[NET] and \ + x[NET]!="default",routeMatrix)))) + return self.performRouteData(getRouteForInterfaceNM) + + def get_os_install_net_route(self): + """Route info for conf.d/net""" + def getRouteForInterfaceConf(interface,net,routeMatrix): + NET,GW,DEV,SRC = 0,1,2,3 + return "\n".join( + # build string for route from net,gateway,dev and src + map(lambda x:"{net}{gateway}{src}".format( + net=x[NET], + gateway=" via %s"%x[GW] if x[GW] else "", + src=" src %s"%x[SRC] if x[SRC] else ""), + # filter by interface and discard direct routes + # example: for 192.168.1.5/24 discard 192.168.1.0/24 net + filter(lambda x:interface==x[DEV] and net!=x[NET],routeMatrix))) + return self.performRouteData(getRouteForInterfaceConf) def get_os_install_net_route_network(self): @@ -1048,9 +1079,9 @@ class fillVars(object, glob_attr): """Current ip""" return self.getAttributeFromHash('os_install_net_hash','ip') - def get_os_install_net_mask(self): + def get_os_install_net_cidr(self): """Current mask""" - return self.getAttributeFromHash('os_install_net_hash','mask') + return self.getAttributeFromHash('os_install_net_hash','cidr') def get_os_install_net_mac(self): """Current mac""" @@ -1093,7 +1124,8 @@ class fillVars(object, glob_attr): """Net setup (networkmanager or openrc)""" if filter(lambda x:x.lower() == ("networkmanager"), listDirectory('/etc/runlevels/boot')+ - listDirectory('/etc/runlevels/default')): + listDirectory('/etc/runlevels/default')) \ + or self.Get('os_install_root_type') == "livecd": if isPkgInstalled("net-misc/networkmanager", prefix=self.Get('cl_chroot_path')): return "networkmanager" diff --git a/pym/cl_install.py b/pym/cl_install.py index 2855194..e90ac8f 100644 --- a/pym/cl_install.py +++ b/pym/cl_install.py @@ -1118,21 +1118,20 @@ class cl_install(color_print, SignalInterrupt): def setNetwork(self,ipaddrs,dhcps,routes): """Set network configuration""" def changeIpData(ipdata): - iface,ipaddr,mask,dhcpset = ipdata + iface,ipaddr,cidr,dhcpset = ipdata if iface in dhcps: if dhcpset == "off": invalidRouteIface.append(iface) dhcpset = "on" - mask = "" + cidr = "" ipaddr = "" elif iface in dictIpAddr: - newipaddr,op,cidr = dictIpAddr[iface].partition('/') - newmask = ip.netToMask(int(cidr)) - if dhcpset == "on" or newipaddr != ipaddr or newmask != mask: + newipaddr,op,newcidr = dictIpAddr[iface].partition('/') + if dhcpset == "on" or newipaddr != ipaddr or newcidr != cidr: invalidRouteIface.append(iface) - ipaddr,mask = newipaddr,mask + ipaddr,cidr = newipaddr,newcidr dhcpset = "off" - return (iface,ipaddr,mask,dhcpset) + return (iface,ipaddr,cidr,dhcpset) def removeInvalidRoutes(routedata): """Remove route for device with new ip""" @@ -1149,16 +1148,20 @@ class cl_install(color_print, SignalInterrupt): return True def specifedRoutes(routes,ipAddrs,routedata): - nets = filter(lambda x:x != "default", - map(lambda x:x[0],routes)+map(lambda x:x[0],routedata)) - wrongGws = map(lambda x:x[1], - filter(lambda x:not ip.isIpInNet(x[1],*nets),routes)) + NET,GW,DEV,SRC=0,1,2,3 + nets = filter(lambda net:net != "default", + map(lambda x:x[NET],routes)+map(lambda x:x[NET],routedata)) + routes = filter(lambda x:x[GW] or x[SRC],routes) + wrongGws = map(lambda x:x[GW], + filter(lambda x:not ip.isIpInNet(x[GW],*nets), + filter(lambda x:x[GW], + routes))) if wrongGws: raise InstallError(_("Gateways %s is unreachable")% (",".join(wrongGws))) - wrongIps = map(lambda x:x[3], - filter(lambda x:not x[3] in ipAddrs, - filter(lambda x:x[3],routes))) + wrongIps = map(lambda x:x[SRC], + filter(lambda x:not x[SRC] in ipAddrs, + filter(lambda x:x[SRC],routes))) if wrongIps: raise InstallError(_("Wrong ip addresses %s in source IP")% (",".join(wrongIps))) @@ -1166,14 +1169,18 @@ class cl_install(color_print, SignalInterrupt): for network,gw,dev,src in routedata+routes: if not dev: gwnetwork = ip.isIpInNet(gw,*nets)[0] - dev = filter(lambda x:x[0]==gwnetwork, - routedata+newroutes)[0][2] + dev = filter(lambda x:x[NET]==gwnetwork, + routedata+newroutes)[0][DEV] + if not gw and not src: + continue newroutes.append((network,gw,dev,src)) return newroutes def standardRoutes(ipMatrix,needDev): - return map(lambda x:(ip.getIpNet(x[1],x[2]),"",x[0],x[1]), - filter(lambda x:x[3] =="off" and x[0] in needDev, + IFACE,IP,CIDR,DHCP = 0,1,2,3 + return map(lambda x:(ip.getIpNet(x[IP],cidr=x[CIDR]), + "",x[IFACE],x[IP]), + filter(lambda x:x[DHCP] =="off" and x[IFACE] in needDev, ipMatrix)) # check interfaces @@ -1197,7 +1204,7 @@ class cl_install(color_print, SignalInterrupt): # set user data to variables ipVars = map(lambda x:'os_install_net_%s'%x, - ('interfaces', 'ip', 'mask', 'dhcp_set')) + ('interfaces', 'ip', 'cidr', 'dhcp_set')) invalidRouteIface = [] self.setVarList(ipVars, map(changeIpData, self.clVars.zipVars(*ipVars))) specifedNet = map(lambda x:x[0],routes) @@ -1780,11 +1787,11 @@ class cl_install(color_print, SignalInterrupt): def generateTableNetworkData(self): """Get bind data for print table""" def ipInformation(listIpMaskDhcp): - ipaddr,mask,dhcp = listIpMaskDhcp + ipaddr,cidr,dhcp = listIpMaskDhcp if dhcp == "on": return _("DHCP") elif ipaddr: - return "{ip}/{net}".format(ip=ipaddr,net=ip.maskToNet(mask)) + return "{ip}/{cidr}".format(ip=ipaddr,cidr=cidr) else: return _("Off") clGet = self.clVars.Get @@ -1795,7 +1802,7 @@ class cl_install(color_print, SignalInterrupt): clGet('os_install_net_mac'), map(ipInformation, zip(clGet('os_install_net_ip'), - clGet('os_install_net_mask'), + clGet('os_install_net_cidr'), clGet('os_install_net_dhcp_set')))) def generateTableRouteData(self): diff --git a/pym/cl_install_cmd.py b/pym/cl_install_cmd.py index 475c267..b33f2a2 100644 --- a/pym/cl_install_cmd.py +++ b/pym/cl_install_cmd.py @@ -235,7 +235,7 @@ class install_cmd(share_cmd): values.dns) if values.route: for route in values.route: - if not re.match("^({net}|default):({ipaddr}" + if not re.match("^({net}|default):(({ipaddr})?" "(:\w+(:{ipaddr})?)?)?$".format( net=iputils.IP_ADDR_NET,ipaddr=iputils.IP_ADDR),route): self.optobj.error(_("option %s:") %"--route" +\ diff --git a/pym/cl_vars_install.py b/pym/cl_vars_install.py index d2a10e1..19c97d7 100644 --- a/pym/cl_vars_install.py +++ b/pym/cl_vars_install.py @@ -269,8 +269,8 @@ class Data: # ip for all network interfaces os_install_net_ip = {} - # ip mask - os_install_net_mask = {} + # ip cidr + os_install_net_cidr = {} # routing os_install_net_route_hash = {} @@ -287,9 +287,12 @@ class Data: # src for route os_install_net_route_src = {} - # data by route for interface + # data by route for conf.d/net os_install_net_route = {'hide':True} + # data by route for NetworkManager + os_install_net_nmroute = {'hide':True} + # dns servers os_install_net_dns = {}