Revisión 218
Añadido por Manu Mora Gordillo hace más de 13 años
controlies/trunk/applications/controlies/models/menu.py | ||
---|---|---|
('Usuarios', False, URL( 'usuarios', 'index' )),
|
||
('Grupos', False,URL( 'grupos', 'index' )),
|
||
('Servidores LTSP',False, URL( 'hosts', 'ltspservers' )),
|
||
#('Workstations', False,URL( 'hosts', 'workstations' )),
|
||
('Workstations', False,URL( 'workstations', 'index' )),
|
||
('Clientes Ligeros', False,URL( 'thinclients', 'index' )),
|
||
#('Parámetros DHCP', False,URL( 'dhcpd', 'index' )),
|
||
|
controlies/trunk/applications/controlies/modules/Hosts.py | ||
---|---|---|
self.ip = ip
|
||
self.mac = mac
|
||
self.type_host = type_host
|
||
|
||
|
||
config = self.ldap.search("cn=DHCP Config","cn=INTERNAL",["dhcpOption"])
|
||
self.domainname = config[0][0][1]['dhcpOption'][4].replace('"','').replace('domain-name ','')
|
||
|
||
def validation(self,action):
|
||
|
||
if action == "add":
|
||
if self.type_host == "none":
|
||
return "type_host"
|
||
|
||
if self.type_host == "none":
|
||
return "type_host"
|
||
|
||
if self.name == "":
|
||
return "name"
|
||
|
||
if self.type_host <> 'thinclient':
|
||
if self.ip == "":
|
||
return "ip"
|
||
|
||
if not ValidationUtils.validIP(self.ip):
|
||
return "ip"
|
||
|
||
if self.mac == "":
|
||
return "mac"
|
||
|
||
if not ValidationUtils.validMAC(self.mac):
|
||
return "mac"
|
||
|
||
if self.type_host =="thinclient":
|
||
if self.group == "":
|
||
return "group"
|
||
|
||
if self.type_host == "":
|
||
return "type_host"
|
||
|
||
if action == "add":
|
||
if self.existsHostname():
|
||
return "hostAlreadyExists"
|
||
|
||
# thinclients no requieren ip, la cogen dinamicamente en el aula
|
||
if self.type_host <> "thinclient":
|
||
if self.existsIP():
|
||
return "ipAlreadyExists"
|
||
|
||
#controlar overflow en nodos
|
||
if self.groupOverflow(300):
|
||
return "groupOverflow"
|
||
|
||
if self.ip == "":
|
||
return "ip"
|
||
|
||
if self.existsMAC():
|
||
return "macAlreadyExists"
|
||
if not ValidationUtils.validIP(self.ip):
|
||
return "ip"
|
||
|
||
if action == "add":
|
||
if self.existsIP():
|
||
return "ipAlreadyExists"
|
||
elif action == "modify":
|
||
if self.groupOverflow(300):
|
||
return "groupOverflow"
|
||
|
||
if not self.equalIP():
|
||
if self.existsIP():
|
||
return "ipAlreadyExists"
|
||
|
||
if self.mac == "":
|
||
return "mac"
|
||
|
||
if not ValidationUtils.validMAC(self.mac):
|
||
return "mac"
|
||
|
||
if action == "add":
|
||
if self.existsMAC():
|
||
return "macAlreadyExists"
|
||
elif action == "modify":
|
||
if not self.equalMAC():
|
||
if self.existsMAC():
|
||
return "macAlreadyExists"
|
||
|
||
|
||
return "OK"
|
||
|
||
def process(self,action):
|
||
... | ... | |
|
||
result = sorted(rows, key=itemgetter(sortBy), reverse=reverseSort)
|
||
return { "page":page, "total":totalPages, "records":len(rows), "rows":result[start:finish] }
|
||
|
||
elif type_host == "thinclient":
|
||
search = self.ldap.search("cn=THINCLIENTS,cn=DHCP Config","cn=*",["cn","dhcpHWAddress"])
|
||
filter="(|(dhcpOption=*subnet*)(dhcpOption=*log*))"
|
||
|
||
rows = []
|
||
|
||
# esto hay que cambiarlo: tenemos 4 groups en thinclientes
|
||
for i in search[6:len(search)]:
|
||
nodeinfo=i[0][0].replace ("cn=","").split(",")
|
||
row = {
|
||
"id":i[0][1]["cn"][0],
|
||
"cell":[i[0][1]["cn"][0], i[0][1]["dhcpHWAddress"][0].replace("ethernet ",""), nodeinfo[1]],
|
||
"cn":i[0][1]["cn"][0],
|
||
"dhcpHWAddress":i[0][1]["dhcpHWAddress"][0],
|
||
"groupName":i[0][1]["dhcpHWAddress"][0]
|
||
}
|
||
rows.append(row)
|
||
if len(rows) > 0:
|
||
totalPages = ceil( len(rows) / int(limit) )
|
||
else:
|
||
totalPages = 0
|
||
if page > totalPages:
|
||
page = totalPages
|
||
|
||
result = sorted(rows, key=itemgetter(sortBy), reverse=reverseSort)
|
||
return { "page":page, "total":totalPages, "records":len(rows), "rows":result[start:finish] }
|
||
|
||
elif type_host == "workstation":
|
||
# Obtengo todos los elementos del nodo hosts
|
||
... | ... | |
return { "page":page, "total":totalPages, "records":len(rows), "rows":result[start:finish] }
|
||
|
||
def add(self):
|
||
if self.type_host=="thinclient":
|
||
attr = [
|
||
('objectclass', ['top','dhcpHost']),
|
||
('cn', [self.name] ),
|
||
('dhcpStatements', ['filename "/var/lib/tftpboot/ltsp/i386/pxelinux.0"'] ),
|
||
('dhcpHWAddress', ['ethernet ' + self.mac] )
|
||
]
|
||
|
||
self.ldap.add("cn="+self.name +",cn="+self.group+",cn=THINCLIENTS,cn=DHCP Config", attr)
|
||
else:
|
||
# Hosts
|
||
attr = [
|
||
('objectclass', ['top','organizationalRole','domainRelatedObject','ipHost','ieee802Device']),
|
||
('associatedDomain', ['santaeulalia']),
|
||
('cn', [self.name]),
|
||
('macAddress', [self.mac]),
|
||
('ipHostNumber', [self.ip])
|
||
]
|
||
self.ldap.add("cn="+self.name+",ou=Hosts", attr)
|
||
# Hosts
|
||
attr = [
|
||
('objectclass', ['top','organizationalRole','domainRelatedObject','ipHost','ieee802Device']),
|
||
('associatedDomain', [self.domainname]),
|
||
('cn', [self.name]),
|
||
('macAddress', [self.mac]),
|
||
('ipHostNumber', [self.ip])
|
||
]
|
||
self.ldap.add("cn="+self.name+",ou=Hosts", attr)
|
||
|
||
# Hosts->domain
|
||
attr = [
|
||
('objectclass', ['dNSDomain2','domainRelatedObject']),
|
||
('associatedDomain', [self.name+'.santaeulalia']),
|
||
('dc', [self.name]),
|
||
('aRecord', [self.ip])
|
||
]
|
||
self.ldap.add("dc="+self.name+",dc=santaeulalia,ou=Hosts", attr)
|
||
# Hosts->domain
|
||
attr = [
|
||
('objectclass', ['dNSDomain2','domainRelatedObject']),
|
||
('associatedDomain', [self.name+'.'+self.domainname]),
|
||
('dc', [self.name]),
|
||
('aRecord', [self.ip])
|
||
]
|
||
self.ldap.add("dc="+self.name+",dc="+self.domainname+",ou=Hosts", attr)
|
||
|
||
# DHCP Config
|
||
attr = [
|
||
('objectclass', ['top','dhcpHost']),
|
||
('dhcpStatements', ['fixed-address '+self.name]),
|
||
('cn', [self.name]),
|
||
('dhcpHWAddress', ['ethernet '+self.mac])
|
||
]
|
||
self.ldap.add("cn="+self.name+",cn=group1,cn=INTERNAL,cn=DHCP Config", attr)
|
||
# DHCP Config
|
||
attr = [
|
||
('objectclass', ['top','dhcpHost']),
|
||
('dhcpStatements', ['fixed-address '+self.name]),
|
||
('cn', [self.name]),
|
||
('dhcpHWAddress', ['ethernet '+self.mac])
|
||
]
|
||
self.ldap.add("cn="+self.name+",cn=group1,cn=INTERNAL,cn=DHCP Config", attr)
|
||
|
||
# Netgroup
|
||
triplets = self.getTriplets()
|
||
triplets.append('('+self.name+',-,-)')
|
||
triplets.sort()
|
||
# Netgroup
|
||
triplets = self.getTriplets()
|
||
triplets.append('('+self.name+',-,-)')
|
||
triplets.sort()
|
||
|
||
attr = [(ldap.MOD_REPLACE, 'nisNetgroupTriple', triplets )]
|
||
self.ldap.modify("cn=ltsp-server-hosts,ou=Netgroup", attr)
|
||
|
||
attr = [(ldap.MOD_REPLACE, 'nisNetgroupTriple', triplets )]
|
||
self.ldap.modify("cn=ltsp-server-hosts,ou=Netgroup", attr)
|
||
|
||
return "OK"
|
||
|
||
def modify(self):
|
||
... | ... | |
|
||
# Hosts->domain
|
||
attr = [(ldap.MOD_REPLACE, 'aRecord', [self.ip] )]
|
||
self.ldap.modify("dc="+self.name+",dc=santaeulalia,ou=Hosts", attr)
|
||
self.ldap.modify("dc="+self.name+",dc="+self.domainname+",ou=Hosts", attr)
|
||
|
||
# DHCP Config
|
||
attr = [(ldap.MOD_REPLACE, 'dhcpHWAddress', [self.mac] )]
|
||
... | ... | |
return "OK"
|
||
|
||
def delete(self):
|
||
if self.type_host=="thinclient":
|
||
self.ldap.delete('cn='+ self.name +',cn=group1,cn=THINCLIENTS,cn=DHCP Config')
|
||
else:
|
||
self.ldap.delete("cn="+self.name+",ou=Hosts")
|
||
self.ldap.delete("dc="+self.name+",dc=santaeulalia,ou=Hosts")
|
||
self.ldap.delete("cn="+self.name+",cn=group1,cn=INTERNAL,cn=DHCP Config")
|
||
self.ldap.delete("cn="+self.name+",ou=Hosts")
|
||
self.ldap.delete("dc="+self.name+",dc="+self.domainname+",ou=Hosts")
|
||
self.ldap.delete("cn="+self.name+",cn=group1,cn=INTERNAL,cn=DHCP Config")
|
||
|
||
# Netgroup
|
||
triplets = self.getTriplets()
|
||
triplets.remove('('+self.name+',-,-)')
|
||
triplets.sort()
|
||
# Netgroup
|
||
triplets = self.getTriplets()
|
||
triplets.remove('('+self.name+',-,-)')
|
||
triplets.sort()
|
||
|
||
attr = [(ldap.MOD_REPLACE, 'nisNetgroupTriple', triplets )]
|
||
self.ldap.modify("cn=ltsp-server-hosts,ou=Netgroup", attr)
|
||
attr = [(ldap.MOD_REPLACE, 'nisNetgroupTriple', triplets )]
|
||
self.ldap.modify("cn=ltsp-server-hosts,ou=Netgroup", attr)
|
||
|
||
return "OK"
|
||
|
||
def wakeup(self):
|
||
from Plugins import NetworkUtils
|
||
NetworkUtils.startup(self.mac)
|
||
|
||
def groupOverflow(self,overflow):
|
||
if self.type_host == 'thinclient':
|
||
search = self.ldap.search("cn=" + self.group +",cn=THINCLIENTS,cn=DHCP Config","cn=*",["cn"])
|
||
if len(search)-2 >= overflow:
|
||
return True
|
||
|
||
return False
|
||
|
||
|
||
def existsHostname(self):
|
||
result = self.ldap.search("ou=hosts","cn="+self.name,["cn"])
|
||
|
||
if self.type_host == 'thinclient':
|
||
result = self.ldap.search("cn=THINCLIENTS,cn=DHCP Config","cn="+self.name,["cn"])
|
||
else:
|
||
result = self.ldap.search("ou=hosts","cn="+self.name,["cn"])
|
||
|
||
if len(result) > 0:
|
||
return True
|
||
|
||
return False
|
||
|
||
def existsMAC(self):
|
||
# Compruebo con las macs de la rama hosts
|
||
if self.type_host == 'thinclient':
|
||
result = self.ldap.search("cn=THINCLIENTS,cn=DHCP Config","dhcpHWAddress=*",["dhcpHWAddress"])
|
||
for i in range (0, len(result) - 1):
|
||
if result [i][0][1]['dhcpHWAddress'][0].replace ("ethernet ", "") == self.mac:
|
||
return True
|
||
else:
|
||
result = self.ldap.search("ou=hosts","macAddress="+self.mac,["macAddress"])
|
||
result = self.ldap.search("ou=hosts","macAddress="+self.mac,["macAddress"])
|
||
|
||
if len(result) > 0:
|
||
return True
|
||
if len(result) > 0:
|
||
return True
|
||
|
||
return False
|
||
|
||
... | ... | |
def getName (self):
|
||
return self.mac
|
||
|
||
def getThinclientGroups (self):
|
||
|
||
groups = []
|
||
search = self.ldap.search("cn=THINCLIENTS,cn=DHCP Config","cn=group*",["cn"])
|
||
|
||
for g in search:
|
||
groups.append (g[0][1]["cn"][0])
|
||
|
||
return { "groups":groups }
|
||
|
||
def getInternalGroups (self):
|
||
|
||
groups = []
|
Exportar a: Unified diff
Bug dominio solucionado