Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
0
    def initialize(self):
        """Here is were all the relative vars get initialized. """

        # see if we can sniff out network info
        netinfo = network.Network()

        devices = netinfo.netdevices
        active_devs = network.getActiveNetDevs()

        self.ip = None
        if active_devs != []:
            devname = devices[active_devs[0]].iface
            try:
                ips = (isys.getIPAddresses(devname, version=4) +
                       isys.getIPAddresses(devname, version=6))
            except Exception as e:
                log.warning("Got an exception trying to get the self.ip addr "
                            "of %s: %s" % (devname, e))
            else:
                if ips and ips[0] not in ("127.0.0.1", "::1"):
                    log.info("IPs (using first) of device %s: %s" % (devname,
                                                                     ips))
                    self.ip = ips[0]

        ipstr = self.ip

        try:
            hinfo = socket.gethostbyaddr(ipstr)
        except Exception as e:
            log.debug("Exception caught trying to get host name of %s: %s" %
                      (ipstr, e))
            self.name = network.getDefaultHostname(self.anaconda)
        else:
            if len(hinfo) == 3:
                self.name = hinfo[0]

        if self.ip.find(':') != -1:
            ipstr = "[%s]" % (self.ip,)

        if (self.name is not None) and (not self.name.startswith('localhost')) and (ipstr is not None):
            self.connxinfo = "%s:%s (%s)" % (socket.getfqdn(name=self.name), self.display, ipstr,)
        elif ipstr is not None:
            self.connxinfo = "%s:%s" % (ipstr, self.display,)
        else:
            self.connxinfo = None

        # figure out product info
        if self.name is not None:
            self.desktop = _("%(productName)s %(productVersion)s installation "
                             "on host %(name)s") \
                           % {'productName': product.productName,
                              'productVersion': product.productVersion,
                              'name': self.name}
        else:
            self.desktop = _("%(productName)s %(productVersion)s installation")\
                           % {'productName': product.productName,
                              'productVersion': product.productVersion}
Exemplo n.º 4
0
    def initialize(self):
        """Here is were all the relative vars get initialized. """

        # see if we can sniff out network info
        netinfo = network.Network()

        devices = netinfo.netdevices
        active_devs = network.getActiveNetDevs()

        if active_devs != []:
            dev = devices[active_devs[0]]

            try:
                devname = dev.iface
                ips = (isys.getIPAddresses(devname, version=4) +
                       isys.getIPAddresses(devname, version=6))
                self.ip = ips[0]
                log.info("IPs (using first) of device %s: %s" % (devname, ips))

                if self.ip == "127.0.0.1" or self.ip == "::1":
                    self.ip = None
            except Exception, e:
                log.warning("Got an exception trying to get the self.ip addr "
                            "of %s: %s" % (devname, e))
Exemplo n.º 5
0
    def initialize(self):
        """Here is were all the relative vars get initialized. """

        # see if we can sniff out network info
        netinfo = network.Network()

        devices = netinfo.netdevices
        active_devs = network.getActiveNetDevs()

        if active_devs != []:
            dev = devices[active_devs[0]]

            try:
                devname = dev.get("DEVICE")
                ips = (isys.getIPAddresses(devname, version=4) +
                       isys.getIPAddresses(devname, version=6))
                self.ip = ips[0]
                log.info("IPs (using first) of device %s: %s" % (devname, ips))

                if self.ip == "127.0.0.1" or self.ip == "::1":
                    self.ip = None
            except Exception, e:
                log.warning("Got an exception trying to get the self.ip addr "
                            "of %s: %s" % (devname, e))