Fin ajout des machines
This commit is contained in:
parent
2d11abe3dd
commit
6053da5101
@ -5,7 +5,11 @@ uri = "ldaps://172.17.31.4"
|
||||
username_base_dn = "ou=membres,"
|
||||
room_base_dn = "ou=chambres,"
|
||||
group_base_dn = "ou=groupes,"
|
||||
parametres_base_dn = "ou=parametres,"
|
||||
ip_reservation_base_dn = "uid=pool_ip," + parametres_base_dn
|
||||
|
||||
aurore_dn = "dc=aurore,dc=u-psud,dc=fr"
|
||||
parametres_aurore_dn = "ou=parametres," + aurore_dn
|
||||
parametres_aurore_dn = parametres_base_dn + aurore_dn
|
||||
|
||||
liste_residence_dn = "cn=residences," + parametres_aurore_dn
|
||||
|
||||
|
@ -7,6 +7,7 @@ from tg.decorators import expose, validate
|
||||
from brie.config import ldap_config
|
||||
from brie.config import groups_enum
|
||||
from brie.lib.ldap_helper import *
|
||||
from brie.lib.aurore_helper import *
|
||||
from brie.model.ldap import *
|
||||
|
||||
from brie.controllers import auth
|
||||
@ -14,8 +15,10 @@ from brie.controllers.auth import AuthenticatedBaseController, AuthenticatedRest
|
||||
|
||||
from operator import itemgetter
|
||||
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
|
||||
#root = tg.config['application_root_module'].RootController
|
||||
|
||||
""" Controller d'edition de details de membres, chambres"""
|
||||
@ -29,11 +32,12 @@ class EditController(AuthenticatedBaseController):
|
||||
wifi = None
|
||||
|
||||
""" Controller fils de gestion des machines """
|
||||
machine = MachineController()
|
||||
|
||||
machine = None
|
||||
def __init__(self, new_show):
|
||||
self.show = new_show
|
||||
self.wifi = WifiRestController(new_show)
|
||||
self.machine = MachineController()
|
||||
|
||||
|
||||
""" Affiche les détails éditables du membre et de la chambre """
|
||||
@expose("brie.templates.edit.member")
|
||||
@ -54,10 +58,12 @@ class MachineController(AuthenticatedBaseController):
|
||||
require_group = groups_enum.admin
|
||||
|
||||
""" Controller fils d'ajout de machine """
|
||||
add = MachineAddController()
|
||||
|
||||
add = None
|
||||
""" Controller fils de suppression de machine """
|
||||
delete = MachineDeleteController()
|
||||
delete = None
|
||||
def __init__(self):
|
||||
self.add = MachineAddController()
|
||||
self.delete = MachineDeleteController()
|
||||
|
||||
#end class
|
||||
|
||||
@ -68,8 +74,8 @@ class MachineController(AuthenticatedBaseController):
|
||||
class MachineAddController(AuthenticatedRestController):
|
||||
require_group = groups_enum.admin
|
||||
|
||||
@expose()
|
||||
""" Fonction de gestion de requete post sur le controller d'ajout """
|
||||
@expose()
|
||||
def post(self, residence, member_uid, name, mac):
|
||||
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
||||
|
||||
@ -80,17 +86,25 @@ class MachineAddController(AuthenticatedRestController):
|
||||
member = Member.get_by_uid(self.user, residence_dn, member_uid)
|
||||
if member is None:
|
||||
#TODO : membre inexistant
|
||||
pass
|
||||
|
||||
# Vérification que le nom de machine n'existe pas déjà
|
||||
# Note : on cherche sur toute la résidence (residence_dn)
|
||||
machine = Machine.get_machine_by_name(self.user, residence_dn, name)
|
||||
|
||||
# TODO :
|
||||
# machine = Machine.get_machine_by_name(self.user, residence_dn, name)
|
||||
machine = None
|
||||
if machine is not None:
|
||||
#TODO : erreur machine existe déjà
|
||||
|
||||
pass
|
||||
# Génération de l'id de la machine et recherche d'une ip libre
|
||||
machine_id = uuid.uuid4()
|
||||
machine_id = str(uuid.uuid4())
|
||||
ip = IpReservation.get_first_free(self.user, residence_dn)
|
||||
|
||||
# Rendre l'ip prise
|
||||
taken_attribute = IpReservation.taken_attr(str(datetime.today()))
|
||||
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(machine_id)
|
||||
|
||||
@ -111,8 +125,10 @@ class MachineAddController(AuthenticatedRestController):
|
||||
# Construction du dn et ajout de l'objet dns
|
||||
dns_dn = "dlzHostName=" + name + "," + machine_dn
|
||||
self.user.ldap_bind.add_entry(dns_dn, machine_dns)
|
||||
|
||||
|
||||
|
||||
|
||||
redirect("/edit/member/" + residence + "/" + member_uid)
|
||||
#end def
|
||||
#end class
|
||||
|
||||
@ -121,18 +137,25 @@ class MachineAddController(AuthenticatedRestController):
|
||||
class MachineDeleteController(AuthenticatedRestController):
|
||||
require_group = groups_enum.admin
|
||||
|
||||
@expose()
|
||||
""" Gestion des requêtes post sur ce controller """
|
||||
@expose()
|
||||
def post(self, residence, member_uid, machine_id):
|
||||
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
||||
|
||||
# Récupération du membre et de la machine
|
||||
# Note : on cherche la machine seulement sur le membre (member.dn)
|
||||
member = Member.get_by_uid(self.user, residence, member_uid)
|
||||
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)
|
||||
ip = IpReservation.get_ip(residence_dn, dns.dlzData.first())
|
||||
|
||||
# Si la machine existe effectivement, on la supprime
|
||||
if machine is not None:
|
||||
|
||||
self.user.ldap_bind.delete_entry_subtree(machine.dn)
|
||||
|
||||
taken_attribute = IpReservation.taken_attr(ip.get("x-taken").first())
|
||||
self.user.ldap_bind.delete_attr(taken_attribute)
|
||||
#end if
|
||||
|
||||
# On redirige sur la page d'édition du membre
|
||||
|
@ -174,6 +174,11 @@ class Machine(object):
|
||||
return user_session.ldap_bind.search_first(member_dn, "(cn=" + machine_id + ")")
|
||||
#end def
|
||||
|
||||
@staticmethod
|
||||
def get_dns_by_id(user_session, machine_dn, machine_id):
|
||||
return user_session.ldap_bind.search_first(machine_dn, "(objectClass=dlzAbstractRecord)")
|
||||
#end def
|
||||
|
||||
#end class
|
||||
|
||||
class Groupes(object):
|
||||
@ -226,10 +231,8 @@ class IpReservation:
|
||||
#end def
|
||||
|
||||
@staticmethod
|
||||
def taken_attr(ip, description):
|
||||
def taken_attr(description):
|
||||
return {
|
||||
"objectClass" : ["top", "auroreIpReservation"],
|
||||
"cn" : str(ip),
|
||||
"x-taken" : description
|
||||
}
|
||||
#end def
|
||||
@ -240,6 +243,12 @@ class IpReservation:
|
||||
|
||||
return results
|
||||
#end def
|
||||
|
||||
@staticmethod
|
||||
def get_ip(user_session, residence_dn, ip):
|
||||
results = user_session.ldap_bind.search_first(ldap_config.ip_reservation_base_dn + residence_dn, "(&(objectClass=auroreIpReservation)(cn=" + ip + "))")
|
||||
|
||||
return results
|
||||
#end def
|
||||
|
||||
#end class
|
||||
|
@ -8,14 +8,14 @@
|
||||
</head>
|
||||
<body>
|
||||
${edit_banner()}
|
||||
${back_show("member", member_ldap.uid.first()}
|
||||
${back_show("member", member_ldap.uid.first())}
|
||||
<div py:choose="member_ldap">
|
||||
<span class="section_name" py:when="None">Entrée inexistante</span>
|
||||
<div py:otherwise="">${member_view(member_ldap)}</div>
|
||||
</div>
|
||||
<div py:choose="room">
|
||||
<div py:choose="room_ldap">
|
||||
<span class="section_name" py:when="None">Pas de chambre associée</span>
|
||||
<div py:otherwise="">${room_view(room)}</div>
|
||||
<div py:otherwise="">${room_view(room_ldap)}</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -58,6 +58,15 @@
|
||||
<span class="item_name">${name}</span>
|
||||
<span>${mac} : ${ip}</span>
|
||||
</div>
|
||||
<div>
|
||||
<form action="/edit/machine/add/" method="post">
|
||||
<input type="text" name="name" class="item_name"/>
|
||||
<input type="text" name="mac"/>
|
||||
<input type="hidden" name="residence" value="${residence}"/>
|
||||
<input type="hidden" name="member_uid" value="${member_ldap.uid.first()}"/>
|
||||
<input type="submit" value="ajouter" class="button"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</py:def>
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
<py:def function="member_view(member_ldap)">
|
||||
<div class="section">
|
||||
<span class="section_name show_section_name">${member_ldap.cn.first()}</span>
|
||||
<a class="link_button some_margin" href="/edit/member/${residence}/${member_ldap.uid.first()}/">éditer</a>
|
||||
<div>
|
||||
<div>
|
||||
<span class="item_name">Fin de connexion</span>
|
||||
|
Loading…
Reference in New Issue
Block a user