Imporve net configuration

master3.3
Mike Hiretsky 12 years ago
parent fd68c6c445
commit a4ffe53013

@ -46,8 +46,8 @@ class NetHelper:
return \
_("Network configuration is unavailable for Flash install")
if self.routing and not self.Select('os_install_net_interfaces',
where='os_install_net_dhcp_set',
eq='off',limit=1):
where='os_install_net_status',
_notin=('off','dhcp'),limit=1):
return _("Network routing configuration is not available if all "
"interfaces are set to DHCP")
return ""
@ -102,25 +102,23 @@ class VariableOsNetInterfacesInfo(NetHelper,ReadonlyVariable):
return ", ".join(map(lambda x:"%s (%s)"%(x[0],x[1]),
listInterfacesInfo))
class VariableOsInstallNetData(NetHelper,TableVariable):
"""
Hash for information about net
"""
opt = ["--ip"]
opt = ["--iface"]
metavalue = "IFACE_SETTINGS"
source = ["os_install_net_interfaces",
"os_install_net_dhcp_set",
"os_install_net_ip",
"os_install_net_mask",
"os_install_net_name",
"os_install_net_mac"]
"os_install_net_status",
"os_install_net_mask",
"os_install_net_name",
"os_install_net_mac"]
def init(self):
self.label = _("Addresses")
# self.help = _("IP address with network (example:%s)")%"192.168.1.1/24"
self.help = _("Network interface, DHCP, IP address and network mask "
"(example: %s)")%" --ip eth0:off:192.168.1.1:24"
self.help = _("Network interface, DHCP or IP address and network mask "
"(example: %s)")%" --iface eth0:192.168.1.1:24"
class VariableOsInstallNetHostname(NetHelper,Variable):
"""
@ -214,26 +212,71 @@ class VariableOsInstallNetMac(NetHelper,ReadonlyVariable):
return map(lambda x:getMac(x),
self.Get('os_install_net_interfaces'))
class VariableOsInstallNetIp(NetHelper,Variable):
class VariableOsInstallNetStatus(NetHelper,Variable):
"""
IP for all network interfaces
Net status (dhcp,ip,or off)
"""
type = "list"
type = "choiceedit-list"
def init(self):
self.label = _("IP address")
def get(self):
return map(lambda x:getIp(x),
return map(self.getDefaultValue,
self.Get('os_install_net_interfaces'))
def getDefaultValue(self,iface):
def statusValue(ipaddr,dhcp):
if dhcp == "on":
return "dhcp"
elif ipaddr:
return ipaddr
else:
return "off"
rootDevNfs = self.Get('os_root_dev') == '/dev/nfs'
return statusValue(getIp(iface),"on" \
if rootDevNfs or isDhcpIp(iface) else "off")
def set(self,value):
value = map(lambda x:x.lower() if x else x,value)
ifaces = self.Get('os_install_net_interfaces')
return map(lambda x:self.getDefaultValue(x[1]) \
if x[0] == "auto" else x[0],
zip(value,ifaces))
def check(self,value):
dhcps = self.Get('os_install_net_dhcp_set')
wrongIp = filter(lambda x:x[0] and not checkIp(x[0]),
zip(value,dhcps))
if wrongIp:
if wrongIp[0][0]:
raise VariableError(_("Wrong IP address %s")%wrongIp[0][0])
for status in value:
if status not in map(lambda x:x[0],self.choice()) and \
not checkIp(status):
raise VariableError(_("Wrong IP address %s")%status)
def choice(self):
return (("dhcp",_("DHCP")),
("off", _("Disable")),
("auto", _("Auto")))
class VariableOsInstallNetIp(NetHelper,ReadonlyVariable):
"""
IP for all network interfaces
"""
type = "list"
def init(self):
self.label = _("IP address")
def get(self):
return map(lambda x:"" if x[1].lower() == "off" else
getIp(x[0]) if x[1].lower() == "dhcp" else x[1],
zip(self.Get('os_install_net_interfaces'),
self.Get('os_install_net_status')))
#def check(self,value):
# dhcps = self.Get('os_install_net_dhcp_set')
# wrongIp = filter(lambda x:x[0] and not checkIp(x[0]),
# zip(value,dhcps))
# if wrongIp:
# if wrongIp[0][0]:
# raise VariableError(_("Wrong IP address %s")%wrongIp[0][0])
class VariableOsInstallNetNetwork(NetHelper,ReadonlyVariable):
"""
@ -291,8 +334,8 @@ class VariableOsInstallNetMask(NetHelper,Variable):
return res
def check(self,value):
dhcps = self.Get('os_install_net_dhcp_set')
wrongMask = filter(lambda x:(x[0] or x[1] != "on") and \
dhcps = self.Get('os_install_net_status')
wrongMask = filter(lambda x:(x[0] or not x[1] in ("off","dhcp")) and \
not checkMask(x[0]),
zip(value,dhcps))
if wrongMask:
@ -316,24 +359,8 @@ class VariableOsInstallNetDhcpSet(NetHelper,Variable):
self.label = _("DHCP")
def get(self):
rootDevNfs = self.Get('os_root_dev') == '/dev/nfs'
return map(lambda x:"on" if rootDevNfs or isDhcpIp(x) else "off",
self.Get('os_install_net_interfaces'))
def set(self,value):
"""
Get method of receiving ip (dhcp on/off)
"""
def dhcpValue(interface,val):
if val.lower() in ("auto",""):
return "on" if isDhcpIp(interface) else "off"
else:
return val
value = Variable.set(self,value)
return list(starmap(dhcpValue,
zip(self.Get('os_install_net_interfaces'),
value)))
return map(lambda x:"on" if x == "dhcp" else "off",
self.Get('os_install_net_status'))
class VariableOsInstallNetRouteData(NetHelper,TableVariable):
"""
@ -359,12 +386,12 @@ class VariableOsInstallNetRouteData(NetHelper,TableVariable):
def get(self,hr=False):
"""Routing hash"""
interfaces = self.Get('os_install_net_interfaces')
interfaces_dhcp = self.Get('os_install_net_dhcp_set')
interfaces_status = self.Get('os_install_net_status')
interfaces_network = self.Get('os_install_net_network')
staticInterface = \
map(itemgetter(0,2),
filter(lambda x:x[1] == "off",
zip(interfaces,interfaces_dhcp,interfaces_network)))
filter(lambda x:not x[1] in ("off","dhcp"),
zip(interfaces,interfaces_status,interfaces_network)))
route_data = []
if staticInterface:
staticInterface,skipNet = zip(*staticInterface)
@ -620,9 +647,9 @@ class VariableOsInstallNetDnsSearch(NetHelper,Variable):
"""
If first interface get ip by DHCP dns must be DHCP
"""
dhcps = self.Get('os_install_net_dhcp_set')
if dhcps:
if dhcps[0] == "on":
statuses = self.Get('os_install_net_status')
if statuses:
if statuses[0] == "dhcp":
return True
return False

Loading…
Cancel
Save