|
|
|
@ -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),
|
|
|
|
|