seveas / python-networkmanager

Easy communication with NetworkManager
http://packages.python.org/python-networkmanager/
Other
166 stars 90 forks source link

Canot create static route-data #59

Closed yanhaizhongyu closed 3 years ago

yanhaizhongyu commented 6 years ago

Got the following error.

ERROR:dbus.connection:Unable to set arguments ({u'802-3-ethernet': {u'auto-negotiate': False}, u'connection': {u'id': u'eth0', u'timestamp': 1537683468, u'type': u'802-3-ethernet', u'interface-name': u'eth0', u'uuid': u'c15deb3e-e4a9-44cb-a9ef-3d5b4c8b3d68'}, u'ipv4': {u'addresses': [[dbus.UInt32(906100746L), dbus.UInt32(24L), dbus.UInt32(33685514L)]], u'gateway': u'10.0.2.2', 'route-data': [{'dest': u'172.16.0.0', 'next-hop': u'172.25.73.161', 'prefix': 12}, {'dest': '192.168.32.0', 'next-hop': '192.168.30.1', 'prefix': 24}], u'dns': [dbus.UInt32(134744072L)], u'address-data': dbus.Array([{u'prefix': dbus.UInt32(24L), u'address': u'10.0.2.54'}], signature=dbus.Signature('a{sv}')), u'method': u'manual'}, u'ipv6': {u'method': u'auto'}},) according to signature u'a{sa{sv}}': <type 'exceptions.TypeError'>: Expected a string or unicode object Traceback (most recent call last): ............. self.connection.Update(self.settings) File "", line 4, in Update File "/usr/lib64/python2.7/site-packages/dbus/proxies.py", line 145, in call *keywords) File "/usr/lib64/python2.7/site-packages/dbus/connection.py", line 641, in call_blocking message.append(signature=signature, args)

yanhaizhongyu commented 6 years ago

need to handle the prefix in route-data: class fixups(object): @staticmethod def to_dbus(klass, method, arg, val, signature):

     ..................................
        if 'ipv4' in settings:
            if 'address-data' in settings['ipv4']:
                for item in settings['ipv4']['address-data']:
                    item['prefix'] = dbus.UInt32(item['prefix'])
                settings['ipv4']['address-data'] = dbus.Array(
                    settings['ipv4']['address-data'],
                    signature=dbus.Signature('a{sv}'))
            if 'route-data' in settings['ipv4']:
                for item in settings['ipv4']['route-data']:
                    item['prefix'] = dbus.UInt32(item['prefix'])
                settings['ipv4']['route-data'] = dbus.Array(
                    settings['ipv4']['route-data'],
                    signature=dbus.Signature('a{sv}'))
PhilippHomann commented 5 years ago

Thanks @yanhaizhongyu for this fix. Faced the same issue too.

@seveas Could you please pull this?