> @@ -509,8 +510,11 @@ def isWireless(dev): > else: > return False > > -# Get the IP address for a network device. > -def getIPAddress(dev): > +# Get IP addresses for a network device. > +# Returns list of ipv4 and ipv6 addresses. > +# With version=4 returns only ipv4 addresses, > +# with version=6 returns only ipv6 addresses. > +def getIPAddresses(dev, version=None): > if dev == '' or dev is None: > return None > What I was thinking here is that version should default to 4, since that's the thing we'll most typically want and having an essentially required parameter default to None doesn't make any sense to me. > + if not version == 6: > + 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.append(ipaddr) > + except ValueError as e: > + log.debug("Exception caught trying to convert IP address %s: %s" % > + (addr, e)) > + > + if not version == 4: > + 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.append(ipaddr) > + except ValueError as e: > + log.debug("Exception caught trying to convert IP address %s: %s" % > + (addr, e)) > + > + return addresses I find the negation thing here unnecessarily confusing. So if I pass version=47 to getIPAddresses, I'll get everything. If I pass version=True, I'll get everything. Same for version="cornbread" and version=("left", "right"). Just converting this to "if version == 4:" and "if version == 6:" means you'll get exactly what you want should you pass the correct parameter. - Chris _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list