Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    def waitForDevicesActivation(self, devices):
        waited_devs_props = {}

        bus = dbus.SystemBus()
        nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH)
        device_paths = nm.get_dbus_method("GetDevices")()
        for device_path in device_paths:
            device = bus.get_object(isys.NM_SERVICE, device_path)
            device_props_iface = dbus.Interface(device, isys.DBUS_PROPS_IFACE)
            iface = str(device_props_iface.Get(isys.NM_DEVICE_IFACE, "Interface"))
            if iface in devices:
                waited_devs_props[iface] = device_props_iface

        i = 0
        reset_resolver = False
        while True:
            for dev, device_props_iface in waited_devs_props.items():
                state = device_props_iface.Get(isys.NM_DEVICE_IFACE, "State")
                if state == isys.NM_DEVICE_STATE_ACTIVATED:
                    waited_devs_props.pop(dev)
                    reset_resolver = True
            if len(waited_devs_props) == 0 or i >= CONNECTION_TIMEOUT:
                break
            i += 1
            time.sleep(1)

        if reset_resolver:
            isys.resetResolv()
        return waited_devs_props.keys()
Ejemplo n.º 3
0
def getDefaultHostname(anaconda):
    isys.resetResolv()

    hn = None

    # First address (we prefer ipv4) of last device (as it used to be) wins
    for dev in getActiveNetDevs():
        addrs = (isys.getIPAddresses(dev, version=4) +
                 isys.getIPAddresses(dev, version=6))
        for ipaddr in addrs:
            try:
                hinfo = socket.gethostbyaddr(ipaddr)
            except Exception as e:
                log.debug("Exception caught trying to get host name of %s: %s" %
                          (ipaddr, e))
            else:
                if len(hinfo) == 3:
                    hn = hinfo[0]
                    break

    if hn and hn != 'localhost' and hn != 'localhost.localdomain':
        return hn

    try:
        hn = anaconda.id.network.hostname
    except:
        hn = None

    if not hn or hn == '(none)' or hn == 'localhost' or hn == 'localhost.localdomain':
        hn = socket.gethostname()

    if not hn or hn == '(none)' or hn == 'localhost':
        hn = 'localhost.localdomain'

    return hn
Ejemplo n.º 4
0
def getDefaultHostname(anaconda):
    isys.resetResolv()

    hn = None

    # First address (we prefer ipv4) of last device (as it used to be) wins
    for dev in getActiveNetDevs():
        addrs = (isys.getIPAddresses(dev, version=4) +
                 isys.getIPAddresses(dev, version=6))
        for ipaddr in addrs:
            try:
                hinfo = socket.gethostbyaddr(ipaddr)
            except Exception as e:
                log.debug("Exception caught trying to get host name of %s: %s" %
                          (ipaddr, e))
            else:
                if len(hinfo) == 3:
                    hn = hinfo[0]
                    break

    if hn and hn != 'localhost' and hn != 'localhost.localdomain':
        return hn

    try:
        hn = anaconda.id.network.hostname
    except:
        hn = None

    if not hn or hn == '(none)' or hn == 'localhost' or hn == 'localhost.localdomain':
        hn = socket.gethostname()

    if not hn or hn == '(none)' or hn == 'localhost':
        hn = 'localhost.localdomain'

    return hn
Ejemplo n.º 5
0
    def waitForDevicesActivation(self, devices):
        waited_devs_props = {}

        bus = dbus.SystemBus()
        nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH)
        device_paths = nm.get_dbus_method("GetDevices")()
        for device_path in device_paths:
            device = bus.get_object(isys.NM_SERVICE, device_path)
            device_props_iface = dbus.Interface(device, isys.DBUS_PROPS_IFACE)
            iface = str(
                device_props_iface.Get(isys.NM_DEVICE_IFACE, "Interface"))
            if iface in devices:
                waited_devs_props[iface] = device_props_iface

        i = 0
        reset_resolver = False
        while True:
            for dev, device_props_iface in waited_devs_props.items():
                state = device_props_iface.Get(isys.NM_DEVICE_IFACE, "State")
                if state == isys.NM_DEVICE_STATE_ACTIVATED:
                    waited_devs_props.pop(dev)
                    reset_resolver = True
            if len(waited_devs_props) == 0 or i >= CONNECTION_TIMEOUT:
                break
            i += 1
            time.sleep(1)

        if reset_resolver:
            isys.resetResolv()
        return waited_devs_props.keys()
