👌 IMPROVE: allow specifying the A records to update
- this allows to explicitely define which A records to update rather than just modifying the two last ones - the records are defined by their complete (sub)domain in a comma separated list as environment variable 'Records' Signed-off-by: Jonas Sulzer <jonas@violoncello.ch>
This commit is contained in:
parent
a2999c3d93
commit
41c70a22ce
|
@ -1,3 +1,4 @@
|
|||
HpLogin=
|
||||
HpPass=
|
||||
Domain=
|
||||
Records=
|
||||
|
|
|
@ -42,32 +42,37 @@ class HpUpdater():
|
|||
|
||||
driver.implicitly_wait(10)
|
||||
|
||||
tableRows = driver.find_element_by_id('dns-record-list').find_elements_by_class_name('b-record')
|
||||
recordRows = driver.find_element_by_id('dns-record-list').find_elements_by_class_name('b-record')
|
||||
|
||||
# The last two entries are my A records
|
||||
for e in tableRows[-2:]:
|
||||
try:
|
||||
e.find_element_by_name('edit').click()
|
||||
|
||||
# For some reason with each iteration it return one more such element
|
||||
editForm = driver.find_elements_by_class_name('dns-record-list-edit')
|
||||
editForm[-1].find_element_by_name('ip_address').clear()
|
||||
editForm[-1].find_element_by_name('ip_address').send_keys(ip)
|
||||
|
||||
editForm[-1].find_element_by_name('apply').click()
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f'Exception during update: {str(e)}')
|
||||
|
||||
logger.info(f'Changed A records ip to {ip}')
|
||||
for recordToUpdate in os.environ.get('Records').split(','):
|
||||
logger.debug(f'recordToUpdate: {recordToUpdate}')
|
||||
for record in recordRows:
|
||||
recordId = None
|
||||
recordChilds = record.find_elements_by_tag_name('td')
|
||||
if recordChilds[1].text == recordToUpdate and recordChilds[2].text == 'A':
|
||||
recordId = record.get_attribute('id')
|
||||
logger.debug(f'recordId: {recordId}')
|
||||
try:
|
||||
record.find_element_by_name('edit').click()
|
||||
editForm = driver.find_element_by_id('edit' + recordId)
|
||||
editForm.find_element_by_name('ip_address').clear()
|
||||
editForm.find_element_by_name('ip_address').send_keys(ip)
|
||||
editForm.find_element_by_name('apply').click()
|
||||
time.sleep(10)
|
||||
logger.info(f'Changed {recordToUpdate} A record ip to {ip}')
|
||||
except Exception as e:
|
||||
logger.error(f'Exception during update: {str(e)}')
|
||||
finally:
|
||||
break
|
||||
|
||||
logger.info(f'Changed all A records ip to {ip}')
|
||||
|
||||
try:
|
||||
|
||||
e = driver.find_element_by_name('execute_now')
|
||||
driver.execute_script("arguments[0].click();", e)
|
||||
|
||||
# Give the site some time to save
|
||||
time.sleep(10)
|
||||
time.sleep(15)
|
||||
|
||||
logger.info('Successfully saved changes')
|
||||
|
||||
|
|
Loading…
Reference in New Issue