mirror of
https://github.com/linux-system-roles/network.git
synced 2026-07-21 02:11:23 +00:00
The details of the issue is described in this ansible issue: https://github.com/ansible/ansible/issues/68361 The workaround contains 2 changes. 1) Advice from @sivel: replacing, e.g., from ansible.module_utils.network_lsr.nm.provider import NetworkManagerProvider with from ansible.module_utils.network_lsr.nm import provider and then use provider.NetworkManagerProvider 2) In the later module_utils path finding path, gi.require_version("NM", "1.0") in module_utils/network_lsr/nm/client.py fails with "ValueError: Namespace NM not available" on the control node. By ignoring the exception, the failure is worked around. Please note that the missing package issue never occurs on the managed nodes since in case of "nm", the NetworkManager package is installed in the network role. Signed-off-by: Noriko Hosoi <nhosoi@redhat.com>
29 lines
1 KiB
Python
29 lines
1 KiB
Python
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
import logging
|
|
|
|
# Relative import is not support by ansible 2.8 yet
|
|
# pylint: disable=import-error, no-name-in-module
|
|
from ansible.module_utils.network_lsr.nm import active_connection # noqa:E501
|
|
from ansible.module_utils.network_lsr.nm import client # noqa:E501
|
|
|
|
# pylint: enable=import-error, no-name-in-module
|
|
|
|
|
|
class NetworkManagerProvider:
|
|
def deactivate_connection(self, connection_name, timeout, check_mode):
|
|
"""
|
|
Return True if changed.
|
|
"""
|
|
nm_client = client.get_client()
|
|
changed = False
|
|
for nm_ac in nm_client.get_active_connections():
|
|
nm_profile = nm_ac.get_connection()
|
|
if nm_profile and nm_profile.get_id() == connection_name:
|
|
changed |= active_connection.deactivate_active_connection(
|
|
nm_ac, timeout, check_mode
|
|
)
|
|
if not changed:
|
|
logging.info("No active connection for {0}".format(connection_name))
|
|
|
|
return changed
|