I need to develop some python code to be executed when a VPN connection is established, the VPN is controlled from NetworkManager, I am trying to figure how to use an NM DBUS event for this.
Using "dbus-monitor --system" I was able to identify the connect signal:
signal sender=:1.1 -> dest=(null destination) serial=464 path=/org/freedesktop/NetworkManager/ActiveConnection/3; interface=org.freedesktop.NetworkManager.VPN.Connection; member=PropertiesChanged
array [
dict entry(
string "VpnState"
variant uint32 5
)
dict entry(
string "State"
variant uint32 2
)
]
Now I need to identify the corresponding signal handler calling signature:
bus.add_signal_receiver(
handler_name_in_your_program,
"signal_name",
"interface_name",
"connection_name",
"object_name"
)
Can someone help me translating the dbus-monitor trace output into the corresponding function values for the bus sginal handler ?
I was able to figure it out:
def vpn_connection_handler(*args, **keywords):
state = args[0].get('State',0)
if state == 2:
# On connect code goes here
system_bus.add_signal_receiver(vpn_connection_handler,
dbus_interface="org.freedesktop.NetworkManager.VPN.Connection",
signal_name="PropertiesChanged")
来源:https://stackoverflow.com/questions/4401851/dbus-signal-handler-for-e-networkmanager-vpn-connection