Add routeing.

develop
Mike Hiretsky 13 years ago
parent 70100bbfbf
commit fe20abe362

@ -15,7 +15,8 @@
# limitations under the License. # limitations under the License.
import math import math
from cl_utils import process, checkUtils, readFile, listDirectory from cl_utils import process, checkUtils, readFile, listDirectory, \
readLinesFile, getRunCommands
import sys import sys
import re import re
from os import path from os import path
@ -151,15 +152,25 @@ def receiveIpAndMask(interface="eth0"):
def isDhcpIp(interface="eth0"): def isDhcpIp(interface="eth0"):
"""Get ip by dhcp or static""" """Get ip by dhcp or static"""
# dhclient # dhclient
fdhcpLeases = "/var/lib/dhcp/dhclient.leases" if filter(lambda x:interface in x and ("dhcpcd" in x or "dhclient" in x),
if interface in readFile(fdhcpLeases): getRunCommands()):
return True return True
# dhcpcd else:
fdhcpInfo = "/var/lib/dhcpcd/dhcpcd-%s.info"%interface return False
fdhcpLease = "/var/lib/dhcpcd/dhcpcd-%s.lease"%interface
if path.exists(fdhcpInfo) or path.exists(fdhcpLease): def getRouteTable(onlyIface=[]):
return True """Get route table, exclude specifed iface"""
return False ipProg = checkUtils('/sbin/ip')
routes = process(ipProg,"route")
if onlyIface:
filterRe = re.compile("|".join(map(lambda x:r"dev %s"%x,onlyIface)))
routes = filter(filterRe.search,routes)
for line in routes:
network,op,line = line.partition(" ")
routeParams = map(lambda x:x.strip(),line.split())
# (network,{'via':value,'dev':value})
if network:
yield (network,dict(zip(routeParams[0::2],routeParams[1::2])))
def getInterfaces(): def getInterfaces():
"""Get available interfaces""" """Get available interfaces"""

Loading…
Cancel
Save