Exemplo n.º 1
0
    def _activated_device_msg(self, devname):
        msg = _("Wired (%(interface_name)s) connected\n") \
                % {"interface_name": devname}

        ipv4config = nm.nm_device_ip_config(devname, version=4)
        ipv6config = nm.nm_device_ip_config(devname, version=6)

        if ipv4config and ipv4config[0]:
            addr_str, prefix, gateway_str = ipv4config[0][0]
            netmask_str = network.prefix2netmask(prefix)
            dnss_str = ",".join(ipv4config[1])
        else:
            addr_str = dnss_str = gateway_str = netmask_str = ""
        msg += _(" IPv4 Address: %(addr)s Netmask: %(netmask)s Gateway: %(gateway)s\n") % \
                {"addr": addr_str, "netmask": netmask_str, "gateway": gateway_str}
        msg += _(" DNS: %s\n") % dnss_str

        if ipv6config and ipv6config[0]:
            for ipv6addr in ipv6config[0]:
                addr_str, prefix, gateway_str = ipv6addr
                # Do not display link-local addresses
                if not addr_str.startswith("fe80:"):
                    msg += _(" IPv6 Address: %(addr)s/%(prefix)d\n") % \
                            {"addr": addr_str, "prefix": prefix}

            dnss_str = ",".join(ipv6config[1])

        return msg
Exemplo n.º 2
0
    def _activated_device_msg(self, devname):
        msg = _("Wired (%(interface_name)s) connected\n") \
                % {"interface_name": devname}

        ipv4config = nm_device_ip_config(devname, version=4)
        ipv6config = nm_device_ip_config(devname, version=6)

        if ipv4config and ipv4config[0]:
            addr_str, prefix, gateway_str = ipv4config[0][0]
            netmask_str = network.prefix2netmask(prefix)
            dnss_str = ",".join(ipv4config[1])
        else:
            addr_str = dnss_str = gateway_str = netmask_str = ""
        msg += _(" IPv4 Address: %s Netmask: %s Gateway: %s\n") % (
            addr_str, netmask_str, gateway_str)
        msg += _(" DNS: %s\n") % dnss_str

        if ipv6config and ipv6config[0]:
            for ipv6addr in ipv6config[0]:
                addr_str, prefix, gateway_str = ipv6addr
                # Do not display link-local addresses
                if not addr_str.startswith("fe80:"):
                    msg += _(" IPv6 Address: %s/%d\n") % (addr_str, prefix)

            dnss_str = ",".join(ipv6config[1])

        return msg
Exemplo n.º 3
0
    def _activated_device_msg(self, devname):
        msg = _("Wired (%(interface_name)s) connected\n") \
              % {"interface_name": devname}

        device = self.nm_client.get_device_by_iface(devname)
        if device:
            ipv4config = device.get_ip4_config()
            if ipv4config:
                addresses = ipv4config.get_addresses()
                if addresses:
                    a0 = addresses[0]
                    addr_str = a0.get_address()
                    prefix = a0.get_prefix()
                    netmask_str = network.prefix2netmask(prefix)
                gateway_str = ipv4config.get_gateway() or ''
                dnss_str = ",".join(ipv4config.get_nameservers())
            else:
                addr_str = dnss_str = gateway_str = netmask_str = ""
            msg += _(" IPv4 Address: %(addr)s Netmask: %(netmask)s Gateway: %(gateway)s\n") % \
                {"addr": addr_str, "netmask": netmask_str, "gateway": gateway_str}
            msg += _(" DNS: %s\n") % dnss_str

            ipv6config = device.get_ip6_config()
            if ipv6config:
                for address in ipv6config.get_addresses():
                    addr_str = address.get_address()
                    prefix = address.get_prefix()
                    # Do not display link-local addresses
                    if not addr_str.startswith("fe80:"):
                        msg += _(" IPv6 Address: %(addr)s/%(prefix)d\n") % \
                            {"addr": addr_str, "prefix": prefix}
        return msg
