Re: NMIP4Config availability in NetworkManger.DeviceState.ACTIVATED

On Monday 14 of May 2012 17:12:53 Radek Vykydal wrote:

> Hi,
> I am trying to get NMIP4Config object after device becomes
> NetworkManager.DeviceState.ACTIVATED but it is not
> available immediately. Do I have to poll for it or is there any
> event/state I can use?
> Thanks,
> Radek

The thing is that StateChanged D-Bus signal (with activated state = 100)
comes before PropertiesChanged signal with the properties of the device.
And libnm-glib does set the state immediately without waiting for
PropertiesChanged in order to allow clients to see the right state when 
requesting it immediately after StateChanged appears.

So, you should wait a bit till PropertiesChanged D-Bus comes and
NMIP4Config is set. Or better monitor changes on NMIP4Config
property via glib "notify" signal on NMDevice.


#! /usr/bin/python

#  Get NMIP4Config from NMDevice
#  We need to listen to notify::ip4-config glib signal. This signal
#  is trigered by D-Bus PropertiesChanged for IP4Config that 
#  comes *after* StateChanged for NMDevice

from gi.repository import NMClient
from gi.repository import GObject
def do_notify(self, property):
    print "notify: %s" % property
    ip4cfg = self.get_ip4_config()
    print "ip4-config: %s" % ip4cfg
    if ip4cfg != None:

def state_changed(obj, arg1, arg2, arg3):
    print "State changed: New: %d, Old: %d, Reason: %d" % (arg1, arg2, arg3)
    ip4cfg = obj.get_ip4_config()
    print "ip4-config: %s" % ip4cfg
    print '---------------------------------------------'
    if arg1 == 100:
        obj.connect('notify::ip4-config', do_notify)

c =
dev = c.get_devices()[0]
print "Device: %s" % dev
print '---------------------------------------------------'

dev.connect('state-changed', state_changed)
loop = GObject.MainLoop() 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]