Re: Creating NetworkManager connections via DBus API
On Tue, 2014-07-08 at 08:57 +1000, Stuart Longland wrote: On 08/07/14 07:56, Dan Williams wrote: and so the 'connection' bit would be mandatory, and you might have *one* each of the other setting types? The type setting (eg 803-3-ethernet, 802-11-wireless, gsm, cdma, bluetooth, etc) is required too. The 'type' setting and the 'connection' setting are the only required ones. Usually you'd lock the connection to a MAC address with the type setting, or it would contain stuff like MTU, SSID, and other hardware-specific stuff, so you can't really leave it out. Okay, so there's a setting called type too, that I presume is distinct from the connection setting's type attribute. i.e. the minimum required: Oh sorry :) I was unclear. By 'type' I mean 802-3-ethernet or 802-11-wireless or gsm or cdma or infiniband or bluetooth. eg, the type of hardware to be used. The name of that setting (a few of which I've typed in quotes in the last sentence) is put into the type property of the connection setting, like: s_con = dbus.Dictionary({ -- 'type': '802-11-wireless', 'uuid': '7371bb78-c1f7-42a3-a9db-5b9566e8ca07', 'id': 'My Wifi'}) ... con = dbus.Dictionary({ 'connection': s_con, -- '802-11-wireless': s_wifi }) Specifically, see: http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/python/dbus/add-connection.py#n36 http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/python/dbus/add-system-wifi-connection.py#n25 for two examples. {'connection': {...}, 'type': {...}, ...} Where do I find information on this type setting? Doing a search for type setting on https://developer.gnome.org/NetworkManager/0.9/ref-settings.html shows no matches. IPv4 and IPv6 are optional if you want automatic (DHCP, PPP/WWAN, etc) addressing, but obviously if you want static you have to specify one or both. Ahh so a minimal one might give a 'connection' object, whose 'interface' attribute references one of the physical network ports, and it'll just configure the network via DHCP. Right; if you don't specify the IPv4 and/or IPv6 settings, they default to automatic which means DHCP for IPv4 and SLAAC for IPv6. Dan ___ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list
Re: Creating NetworkManager connections via DBus API
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
Re: Creating NetworkManager connections via DBus API
Hi Dan, On 08/07/14 02:55, Dan Williams wrote: 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: [...] 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. Yep, just experimenting with python-networkmanager, it seems this is one of the details it looks after: IP addresses are translated to strings, endianness is taken care of, etc. Dicts are plain Python dicts. Just looking at the documentation there though, am I correct in assuming that to set up a simple connection, you would have a dict of the form: {'connection': { global connection settings }, 'ipv4': { IPv4 address settings }, 'ipv6': { IPv6 address settings }, } and so the 'connection' bit would be mandatory, and you might have *one* each of the other setting types? Regards, -- Stuart Longland Systems Engineer _ ___ \ /|_) | T: +61 7 3535 9619 \/ | \ | 38b Douglas StreetF: +61 7 3535 9699 SYSTEMSMilton QLD 4064 http://www.vrt.com.au ___ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list
Re: Creating NetworkManager connections via DBus API
On Tue, 2014-07-08 at 05:55 +1000, Stuart Longland wrote: Hi Dan, On 08/07/14 02:55, Dan Williams wrote: 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: [...] 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. Yep, just experimenting with python-networkmanager, it seems this is one of the details it looks after: IP addresses are translated to strings, endianness is taken care of, etc. Dicts are plain Python dicts. Just looking at the documentation there though, am I correct in assuming that to set up a simple connection, you would have a dict of the form: {'connection': { global connection settings }, 'ipv4': { IPv4 address settings }, 'ipv6': { IPv6 address settings }, } and so the 'connection' bit would be mandatory, and you might have *one* each of the other setting types? The type setting (eg 803-3-ethernet, 802-11-wireless, gsm, cdma, bluetooth, etc) is required too. The 'type' setting and the 'connection' setting are the only required ones. Usually you'd lock the connection to a MAC address with the type setting, or it would contain stuff like MTU, SSID, and other hardware-specific stuff, so you can't really leave it out. IPv4 and IPv6 are optional if you want automatic (DHCP, PPP/WWAN, etc) addressing, but obviously if you want static you have to specify one or both. Dan ___ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list
Re: Creating NetworkManager connections via DBus API
On 08/07/14 07:56, Dan Williams wrote: and so the 'connection' bit would be mandatory, and you might have *one* each of the other setting types? The type setting (eg 803-3-ethernet, 802-11-wireless, gsm, cdma, bluetooth, etc) is required too. The 'type' setting and the 'connection' setting are the only required ones. Usually you'd lock the connection to a MAC address with the type setting, or it would contain stuff like MTU, SSID, and other hardware-specific stuff, so you can't really leave it out. Okay, so there's a setting called type too, that I presume is distinct from the connection setting's type attribute. i.e. the minimum required: {'connection': {...}, 'type': {...}, ...} Where do I find information on this type setting? Doing a search for type setting on https://developer.gnome.org/NetworkManager/0.9/ref-settings.html shows no matches. IPv4 and IPv6 are optional if you want automatic (DHCP, PPP/WWAN, etc) addressing, but obviously if you want static you have to specify one or both. Ahh so a minimal one might give a 'connection' object, whose 'interface' attribute references one of the physical network ports, and it'll just configure the network via DHCP. -- Stuart Longland Systems Engineer _ ___ \ /|_) | T: +61 7 3535 9619 \/ | \ | 38b Douglas StreetF: +61 7 3535 9699 SYSTEMSMilton QLD 4064 http://www.vrt.com.au ___ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list
Re: Creating NetworkManager connections via DBus API
Hi Thomas, On 05/07/14 00:40, Thomas Haller wrote: 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: 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. Did you see https://wiki.gnome.org/Projects/NetworkManager/Developers ? especially https://developer.gnome.org/NetworkManager/0.9/ref-settings.html (or try `man nm-settings` if you have the manual pages installed) Ahh no, I didn't see that, and it seems I wasn't asking Google the right question. :-) Is there any reason why those aren't mentioned under the Development Resources on https://wiki.gnome.org/action/show/Projects/NetworkManager?action=showredirect=NetworkManager ? Probably host name too (not sure if that's doable in NetworkManager). SaveHostname , see https://developer.gnome.org/NetworkManager/0.9/spec.html Brilliant. Thanks. :-) Regards, -- Stuart Longland Systems Engineer _ ___ \ /|_) | T: +61 7 3535 9619 \/ | \ | 38b Douglas StreetF: +61 7 3535 9699 SYSTEMSMilton QLD 4064 http://www.vrt.com.au ___ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list
Re: Creating NetworkManager connections via DBus API
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. Did you see https://wiki.gnome.org/Projects/NetworkManager/Developers ? especially https://developer.gnome.org/NetworkManager/0.9/ref-settings.html (or try `man nm-settings` if you have the manual pages installed) Probably host name too (not sure if that's doable in NetworkManager). SaveHostname , see https://developer.gnome.org/NetworkManager/0.9/spec.html 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. I would say, this *should* all work (without knowing your exact requirements) Is there some documentation as to how these various network types are specified as dict objects to NetworkManager? I think above links is a good starting point, otherwise just ask. Thomas signature.asc Description: This is a digitally signed message part ___ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list
Creating NetworkManager connections via DBus API
Hi all, I'm in the process of writing a web frontend for a small Linux-based appliance, thus am in need of a tool for configuring the network interfaces. NetworkManager seems to be a good fit in that it supports a wide variety of networks and runs as a daemon which is then accessed by unprivileged users. The web front-end software we're writing is based on Django, and I'm creating a collection of models which will represent the configuration of the network interface. There's a nice Python library; python-networkmanager which provides an abstraction ontop of DBus so accessing NetworkManager isn't too painful. https://pythonhosted.org/python-networkmanager/ So my task now, is knowing the name of a network device, its intended IP address, routes, DNS configuration, etc, is to figure out how to tell NetworkManager about it and get it to connect. Now, there's a DBus spec which describes the objects here: https://developer.gnome.org/NetworkManager/unstable/spec.html Great. By the looks of things, I create a org.freedesktop.NetworkManager.Settings.Connection object, then hand that to org.freedesktop.NetworkManager's ActivateConnection method. 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? Regards, -- Stuart Longland Systems Engineer _ ___ \ /|_) | T: +61 7 3535 9619 \/ | \ | 38b Douglas StreetF: +61 7 3535 9699 SYSTEMSMilton QLD 4064 http://www.vrt.com.au ___ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list
Re: Creating NetworkManager connections via DBus API
On Fri, 2014-07-04 at 09:18 +1000, Stuart Longland wrote: Hi all, I'm in the process of writing a web frontend for a small Linux-based appliance, thus am in need of a tool for configuring the network interfaces. NetworkManager seems to be a good fit in that it supports a wide variety of networks and runs as a daemon which is then accessed by unprivileged users. The web front-end software we're writing is based on Django, and I'm creating a collection of models which will represent the configuration of the network interface. There's a nice Python library; python-networkmanager which provides an abstraction ontop of DBus so accessing NetworkManager isn't too painful. https://pythonhosted.org/python-networkmanager/ So my task now, is knowing the name of a network device, its intended IP address, routes, DNS configuration, etc, is to figure out how to tell NetworkManager about it and get it to connect. Now, there's a DBus spec which describes the objects here: https://developer.gnome.org/NetworkManager/unstable/spec.html Great. By the looks of things, I create a org.freedesktop.NetworkManager.Settings.Connection object, then hand that to org.freedesktop.NetworkManager's ActivateConnection method. 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? Hi! 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? 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(). Let me know if this helps, happy to answer any more questions you might have! Dan ___ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list
Re: Creating NetworkManager connections via DBus API
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. 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, -- Stuart Longland Systems Engineer _ ___ \ /|_) | T: +61 7 3535 9619 \/ | \ | 38b Douglas StreetF: +61 7 3535 9699 SYSTEMSMilton QLD 4064 http://www.vrt.com.au ___ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list