fin support dossiers machines

This commit is contained in:
Roven Gabriel 2013-08-12 15:54:40 +02:00
parent 5d30c3f0a5
commit f46cbb76e4
5 changed files with 18 additions and 15 deletions

View File

@ -6,6 +6,7 @@ username_base_dn = "ou=membres,"
room_base_dn = "ou=chambres,"
group_base_dn = "ou=groupes,"
parametres_base_dn = "ou=parametres,"
machine_base_dn = "cn=machines,"
ip_reservation_base_dn = "uid=pool_ip," + parametres_base_dn
plugins_base_dn = "uid=plugins," + parametres_base_dn

View File

@ -98,7 +98,6 @@ class MachineAddController(AuthenticatedRestController):
#TODO : erreur machine existe déjà
pass
# Génération de l'id de la machine et recherche d'une ip libre
machine_id = str(uuid.uuid4())
ip = IpReservation.get_first_free(self.user, residence_dn)
# Rendre l'ip prise
@ -106,15 +105,15 @@ class MachineAddController(AuthenticatedRestController):
self.user.ldap_bind.add_attr(ip.dn, taken_attribute)
# Attributs ldap de l'objet machine (regroupant dns et dhcp)
machine_top = Machine.entry_attr(name, machine_id)
machine_top = Machine.entry_attr(name)
# Attributs ldap des objets dhcp et dns, fils de l'objet machine
machine_dhcp = Machine.dhcp_attr(machine_id, name, mac)
machine_dns = Machine.dns_attr(machine_id, name, ip.cn.first())
machine_dhcp = Machine.dhcp_attr(name, mac)
machine_dns = Machine.dns_attr(name, ip.cn.first())
# Construction du dn et ajout de l'objet machine
# en fils du membre (membre.dn)
machine_dn = "cn=" + name + "," + member.dn
machine_dn = "cn=" + name + "," + ldap_config.machine_base_dn + member.dn
self.user.ldap_bind.add_entry(machine_dn, machine_top)
# Construction du dn et ajout de l'objet dhcp
@ -146,7 +145,7 @@ class MachineDeleteController(AuthenticatedRestController):
# Note : on cherche la machine seulement sur le membre (member.dn)
member = Member.get_by_uid(self.user, residence_dn, member_uid)
machine = Machine.get_machine_by_id(self.user, member.dn, machine_id)
dns = Machine.get_dns_by_id(self.user, machine.dn, machine_id)
dns = Machine.get_dns_by_id(self.user, machine.dn)
ip = IpReservation.get_ip(self.user, residence_dn, dns.dlzData.first())
# Si la machine existe effectivement, on la supprime

View File

@ -38,7 +38,7 @@ class Ldap(object):
""" Recherche sur la base
dn : base de recherche
filter : filtre ldap de recherche
scope : portée de recherche (voir la librairie ldap)
scope : portée de recherche (SCOPE_SUBTREE, SCOPE_BASE, SCOPE_ONELEVEL)
"""
def search(self, dn, filter, scope = ldap.SCOPE_SUBTREE):
try:

View File

@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from brie.config import ldap_config
import ldap
class Member(object):
@ -149,7 +151,8 @@ class Machine(object):
@staticmethod
def get_machine_tuples_of_member(user_session, member_dn):
results = user_session.ldap_bind.search(member_dn, "(objectClass=organizationalRole)")
machine_dn = ldap_config.machine_base_dn + member_dn
results = user_session.ldap_bind.search(machine_dn, "(objectClass=organizationalRole)", scope = ldap.SCOPE_ONELEVEL)
machines = list()
for result in results:
dhcp = user_session.ldap_bind.search_first(result.dn, "(objectClass=dhcpHost)")
@ -158,10 +161,9 @@ class Machine(object):
mac = dhcp.dhcpHWAddress.first().replace("ethernet ", "")
machines.append(
(
dhcp.cn.first(),
result.cn.first(),
mac,
dns.dlzData.first(),
result.cn.first()
dns.dlzData.first()
) #tuple
)
#end if
@ -172,11 +174,12 @@ class Machine(object):
@staticmethod
def get_machine_by_id(user_session, member_dn, machine_id):
return user_session.ldap_bind.search_first(member_dn, "(cn=" + machine_id + ")")
machines_dn = ldap_config.machine_base_dn + member_dn
return user_session.ldap_bind.search_first(machines_dn, "(cn=" + machine_id + ")")
#end def
@staticmethod
def get_dns_by_id(user_session, machine_dn, machine_id):
def get_dns_by_id(user_session, machine_dn):
return user_session.ldap_bind.search_first(machine_dn, "(objectClass=dlzAbstractRecord)")
#end def

View File

@ -54,13 +54,13 @@
</div>
<div class="section">
<span class="section_name show_section_name">MACHINES</span>
<div py:for="name, mac, ip, id in machines">
<div py:for="name, mac, ip in machines">
<span class="item_name">${name}</span>
<span>${mac} : ${ip}</span>
<form action="/edit/machine/delete/" method="post" class="inline_block">
<input type="hidden" name="residence" value="${residence}"/>
<input type="hidden" name="member_uid" value="${member_ldap.uid.first()}"/>
<input type="hidden" name="machine_id" value="${id}"/>
<input type="hidden" name="machine_id" value="${name}"/>
<input type="submit" value="X" class="button"/>
</form>
</div>