Update roles
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -2,22 +2,39 @@
|
||||
""" Support for NetworkManager aka the NM provider """
|
||||
|
||||
# pylint: disable=import-error, no-name-in-module
|
||||
from ansible.module_utils.network_lsr.utils import Util
|
||||
from ansible.module_utils.network_lsr.utils import Util # noqa:E501
|
||||
|
||||
ETHTOOL_FEATURE_PREFIX = "ETHTOOL_OPTNAME_FEATURE_"
|
||||
ETHTOOL_COALESCE_PREFIX = "ETHTOOL_OPTNAME_COALESCE_"
|
||||
|
||||
|
||||
def get_nm_ethtool_feature(name):
|
||||
"""
|
||||
Translate ethtool feature into Network Manager name
|
||||
Translate ethtool feature into Network Manager name
|
||||
|
||||
:param name: Name of the feature
|
||||
:type name: str
|
||||
:returns: Name of the feature to be used by `NM.SettingEthtool.set_feature()`
|
||||
:rtype: str
|
||||
:param name: Name of the feature
|
||||
:type name: str
|
||||
:returns: Name of the feature to be used by `NM.SettingEthtool.set_feature()`
|
||||
:rtype: str
|
||||
"""
|
||||
|
||||
name = ETHTOOL_FEATURE_PREFIX + name.upper().replace("-", "_")
|
||||
name = ETHTOOL_FEATURE_PREFIX + name.upper()
|
||||
|
||||
feature = getattr(Util.NM(), name, None)
|
||||
return feature
|
||||
|
||||
|
||||
def get_nm_ethtool_coalesce(name):
|
||||
"""
|
||||
Translate ethtool coalesce into Network Manager name
|
||||
|
||||
:param name: Name of the coalesce
|
||||
:type name: str
|
||||
:returns: Name of the setting to be used by `NM.SettingEthtool.set_coalesce()`
|
||||
:rtype: str
|
||||
"""
|
||||
|
||||
name = ETHTOOL_COALESCE_PREFIX + name.upper()
|
||||
|
||||
coalesce = getattr(Util.NM(), name, None)
|
||||
return coalesce
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
# vim: fileencoding=utf8
|
||||
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
# pylint: disable=import-error, no-name-in-module
|
||||
from ansible.module_utils.network_lsr import MyError
|
||||
from ansible.module_utils.network_lsr import MyError # noqa:E501
|
||||
|
||||
|
||||
class Util:
|
||||
@@ -25,19 +24,31 @@ class Util:
|
||||
return default
|
||||
|
||||
@staticmethod
|
||||
def check_output(argv):
|
||||
# subprocess.check_output is python 2.7.
|
||||
with open("/dev/null", "wb") as DEVNULL:
|
||||
import subprocess
|
||||
def path_to_glib_bytes(path):
|
||||
"""
|
||||
Converts a path to a GLib.Bytes object that can be accepted by NM
|
||||
"""
|
||||
return Util.GLib().Bytes.new(("file://%s\x00" % path).encode("utf-8"))
|
||||
|
||||
env = os.environ.copy()
|
||||
env["LANG"] = "C"
|
||||
p = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=DEVNULL, env=env)
|
||||
# FIXME: Can we assume this to always be UTF-8?
|
||||
out = p.communicate()[0].decode("UTF-8")
|
||||
if p.returncode != 0:
|
||||
raise MyError("failure calling %s: exit with %s" % (argv, p.returncode))
|
||||
return out
|
||||
@staticmethod
|
||||
def convert_passwd_flags_nm(secret_flags):
|
||||
"""
|
||||
Converts an array of "secret flags" strings
|
||||
to an integer represantion understood by NetworkManager
|
||||
"""
|
||||
|
||||
flag_int = 0
|
||||
|
||||
if "none" in secret_flags:
|
||||
flag_int += 0
|
||||
if "agent-owned" in secret_flags:
|
||||
flag_int += 1
|
||||
if "not-saved" in secret_flags:
|
||||
flag_int += 2
|
||||
if "not-required" in secret_flags:
|
||||
flag_int += 4
|
||||
|
||||
return flag_int
|
||||
|
||||
@classmethod
|
||||
def create_uuid(cls):
|
||||
@@ -147,7 +158,7 @@ class Util:
|
||||
|
||||
if not cls.GMainLoop_run(mainloop_timeout):
|
||||
cancellable.cancel()
|
||||
raise MyError("failure to call %s.%s(): timeout" % object_, async_action)
|
||||
raise MyError("failure to call %s.%s(): timeout" % (object_, async_action))
|
||||
|
||||
success = user_data.get("success", None)
|
||||
if success is not None:
|
||||
@@ -249,7 +260,8 @@ class Util:
|
||||
def mac_ntoa(mac):
|
||||
if mac is None:
|
||||
return None
|
||||
return ":".join(["%02x" % c for c in mac])
|
||||
# bytearray() is needed for python2 compatibility
|
||||
return ":".join(["%02x" % c for c in bytearray(mac)])
|
||||
|
||||
@staticmethod
|
||||
def mac_norm(mac_str, force_len=None):
|
||||
|
||||
Reference in New Issue
Block a user