Исправлено определение DHCP при использовании NetworkManager

legacy27 3.6.9.7
Mike Hiretsky 3 years ago
parent 7be8d47fdb
commit 11c2218e69

@ -15,7 +15,7 @@
# limitations under the License. # limitations under the License.
from files import (process, checkUtils, readFile, listDirectory, from files import (process, checkUtils, readFile, listDirectory,
getRunCommands, getProgPath) getRunCommands, getProgPath, FilesError)
import device import device
import sys import sys
import os import os
@ -185,10 +185,25 @@ def isIpInNet(checkip, *ipnets):
map(lambda x: (x, x.partition('/')[0::2]), map(lambda x: (x, x.partition('/')[0::2]),
ipnets)))) 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"): def isDhcpIp(interface="eth0"):
"""Get ip by dhcp or static""" """Get ip by dhcp or static"""
# dhclients (dhcpcd, dhclient (dhcp), udhcpc (busybox) # dhclients (dhcpcd, dhclient (dhcp), udhcpc (busybox)
if isUsingNetworkManager() and isNMDhcp(interface):
return True
commands = getRunCommands() commands = getRunCommands()
dhcpProgs = ("dhcpcd", "dhclient", "udhcpc") dhcpProgs = ("dhcpcd", "dhclient", "udhcpc")
if filter(lambda x: interface in x and any(prog in x for prog in dhcpProgs), if filter(lambda x: interface in x and any(prog in x for prog in dhcpProgs),

Loading…
Cancel
Save