Skip to content
Snippets Groups Projects
Commit 5ea2c134 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Save ansible var when setting boot profile

The csentry_autoinstall_boot_profile variable shall be saved to setup the
DHCP option.
The DHCP shall be updated when a change occurs.

JIRA INFRA-1016 #action In Progress
parent b9c1b838
No related branches found
No related tags found
No related merge requests found
......@@ -193,6 +193,14 @@ def view_host(name):
task = utils.trigger_set_network_boot_profile(
host, boot_profile=boot_profile
)
if boot_profile != "localboot":
# For localboot, there is no need to update the variable
# csentry_autoinstall_boot_profile is used for DHCP options
if utils.update_ansible_vars(
host, {"csentry_autoinstall_boot_profile": boot_profile}
):
# If a change occured, force DHCP update
utils.trigger_core_services_update()
db.session.commit()
current_app.logger.info(
f"Set network boot profile to {boot_profile} for {name} requested: task {task.id}"
......
......@@ -501,3 +501,24 @@ def retrieve_data_for_datatables(values, model):
def minutes_ago(minutes):
"""Return the datetime x minutes ago"""
return datetime.datetime.utcnow() - datetime.timedelta(minutes=minutes)
def update_ansible_vars(host, vars):
"""Update the host ansible_vars
Return False if no variables were changed, True otherwise
"""
if host.ansible_vars:
local_ansible_vars = host.ansible_vars.copy()
local_ansible_vars.update(vars)
if local_ansible_vars == host.ansible_vars:
# No change
return False
else:
host.ansible_vars.update(vars)
# If we don't flag the field as modified, it's not saved to the database
# Probably because we update an existing dictionary
sa.orm.attributes.flag_modified(host, "ansible_vars")
else:
host.ansible_vars = vars
return True
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment