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
cea539b5
Commit
cea539b5
authored
May 26, 2018
by
moamoak
Browse files
Check and update need_regen info
parent
0a8c6243
Changes
2
Hide whitespace changes
Inline
Side-by-side
main.py
View file @
cea539b5
import
time
t1
=
time
.
time
()
from
configparser
import
ConfigParser
import
socket
from
re2oapi
import
Re2oAPIClient
config
=
ConfigParser
()
config
.
read
(
'config.ini'
)
hostname
=
config
.
get
(
'Re2o'
,
'hostname'
)
password
=
config
.
get
(
'Re2o'
,
'password'
)
username
=
config
.
get
(
'Re2o'
,
'username'
)
api_hostname
=
config
.
get
(
'Re2o'
,
'hostname'
)
api_password
=
config
.
get
(
'Re2o'
,
'password'
)
api_username
=
config
.
get
(
'Re2o'
,
'username'
)
def
regen_dhcp
(
api_client
):
for
hmi
in
api_client
.
list_hostmacip
():
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
,
mac_address
=
mac_address
,
ipv4
=
ipv4
)
for
hostname
,
mac_address
,
ipv4
in
hmi_list
)
filename
=
'dhcp{extension}.list'
.
format
(
extension
=
extension
)
with
open
(
filename
,
'w+'
)
as
f
:
f
.
write
(
dhcp_leases_content
)
host_mac_ip
=
{}
api_client
=
Re2oAPIClient
(
hostname
,
username
,
password
)
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
,
mac_address
=
mac_address
,
ipv4
=
ipv4
)
for
hostname
,
mac_address
,
ipv4
in
hmi_list
)
filename
=
'dhcp{extension}.list'
.
format
(
extension
=
extension
)
with
open
(
filename
,
'w+'
)
as
f
:
f
.
write
(
dhcp_leases_content
)
print
(
time
.
time
()
-
t1
)
api_client
=
Re2oAPIClient
(
api_hostname
,
api_username
,
api_password
)
client_hostname
=
socket
.
gethostname
().
split
(
'.'
,
1
)[
0
]
for
service
in
api_client
.
list_servicesregen
():
if
service
[
'hostname'
]
==
client_hostname
and
\
service
[
'service_name'
]
==
'dhcp'
and
\
service
[
'need_regen'
]:
regen_dhcp
(
api_client
)
api_client
.
patch
(
service
[
'api_url'
],
data
=
{
'need_regen'
:
False
})
re2oapi
@
7bcd0924
Compare
74fa513e
...
7bcd0924
Subproject commit 7
4fa513e9a0348e6d4ce030c2364a40268c8eef0
Subproject commit 7
bcd0924b823cc11a5714b96cc96fe26638ac9c7
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