Exemplo n.º 4
0
    def set_from_connection(self, connection):
        """Set the object from NM RemoteConnection.

        :param connection: connection to be used to set the object
        :type connection: NM.RemoteConnection
        """
        connection_uuid = connection.get_uuid()

        ip4_config = connection.get_setting_ip4_config()
        ip4_method = ip4_config.get_method()
        if ip4_method == NM.SETTING_IP4_CONFIG_METHOD_AUTO:
            self.ip = "dhcp"
        elif ip4_method == NM.SETTING_IP4_CONFIG_METHOD_MANUAL:
            if ip4_config.get_num_addresses() > 0:
                addr = ip4_config.get_address(0)
                self.ip = addr.get_address()
                self.netmask = network.prefix2netmask(addr.get_prefix())
            else:
                log.error("No ip4 address found for manual method in %s",
                          connection_uuid)
        elif ip4_method == NM.SETTING_IP4_CONFIG_METHOD_DISABLED:
            self.ip = ""
        else:
            log.error("Unexpected ipv4 method %s found in connection %s",
                      ip4_method, connection_uuid)
            self.ip = "dhcp"
        self.gateway = ip4_config.get_gateway() or ""

        ip6_config = connection.get_setting_ip6_config()
        ip6_method = ip6_config.get_method()
        if ip6_method == NM.SETTING_IP6_CONFIG_METHOD_AUTO:
            self.ipv6 = "auto"
        elif ip6_method == NM.SETTING_IP6_CONFIG_METHOD_IGNORE:
            self.ipv6 = "ignore"
        elif ip6_method == NM.SETTING_IP6_CONFIG_METHOD_DHCP:
            self.ipv6 = "dhcp"
        elif ip6_method == NM.SETTING_IP6_CONFIG_METHOD_MANUAL:
            if ip6_config.get_num_addresses() > 0:
                addr = ip6_config.get_address(0)
                self.ipv6 = "{}/{}".format(addr.get_address(),
                                           addr.get_prefix())
            else:
                log.error("No ip6 address found for manual method in %s",
                          connection_uuid)
        else:
            log.error("Unexpected ipv6 method %s found in connection %s",
                      ip6_method, connection_uuid)
            self.ipv6 = "auto"
        self.ipv6gateway = ip6_config.get_gateway() or ""

        nameservers = []
        for i in range(0, ip4_config.get_num_dns()):
            nameservers.append(ip4_config.get_dns(i))
        for i in range(0, ip6_config.get_num_dns()):
            nameservers.append(ip6_config.get_dns(i))
        self.nameserver = ",".join(nameservers)

        self.onboot = connection.get_setting_connection().get_autoconnect()
Exemplo n.º 5
0
    def mapAnacondaValues(self, info):
        """ Should be called only after json file has loaded 
            These are variables read directly from anaconda objects or 
            derived from them.  
            XXX: This really should be a file of mappings"""
        ## This method basically has to reverse engineer what
        ## other parts of anaconda is doing
        ksdata = self.data
        mapping = {}
        mapping["Kickstart_Lang"] = "ksdata.lang.lang"
        mapping["Kickstart_Langsupport"] = mapping["Kickstart_Lang"]
        mapping["Kickstart_Timezone"] = "ksdata.timezone.timezone"
        # Need to find a better way to get NTP info.
        # mapping["Kickstart_PublicNTPHost"] = "ksdata.timezone.ntpservers"
        mapping["Kickstart_PublicDNSServers"] = "self.readDNSConfig()"
        ## Network may not be up, so these may fail
        try:
            mapping[
                "Kickstart_PublicInterface"] = "network.default_route_device()"
            mapping[
                "Kickstart_PublicAddress"] = "network.get_default_device_ip()"
            mapping[
                "Kickstart_PublicFQDN"] = "subprocess.check_output(['hostname']).strip()"
            mapping[
                "Kickstart_PublicHostname"] = "subprocess.check_output(['hostname']).strip().split('.',1)[0]"
            mapping[
                "Kickstart_PublicDNSDomain"] = "subprocess.check_output(['hostname']).strip().split('.',1)[1]"
            ## get the public networking values
            pubif = eval(mapping["Kickstart_PublicInterface"])
            pubaddr = eval(mapping["Kickstart_PublicAddress"])
            cidr = nm.nm_device_ip_config(pubif)[0][0][1]
            gateway = nm.nm_device_ip_config(pubif)[0][0][2]
            netmask = network.prefix2netmask(cidr)
            nparts = map(lambda x: int(x), netmask.split('.'))
            aparts = map(lambda x: int(x), pubaddr.split('.'))
            netaddr = map(lambda x: nparts[x] & aparts[x],
                          range(0, len(nparts)))
            pubnetwork = ".".join(map(lambda x: x.__str__(), netaddr))
            mapping["Kickstart_PublicNetwork"] = "pubnetwork"
            mapping["Kickstart_PublicNetmask"] = "netmask"
            mapping["Kickstart_PublicNetmaskCIDR"] = "cidr"
            mapping["Kickstart_PublicGateway"] = "gateway"
            mtu = nm.nm_device_property(pubif, 'Mtu')
            mapping["Kickstart_PublicMTU"] = mtu.__str__()
        except:
            pass

        ## set the values in our own info structure
        for var in mapping.keys():
            try:
                setValue(info, var, eval(mapping[var]))
            except Exception as e:
                self.log.info("ROCKS: Exception(%s) setting var (%s)" %
                              (e, var))
