Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Re2o
dhcp
Commits
7ce46958
Commit
7ce46958
authored
May 24, 2018
by
moamoak
Browse files
Optimize DHCP API requests
parent
93c596c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
main.py
View file @
7ce46958
...
...
@@ -12,38 +12,31 @@ hostname = config.get('Re2o', 'hostname')
password
=
config
.
get
(
'Re2o'
,
'password'
)
username
=
config
.
get
(
'Re2o'
,
'username'
)
host_mac_ip
=
{}
api_client
=
Re2oAPIClient
(
hostname
,
username
,
password
)
domains
=
api_client
.
list_domains
()
extensions
=
api_client
.
list_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
"
"}}"
)
for
hmi
in
api_client
.
list_hostmacip
(
params
=
{
'page_size'
:
'all'
}):
if
hmi
[
'extension'
]
not
in
host_mac_ip
.
keys
():
host_mac_ip
[
hmi
[
'extension'
]]
=
[]
host_mac_ip
[
hmi
[
'extension'
]].
append
((
hmi
[
'hostname'
],
hmi
[
'mac_address'
],
hmi
[
'ipv4'
]))
template
=
(
"host {hostname}{extension} {{
\n
"
" hardware ethernet {mac_address};
\n
"
" fixed-address {ipv4};
\n
"
"}}"
)
for
extension
,
hmi_list
in
host_mac_ip
.
items
():
dhcp_leases_content
=
'
\n\n
'
.
join
(
template
.
format
(
hostname
=
hostname
,
extension
=
extension
[
'name'
]
,
mac
=
mac
,
ipv4
=
ip
)
for
hostname
,
mac
,
ip
in
h
ost_mac_ip
)
extension
=
extension
,
mac
_address
=
mac_address
,
ipv4
=
ip
v4
)
for
hostname
,
mac
_address
,
ip
v4
in
h
mi_list
)
filename
=
'dhcp
-
{extension}.list'
.
format
(
extension
=
extension
[
'name'
][
1
:]
)
filename
=
'dhcp{extension}.list'
.
format
(
extension
=
extension
)
with
open
(
filename
,
'w+'
)
as
f
:
f
.
write
(
dhcp_leases_content
)
...
...
re2oapi
@
de759e41
Compare
f151d483
...
de759e41
Subproject commit
f151d483dc1c9bd59b18ea283ab734c91a72e18c
Subproject commit
de759e417d1046306372bf47a12f513b112dc6de
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