-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
72 lines (59 loc) · 1.81 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python3
from UniFi.UniFi import API as Unifi_API
import logging
import pprint
# Set logging level
logging.basicConfig(level=logging.INFO)
# set controller information
api = Unifi_API(username="ubnt", password="ubnt", baseurl="https://unifi.ui:8443", site="default",
verify_ssl=False)
# LOGIN
api.login()
# Show all devices within site
succes, device_list = api.list_devices()
print("Printing devices")
for device in device_list:
print("Device with name: %30s and id: %20s " % (device["name"], device["_id"]))
# List all sites
succes, sites = api.list_sites()
print("Printing Sites")
for site in sites:
pprint.pprint(site)
# Create a new site
sitename = 'GeneratedSite'
print("creating new Site")
if api.create_site(sitename):
print("Site has been created")
# Create new Wlangroup
wlangroupName = '5bmlimit'
maxUp = 5000 # NOTE: Always in kb
maxDown = 5000 # NOTE: Always in kb
print("creating new usergroup")
if api.create_usergroup(wlangroupName, maxUp, maxDown):
print("User group created.")
# list all Wlans configured in site
wlans = api.list_wlanconf()
pprint.pprint(wlans)
# Create new WLAN
wlanName = 'Generated Wi-Fi'
wlangroupName = '5bmlimit'
usergroup = 'Default'
password = 'Generatedpass'
print("Creating WLAN")
if api.create_wlan(wlanName, wlangroupName, usergroup, security="wpapsk", x_passphrase=password):
print("WLAN created.")
# List adoptable devices
succes, devices = api.list_adoptable()
pprint.pprint(devices)
# List status of Controller
print(api.status_controller())
# move device to different site
deviceMAC = "xx:xx:xx:xx:xx:xx"
siteID = "xxxxxxxxxxxxxxxxxxxxxxxx"
print("Moving device %s to site %s", deviceMAC, siteID)
print(api.move_device(deviceMAC, siteID))
# Delete device
deviceMAC = "xx:xx:xx:xx:xx:xx"
api.delete_device(deviceMAC)
# LOGOUT
api.logout()