8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-05 01:16:27 +00:00

Unifi_ap_sync , commande manage.py pour nommer les bornes

This commit is contained in:
Gabriel Detraz 2018-03-24 04:20:27 +01:00 committed by chirac
parent 5de22014eb
commit 14a7431f45

View file

@ -21,6 +21,7 @@
from django.core.management.base import BaseCommand, CommandError
from pymongo import MongoClient
from topologie.models import Borne
class Command(BaseCommand):
help = 'Ce script donne un nom aux bornes dans le controleur unifi.
@ -32,10 +33,15 @@ class Command(BaseCommand):
db = client.ace
device = db['device']
bornes = Borne.objects.all()
def set_bornes_names(liste_bornes):
"""Met à jour les noms des bornes dans la bdd du controleur"""
for borne in liste_bornes:
device.find_one_and_update({'ip': str(borne['ipHostNumber'][0])}, {'$set': {'name': borne['host'][0].split('.')[0]}})
if borne.ipv4 and borne.domain:
device.find_one_and_update({'ip': str(borne.ipv4)}, {'$set': {'name': str(borne.domain.name)}})
return
set_bornes_names(bornes)
self.stdout.write(self.style.SUCCESS('Mise à jour de la base de donnée unifi avec succès'))