Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
re2o-unifi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nounous
re2o-unifi
Commits
93c596c3
Commit
93c596c3
authored
May 24, 2018
by
Maël Kervella
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Non-optimized script but working
parent
d72f23d0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
1 deletion
+36
-1
main.py
main.py
+36
-1
No files found.
main.py
View file @
93c596c3
import
time
t1
=
time
.
time
()
from
configparser
import
ConfigParser
from
re2oapi
import
Re2oAPIClient
...
...
@@ -10,6 +13,38 @@ password = config.get('Re2o', 'password')
username
=
config
.
get
(
'Re2o'
,
'username'
)
api_client
=
Re2oAPIClient
(
hostname
,
username
,
password
)
domains
=
api_client
.
list_domains
()
extensions
=
api_client
.
list_extensions
()
print
(
len
(
extensions
))
for
extension
in
extensions
:
host_mac_ip
=
[]
for
domain
in
domains
:
if
domain
[
'interface_parent'
]
is
not
None
and
\
api_client
.
get
(
domain
[
'extension'
])[
'name'
]
==
extension
[
'name'
]:
interface
=
api_client
.
get
(
domain
[
'interface_parent'
])
if
interface
[
'active'
]:
host_mac_ip
.
append
((
domain
[
'name'
],
interface
[
'mac_address'
],
api_client
.
get
(
interface
[
'ipv4'
])[
'ipv4'
]
))
template
=
(
"host {hostname}{extension} {{
\n
"
" hardware ethernet {mac};
\n
"
" fixed-address {ipv4};
\n
"
"}}"
)
dhcp_leases_content
=
'
\n\n
'
.
join
(
template
.
format
(
hostname
=
hostname
,
extension
=
extension
[
'name'
],
mac
=
mac
,
ipv4
=
ip
)
for
hostname
,
mac
,
ip
in
host_mac_ip
)
filename
=
'dhcp-{extension}.list'
.
format
(
extension
=
extension
[
'name'
][
1
:])
with
open
(
filename
,
'w+'
)
as
f
:
f
.
write
(
dhcp_leases_content
)
print
(
time
.
time
()
-
t1
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment