Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse unificontrol.UnifiClient when iterating sites on same controller #33

Open
smarthotspots opened this issue Aug 28, 2022 · 0 comments

Comments

@smarthotspots
Copy link

smarthotspots commented Aug 28, 2022

Currently if we "login" to unifi controllers and then get a list of sites to iterate for more details , it looks like a new instance of unificontrol.UnifiClient needs to be created each time in the loop. So for example, if there are 100 sites on a controller and we iterate them and an API for each site, there are 100 "logins" to the controller API created.
For example if we iterate a list of controller, extract list of sites from each one, and then attempt to device level detail of each .
Can there be a way to create an instance of unificlient without if calling a login to controller as we've already been authenticated in the first "cont" loop . Just trying to reduce the amount of logins required and load on unfi controller..

controllers =[ ["myserver.acme.com","8443","admin","mysecretpassword1"],"myserver2.acme.com","8443","admin","mysecretpassword2"]]

for cont in controllers:
login = unificontrol.UnifiClient(host=cont[0],port=cont[1],username=cont[2], password=cont[3], site="default",cert=None)

sites = login.list_sites()

for site in sites:
    current_site = site.get("name")
    current_sitedesc = site.get("desc")
    client = unificontrol.UnifiClient(host=cont[0],port=cont[1],username=cont[2], password=cont[3], site=current_site,cert=None)
    devices=  client.list_devices()

    for device in devices:
        ip =  device.get("ip")
        device_name = device.get("name")
        print (current_sitedesc , " " , device_name, " " , ip)


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant