summaryrefslogtreecommitdiff
path: root/examples
Commit message (Collapse)AuthorAgeFilesLines
* examples: support older libnm without NM.SettingOvsOtherConfig in ↵Thomas Haller2023-02-161-17/+24
| | | | | | | "ovs-external-ids.py" This example script is used by our NM-ci. Make it work also with libnm versions that don't yet support NM.SettingOvsOtherConfig.
* examples: rework "python/gi/show-wifi-networks.py" exampleThomas Haller2023-02-131-90/+159
| | | | | | | | | | | | | - only printing the scan list is not gonna cut it. It's usually stale, and we need to request a new scan. - don't hard-code the GEnum and GFlags values that we understand. We have libnm, which provides us some meta information about the data. Use it. - Some code cleanup. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1531
* ovs: add support for "other_config" settingsThomas Haller2023-01-111-55/+102
| | | | | | See `man ovs-vswitchd.conf.db` for documentation of "other_config" keys. https://bugzilla.redhat.com/show_bug.cgi?id=2151455
* examples: add python example for reapplyThomas Haller2022-12-141-0/+147
|
* examples: fix handling "--last" argument in "examples/python/gi/checkpoint.py"Thomas Haller2022-12-091-3/+3
| | | | Fixes: 3ce3ed4c92fb ('examples: improve finding last checkpoint in "checkpoint.py"')
* examples: fix code formatting in "gmaincontext.py"Thomas Haller2022-10-251-1/+1
|
* examples: avoid unreachable code in "gmaincontext.py"Thomas Haller2022-10-251-7/+5
| | | | lgtm.com warns about this. Avoid it.
* examples: drop unused import from "gmaincontext.py" exampleThomas Haller2022-10-251-1/+0
| | | | Complained by lgtm.com.
* examples: avoid lgtm warning about calling traceback.format_exception()Thomas Haller2022-10-251-1/+1
| | | | | | | lgtm.com says: Call to function format_exception with too few arguments; should be no fewer than 3.
* libnm: add nm_client_wait_shutdown() function for cleaning up NMClientThomas Haller2022-10-141-42/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a fire-and-forget function to wait for shutdown to be complete. It's not entirely trivial to ensure all resources of NMClient are cleaned up. That matters only if NMClient uses a temporary GMainContext that the user wants to release while the application continues. For example, to do some short-lived operations an a worker thread. It's not trivial also because glib provides no convenient API to integrate a GMainContext in another GMainContext. We have that code as nm_utils_g_main_context_create_integrate_source(), so add a helper function to allow the user to do this. The function allows to omit the callback, in which case the caller wouldn't know when shutdown is complete. That would still be useful however, when integrating the client's context into the caller's context, so that the client's context gets automatically iterated until completion. The following test script will run out of file descriptors, when wait_shutdown() is not used: #!/bin/python import gi gi.require_version("NM", "1.0") from gi.repository import NM, GLib for i in range(1200): print(f">>>{i}") ctx = GLib.MainContext() ctx.push_thread_default() nmc = NM.Client.new() ctx.pop_thread_default() def cb(unused, result, i): try: NM.Client.wait_shutdown_finish(result) except Exception: # cannot happen assert False else: print(f">>>>> {i} complete") nmc.wait_shutdown(True, None, cb, i) while GLib.MainContext.default().iteration(False): pass
* examples: fix tracking destruction in destroy_nmc()Thomas Haller2022-07-131-3/+3
| | | | | | | | | | While iterating the context (once), multiple sources can be dispatched. So if we get a timeout and shortly after the weak-ref callback, then we still need to honor the weak-ref. In particular, because weak_ref.unref() is not safe to do after the object was already destroyed. So we need to be correct about tracking destruction.
* example: add python example for libnm, NMClient, GMainContext and asyncThomas Haller2022-07-051-0/+448
| | | | https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1290
* feat: add example for wifi sae connectionliaohanqin2022-06-161-0/+36
| | | | https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1247
* examples: reword comments in "30-anon.conf" snippetThomas Haller2022-05-271-13/+12
|
* examples: improve finding last checkpoint in "checkpoint.py"Thomas Haller2022-05-021-5/+5
| | | | | This is a python example. We should do nice things, like using max() for finding the maximum, instead of sorting.
* examples: add "--last" argument to "examples/python/gi/checkpoint.py"Thomas Haller2022-02-231-44/+73
| | | | | | | | | | | | | "examples/python/gi/checkpoint.py" is not only an example. It's also a useful script for testing checkpoints. Support a "--last" argument to specify the last checkpoint created. Otherwise, when you are using this example from a test script, it can be cumbersome to find the right checkpoint point. Also, rename "client" and "nm_client" variables to "nmc". The purpose of using the same variable name for the same thing is readability, but also it works better when copy+paste snippets into the Python REPL.
* examples/python: avoid Python2 "print" statementThomas Haller2022-02-143-22/+28
| | | | | Recent python-black (22.0) dropped support for Python 2 and thus fail for those files. Make the examples Python3 compatible.
* example: Match more AP securityxiangnian2021-12-101-3/+21
| | | | https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1043
* format: reformat source tree with clang-format 13.0Thomas Haller2021-11-299-63/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | We use clang-format for automatic formatting of our source files. Since clang-format is actively maintained software, the actual formatting depends on the used version of clang-format. That is unfortunate and painful, but really unavoidable unless clang-format would be strictly bug-compatible. So the version that we must use is from the current Fedora release, which is also tested by our gitlab-ci. Previously, we were using Fedora 34 with clang-tools-extra-12.0.1-1.fc34.x86_64. As Fedora 35 comes along, we need to update our formatting as Fedora 35 comes with version "13.0.0~rc1-1.fc35". An alternative would be to freeze on version 12, but that has different problems (like, it's cumbersome to rebuild clang 12 on Fedora 35 and it would be cumbersome for our developers which are on Fedora 35 to use a clang that they cannot easily install). The (differently painful) solution is to reformat from time to time, as we switch to a new Fedora (and thus clang) version. Usually we would expect that such a reformatting brings minor changes. But this time, the changes are huge. That is mentioned in the release notes [1] as Makes PointerAligment: Right working with AlignConsecutiveDeclarations. (Fixes https://llvm.org/PR27353) [1] https://releases.llvm.org/13.0.0/tools/clang/docs/ReleaseNotes.html#clang-format
* docs: update URL for latest online documentationThomas Haller2021-09-249-9/+9
|
* examples: rework nm-up-many.py for ratelimiting parallel activationsThomas Haller2021-06-221-174/+147
| | | | | | | | | | | | | | | | The previous implementation did some ratelimiting, namely how many parallel ActivateConnection D-Bus calls are in fly. This way we are able to kick off many parallel calls, but the activations themselves were not ratelimited. Rework the code. Now there are two rate limits (that can be set via environment variables): NUM_PARALLEL_STARTING NUM_PARALLEL_IN_PROGRESS This allows more control about how much is happening in parallel. If we are going to activate 1000 profiles, then it matters that we do things in parallel, but not everything at the same time.
* example: drop unused import from "nm-up-many.py"Thomas Haller2021-06-171-2/+1
| | | | lgtm.com complains about this. Avoid the warning.
* examples: add "examples/python/gi/nm-up-many.py"Thomas Haller2021-06-111-0/+373
| | | | | | | | | | | | | | | | | | | It's an example for how to use libnm and asynchronous API. But it's also a script I will use to test activating many profiles in parallel. Also add a test script that creates many veth interfaces and connection profiles. So now you can do: sudo NUM_DEVS=100 contrib/scripts/test-create-many-device-setup.sh setup ./examples/python/gi/nm-up-many.py c-a{1..100} and cleanup with nmcli connection down c-a{1..100} sudo contrib/scripts/test-create-many-device-setup.sh cleanup Of course, be careful to do this on your production machine.
* examples/trivial: fix black formatting of python codeThomas Haller2021-05-271-1/+3
|
* examples: explicitly catch "Exception" in "ovs-external-ids.py"Thomas Haller2021-05-271-1/+1
| | | | | lgtm.com warns about unqualified "except". This catches any "BaseException", when we really only should handle "Exception" here.
* examples: fix printing applied connection in "ovs-external-ids.py"Thomas Haller2021-05-271-1/+1
| | | | | lgtm.com also complained about "connection_after" being unused. This hopefully works around that warning.
* examples: drop unused variable in "examples/python/gi/ovs-external-ids.py"Thomas Haller2021-05-271-1/+0
|
* python: remove unused importsThomas Haller2021-05-271-1/+2
| | | | | They are flagged by lgtm.com. Avoid the warning by dropping unused includes.
* examples: drop confusing UID handling in "vpn.py" exampleThomas Haller2021-05-271-8/+0
| | | | | | | | | | | | | | | | First of all, the "os.setuid()" call is never reached. lgtm.com warns about that, and warnings are annoying because they require investigation. This code is only in the example, so that the user would understand that they should edit the source and set the desired UID. But you can only call setuid() if you have CAP_SETUID, so commonly this anyway doesn't work -- unless you are root already, and then you actually don't need it either. Let's drop this code from the example. Maybe this example really should be dropped. Does the "dbus" python module even still work? Doesn't for me...
* examples: fix usage of input() with Python2Thomas Haller2021-05-261-0/+6
| | | | | | | | | | | | input() in Python2 evaluated the string and was thus unsafe. On Python2, the right choice is raw_input. In Python3, input does what raw_input did. Work around this. The main "problem" is that lgtm.com flags this as error. The fix in the example is not important, but getting a low number of warnings is.
* examples: avoid deprecated PropertiesChanged signal in "create-bond.py" exampleThomas Haller2021-05-141-7/+11
|
* example: rework "vpn-import-libnm" exampleThomas Haller2021-04-011-41/+130
| | | | | | | | | | | | - add more error handling and free/unref data. - split code in 3 functions: vpn_connection_import(), connection_add() and main(). These steps are mostly independent, and having them in separate functions makes their separation clearer. - handle error from nm_client_add_connection_async() to exit program with non zero exit code.
* examples: fix exit from "vpn-import-libnm.c" exampleThomas Haller2021-03-221-0/+2
| | | | | | | | | ../examples/C/glib/vpn-import-libnm.c: In function main: ../examples/C/glib/vpn-import-libnm.c:72:1: error: control reaches end of non-void function [-Werror=return-type] } ^ Fixes: 905f9975d286 ('example: importing vpn with libnm')
* example: importing vpn with libnmJagadeesh Kotra2021-03-222-0/+73
| | | | https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/789
* examples: use python3 compatible exception syntaxJagadeesh Kotra2021-03-161-1/+1
| | | | https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/781
* build/meson: drop libnm_nm_default_dep dependencyThomas Haller2021-02-281-10/+12
|
* build: move "libnm/" to "src/" and split itThomas Haller2021-02-241-2/+2
| | | | | | Like with "libnm-core/", split "libnm/" into different directories for the public headers, for the implementation and for the helper "aux" library.
* build: move "libnm-core/" to "src/" and split itThomas Haller2021-02-181-9/+7
| | | | | | | | | | | | | | | | | | | | "libnm-core/" is rather complicated. It provides a static library that is linked into libnm.so and NetworkManager. It also contains public headers (like "nm-setting.h") which are part of public libnm API. Then we have helper libraries ("libnm-core/nm-libnm-core-*/") which only rely on public API of libnm-core, but are themself static libraries that can be used by anybody who uses libnm-core. And "libnm-core/nm-libnm-core-intern" is used by libnm-core itself. Move "libnm-core/" to "src/". But also split it in different directories so that they have a clearer purpose. The goal is to have a flat directory hierarchy. The "src/libnm-core*/" directories correspond to the different modules (static libraries and set of headers that we have). We have different kinds of such modules because of how we combine various code together. The directory layout now reflects this.
* examples/python: some style update to avoid changes in black code formattingThomas Haller2021-01-281-2/+2
| | | | | | | | | | | | Fedora 33's version of python-black is the authoritative version we use for formatting -- note that formatting may look different depending on the black version. Recently, the package was updated to 20.8~b1-1.fc33, which treats these lines different. Work around that by adjusting the code so that both older and current versions of python black behave the same.
* examples: minor bugfix comparing device state in "python/dbus/show-bssids.py"Thomas Haller2021-01-261-1/+1
|
* examples: add comment about scanning to "python/dbus/show-bssids.py" exampleThomas Haller2021-01-181-0/+5
| | | | https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/630
* all: update deprecated SPDX license identifiersThomas Haller2021-01-0572-72/+72
| | | | | | | | | | | | | | | | These SPDX license identifiers are deprecated ([1]). Update them. [1] https://spdx.org/licenses/ sed \ -e '1 s%^/\* SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+ \*/$%/* SPDX-License-Identifier: \1-or-later */%' \ -e '1,2 s%^\(--\|#\|//\) SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+$%\1 SPDX-License-Identifier: \2-or-later%' \ -i \ $(git grep -l SPDX-License-Identifier -- \ ':(exclude)shared/c-*/' \ ':(exclude)shared/n-*/' \ ':(exclude)shared/systemd/src' \ ':(exclude)src/systemd/src')
* examples: remove editor hint to mark source code as UTF-8Thomas Haller2021-01-051-1/+0
| | | | All our source code is UTF-8. We don't need to mark it as such.
* examples: extend "ovs-external-ids.py" to support `nmcli device modify`Thomas Haller2020-11-171-67/+305
| | | | | | The python example is (also) used to test the feature. That is because currently nmcli does not yet have support for ovs.external-ids and this API is only accessible via D-Bus (or a tool like this example).
* examples: add "ovs-external-ids.py" example scriptThomas Haller2020-11-091-0/+425
| | | | | | | | | | | | | And example script for getting and setting OVS external-ids. Since currently there is no nmcli support for these properties yet, the script becomes more interesting. This "example" is rather long, and it showcases less the usage of libnm (which is rather trivial, with respect to configuring NMSettingOvsExternalIDs). Instead, it aims to provide a useful command line tool for debugging. Hence, it's mostly concerned with an elaborate command line syntax and useful print output.
* Correct python black rulesFrederic Martinsons2020-10-291-2/+2
| | | | Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
* example: add python gi example for keyfile handlingth/keyfile-public-apiThomas Haller2020-10-281-0/+139
|
* all: unify comment style for SPDX-License-Identifier tagThomas Haller2020-09-2912-12/+12
| | | | | | | | | | Our coding style recommends C style comments (/* */) instead of C++ (//). Also, systemd (which we partly fork) uses C style comments for the SPDX-License-Identifier. Unify the style. $ sed -i '1 s#// SPDX-License-Identifier: \([^ ]\+\)$#/* SPDX-License-Identifier: \1 */#' -- $(git ls-files -- '*.[hc]' '*.[hc]pp')
* format: replace tabs for indentation in code commentsac/clang-formatThomas Haller2020-09-283-14/+14
| | | | | | | | | | | | sed -i \ -e 's/^'$'\t'' \*/ */g' \ -e 's/^'$'\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t\t\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t\t\t\t\t'' \*/ */g' \ $(git ls-files -- '*.[hc]')
* all: reformat all with new clang-format styleAntonio Cardace2020-09-288-744/+759
| | | | | | | | | | | | Run: ./contrib/scripts/nm-code-format.sh -i ./contrib/scripts/nm-code-format.sh -i Yes, it needs to run twice because the first run doesn't yet produce the final result. Signed-off-by: Antonio Cardace <acardace@redhat.com>