Add setting route by cmdline.

netsetup
Mike Hiretsky 13 years ago
parent 54c9e5b17b
commit 3dfd161d84

Binary file not shown.

@ -1134,16 +1134,53 @@ class cl_install(color_print, SignalInterrupt):
return (iface,ipaddr,mask,dhcpset)
def removeInvalidRoutes(routedata):
"""Remove route for device with new ip"""
network,gw,dev,src = routedata
if dev in invalidRouteIface:
return False
return True
def removeSpecifiedRoutes(routedata):
"""Remove route for user specified"""
network,gw,dev,src = routedata
if network in specifedNet:
return False
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))
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)))
if wrongIps:
raise InstallError(_("Wrong ip addresses %s in source IP")%
(",".join(wrongIps)))
newroutes = []
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]
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,
ipMatrix))
# check interfaces
getVar = self.clVars.Get
interfaces = getVar('os_install_net_interfaces')
specifiedIface = dhcps + map(lambda x:x[0],ipaddrs)
routeIface = map(lambda x:x[2],filter(lambda x:len(x)>2,routes))
routeIface = filter(lambda x:x,
map(lambda x:x[2],filter(lambda x:len(x)>2,routes)))
wrongIface = set(specifiedIface+routeIface)-set(interfaces)
# check correct iface
if wrongIface:
@ -1162,14 +1199,20 @@ class cl_install(color_print, SignalInterrupt):
('interfaces', 'ip', 'mask', 'dhcp_set'))
invalidRouteIface = []
self.setVarList(ipVars, map(changeIpData, self.clVars.zipVars(*ipVars)))
staticIps = filter(lambda x:x,getVar('os_install_net_ip'))
specifedNet = map(lambda x:x[0],routes)
routeVars = map(lambda x:'os_install_net_route_%s'%x,
('network', 'gw', 'dev', 'src'))
self.setVarList(routeVars,
#map(changeRouteData
filter(removeInvalidRoutes,
self.clVars.zipVars(*routeVars)))
try:
self.setVarList(routeVars,
specifedRoutes(routes,getVar('os_install_net_ip'),
filter(removeSpecifiedRoutes,
standardRoutes(self.clVars.zipVars(*ipVars),invalidRouteIface)+
filter(removeInvalidRoutes,
self.clVars.zipVars(*routeVars)))))
except InstallError,e:
self.printERROR(str(e))
return False
# check dup nets
if not self.checkDuplicate(routes,_("networks"),key=lambda x:x[0]):

@ -225,8 +225,9 @@ class install_cmd(share_cmd):
for ipaddr in values.ip:
if not re.match("^\w+:%s$"%iputils.IP_ADDR_NET,ipaddr):
self.optobj.error(_("option %s:") %"--ip" +\
" " + _("ip specifing error: '%s'") %\
ipaddr)
" " + _("ip specifing error: '{ip}' "
"(example: '{example}')").format(\
ip=ipaddr,example="eth0:192.168.0.21/16"))
if values.dns:
if not re.match("^{0}(,{0})*$".format(iputils.IP_ADDR),values.dns):
self.optobj.error(_("option %s:") %"--dns" +\
@ -238,7 +239,10 @@ class install_cmd(share_cmd):
"(:\w+(:{ipaddr})?)?)?$".format(
net=iputils.IP_ADDR_NET,ipaddr=iputils.IP_ADDR),route):
self.optobj.error(_("option %s:") %"--route" +\
" " + _("route specifing error: '%s'") % route)
" " + _("route specifing error: '{route}'"
"(example: '{example}'").format(
route=route,
example="10.0.0.0/24:192.168.1.1:eth0"))
if not (values.install or values.uninstall or values.live):
if values.v is False and \
values.d is None and \
@ -318,7 +322,8 @@ class install_cmd(share_cmd):
if dns:
self.logicObj.clVars.Set("os_install_net_dns",dns,True)
ipaddrs = map(lambda x:x.split(":"),ipaddrs or [])
routes = map(lambda x:x.split(":"),routes or [])
routes = map(lambda x:x+[""]*(4-len(x)),
map(lambda x:x.split(":"),routes or []))
dhcps = dhcps or []
if not self.logicObj.setNetwork(ipaddrs,dhcps,routes):
return False

Loading…
Cancel
Save