Check and update need_regen info
This commit is contained in:
parent
0a8c6243ad
commit
cea539b5d5
2 changed files with 37 additions and 32 deletions
29
main.py
29
main.py
|
@ -1,22 +1,17 @@
|
||||||
import time
|
|
||||||
t1 = time.time()
|
|
||||||
|
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
import socket
|
||||||
|
|
||||||
from re2oapi import Re2oAPIClient
|
from re2oapi import Re2oAPIClient
|
||||||
|
|
||||||
config = ConfigParser()
|
config = ConfigParser()
|
||||||
config.read('config.ini')
|
config.read('config.ini')
|
||||||
|
|
||||||
hostname = config.get('Re2o', 'hostname')
|
api_hostname = config.get('Re2o', 'hostname')
|
||||||
password = config.get('Re2o', 'password')
|
api_password = config.get('Re2o', 'password')
|
||||||
username = config.get('Re2o', 'username')
|
api_username = config.get('Re2o', 'username')
|
||||||
|
|
||||||
|
def regen_dhcp(api_client):
|
||||||
host_mac_ip = {}
|
for hmi in api_client.list_hostmacip():
|
||||||
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():
|
if hmi['extension'] not in host_mac_ip.keys():
|
||||||
host_mac_ip[hmi['extension']] = []
|
host_mac_ip[hmi['extension']] = []
|
||||||
host_mac_ip[hmi['extension']].append((hmi['hostname'],
|
host_mac_ip[hmi['extension']].append((hmi['hostname'],
|
||||||
|
@ -40,4 +35,14 @@ for extension, hmi_list in host_mac_ip.items():
|
||||||
with open(filename, 'w+') as f:
|
with open(filename, 'w+') as f:
|
||||||
f.write(dhcp_leases_content)
|
f.write(dhcp_leases_content)
|
||||||
|
|
||||||
print(time.time() - t1)
|
host_mac_ip = {}
|
||||||
|
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})
|
||||||
|
|
2
re2oapi
2
re2oapi
|
@ -1 +1 @@
|
||||||
Subproject commit 74fa513e9a0348e6d4ce030c2364a40268c8eef0
|
Subproject commit 7bcd0924b823cc11a5714b96cc96fe26638ac9c7
|
Loading…
Reference in a new issue