Dynamically update device attributes using a loop #15479
Replies: 1 comment
-
Add a Btw, adding code lines here in GitHub comments should be separated by ``` on their own lines, before and after the code snippet, to show it nicely. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am facing issues while updating params in netbox devices. Have tried in two methods, one is working fine but the other one is not working.
params = {"custom_fields['CGF_OS_information']": 'Linux Red Hat', "custom_fields['CGF_Last_Discovered']": '2024-02-28 04:03', "custom_fields['CGF_CPU_Memory']": '6'}
Working method:
device.custom_fields['CGF_OS_information'] = params["custom_fields['CGF_OS_information']"]
device.custom_fields['CGF_Last_Discovered'] = params["custom_fields['CGF_Last_Discovered']"]
device.custom_fields['CGF_Memory'] = params["custom_fields['CGF_Memory']"]
Not Working:
for param, value in params.items():
if param == "comments":
device.comments = value
device.save()
elif param.startswith("custom_fields[") and param.endswith("]"):
field_name = param.split("[")[1].split("]")[0]
device.custom_fields[field_name] = valueI
Beta Was this translation helpful? Give feedback.
All reactions