On Fri, 2014-07-04 at 11:51 +1000, Stuart Longland wrote:
> Hi Dan,
> On 04/07/14 10:51, Dan Williams wrote:
> > On Fri, 2014-07-04 at 09:18 +1000, Stuart Longland wrote:
> >> But how do I encode my address settings in a Settings.Connection object?
> >>  Where do I find a list of the settings and their possible values?
> > There's actually a bunch of Python examples here:
> > 
> > http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/python
> > 
> > that use both plain dbus and Python GObject introspection.  The GObject
> > introspection ones are similar to python-networkmanager actually.  I'm
> > not sure how python-networkmanager accepts a new connection to add, but
> > perhaps the examples give you an idea how to do that?
> 
> Ahh okay, that's handy.  I'll have a dig through those and see what I
> can uncover.
> 
> > I'd expect it to
> > be a normal "dict of dicts" like the examples above show which is then
> > passed to org.freedesktop.NetworkManager.Settings.AddConnection().
> 
> It does appear that way, I tried pulling the information out for my
> Ethernet connection and got:
> > In [9]: conn.GetSettings()
> > Out[9]: 
> > {u'bridge': {u'interface-name': u'br0', u'stp': False},
> >  u'connection': {u'id': u'Bridge Ethernet',
> >   u'type': u'bridge',
> >   u'uuid': u'357c4dcf-2600-45fa-8687-05f4c2cb82b4',
> >   u'zone': u'work'},
> >  u'ipv4': {u'addresses': [],
> >   u'dns': [],
> >   u'may-fail': False,
> >   u'method': u'auto',
> >   u'routes': []},
> >  u'ipv6': {u'addresses': [], u'dns': [], u'method': u'auto', u'routes': []}}
> 
> It seems NetworkManager doesn't much like my hand-configured bridge
> (won't see its IP address), but that's a side issue.
> 
> What I'm curious about is what sorts of keys and values are expected in
> that dict of dicts?  At a basic level I need to be able to set IP
> addresses, static routes, DNS servers, domain and DNS search order.

As thomas already mentioned, these should be covered in the API
documentation that he linked.  Note that IPv4 addresses are arrays of
uint32 (address/prefix/optional gateway) and IPv4 routes are too
(network/prefix/next-hop/metric).  The address/network/next-hop IP
address members are network-byte-order.  So the code in Python to push
that into the dict that can be sent over D-Bus is something like this,
taken from:

http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/python/dbus/add-connection.py

def ip_to_int(ip_string):
    return struct.unpack("=I", socket.inet_aton(ip_string))[0]

addr1 = dbus.Array([ip_to_int("10.1.2.3"), dbus.UInt32(8L), 
ip_to_int("10.1.2.1")], signature=dbus.Signature('u'))
s_ip4 = dbus.Dictionary({
            'addresses': dbus.Array([addr1], signature=dbus.Signature('au')),
            'method': 'manual'})
...
con = dbus.Dictionary({
    '802-3-ethernet': s_wired,
    'connection': s_con,
    'ipv4': s_ip4,
    'ipv6': s_ip6})

this is mainly because Python doesn't have strongly-typed variables, but
D-Bus does, so you have to tell Python what the mapping is between the
Python types and the D-Bus types.

Dan

> Probably host name too (not sure if that's doable in NetworkManager).
> 
> At least that will be the starting point.  The devices in question we're
> setting up will be headless boxes, basically appliances, intended to
> poll energy meters in an energy management system and pump the data
> elsewhere.
> 
> So mostly wired access, there's a couple of places where we have a
> bridges and OpenVPN for technical support on some sites and I envisage
> some possibly needing cellular 3G support.
> 
> No one has approached us with the need for WIFI support, but I bet
> someone will some day, thus it'd be useful to know how that's configured
> too.
> 
> Is there some documentation as to how these various network types are
> specified as dict objects to NetworkManager?
> 
> Regards,


_______________________________________________
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list

Reply via email to