|
|
|
@ -19,5 +19,36 @@ import re
|
|
|
|
|
from cl_datavars import glob_attr
|
|
|
|
|
|
|
|
|
|
class fillVars(object, glob_attr):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def get_os_net_interfaces_info(self):
|
|
|
|
|
"""Информация о существующих сетевых интерфейсах"""
|
|
|
|
|
netInterfaces=self.Get("os_net_interfaces")
|
|
|
|
|
listInterfacesInfo = []
|
|
|
|
|
# Получена ли сеть по DHCP если нет to ip или off
|
|
|
|
|
for interfaces in netInterfaces:
|
|
|
|
|
fdhcpLeases = "/var/lib/dhcp/dhclient.leases"
|
|
|
|
|
if os.access(fdhcpLeases, os.R_OK) and\
|
|
|
|
|
interfaces in open(fdhcpLeases).read():
|
|
|
|
|
listInterfacesInfo.append((interfaces, "DHCP"))
|
|
|
|
|
continue
|
|
|
|
|
fdhcpInfo = "/var/lib/dhcpcd/dhcpcd-%s.info"%interfaces
|
|
|
|
|
fdhcpLease = "/var/lib/dhcpcd/dhcpcd-%s.lease"%interfaces
|
|
|
|
|
if os.path.exists(fdhcpInfo) or os.path.exists(fdhcpLease):
|
|
|
|
|
listInterfacesInfo.append((interfaces, "DHCP"))
|
|
|
|
|
# Если интерфейс без DHCP
|
|
|
|
|
if not (interfaces, "DHCP") in listInterfacesInfo:
|
|
|
|
|
# Находим ip
|
|
|
|
|
res = self._runos("/sbin/ifconfig %s"%interfaces)
|
|
|
|
|
ip = ""
|
|
|
|
|
for j in res:
|
|
|
|
|
sIP=re.search('addr:([0-9\.]+).+',j)
|
|
|
|
|
if sIP:
|
|
|
|
|
ip = sIP.group(1)
|
|
|
|
|
listInterfacesInfo.append((interfaces, ip))
|
|
|
|
|
break
|
|
|
|
|
if not ip:
|
|
|
|
|
listInterfacesInfo.append((interfaces, "Off"))
|
|
|
|
|
return ", ".join(map(lambda x:"%s (%s)"%(x[0],x[1]),listInterfacesInfo))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|