Ejemplo n.º 6
0
def getDefaultHostname(anaconda):
    isys.resetResolv()

    hn = None
    bus = dbus.SystemBus()
    nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH)
    nm_props_iface = dbus.Interface(nm, isys.DBUS_PROPS_IFACE)

    active_connections = nm_props_iface.Get(isys.NM_MANAGER_IFACE, "ActiveConnections")

    # XXX: account for Ip6Config objects when NetworkManager supports them
    for connection in active_connections:
        active_connection = bus.get_object(isys.NM_SERVICE, connection)
        active_connection_props_iface = dbus.Interface(active_connection, isys.DBUS_PROPS_IFACE)
        devices = active_connection_props_iface.Get(isys.NM_ACTIVE_CONNECTION_IFACE, 'Devices')

        for device_path in devices:
            device = bus.get_object(isys.NM_SERVICE, device_path)
            device_props_iface = dbus.Interface(device, isys.DBUS_PROPS_IFACE)

            ip4_config_path = device_props_iface.Get(isys.NM_DEVICE_IFACE, 'Ip4Config')
            ip4_config_obj = bus.get_object(isys.NM_SERVICE, ip4_config_path)
            ip4_config_props = dbus.Interface(ip4_config_obj, isys.DBUS_PROPS_IFACE)

            # addresses (3-element list:  ipaddr, netmask, gateway)
            try:
                addrs = ip4_config_props.Get(isys.NM_IP4CONFIG_IFACE, "Addresses")[0]
            except:
                # DBusException
                continue
            try:
                tmp = struct.pack('I', addrs[0])
                ipaddr = socket.inet_ntop(socket.AF_INET, tmp)
                hinfo = socket.gethostbyaddr(ipaddr)

                if len(hinfo) == 3:
                    hn = hinfo[0]
                else:
                    continue
            except:
                continue

    if hn and hn != 'localhost' and hn != 'localhost.localdomain':
        return hn

    try:
        hn = anaconda.network.hostname
    except:
        hn = None

    if not hn or hn == '(none)' or hn == 'localhost' or hn == 'localhost.localdomain':
        hn = socket.gethostname()

    if not hn or hn == '(none)' or hn == 'localhost':
        hn = 'localhost.localdomain'

    return hn
Ejemplo n.º 7
0
    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():
                if (dev.get('bootproto') == "dhcp"
                        and dev.get('onboot') == "yes"):
                    ret = isys.pumpNetDevice(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(
                            "failed to configure network device %s when "
                            "looking up host name", dev.get('device'))

        if not self.isConfigured:
            log("no network devices were available to look up host name")
            return None

        f = open("/etc/resolv.conf", "w")
        f.write("nameserver %s\n" % myns)
        f.close()
        isys.resetResolv()
        isys.setResolvRetry(1)

        try:
            ip = socket.gethostbyname(self.hostname)
        except:
            return None

        return ip
Ejemplo n.º 8
0
    def waitForConnection(self):
        bus = dbus.SystemBus()
        nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH)
        props = dbus.Interface(nm, isys.DBUS_PROPS_IFACE)

        i = 0
        while i < CONNECTION_TIMEOUT:
            state = props.Get(isys.NM_SERVICE, "State")
            if int(state) == isys.NM_STATE_CONNECTED:
                isys.resetResolv()
                return True
            i += 1
            time.sleep(1)

        state = props.Get(isys.NM_SERVICE, "State")
        if int(state) == isys.NM_STATE_CONNECTED:
            isys.resetResolv()
            return True

        return False
Ejemplo n.º 9
0
    def waitForConnection(self):
        bus = dbus.SystemBus()
        nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH)
        props = dbus.Interface(nm, isys.DBUS_PROPS_IFACE)

        i = 0
        while i < CONNECTION_TIMEOUT:
            state = props.Get(isys.NM_SERVICE, "State")
            if int(state) == isys.NM_STATE_CONNECTED:
                isys.resetResolv()
                return True
            i += 1
            time.sleep(1)

        state = props.Get(isys.NM_SERVICE, "State")
        if int(state) == isys.NM_STATE_CONNECTED:
            isys.resetResolv()
            return True

        return False
Ejemplo n.º 10
0
    def bringUp(self, devices=None):
        self.write("", devices=devices)

        bus = dbus.SystemBus()
        nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH)
        props = dbus.Interface(nm, isys.DBUS_PROPS_IFACE)

        i = 0
        while i < 45:
            state = props.Get(isys.NM_SERVICE, "State")
            if int(state) == isys.NM_STATE_CONNECTED:
                isys.resetResolv()
                return True
            i += 1
            time.sleep(1)

        state = props.Get(isys.NM_SERVICE, "State")
        if int(state) == isys.NM_STATE_CONNECTED:
            isys.resetResolv()
            return True

        return False