Exemplo n.º 6
0
    def prefix2netmask2prefix_test(self):
        lore = [
            (0, "0.0.0.0"),
            (1, "128.0.0.0"),
            (2, "192.0.0.0"),
            (3, "224.0.0.0"),
            (4, "240.0.0.0"),
            (5, "248.0.0.0"),
            (6, "252.0.0.0"),
            (7, "254.0.0.0"),
            (8, "255.0.0.0"),
            (9, "255.128.0.0"),
            (10, "255.192.0.0"),
            (11, "255.224.0.0"),
            (12, "255.240.0.0"),
            (13, "255.248.0.0"),
            (14, "255.252.0.0"),
            (15, "255.254.0.0"),
            (16, "255.255.0.0"),
            (17, "255.255.128.0"),
            (18, "255.255.192.0"),
            (19, "255.255.224.0"),
            (20, "255.255.240.0"),
            (21, "255.255.248.0"),
            (22, "255.255.252.0"),
            (23, "255.255.254.0"),
            (24, "255.255.255.0"),
            (25, "255.255.255.128"),
            (26, "255.255.255.192"),
            (27, "255.255.255.224"),
            (28, "255.255.255.240"),
            (29, "255.255.255.248"),
            (30, "255.255.255.252"),
            (31, "255.255.255.254"),
            (32, "255.255.255.255"),
        ]
        for prefix, netmask in lore:
            self.assertEqual(network.prefix2netmask(prefix), netmask)
            self.assertEqual(network.netmask2prefix(netmask), prefix)

        self.assertEqual(network.prefix2netmask(33), "255.255.255.255")
Exemplo n.º 7
0
    def prefix2netmask2prefix_test(self):
        lore = [
                (0, "0.0.0.0"),
                (1, "128.0.0.0"),
                (2, "192.0.0.0"),
                (3, "224.0.0.0"),
                (4, "240.0.0.0"),
                (5, "248.0.0.0"),
                (6, "252.0.0.0"),
                (7, "254.0.0.0"),
                (8, "255.0.0.0"),
                (9, "255.128.0.0"),
                (10, "255.192.0.0"),
                (11, "255.224.0.0"),
                (12, "255.240.0.0"),
                (13, "255.248.0.0"),
                (14, "255.252.0.0"),
                (15, "255.254.0.0"),
                (16, "255.255.0.0"),
                (17, "255.255.128.0"),
                (18, "255.255.192.0"),
                (19, "255.255.224.0"),
                (20, "255.255.240.0"),
                (21, "255.255.248.0"),
                (22, "255.255.252.0"),
                (23, "255.255.254.0"),
                (24, "255.255.255.0"),
                (25, "255.255.255.128"),
                (26, "255.255.255.192"),
                (27, "255.255.255.224"),
                (28, "255.255.255.240"),
                (29, "255.255.255.248"),
                (30, "255.255.255.252"),
                (31, "255.255.255.254"),
                (32, "255.255.255.255"),
               ]
        for prefix, netmask in lore:
            self.assertEqual(network.prefix2netmask(prefix), netmask)
            self.assertEqual(network.netmask2prefix(netmask), prefix)

        self.assertEqual(network.prefix2netmask(33), "255.255.255.255")