Revisión 223
Añadido por Manu Mora Gordillo hace más de 13 años
controlies/trunk/applications/controlies/controllers/hosts.py | ||
---|---|---|
l.close()
|
||
return dict(response=response)
|
||
|
||
@service.json
|
||
@auth.requires_login()
|
||
def getallranges():
|
||
from Utils import LdapUtils
|
||
l=conecta()
|
||
myRanges = LdapUtils.getAllRanges(l)
|
||
return dict(response=myRanges)
|
||
|
||
#necesaria estas funciones en el controlador para poder cargar las vistas correspondientes:
|
||
def ltspservers():
|
||
return dict()
|
controlies/trunk/applications/controlies/modules/Utils/LdapUtils.py | ||
---|---|---|
|
||
return { "departments":departments, "classrooms":classrooms }
|
||
|
||
def getAllRanges(ldap):
|
||
myRange = []
|
||
my_search = ldap.search("dc=23,dc=172,dc=in-addr,dc=arpa,ou=hosts","dc=*",["dc"])
|
||
for s in my_search:
|
||
address = s[0][0].split(",")
|
||
if len(address) == 9:
|
||
myRange.append(address[0].replace("dc=",""))
|
||
|
||
myRange.sort()
|
||
return myRange
|
||
|
||
# Get the max ID of the groups and users
|
||
def getMaxID(ldap):
|
controlies/trunk/applications/controlies/modules/Hosts.py | ||
---|---|---|
response = self.list();
|
||
return response
|
||
|
||
def list(self,args):
|
||
self.getIPRanges()
|
||
def list(self,args):
|
||
# grid parameters
|
||
limit = int(args['rows'])
|
||
page = int(args['page'])
|
||
... | ... | |
# Obtengo todos los elementos del nodo hosts
|
||
#search = l.search("ou=hosts","cn=*",["cn","ipHostNumber","macAddress"])
|
||
#filter = self.buildFilter(args)
|
||
search = self.ldap.search("ou=hosts","cn=*",["cn","ipHostNumber","macAddress"])
|
||
|
||
# triplets que contiene los nombres de los ltsp-servers
|
||
hostnames = self.getLTSPServers()
|
||
hostnames = self.getListTriplets()
|
||
hostnames_data = {}
|
||
|
||
# Ahora tengo que quedarme con los elementos de search que estan en hostnames: los que son ltsp
|
||
resultado=list()
|
||
for element in search:
|
||
if element[0][1]["cn"][0] in hostnames:
|
||
resultado.append(element)
|
||
search = self.ldap.search("cn=INTERNAL,cn=DHCP Config","cn=*",["cn","dhcpHWAddress"])
|
||
for s in search:
|
||
if s[0][1]['cn'][0] in hostnames:
|
||
hostnames_data[s[0][1]['cn'][0]] = {"mac" : s[0][1]['dhcpHWAddress'][0].replace("ethernet ",""), "host":s[0][1]['cn'][0]}
|
||
|
||
search = resultado
|
||
|
||
search = self.ldap.search("dc="+self.domainname+",ou=hosts","dc=*",["dc","aRecord"])
|
||
for s in search:
|
||
if s[0][1]['dc'][0] in hostnames:
|
||
hostnames_data[s[0][1]['dc'][0]]["ip"] = s[0][1]['aRecord'][0]
|
||
|
||
rows = []
|
||
for i in search:
|
||
for k, v in hostnames_data.iteritems():
|
||
row = {
|
||
"id":i[0][1]["cn"][0],
|
||
"cell":[i[0][1]["cn"][0], i[0][1]["ipHostNumber"][0],i[0][1]["macAddress"]],
|
||
"cn":i[0][1]["cn"][0],
|
||
"ipHostNumber":i[0][1]["ipHostNumber"][0],
|
||
"macAddress":i[0][1]["macAddress"][0]
|
||
"id":v["host"],
|
||
"cell":[v["host"], v["ip"],v["mac"]],
|
||
"cn":v["host"],
|
||
"ipHostNumber":v["ip"],
|
||
"macAddress":v["mac"]
|
||
}
|
||
#row = { "cn":i[0][0], "cell":[i[0][1]["cn"][0], i[0][1]["ipHostNumber"][0],i[0][1]["macAddress"]]}
|
||
rows.append(row)
|
||
|
||
|
||
if len(rows) > 0:
|
||
totalPages = ceil( len(rows) / int(limit) )
|
||
else:
|
||
... | ... | |
|
||
def add(self):
|
||
# Hosts
|
||
attr = [
|
||
"""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)
|
||
self.ldap.add("cn="+self.name+",ou=Hosts", attr)"""
|
||
|
||
# Hosts->domain
|
||
attr = [
|
||
... | ... | |
triplets = self.getTriplets()
|
||
triplets.append('('+self.name+',-,-)')
|
||
triplets.sort()
|
||
|
||
attr = [(ldap.MOD_REPLACE, 'nisNetgroupTriple', triplets )]
|
||
self.ldap.modify("cn="+self.type_host+",ou=Netgroup", attr)
|
||
|
||
... | ... | |
|
||
def modify(self):
|
||
# Hosts
|
||
attr = [
|
||
"""attr = [
|
||
(ldap.MOD_REPLACE, 'ipHostNumber', [self.ip] ),
|
||
(ldap.MOD_REPLACE, 'macAddress', [self.mac])
|
||
]
|
||
self.ldap.modify("cn="+self.name+",ou=Hosts", attr)
|
||
self.ldap.modify("cn="+self.name+",ou=Hosts", attr)"""
|
||
|
||
# Hosts->domain
|
||
attr = [(ldap.MOD_REPLACE, 'aRecord', [self.ip] )]
|
||
... | ... | |
return "OK"
|
||
|
||
def delete(self):
|
||
self.ldap.delete("cn="+self.name+",ou=Hosts")
|
||
"""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")
|
||
|
||
... | ... | |
NetworkUtils.startup(self.mac)
|
||
|
||
def existsHostname(self):
|
||
result = self.ldap.search("ou=hosts","cn="+self.name,["cn"])
|
||
|
||
if len(result) > 0:
|
||
if self.name in self.getListTriplets():
|
||
return True
|
||
|
||
return False
|
||
|
||
def existsMAC(self):
|
||
result = self.ldap.search("ou=hosts","macAddress="+self.mac,["macAddress"])
|
||
search = self.ldap.search("cn=INTERNAL,cn=DHCP Config","cn=*",["cn","dhcpHWAddress"])
|
||
|
||
for s in search:
|
||
try:
|
||
if s[0][1]["dhcpHWAddress"][0].replace("ethernet ","") == self.mac:
|
||
return True
|
||
except:
|
||
pass
|
||
|
||
if len(result) > 0:
|
||
return True
|
||
|
||
return False
|
||
|
||
|
||
... | ... | |
return False
|
||
|
||
def equalMAC(self):
|
||
result = self.ldap.search("ou=hosts","cn="+self.name,["macAddress"])
|
||
if result[0][0][1]['macAddress'][0] == self.mac:
|
||
if self.getMAC() == self.mac:
|
||
return True
|
||
|
||
return False
|
||
|
||
def equalIP(self):
|
||
result = self.ldap.search("ou=hosts","cn="+self.name,["ipHostNumber"])
|
||
if result[0][0][1]['ipHostNumber'][0] == self.ip:
|
||
def equalIP(self):
|
||
if self.getIP() == self.ip:
|
||
return True
|
||
|
||
return False
|
||
... | ... | |
triplets = self.ldap.search("ou=Netgroup","cn="+self.type_host+"",["nisNetgroupTriple"])
|
||
triplets = triplets [0][0][1]["nisNetgroupTriple"]
|
||
return triplets
|
||
|
||
def getListTriplets(self):
|
||
hostnames = []
|
||
triplets = self.ldap.search("ou=Netgroup","cn="+self.type_host+"",["nisNetgroupTriple"])
|
||
triplets = triplets [0][0][1]["nisNetgroupTriple"]
|
||
|
||
for t in triplets:
|
||
hostnames.append(t.replace("(","").replace(",-,-)",""))
|
||
return hostnames
|
||
|
||
def getHostData(self):
|
||
result = self.ldap.search("ou=hosts","cn="+self.name,["cn","ipHostNumber","macAddress"])
|
||
def getHostData(self):
|
||
|
||
dataHost = {
|
||
"cn":self.name,
|
||
"mac":result[0][0][1]["macAddress"][0],
|
||
"ip":result[0][0][1]["ipHostNumber"][0]
|
||
"mac":self.getMAC(),
|
||
"ip":self.getIP()
|
||
}
|
||
return dataHost
|
||
|
||
def getLTSPServers (self):
|
||
triplets = self.ldap.search("ou=Netgroup","cn="+self.type_host+"",["nisNetgroupTriple"])
|
||
triplets = triplets [0][0][1]["nisNetgroupTriple"]
|
||
hostnames=list()
|
||
|
||
for node in triplets:
|
||
name = node.replace(",-,-)","").replace("(","")
|
||
hostnames.append(name)
|
||
hostnames.sort()
|
||
return hostnames
|
||
return dataHost
|
||
|
||
def getIP(self):
|
||
search = self.ldap.search("dc="+self.domainname+",ou=hosts","dc="+self.name,["dc","aRecord"])
|
||
ip = search[0][0][1]["aRecord"][0]
|
||
return ip
|
||
|
||
def getMAC(self):
|
||
search = self.ldap.search("cn=INTERNAL,cn=DHCP Config","cn="+self.name,["cn","dhcpHWAddress"])
|
||
mac = search[0][0][1]["dhcpHWAddress"][0].replace("ethernet ","")
|
||
return mac
|
||
|
||
def getLTSPStatus (self):
|
||
from Utils.avahiClient import avahiClient
|
||
import threading
|
||
... | ... | |
a.kill()"""
|
||
return names
|
||
|
||
def getIPRanges(self):
|
||
ranges = self.ldap.search("dc=23,dc=172,dc=in-addr,dc=arpa,ou=hosts","dc=*",["dc"])
|
||
#print ranges
|
||
for r in ranges:
|
||
print ranges[2]
|
||
return True
|
||
|
||
# def wakeup(self):
|
||
# from twisted.internet.task import LoopingCall
|
||
# from twisted.internet import defer
|
controlies/trunk/applications/controlies/views/layout_form_hosts.html | ||
---|---|---|
|
||
$("#cancelButton")
|
||
.button({ icons: { primary: "ui-icon-close"}})
|
||
.click( function(){ $('#dialog-form').dialog('close'); });
|
||
.click( function(){ $('#dialog-form').dialog('close'); });
|
||
});
|
||
|
||
function restartStyle(){
|
||
... | ... | |
<div style="text-align:center;"><button id="saveButton" type="submit" style="width:100px;">Guardar</button> <button type="button" id="cancelButton" style="width:100px;">Cancelar</button></div>
|
||
<p style="padding-top:10px; text-align:center; font-size:10px;" id="messageForm"></p>
|
||
</form>
|
||
|
||
<script language="javascript">
|
||
|
||
</script>
|
controlies/trunk/applications/controlies/views/layout_hosts.html | ||
---|---|---|
|
||
|
||
function addRecord(){
|
||
|
||
jQuery.post('call/json/getallranges', {cn:"hola"}, function(result) {
|
||
alert("hola");
|
||
});
|
||
|
||
jQuery("#dialog-form").html("");
|
||
jQuery("#dialog-form").load("form_ltspserver.html", function() {
|
Exportar a: Unified diff
Ya no trabajo con lo que cuelga de la rama hosts