NetworkManager Settings and D-Bus



I am having a problem with my python script that does a IP refresh for our product.  When I run this script in Fedora 12 it works fine but when I run it in Fedora 15 it fails.  I have been told it works in Fedora 14 also.  The digging I did I found a few things but could not get ActivateConnection to work.

 

I found a python example from the NetworkManager web page that has all the components that I am using so I thought I would try it to see if it would work for me and I get the same error using this as I do my own code.

 

I am running Python 2.7.1 (r271:86832, Apr 12 2011, 16:16:18)   and the NetworkManager version that is returned is 0.8.9997.

 

The error I am getting is this:

 

ERROR:dbus.connection:Unable to set arguments ('org.freedesktop.NetworkManager', dbus.ObjectPath('/org/freedesktop/NetworkManager/Settings/0'), dbus.ObjectPath('/org/freedesktop/NetworkManager/Devices/0'), '/') according to signature u'ooo': <type 'exceptions.TypeError'>: Fewer items found in D-Bus signature than in Python arguments

Traceback (most recent call last):

  File "/usr/lib/python2.7/site-packages/dbus/connection.py", line 586, in msg_reply_handler

    reply_handler(*message.get_args_list(**get_args_opts))

  File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 391, in _introspect_reply_handler

    self._introspect_execute_queue()

  File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 378, in _introspect_execute_queue

    proxy_method(*args, **keywords)

  File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 132, in __call__

    **keywords)

  File "/usr/lib/python2.7/site-packages/dbus/connection.py", line 566, in call_async

    message.append(signature=signature, *args)

TypeError: Fewer items found in D-Bus signature than in Python arguments

 

 

The code I am running to get this error is below in the e-mail and is modified slightly, I added my UUID, changed it to detect wired instead of wireless and have it activate even if the connection is already active.

 

Does anyone know what changed in the API that would cause this?

 

Thanks for any help you can provide.

Bob

 

 

#!/usr/bin/env python

#

# This program is free software; you can redistribute it and/or modify

# it under the terms of the GNU General Public License as published by

# the Free Software Foundation; either version 2 of the License, or

# (at your option) any later version.

#

# This program is distributed in the hope that it will be useful,

# but WITHOUT ANY WARRANTY; without even the implied warranty of

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

# GNU General Public License for more details.

#

# You should have received a copy of the GNU General Public License along

# with this program; if not, write to the Free Software Foundation, Inc.,

# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#

# Copyright (C) 2009 Novell, Inc.

# Copyright (C) 2009 Red Hat, Inc.

#

 

# Run this script without any arguments to list the available connection uuids.

 

# The uuid of the connection to activate

CONNECTION_UUID="b3f183d2-2455-f5ce-8174-edd8fc884742"

 

#CONNECTION_UUID="ac6dc9b2-85ef-4311-83d8-add5d7db3f59"

 

# UID to use. Note that NM only allows the owner of the connection to activate it.

#UID=1000

UID=0

 

import sys

import os

import dbus

from dbus.mainloop.glib import DBusGMainLoop

import gobject

 

DBusGMainLoop(set_as_default=True)

 

def get_connections():

    bus = dbus.SystemBus()

    proxy = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager/Settings')

    iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager.Settings')

    return iface.ListConnections()

 

 

def get_connection_by_uuid(uuid):

    bus = dbus.SystemBus()

    for c in get_connections():

        proxy = bus.get_object('org.freedesktop.NetworkManager', c)

        iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager.Settings.Connection')

        settings = iface.GetSettings()

        if settings['connection']['uuid'] == uuid:

            return c

 

    return None

 

 

def list_uuids():

    bus = dbus.SystemBus()

    for c in get_connections():

        proxy = bus.get_object('org.freedesktop.NetworkManager', c)

        iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager.Settings.Connection')

        settings = iface.GetSettings()

        conn = settings['connection']

        print "%s - %s (%s)" % (conn['uuid'], conn['id'], conn['type'])

 

 

def get_active_connection_path(uuid):

    bus = dbus.SystemBus()

    proxy = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')

    iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.DBus.Properties')

    active_connections = iface.Get('org.freedesktop.NetworkManager', 'ActiveConnections')

    all_connections = get_connections()

 

    for a in active_connections:

        proxy = bus.get_object('org.freedesktop.NetworkManager', a)

        iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.DBus.Properties')

        path = iface.Get('org.freedesktop.NetworkManager.Connection.Active', 'Connection')

 

        proxy = bus.get_object('org.freedesktop.NetworkManager', path)

        iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager.Settings.Connection')

        settings = iface.GetSettings()

 

        if settings['connection']['uuid'] == uuid:

            return a

 

    return None

 

 

def get_wifi_device_path():

    bus = dbus.SystemBus()

    proxy = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')

    iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager')

    devices = iface.GetDevices()

    for d in devices:

        proxy = bus.get_object('org.freedesktop.NetworkManager', d)

        iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.DBus.Properties')

        devtype = iface.Get('org.freedesktop.NetworkManager.Device', 'DeviceType')

        if devtype == 1:

            return d

    return None

 

def activate_connection(connection_path, device_path):

 

    def reply_handler(opath):

                print "Success: device activating"

        sys.exit(0)

 

    def error_handler(*args):

                print "Error activating device: %s" % args

        sys.exit(1)

 

    bus = dbus.SystemBus()

    proxy = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')

    iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager')

    iface.ActivateConnection('org.freedesktop.NetworkManager',

                             connection_path,

                             device_path,

                             "/",

                             reply_handler=reply_handler,

                             error_handler=error_handler)

 

 

# Change the UID first if required

if UID != 0:

    os.setuid(UID)

 

# Are we configured?

if not len(CONNECTION_UUID):

    print "missing connection UUID"

    sys.exit(0)

 

connection_path = get_connection_by_uuid(CONNECTION_UUID)

if not connection_path:

    # Configured VPN connection is not known to NM, check CONNECTION_UUID.

    print "couldn't find the connection"

    sys.exit(1)

 

device_path = get_wifi_device_path()

if not device_path:

    print "no wifi device found"

    sys.exit(1)

 

# Is it already activated?

if get_active_connection_path(CONNECTION_UUID):

    print "already connected"

#    sys.exit(0)

 

print "Activating connection..."

activate_connection(connection_path, device_path)

loop = gobject.MainLoop()

loop.run()

 



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