Changed the generation of value for the variable profile 'os_net_allow'

develop
Самоукин Алексей 15 years ago
parent 27503759b1
commit c4b4f6dafd

@ -145,12 +145,24 @@ class fillVars(object, cl_base.glob_attr):
# Разрешенные сети (в данном случае все сети)
def get_os_net_allow(self):
"""Разрешенные сети разделитель запятая"""
net={'255.0.0.0':'/8',
'255.255.0.0':'/16',
'255.255.255.0':'/24',
'255.255.255.128':'/25',
'255.255.255.252':'/30',
'255.255.255.255':''}
def getNet(ip, mask):
"""По ip и маске получаем сеть"""
octetsMult = (0x1, 0x100, 0x10000, 0x1000000)
octetsIp = map(lambda x: int(x), ip.split("."))
octetsMask = map(lambda x: int(x), mask.split("."))
ipNumb = 0
for i in octetsMult:
ipNumb += octetsIp.pop()*i
maskNumb = 0
for i in octetsMult:
maskNumb += octetsMask.pop()*i
startIpNumber = maskNumb&ipNumb
x = startIpNumber
nMask = lambda y: len(filter(lambda x: y >> x &1 ,range(32)))
return "%s.%s.%s.%s/%s"\
%(x>>24, x>>16&255, x>>8&255, x&255, nMask(maskNumb))
networks=[]
netInterfaces=cl_utils.getdirlist("/sys/class/net/")
flagError = False
@ -162,27 +174,8 @@ class fillVars(object, cl_base.glob_attr):
for j in res:
s_ip=re.search('addr:([0-9\.]+).+Bcast:.+Mask:([0-9\.]+)' ,j)
if s_ip:
ip, netmask=s_ip.groups()
ip=ip.split('.')
if ip[0]=='10' or\
(ip[0]=='172' and int(ip[1])>=16 and int(ip[1])<=31)or\
(ip[0]=='192' and ip[1]=='168'):
if netmask=='255.255.255.255':
networks.append(ip)
elif netmask=='255.255.255.252':
networks.append(ip[0]+"."+ip[1]+"."+ip[2]+"."+\
"252"+net[netmask])
elif netmask=='255.255.255.128':
networks.append(ip[0]+"."+ip[1]+"."+ip[2]+"."+\
"128"+net[netmask])
elif netmask=='255.255.255.0':
networks.append(ip[0]+"."+ip[1]+"."+ip[2]+"."+"0"+\
net[netmask])
elif netmask=='255.255.0.0':
networks.append(ip[0]+"."+ip[1]+".0.0"+net[netmask])
elif netmask=='255.0.0.0':
networks.append(ip[0]+".0.0.0"+net[netmask])
ip, mask = s_ip.groups()
networks.append(getNet(ip, mask))
if flagError:
return ""
return ",".join(networks)

Loading…
Cancel
Save