From 11c2218e69370f2c13a26b010348e4127ed3fb1d Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Fri, 23 Apr 2021 11:33:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20DHCP=20=D0=BF=D1=80=D0=B8=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B8=20NetworkManager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/calculate/lib/utils/ip.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pym/calculate/lib/utils/ip.py b/pym/calculate/lib/utils/ip.py index 8c65baa..7053791 100644 --- a/pym/calculate/lib/utils/ip.py +++ b/pym/calculate/lib/utils/ip.py @@ -15,7 +15,7 @@ # limitations under the License. from files import (process, checkUtils, readFile, listDirectory, - getRunCommands, getProgPath) + getRunCommands, getProgPath, FilesError) import device import sys import os @@ -185,10 +185,25 @@ def isIpInNet(checkip, *ipnets): map(lambda x: (x, x.partition('/')[0::2]), ipnets)))) +def isUsingNetworkManager(): + try: + p = process("/usr/bin/nmcli", "general", "status") + return p.success() + except FilesError: + return False + +def isNMDhcp(interface="eth0"): + p = process("/usr/bin/nmcli", "-g", "ipv4.method", "connection", "show", "eth0") + if p.success(): + if "auto" in p.read(): + return True + return False def isDhcpIp(interface="eth0"): """Get ip by dhcp or static""" # dhclients (dhcpcd, dhclient (dhcp), udhcpc (busybox) + if isUsingNetworkManager() and isNMDhcp(interface): + return True commands = getRunCommands() dhcpProgs = ("dhcpcd", "dhclient", "udhcpc") if filter(lambda x: interface in x and any(prog in x for prog in dhcpProgs),