Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nmcli: Add compatibility for new networkmanager library #65726

Merged
merged 4 commits into from Dec 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 18 additions & 10 deletions lib/ansible/modules/net_tools/nmcli.py
Expand Up @@ -22,14 +22,18 @@
short_description: Manage Networking
requirements:
- dbus
- NetworkManager-glib
- NetworkManager-libnm (or NetworkManager-glib on older systems)
- nmcli
version_added: "2.0"
description:
- Manage the network devices. Create, modify and manage various connection and device type e.g., ethernet, teams, bonds, vlans etc.
- 'On CentOS and Fedora like systems, the requirements can be met by installing the following packages: NetworkManager-glib,
- 'On CentOS 8 and Fedora >=29 like systems, the requirements can be met by installing the following packages: NetworkManager-nmlib,
libsemanage-python, policycoreutils-python.'
- 'On CentOS 7 and Fedora <=28 like systems, the requirements can be met by installing the following packages: NetworkManager-glib,
libnm-qt-devel.x86_64, nm-connection-editor.x86_64, libsemanage-python, policycoreutils-python.'
- 'On Ubuntu and Debian like systems, the requirements can be met by installing the following packages: network-manager,
python-dbus (or python3-dbus, depending on the Python version in use), libnm-dev.'
- 'On older Ubuntu and Debian like systems, the requirements can be met by installing the following packages: network-manager,
python-dbus (or python3-dbus, depending on the Python version in use), libnm-glib-dev.'
options:
state:
Expand Down Expand Up @@ -367,7 +371,7 @@
- name: install needed network manager libs
package:
name:
- NetworkManager-glib
- NetworkManager-libnm
- nm-connection-editor
- libsemanage-python
- policycoreutils-python
Expand Down Expand Up @@ -561,16 +565,20 @@
HAVE_DBUS = False

NM_CLIENT_IMP_ERR = None
HAVE_NM_CLIENT = True
try:
import gi
gi.require_version('NMClient', '1.0')
gi.require_version('NetworkManager', '1.0')

from gi.repository import NetworkManager, NMClient
HAVE_NM_CLIENT = True
gi.require_version('NM', '1.0')
from gi.repository import NM
except (ImportError, ValueError):
NM_CLIENT_IMP_ERR = traceback.format_exc()
HAVE_NM_CLIENT = False
try:
import gi
gi.require_version('NMClient', '1.0')
torvitas marked this conversation as resolved.
Show resolved Hide resolved
gi.require_version('NetworkManager', '1.0')
from gi.repository import NetworkManager, NMClient
except (ImportError, ValueError):
NM_CLIENT_IMP_ERR = traceback.format_exc()
HAVE_NM_CLIENT = False

from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils._text import to_native
Expand Down