FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Kubuntu User

 
 
LinkBack Thread Tools
 
Old 06-04-2010, 09:49 AM
Radek Vykydal
 
Default Account for ipv6 addresses too (#594090)

---
isys/isys.py | 50 ++++++++++++++++++++++++++++++++++++++++----------
network.py | 37 +++++++++----------------------------
vnc.py | 7 +++++--
3 files changed, 54 insertions(+), 40 deletions(-)

diff --git a/isys/isys.py b/isys/isys.py
index 7ab5988..bc1777a 100755
--- a/isys/isys.py
+++ b/isys/isys.py
@@ -49,6 +49,7 @@ NM_ACTIVE_CONNECTION_IFACE = "org.freedesktop.NetworkManager.Connection.Act ive"
NM_CONNECTION_IFACE = "org.freedesktop.NetworkManagerSettings.Connection "
NM_DEVICE_IFACE = "org.freedesktop.NetworkManager.Device"
NM_IP4CONFIG_IFACE = "org.freedesktop.NetworkManager.IP4Config"
+NM_IP6CONFIG_IFACE = "org.freedesktop.NetworkManager.IP6Config"

NM_STATE_UNKNOWN = 0
NM_STATE_ASLEEP = 1
@@ -509,8 +510,9 @@ def isWireless(dev):
else:
return False

-# 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

@@ -518,16 +520,44 @@ def getIPAddress(dev):
if device_props_iface is None:
return None

- # XXX: add support for IPv6 addresses when NM can do that
- device_ip4addr = device_props_iface.Get(NM_DEVICE_IFACE, "Ip4Address")
+ bus = dbus.SystemBus()

- try:
- tmp = struct.pack('I', device_ip4addr)
- address = socket.inet_ntop(socket.AF_INET, tmp)
- except ValueError, e:
- return None
+ addresses = {'ipv4':[], 'ipv6':[]}

- 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

## Get the correct context for a file from loaded policy.
# @param fn The filename to query.
diff --git a/network.py b/network.py
index 02f1ff2..1f4d393 100644
--- a/network.py
+++ b/network.py
@@ -79,39 +79,20 @@ 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_C ONNECTION_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)
- addrs = ip4_config_props.Get(isys.NM_IP4CONFIG_IFACE, "Addresses")[0]
+ # First address (we prefer ipv4) of last device (as it used to be) wins
+ for dev in getActiveNetDevs():
+ addrs = isys.getIPAddresses(dev)
+ for ipaddr in addrs['ipv4'] + addrs['ipv6']:
try:
- tmp = struct.pack('I', addrs[0])
- ipaddr = socket.inet_ntop(socket.AF_INET, tmp)
hinfo = socket.gethostbyaddr(ipaddr)
-
+ except Exception as e:
+ log.debug("Exception caught trying to het host name of %s: %s" %
+ (ipaddr, e))
+ else:
if len(hinfo) == 3:
hn = hinfo[0]
- else:
- continue
- except:
- continue
+ break

if hn and hn != 'localhost' and hn != 'localhost.localdomain':
return hn
diff --git a/vnc.py b/vnc.py
index 0a6a049..66bb351 100644
--- a/vnc.py
+++ b/vnc.py
@@ -108,8 +108,11 @@ class VncServer:
dev = devices[active_devs[0]]

try:
- self.ip = isys.getIPAddress(dev.get("DEVICE"))
- log.info("ip of %s is %s" % (dev.get("DEVICE"), self.ip))
+ addrs = isys.getIPAddresses(dev.get("DEVICE"))
+ ips = addrs['ipv4'] + addrs['ipv6']
+ self.ip = ips[0]
+ log.info("IPs (using first) of device %s: %s" % (dev.get("DEVICE"),
+ ips))

if self.ip == "127.0.0.1" or self.ip == "::1":
self.ip = None
--
1.6.0.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 06-18-2010, 05:30 PM
Chris Lumens
 
Default Account for ipv6 addresses too (#594090)

> -# 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@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 06-21-2010, 10:51 AM
Radek Vykydal
 
Default Account for ipv6 addresses too (#594090)

Chris Lumens wrote:

-# 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.



In one of the places, the order is important and the caller
code seems more readable to me with getIPAddresses returning
the dict because suggested list would require to detect type and sort
addresses in the list (I don't like the idea of having another
function/code doing this), or it would have to rely on assumption
of order addresses returned in the list.

How about having a parameter version='ipv4' to return ipv4 addresses
only, 'ipv6' to return ipv6 addresses and None to return list as
you suggested?

The caller code would be then:

ips = (isys.getIPAddresses(devname, version='ipv4') +
isys.getIPAddresses(devname, version='ipv6'))

... of course we could rely on implicit order ipv4, ipv6, but I like
to be more explicit for code reader.

Radek

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 06-21-2010, 06:47 PM
David Cantrell
 
Default Account for ipv6 addresses too (#594090)

On Mon, 21 Jun 2010, Radek Vykydal wrote:


Chris Lumens wrote:

-# 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.



In one of the places, the order is important and the caller
code seems more readable to me with getIPAddresses returning
the dict because suggested list would require to detect type and sort
addresses in the list (I don't like the idea of having another
function/code doing this), or it would have to rely on assumption
of order addresses returned in the list.

How about having a parameter version='ipv4' to return ipv4 addresses
only, 'ipv6' to return ipv6 addresses and None to return list as
you suggested?

The caller code would be then:

ips = (isys.getIPAddresses(devname, version='ipv4') +
isys.getIPAddresses(devname, version='ipv6'))

... of course we could rely on implicit order ipv4, ipv6, but I like
to be more explicit for code reader.


A version parameter seems fine, but I would prefer to see it as an int rather
than a string:

version=4
version=6

With the default as version=None.

--
David Cantrell <dcantrell@redhat.com>
Red Hat / Honolulu, HI

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 

Thread Tools




All times are GMT. The time now is 08:34 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org