> -# Get the IP address for a network device. > -def getIPAddress(dev): > +# Get the IP addresses for a network device. > +# returns dict of lists with keys 'ipv4' and 'ipv6' > +def getIPAddresses(dev): > if dev == '' or dev is None: > return None > You return a dict of two lists, but in the two places getIPAddresses is called, you only use the concatenation of those two lists. It looks to me like it makes more sense to always return a single list. We can always figure out if an address is IPv6 or not later, should we care. > - return address > + ip4_config_path = device_props_iface.Get(NM_DEVICE_IFACE, 'Ip4Config') > + if ip4_config_path != '/': > + ip4_config_obj = bus.get_object(NM_SERVICE, ip4_config_path) > + ip4_config_props = dbus.Interface(ip4_config_obj, DBUS_PROPS_IFACE) > + > + # addresses (3-element list: ipaddr, netmask, gateway) > + addrs = ip4_config_props.Get(NM_IP4CONFIG_IFACE, "Addresses") > + for addr in addrs: > + try: > + tmp = struct.pack('I', addr[0]) > + ipaddr = socket.inet_ntop(socket.AF_INET, tmp) > + addresses['ipv4'].append(ipaddr) > + except ValueError as e: > + log.debug("Exception caught trying to convert IP address %s: %s" % > + (addr, e)) > + > + ip6_config_path = device_props_iface.Get(NM_DEVICE_IFACE, 'Ip6Config') > + if ip6_config_path != '/': > + ip6_config_obj = bus.get_object(NM_SERVICE, ip6_config_path) > + ip6_config_props = dbus.Interface(ip6_config_obj, DBUS_PROPS_IFACE) > + > + addrs = ip6_config_props.Get(NM_IP6CONFIG_IFACE, "Addresses") > + for addr in addrs: > + try: > + addrstr = "".join(str(byte) for byte in addr[0]) > + ipaddr = socket.inet_ntop(socket.AF_INET6, addrstr) > + # XXX - should we prefer Global or Site-Local types? > + # does NM prefer them? > + addresses['ipv6'].append(ipaddr) > + except ValueError as e: > + log.debug("Exception caught trying to convert IP address %s: %s" % > + (addr, e)) > + > + return addresses This could perhaps be abstracted out a bit, but I think it would make for more confusing code. - Chris _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list