mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 22:22:26 +00:00
Unifi_ap_sync , commande manage.py pour nommer les bornes
This commit is contained in:
parent
5de22014eb
commit
14a7431f45
1 changed files with 11 additions and 5 deletions
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from pymongo import MongoClient
|
from pymongo import MongoClient
|
||||||
|
from topologie.models import Borne
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = 'Ce script donne un nom aux bornes dans le controleur unifi.
|
help = 'Ce script donne un nom aux bornes dans le controleur unifi.
|
||||||
|
@ -32,10 +33,15 @@ class Command(BaseCommand):
|
||||||
db = client.ace
|
db = client.ace
|
||||||
device = db['device']
|
device = db['device']
|
||||||
|
|
||||||
|
bornes = Borne.objects.all()
|
||||||
|
|
||||||
def set_bornes_names(liste_bornes):
|
def set_bornes_names(liste_bornes):
|
||||||
"""Met à jour les noms des bornes dans la bdd du controleur"""
|
"""Met à jour les noms des bornes dans la bdd du controleur"""
|
||||||
for borne in liste_bornes:
|
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
|
return
|
||||||
|
|
||||||
|
set_bornes_names(bornes)
|
||||||
|
|
||||||
self.stdout.write(self.style.SUCCESS('Mise à jour de la base de donnée unifi avec succès'))
|
self.stdout.write(self.style.SUCCESS('Mise à jour de la base de donnée unifi avec succès'))
|
||||||
|
|
Loading…
Reference in a new issue