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
01694fc6
Commit
01694fc6
authored
Feb 04, 2020
by
chapeau
Committed by
root
Feb 04, 2020
Browse files
Retrocompatibility
parent
0f4cd64e
Changes
1
Hide whitespace changes
Inline
Side-by-side
main.py
View file @
01694fc6
...
...
@@ -18,22 +18,35 @@ api_password = config.get('Re2o', 'password')
api_username
=
config
.
get
(
'Re2o'
,
'username'
)
def
regen_dhcp
(
api_client
):
host_mac_ip
=
{}
"""Genere les fichiers de zone du DHCP, par extension et par plage d'ip"""
host_mac_ip_ext
=
{}
host_mac_ip_type
=
{}
for
hmi
in
api_client
.
list
(
"dhcp/hostmacip/"
):
if
hmi
[
'ip_type'
]
not
in
host_mac_ip
.
keys
():
host_mac_ip
[
hmi
[
'ip_type'
]]
=
[]
host_mac_ip
[
hmi
[
'ip_type'
]].
append
((
hmi
[
'hostname'
],
hmi
[
'extension'
],
hmi
[
'mac_address'
],
hmi
[
'ipv4'
]))
api_res
=
api_client
.
list
(
"dhcp/hostmacip/"
)
build_hmi
(
host_mac_ip_ext
,
api_res
,
'extension'
)
build_hmi
(
host_mac_ip_type
,
api_res
,
'ip_type'
)
template
=
(
"host {hostname}{extension} {{
\n
"
" hardware ethernet {mac_address};
\n
"
" fixed-address {ipv4};
\n
"
"}}"
)
for
ip_type
,
hmi_list
in
host_mac_ip
.
items
():
generate_file
(
template
,
host_mac_ip_ext
,
"dhcp"
)
generate_file
(
template
,
host_mac_ip_type
,
"dhcp.ip_type."
)
def
build_hmi
(
host_mac_ip
,
api_res
,
key
):
for
hmi
in
api_res
:
if
hmi
[
key
]
not
in
host_mac_ip
.
keys
():
host_mac_ip
[
hmi
[
key
]]
=
[]
host_mac_ip
[
hmi
[
key
]].
append
((
hmi
[
'hostname'
],
hmi
[
'extension'
],
hmi
[
'mac_address'
],
hmi
[
'ipv4'
]))
def
generate_file
(
template
,
host_mac_ip
,
file_prefix
):
for
key
,
hmi_list
in
host_mac_ip
.
items
():
dhcp_leases_content
=
'
\n\n
'
.
join
(
template
.
format
(
hostname
=
hostname
,
extension
=
extension
,
...
...
@@ -41,10 +54,13 @@ def regen_dhcp(api_client):
ipv4
=
ipv4
)
for
hostname
,
extension
,
mac_address
,
ipv4
in
hmi_list
)
filename
=
path
+
'/generated/dhcp.{ip_type}.list'
.
format
(
ip_type
=
ip_type
)
filename
=
path
+
'/generated/{file_prefix}{key}.list'
.
format
(
key
=
key
,
file_prefix
=
file_prefix
)
with
open
(
filename
,
'w+'
)
as
f
:
f
.
write
(
dhcp_leases_content
)
def
reload_server
():
"""Relance le serveur DHCP."""
try
:
...
...
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