Merge branch 'adding_verification' into main

This commit is contained in:
2025-10-25 08:54:44 +03:00
2 changed files with 46 additions and 0 deletions

1
files/empty_file Normal file
View File

@@ -0,0 +1 @@
asdf

View File

@@ -55,9 +55,30 @@ nb_find_device_id() {
jq -r '.results[0].id // empty' <<<"$resp"
}
# --- READ a custom field value for a device (prints current value or empty if unset) ---
nb_read_custom_field() {
local dev_id="$1" key="$2"
local resp
resp="$(curl -sS \
-H "Authorization: Token $NB_TOKEN" \
-H "Accept: application/json" \
"$NB_URL/api/dcim/devices/$dev_id/")" || return 1
jq -r --arg k "$key" '
(.custom_fields[$k] // empty)
| (if type=="object" or type=="array" then tojson else . end)
' <<<"$resp"
}
# PATCH NetBox custom fields (update_wo_restart)
nb_patch_update_wo_restart() {
local dev_id="$1" update_progress="$2" updating_to="$3"
# Pre-read current values and print
local prev_p prev_u
prev_p="$(nb_read_custom_field "$dev_id" "update_progress" || true)"
prev_u="$(nb_read_custom_field "$dev_id" "updating_to" || true)"
echo ">>> Pre-change (id=$dev_id): update_progress='${prev_p:-<unset>}'; updating_to='${prev_u:-<unset>}'"
local body
body="$(jq -n --arg p "$update_progress" --arg u "$updating_to" \
'{custom_fields: {update_progress: $p, updating_to: $u}}')"
@@ -81,6 +102,12 @@ nb_patch_update_wo_restart() {
# PATCH NetBox custom field: wifidebug (deploy_wifidebug)
nb_patch_wifidebug() {
local dev_id="$1" value="$2"
# Pre-read current value and print
local prev
prev="$(nb_read_custom_field "$dev_id" "wifidebug" || true)"
echo ">>> Pre-change (id=$dev_id): wifidebug='${prev:-<unset>}'"
local body
body="$(jq -n --arg v "$value" '{custom_fields: {wifidebug: $v}}')"
@@ -150,6 +177,12 @@ nb_add_journal_raw() {
# PATCH custom field: multiple_ssids = "yes" — used for task_notify path
nb_set_multiple_ssids_yes() {
local dev_id="$1"
# Pre-read current value and print
local prev
prev="$(nb_read_custom_field "$dev_id" "multiple_ssids" || true)"
echo ">>> Pre-change (id=$dev_id): multiple_ssids='${prev:-<unset>}'"
local body='{"custom_fields":{"multiple_ssids":"yes"}}'
local code
@@ -319,6 +352,12 @@ nb_remove_tag_by_slug() {
# --- clear only custom_field update_progress (set to null) ---
nb_clear_update_progress() {
local dev_id="$1"
# Pre-read current value and print
local prev
prev="$(nb_read_custom_field "$dev_id" "update_progress" || true)"
echo ">>> Pre-change (id=$dev_id): update_progress='${prev:-<unset>}'"
local body='{"custom_fields":{"update_progress":null}}'
local code
code="$(curl -sS -o /dev/null -w "%{http_code}" \
@@ -338,6 +377,12 @@ nb_clear_update_progress() {
# --- NEW: generic single custom field patch ---
nb_patch_custom_field() {
local dev_id="$1" key="$2" value="$3"
# Pre-read current value and print
local prev
prev="$(nb_read_custom_field "$dev_id" "$key" || true)"
echo ">>> Pre-change (id=$dev_id): ${key}='${prev:-<unset>}'"
# Build {"custom_fields": { "<key>": "<value>" }}
local body
body="$(jq -n --arg k "$key" --arg v "$value" '{custom_fields: {($k): $v}}')"