summaryrefslogtreecommitdiffstats
path: root/python
Commit message (Collapse)AuthorAgeFilesLines
* python: fix flake8 warningsThomas Haller2024-07-192-3/+3
| | | | | | ./python/netlink/route/tc.py:599:37: C408 Unnecessary dict call - rewrite as a literal. ./python/netlink/route/tc.py:610:16: C416 Unnecessary list comprehension - rewrite using list(). ./python/netlink/util.py:106:47: C408 Unnecessary dict call - rewrite as a literal.
* python: Use correct decorator syntax in HTBQdiscDavid Ward2023-08-301-1/+1
| | | | | | Fixes: 87d370912ca8 ("netlink.nlattr re-implemented in more pythonic way") https://github.com/thom311/libnl/pull/359
* python: drop unused "python/netlink/fixes.h"Thomas Haller2023-08-031-1/+0
|
* python: fix flake8 warnings E712Thomas Haller2023-07-251-1/+1
| | | | ./python/netlink/route/links/bridge.py:29:31: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
* python: fix flake8 warnings E711Thomas Haller2023-07-251-1/+1
| | | | ./python/netlink/core.py:194:17: E711 comparison to None should be 'if cond is None:'
* python: fix flake8 warnings E302Thomas Haller2023-07-251-0/+1
| | | | ./python/netlink/util.py:19:1: E302 expected 2 blank lines, found 1
* python: fix flake8 warnings E741Thomas Haller2023-07-253-12/+12
| | | | | | | ./python/netlink/core.py:424:9: E741 ambiguous variable name 'l' ./python/netlink/route/link.py:476:13: E741 ambiguous variable name 'l' ./python/netlink/route/tc.py:554:5: E741 ambiguous variable name 'l' ./python/netlink/route/tc.py:574:5: E741 ambiguous variable name 'l'
* python: fix flake8 warnings F841Thomas Haller2023-07-252-4/+4
| | | | | | | | | ./python/examples/iface.py:66:5: F841 local variable 'e' is assigned to but never used ./python/examples/iface.py:66:5: F841 local variable 'e' is assigned to but never used ./python/examples/iface.py:109:1: F841 local variable 'e' is assigned to but never used ./python/examples/wiphy.py:116:5: F841 local variable 'e' is assigned to but never used ./python/examples/wiphy.py:116:5: F841 local variable 'e' is assigned to but never used ./python/examples/wiphy.py:158:1: F841 local variable 'e' is assigned to but never used
* python: fix flake8 warnings F401Thomas Haller2023-07-252-4/+0
| | | | | | | | | ./doc/doxygen-link.py:4:1: F401 'fileinput' imported but unused ./doc/resolve-asciidoc-refs.py:5:1: F401 'fileinput' imported but unused ./python/doc/conf.py:14:1: F401 'sys' imported but unused ./python/doc/conf.py:14:1: F401 'os' imported but unused ./python/netlink/util.py:13:1: F401 '.core as netlink' imported but unused ./python/netlink/util.py:16:1: F401 'types' imported but unused
* python: reformat all Python files with python-blackThomas Haller2023-07-2516-1352/+1495
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Automated code formatting is great. Use python-black for that ([1]). Black us not configurable much (uncompromising) and follows PEP8. It thus generates quite a standard, pleasing format. But the point isn't whether the formatting is always the most subjectively pleasing. The point is that the style is generated and enforceable by an automated tool. It takes away places for nit picking, while resulting in a more consistent code base. As this reformats the entire code base, it introduces a large diff and interferes with tools like git-blame. That will be somewhat alleviated by adding a "blame.ignoreRevsFile" for git in the next commit. The change is done automatically, by running python-black version black-22.8.0-2.fc38.noarch: $ black . The result is the same as $ ( git grep -l '#!.*\(PYTHON\|python\)' ; git ls-files '*.py' '*.py.in' ) \ | sort -u \ | xargs -d '\n' black Note that the exact result depends on the version of black. Currently that version is black==22.12.0 from pip. Yes, this means when we bump the version in the future, some reformatting will happen. [1] https://github.com/psf/black
* Use print() function in both Python 2 and Python 3Christian Clauss2022-07-067-46/+47
| | | | https://github.com/thom311/libnl/pull/327
* gitignore: merge all gitignore files in top level directoryThomas Haller2020-04-161-4/+0
| | | | | | | The source tree of libnl3 is fairly simple. We can afford thinking and reasoning about it as one. Don't spread out the .gitignore files, instead ignore all files consistently via the ignore file in the top level directory.
* all: Use __typeof__ instead of typeofMichael Forney2019-08-161-1/+1
| | | | | This allows libnl to be built with -std=c99, which prevents the compiler from using non-reserved identifiers for extensions.
* build: merge python/Makefile.am into top-level makefileThomas Haller2017-02-277-52/+0
|
* python: genl: capi: add genlmsg_hdr() to capiArend van Spriel2015-05-121-0/+8
| | | | | | | Allow using genlmsg_hdr() function and make the header fields accessible in Python scripts. Signed-off-by: Arend van Spriel <aspriel@gmail.com>
* python: capi: add nla_put() function to python capiArend van Spriel2015-05-121-0/+14
| | | | | | | | Adding nla_put() to the capi using a typemap on the input parameter which needs to be either a str or bytearray. Otherwise a SWIG exception with be thrown. Signed-off-by: Arend van Spriel <aspriel@gmail.com>
* python: capi: expose multicast membership functionsArend van Spriel2015-05-121-0/+3
| | | | | | Adding functions to add/drop membership to single multicast group. Signed-off-by: Arend van Spriel <aspriel@gmail.com>
* python: disable swig debug print messagesArend van Spriel2015-05-121-1/+2
| | | | | | | | The define was left enabled during development on netlink (and genl) python swig api. It is a bit annoying in production release so disable the define. Signed-off-by: Arend van Spriel <aspriel@gmail.com>
* python: fix package meta data in setup.pyThomas Haller2015-01-121-0/+4
| | | | | | | http://lists.infradead.org/pipermail/libnl/2015-January/001802.html Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
* Use paths relative to srcdir in setup.py.Michał Górny2014-05-251-4/+5
| | | | | | | | | | | | | | | | | Currently, setup.py is created by configure in builddir while source files (.py and .i) reside in srcdir. Adjust paths in setup.py appropriately to make it possible to perform an out-of-source build. This is far from perfect but it mostly works. Python files are copied from srcdir, and swig *.i files are read from there. However, swig output files are created in srcdir rather than builddir, and distutils copies '..' literally when constructing '.o' paths. As a result, '../python/foo.i' would end up being compiled to 'build/temp*/../python/foo.i'. The alternative would be to copy '*.i' files to builddir before proceeding with the build, either in Makefile or through creating additional distutils command.
* python: fix wrongly passing argument to function in ObjIterator.next()Hiroaki KAWAI2014-04-091-1/+1
| | | | | | | | | self.__next__() bound method does not take an extra argument. https://github.com/thom311/libnl/pull/57 Signed-off-by: Hiroaki KAWAI <kawai@stratosphere.co.jp> Signed-off-by: Thomas Haller <thaller@redhat.com>
* python: fix build error for missing library_path in setup.pyThomas Haller2014-01-211-0/+4
| | | | | | | | | Patch obtained from gentoo package. https://bugs.gentoo.org/show_bug.cgi?id=477110 https://bugs.gentoo.org/show_bug.cgi?id=490584 Signed-off-by: Thomas Haller <thaller@redhat.com>
* python: Include all files in distributionThomas Graf2013-11-065-2/+22
| | | | Signed-off-by: Thomas Graf <tgraf@suug.ch>
* python: add bridge flags APINicolas PLANEL2013-10-222-0/+45
| | | | | | | | | | | Add flags set/get methods aim to change bridge flags : o hairpin_mode o bpdu_guard o root_block o fast_leave Signed-off-by: Nicolas PLANEL <nicolas.planel@enovance.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* test: add python bridge testing sampleNicolas PLANEL2013-10-221-0/+28
| | | | | | | | New test sample file, test-create-bridge.py Create an bridge (testbrige) and attach an already setup interface (testtap1) to it. Signed-off-by: Nicolas PLANEL <nicolas.planel@enovance.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* python: add basic netlink protocol bridge interface supportNicolas PLANEL2013-10-223-0/+118
| | | | | | | Implements basic bridge interface support using netlink protocol Signed-off-by: Nicolas PLANEL <nicolas.planel@enovance.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* Fixed ObjIterator for python3, fixed output of _color and added missing ↵Teto2013-10-072-3/+9
| | | | | | | | | | | | | | | | | | | | parameter to nl_cache_resync Here are a few things I fixed and that provoked a python error. I canno't answer to this thread but one solution I found while using the python binding is to iterate over all and filter via python http://list-archives.org/2013/09/09/libnl-lists-infradead-org/missing-feature-for-retrieving-cached- address-objects/f/5031600704 Example: cache = nlrta.AddressCache() cache.resync() for i in cache: print ("item", i ) # then you can filter here Signed-off-by: Thomas Graf <tgraf@suug.ch>
* python: fixup VLANLink() initializationNicolas PLANEL2013-10-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | | The varialble name should be link._rtnl_link instead of link._link to get rid of the AttributeError. Traceback (most recent call last): File "examples/test.py", line 11, in <module> eth0 = link.resolve('eth0.800') ... File "/home/ubuntu/libnl/python/build/lib.linux-x86_64-2.7/netlink/route/link.py", line 151, in __init__ self._module_lookup('netlink.route.links.' + self.type) ... File "/home/ubuntu/libnl/python/build/lib.linux-x86_64-2.7/netlink/route/links/vlan.py", line 70, in init link.vlan = VLANLink(link._link) AttributeError: 'Link' object has no attribute '_link' Signed-off-by: Nicolas PLANEL <nicolas.planel@enovance.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* python: remove use of PyArg_ParseTuple() for callback resultArend van Spriel2013-10-072-12/+17
| | | | | | | | | | | | | | The message receive callback handler in the netlink api processes the result object from the python callback. It used PyArg_ParseTuple() to get the value, but this does not work as intended (see ref [1]). Instead check the type and convert it accordingly. refs: [1] http://stackoverflow.com/questions/13636711/what-is-the-proper-usage-of-pyarg-parsetuple Reported-by: Teto <mattator@gmail.com> Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* python: add send and receive functions to Socket classArend van Spriel2013-09-051-0/+15
| | | | | | | | Adding class methods send_auto_complete() and recvmsgs() that call their swig capi equivalent function. Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* python: fix typo in Socket::__str__() functionArend van Spriel2013-09-051-1/+1
| | | | | | | | | | | | | | | The property name used in __str__ should be local_port instead of localPort to get rid of the AttributeError. >>> str(s) Traceback (most recent call last): File "<stdin>", line 1, in <module> File ".../netlink/core.py", line 172, in __str__ return 'nlsock<{0}>'.format(self.localPort) AttributeError: 'Socket' object has no attribute 'localPort' Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* python: remove unnecessary callback type definitionsArend van Spriel2013-09-051-18/+0
| | | | | | | | Copied the typedefs when adding callback support, but they serve no actual use in the swig input file. Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* python: allow callback function to be a class methodArend van Spriel2013-09-051-4/+28
| | | | | | | | | | | | | | | | | | | | | | The callback functionality only worked for regular Python functions. With this patch it also allows the callback to be a class method (bounded or unbounded) as show in example below. class test_class(object): def my_callback(self, msg, arg): print('handling %s' % str(msg)) s = netlink.core.Socket() testobj = test_class() netlink.capi.py_nl_cb_set(cb, netlink.capi.NL_CB_VALID, netlink.capi.NL_CB_CUSTOM, test_class.my_callback, testobj) netlink.capi.py_nl_cb_err(cb, netlink.capi.NL_CB_CUSTOM, test_class.my_callback, s) Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* use Callback object constructing SocketArend van Spriel2013-09-051-2/+4
| | | | | Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* python: rework netlink callback handlingArend van Spriel2013-09-053-27/+221
| | | | | | | | | | | | | | | | | | The initial commit adding netlink callback handling also introduced memory leak issue. The python callback info was stored in an allocated structure, but that was never freed. Only exposing nl_cb_alloc() as is. nl_cb_get() is removed as it is not very useful to use reference counting mechanism. Python uses that itself internally. To deal properly with Python callback info the function nl_cb_put() and nl_cb_clone() have a custom wrapper taking care of Python reference counting. This commit also adds a Callback python class using the netlink callback functions. Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* add python examples using swig provided apiArend van Spriel2013-09-053-0/+1811
| | | | | | | | using the nl80211 family to show use of generic netlink api and attribute parsing. Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* Add VXLAN support.Yasunobu Chiba2013-08-041-0/+63
|
* add generic netlink functions to swigArend van Spriel2013-07-181-0/+97
| | | | | | | | | Provide wrapper function for generic netlink library functions. The genlmsg_parse() function is handled similar to nla_parse_nested() so it returns tuple with error code and dictionary of parsed attributes. Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* add python module for generic netlink libraryArend van Spriel2013-07-185-4/+27
| | | | | | | | | This commit adds creation of the netlink.genl package. The actual capi.i will be filled in upcoming commits so the module is rather dumb for now. Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* add support functions for attributes and callback handlersArend van Spriel2013-07-181-0/+373
| | | | | | | | | | | | | | | | | | | | | | | | | | | | added support functions to access the netlink attributes and use custom callback handlers. Most is wrapped as is, but there are a couple of special cases handled. 1) void *nla_data(struct nlattr *); The return value is changed to a Python byte array so it includes the lenght of the data stream. 2) int nla_parse_nested(...); This returns a tuple (err, dict). 'err' is the error code and 'dict' is a dictionary with attribute identifier as key and value represents a struct nlattr object. 3) macro nla_for_each_nested() Provide nla_get_nested() which returns a Python list of struct nlattr objects that is iterable. 4) allocate struct nla_policy array Provide nla_policy_array() function that allocates consecutive space in memory for struct nla_policy array entries. Each entry is put in a Python list so the entry fields can be modified in Python. This array object can be passed to the nla_parse_nested() function. Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* Add macvlan supportMichael Braun2013-05-161-0/+16
| | | | | | This patch add support for kernel macvlan interfaces. Signed-off-by: Michael Braun <michael-dev@fami-braun.de>
* Enabled the use of Links as context managers.Antoni S. Puimedon2012-10-041-0/+9
| | | | | | | | | | | | | | | | | With this change you can still set do modifications of Links and then to change to pass the changes to the kernel. But it additionally enables you to interact with this part of libnl-python in a more pythonic way. Instead of: eth0 = links['eth0'] eth0.mtu = 5000 eth0.change() you can do: with links['eth0'] as eth0: eth0.mtu = 5000
* Fixed memory leak in Cache destructorКоренберг Марк2012-06-081-1/+1
| | | | destructor of Cache was missing due to typo
* rtnl_link_(get|set)_weight is deprecated in libnl.Коренберг Марк (ноутбук дома)2012-06-082-21/+0
| | | | So, remove from python binding. Should not break compatibility.
* netlink.nlattr re-implemented in more pythonic wayКоренберг Марк2012-06-088-116/+66
|
* nl_pickup removed from python bindingКоренберг Марк2012-06-081-5/+0
|
* Remove unnecessary commentsКоренберг Марк (ноутбук дома)2012-06-086-186/+0
|
* Refine some placesКоренберг Марк (ноутбук дома)2012-06-082-19/+20
| | | | No real logick change
* pylint's first review and trivial fixesКоренберг Марк (ноутбук дома)2012-06-088-91/+105
|
* Using only single quotes now and multi-line listsКоренберг Марк (ноутбук дома)2012-06-087-41/+59
| | | | Nothing algorithmic changed really, just cosmetics