Ejemplo n.º 11
0
    def bringUp(self, devices=None):
        self.write(devices=devices)

        bus = dbus.SystemBus()
        nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH)
        props = dbus.Interface(nm, isys.DBUS_PROPS_IFACE)

        i = 0
        while i < 45:
            state = props.Get(isys.NM_SERVICE, "State")
            if int(state) == isys.NM_STATE_CONNECTED:
                isys.resetResolv()
                return True
            i += 1
            time.sleep(1)

        state = props.Get(isys.NM_SERVICE, "State")
        if int(state) == isys.NM_STATE_CONNECTED:
            isys.resetResolv()
            return True

        return False
Ejemplo n.º 12
0
    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
Ejemplo n.º 13
0
    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
Ejemplo n.º 14
0
            except network.IPError, msg:
                self._handleIPError(_("Nameserver"), msg)
                return

            try:
                isys.configNetDevice(netdev.get("device"),
                                     ipv4addr, ipv4nm, gateway)
            except Exception, e:
                log.error("Error configuring network device: %s" %(e,))

            self.rc = gtk.RESPONSE_OK
            if ns:
                f = open("/etc/resolv.conf", "w")
                f.write("nameserver %s\n" %(ns,))
                f.close()
                isys.resetResolv()
                isys.setResolvRetry(1)

        if self.rc != gtk.RESPONSE_OK:
            gui.MessageWindow(_("Error"),
                              _("Error configuring network device"),
                              type = "ok", custom_icon="error")
            return

        gtk.main_quit()

def main():
    net = network.Network()
    d = NetworkConfigurator(net)
    ret = d.run()
Ejemplo n.º 15
0
def getDefaultHostname(anaconda):
    isys.resetResolv()

    hn = None
    bus = dbus.SystemBus()
    nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH)
    nm_props_iface = dbus.Interface(nm, isys.DBUS_PROPS_IFACE)

    active_connections = nm_props_iface.Get(isys.NM_MANAGER_IFACE,
                                            "ActiveConnections")

    # XXX: account for Ip6Config objects when NetworkManager supports them
    for connection in active_connections:
        active_connection = bus.get_object(isys.NM_SERVICE, connection)
        active_connection_props_iface = dbus.Interface(active_connection,
                                                       isys.DBUS_PROPS_IFACE)
        devices = active_connection_props_iface.Get(
            isys.NM_ACTIVE_CONNECTION_IFACE, 'Devices')

        for device_path in devices:
            device = bus.get_object(isys.NM_SERVICE, device_path)
            device_props_iface = dbus.Interface(device, isys.DBUS_PROPS_IFACE)

            ip4_config_path = device_props_iface.Get(isys.NM_DEVICE_IFACE,
                                                     'Ip4Config')
            ip4_config_obj = bus.get_object(isys.NM_SERVICE, ip4_config_path)
            ip4_config_props = dbus.Interface(ip4_config_obj,
                                              isys.DBUS_PROPS_IFACE)

            # addresses (3-element list:  ipaddr, netmask, gateway)
            try:
                addrs = ip4_config_props.Get(isys.NM_IP4CONFIG_IFACE,
                                             "Addresses")[0]
            except:
                # DBusException
                continue
            try:
                tmp = struct.pack('I', addrs[0])
                ipaddr = socket.inet_ntop(socket.AF_INET, tmp)
                hinfo = socket.gethostbyaddr(ipaddr)

                if len(hinfo) == 3:
                    hn = hinfo[0]
                else:
                    continue
            except:
                continue

    if hn and hn != 'localhost' and hn != 'localhost.localdomain':
        return hn

    try:
        hn = anaconda.network.hostname
    except:
        hn = None

    if not hn or hn == '(none)' or hn == 'localhost' or hn == 'localhost.localdomain':
        hn = socket.gethostname()

    if not hn or hn == '(none)' or hn == 'localhost':
        hn = 'localhost.localdomain'

    return hn
Ejemplo n.º 16
0
    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
Ejemplo n.º 17
0
            except network.IPError, msg:
                self._handleIPError(_("Nameserver"), msg)
                return

            try:
                isys.configNetDevice(netdev.get("device"), ipv4addr, ipv4nm,
                                     gateway)
            except Exception, e:
                log.error("Error configuring network device: %s" % (e, ))

            self.rc = gtk.RESPONSE_OK
            if ns:
                f = open("/etc/resolv.conf", "w")
                f.write("nameserver %s\n" % (ns, ))
                f.close()
                isys.resetResolv()
                isys.setResolvRetry(1)

        if self.rc != gtk.RESPONSE_OK:
            gui.MessageWindow(_("Error"),
                              _("Error configuring network device"),
                              type="ok",
                              custom_icon="error")
            return

        gtk.main_quit()


def main():
    net = network.Network()
    d = NetworkConfigurator(net)
Ejemplo n.º 18
0
def resetResolver():
    isys.resetResolv()
    urlgrabber.grabber.reset_curl_obj()
Ejemplo n.º 19
0
def resetResolver():
    isys.resetResolv()
    urlgrabber.grabber.reset_curl_obj()