def _ok(self, *args): combo = self.xml.get_widget("interfaceCombo") active = combo.get_active_iter() val = combo.get_model().get_value(active, 1) netdev = self.network.available()[val] # FIXME: need to do input validation if self.xml.get_widget("dhcpCheckbutton").get_active(): self.window.hide() w = gui.WaitWindow(_("Dynamic IP"), _("Sending request for IP information " "for %s...") %(netdev.get("device"))) ns = isys.dhcpNetDevice(netdev.get("device")) w.pop() if ns is not None: self.rc = gtk.RESPONSE_OK if ns: f = open("/etc/resolv.conf", "w") f.write("nameserver %s\n" % ns) f.close() isys.resetResolv() else: ipv4addr = self.xml.get_widget("ipv4Address").get_text() ipv4nm = self.xml.get_widget("ipv4Netmask").get_text() gateway = self.xml.get_widget("gatewayEntry").get_text() ns = self.xml.get_widget("nameserverEntry").get_text() try: network.sanityCheckIPString(ipv4addr) except network.IPMissing, msg: self._handleIPMissing(_("IP Address")) return except network.IPError, msg: self._handleIPError(_("IP Address"), msg) return
def _ok(self, *args): combo = self.xml.get_widget("interfaceCombo") active = combo.get_active_iter() val = combo.get_model().get_value(active, 1) netdev = self.network.available()[val] # FIXME: need to do input validation if self.xml.get_widget("dhcpCheckbutton").get_active(): self.window.hide() w = gui.WaitWindow( _("Dynamic IP"), _("Sending request for IP information " "for %s...") % (netdev.get("device"))) ns = isys.dhcpNetDevice(netdev.get("device")) w.pop() if ns is not None: self.rc = gtk.RESPONSE_OK if ns: f = open("/etc/resolv.conf", "w") f.write("nameserver %s\n" % ns) f.close() isys.resetResolv() else: ipv4addr = self.xml.get_widget("ipv4Address").get_text() ipv4nm = self.xml.get_widget("ipv4Netmask").get_text() gateway = self.xml.get_widget("gatewayEntry").get_text() ns = self.xml.get_widget("nameserverEntry").get_text() try: network.sanityCheckIPString(ipv4addr) except network.IPMissing, msg: self._handleIPMissing(_("IP Address")) return except network.IPError, msg: self._handleIPError(_("IP Address"), msg) return
def lookupHostname(self): # can't look things up if they don't exist! if not self.hostname or self.hostname == "localhost": return None if not self.primaryNS: return myns = self.primaryNS if not self.isConfigured: for dev in self.netdevices.values(): usemethod = dev.get('bootproto').lower() while True: if (usemethod == "ibft" and dev.get('onboot') == "yes"): try: if anaconda.id.iscsi.fwinfo["iface.bootproto"].lower() == "dhcp": usemethod = "dhcp" continue else: hwaddr = isys.getMacAddress(dev) if hwaddr != anaconda.id.iscsi.fwinfo["iface.hwaddress"]: log.error("The iBFT configuration does not belong to device %s," "falling back to dhcp", dev.get('device')) usemethod = "dhcp" continue isys.configNetDevice(dev.get('device'), anaconda.id.iscsi.fwinfo["iface.ipaddress"], anaconda.id.iscsi.fwinfo["iface.subnet_mask"], anaconda.id.iscsi.fwinfo["iface.gateway"]) self.isConfigured = 1 except: log.error("failed to configure network device %s using " "iBFT information, falling back to dhcp", dev.get('device')) usemethod = "dhcp" continue elif (usemethod == "dhcp" and dev.get('onboot') == "yes"): ret = isys.dhcpNetDevice(dev.get('device'), dev.get('dhcpclass')) # if ret is None: # continue # myns = ret self.isConfigured = 1 break elif (dev.get('ipaddr') and dev.get('netmask') and self.gateway is not None and dev.get('onboot') == "yes"): try: isys.configNetDevice(dev.get('device'), dev.get('ipaddr'), dev.get('netmask'), self.gateway) self.isConfigured = 1 break except SystemError: log.error("failed to configure network device %s when " "looking up host name", dev.get('device')) #try it only once break if self.isConfigured and not flags.rootpath: f = open("/etc/resolv.conf", "w") f.write("nameserver %s\n" % myns) f.close() isys.resetResolv() isys.setResolvRetry(1) if not self.isConfigured: log.warning("no network devices were available to look up host name") return None try: (family, socktype, proto, canonname, sockaddr) = \ socket.getaddrinfo(self.hostname, None, socket.AF_INET)[0] (ip, port) = sockaddr except: try: (family, socktype, proto, canonname, sockaddr) = \ socket.getaddrinfo(self.hostname, None, socket.AF_INET6)[0] (ip, port, flowinfo, scopeid) = sockaddr except: return None return ip
def startNetworking(network, intf, anaconda): # do lo first try: os.system("/usr/sbin/ifconfig lo 127.0.0.1") except: log.error("Error trying to start lo in rescue.py::startNetworking()") # start up dhcp interfaces first dhcpGotNS = 0 devs = network.netdevices.keys() devs.sort() for devname in devs: dev = network.netdevices[devname] waitwin = intf.waitWindow(_("Starting Interface"), _("Attempting to start %s") % (dev.get('device'),)) log.info("Attempting to start %s", dev.get('device')) method = dev.get('bootproto') while True: if method == "ibft": try: if anaconda.id.iscsi.fwinfo["iface.bootproto"].lower() == "dhcp": method = "dhcp" continue else: hwaddr = isys.getMacAddress(dev) if hwaddr != anaconda.id.iscsi.fwinfo["iface.hwaddress"]: log.error("The iBFT configuration does not belong to device %s," "falling back to dhcp", dev.get('device')) method = "dhcp" continue isys.configNetDevice(dev.get('device'), anaconda.id.iscsi.fwinfo["iface.ipaddress"], anaconda.id.iscsi.fwinfo["iface.subnet_mask"], anaconda.id.iscsi.fwinfo["iface.gateway"]) except: log.error("failed to configure network device %s using " "iBFT information, falling back to dhcp", dev.get('device')) usemethod = "dhcp" continue elif method == "dhcp": try: ns = isys.dhcpNetDevice(dev.get('device')) if ns: if not dhcpGotNS: dhcpGotNS = 1 f = open("/etc/resolv.conf", "w") f.write("nameserver %s\n" % ns) f.close() except: log.error("Error trying to start %s in rescue.py::startNetworking()", dev.get('device')) elif dev.get('ipaddr') and dev.get('netmask') and network.gateway is not None: try: isys.configNetDevice(dev.get('device'), dev.get('ipaddr'), dev.get('netmask'), network.gateway) except: log.error("Error trying to start %s in rescue.py::startNetworking()", dev.get('device')) #do that only once break waitwin.pop() # write out resolv.conf if dhcp didnt get us one if not dhcpGotNS: f = open("/etc/resolv.conf", "w") if network.domains != ['localdomain'] and network.domains: f.write("search %s\n" % (string.joinfields(network.domains, ' '),)) for ns in network.nameservers(): if ns: f.write("nameserver %s\n" % (ns,)) f.close()
def startNetworking(network, intf, anaconda): # do lo first try: os.system("/usr/sbin/ifconfig lo 127.0.0.1") except: log.error("Error trying to start lo in rescue.py::startNetworking()") # start up dhcp interfaces first dhcpGotNS = 0 devs = network.netdevices.keys() devs.sort() for devname in devs: dev = network.netdevices[devname] waitwin = intf.waitWindow( _("Starting Interface"), _("Attempting to start %s") % (dev.get('device'), )) log.info("Attempting to start %s", dev.get('device')) method = dev.get('bootproto') while True: if method == "ibft": try: if anaconda.id.iscsi.fwinfo["iface.bootproto"].lower( ) == "dhcp": method = "dhcp" continue else: hwaddr = isys.getMacAddress(dev) if hwaddr != anaconda.id.iscsi.fwinfo[ "iface.hwaddress"]: log.error( "The iBFT configuration does not belong to device %s," "falling back to dhcp", dev.get('device')) method = "dhcp" continue isys.configNetDevice( dev.get('device'), anaconda.id.iscsi.fwinfo["iface.ipaddress"], anaconda.id.iscsi.fwinfo["iface.subnet_mask"], anaconda.id.iscsi.fwinfo["iface.gateway"]) except: log.error( "failed to configure network device %s using " "iBFT information, falling back to dhcp", dev.get('device')) usemethod = "dhcp" continue elif method == "dhcp": try: ns = isys.dhcpNetDevice(dev.get('device')) if ns: if not dhcpGotNS: dhcpGotNS = 1 f = open("/etc/resolv.conf", "w") f.write("nameserver %s\n" % ns) f.close() except: log.error( "Error trying to start %s in rescue.py::startNetworking()", dev.get('device')) elif dev.get('ipaddr') and dev.get( 'netmask') and network.gateway is not None: try: isys.configNetDevice(dev.get('device'), dev.get('ipaddr'), dev.get('netmask'), network.gateway) except: log.error( "Error trying to start %s in rescue.py::startNetworking()", dev.get('device')) #do that only once break waitwin.pop() # write out resolv.conf if dhcp didnt get us one if not dhcpGotNS: f = open("/etc/resolv.conf", "w") if network.domains != ['localdomain'] and network.domains: f.write("search %s\n" % (string.joinfields(network.domains, ' '), )) for ns in network.nameservers(): if ns: f.write("nameserver %s\n" % (ns, )) f.close()
def lookupHostname(self): # can't look things up if they don't exist! if not self.hostname or self.hostname == "localhost.localdomain": return None if not self.primaryNS: return myns = self.primaryNS if not self.isConfigured: for dev in self.netdevices.values(): usemethod = dev.get('bootproto').lower() while True: if (usemethod == "ibft" and dev.get('onboot') == "yes"): try: if anaconda.id.iscsi.fwinfo[ "iface.bootproto"].lower() == "dhcp": usemethod = "dhcp" continue else: hwaddr = isys.getMacAddress(dev) if hwaddr != anaconda.id.iscsi.fwinfo[ "iface.hwaddress"]: log.error( "The iBFT configuration does not belong to device %s," "falling back to dhcp", dev.get('device')) usemethod = "dhcp" continue isys.configNetDevice( dev.get('device'), anaconda.id.iscsi. fwinfo["iface.ipaddress"], anaconda.id. iscsi.fwinfo["iface.subnet_mask"], anaconda.id.iscsi.fwinfo["iface.gateway"]) self.isConfigured = 1 except: log.error( "failed to configure network device %s using " "iBFT information, falling back to dhcp", dev.get('device')) usemethod = "dhcp" continue elif (usemethod == "dhcp" and dev.get('onboot') == "yes"): ret = isys.dhcpNetDevice(dev.get('device'), dev.get('dhcpclass')) if ret is None: continue myns = ret self.isConfigured = 1 break elif (dev.get('ipaddr') and dev.get('netmask') and self.gateway is not None and dev.get('onboot') == "yes"): try: isys.configNetDevice(dev.get('device'), dev.get('ipaddr'), dev.get('netmask'), self.gateway) self.isConfigured = 1 break except SystemError: log.error( "failed to configure network device %s when " "looking up host name", dev.get('device')) #try it only once break if self.isConfigured and not flags.rootpath: f = open("/etc/resolv.conf", "w") f.write("nameserver %s\n" % myns) f.close() isys.resetResolv() isys.setResolvRetry(1) if not self.isConfigured: log.warning( "no network devices were available to look up host name") return None try: (family, socktype, proto, canonname, sockaddr) = \ socket.getaddrinfo(self.hostname, None, socket.AF_INET)[0] (ip, port) = sockaddr except: try: (family, socktype, proto, canonname, sockaddr) = \ socket.getaddrinfo(self.hostname, None, socket.AF_INET6)[0] (ip, port, flowinfo, scopeid) = sockaddr except: return None return ip