0838
This commit is contained in:
@@ -55,9 +55,30 @@ nb_find_device_id() {
|
|||||||
jq -r '.results[0].id // empty' <<<"$resp"
|
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)
|
# PATCH NetBox custom fields (update_wo_restart)
|
||||||
nb_patch_update_wo_restart() {
|
nb_patch_update_wo_restart() {
|
||||||
local dev_id="$1" update_progress="$2" updating_to="$3"
|
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
|
local body
|
||||||
body="$(jq -n --arg p "$update_progress" --arg u "$updating_to" \
|
body="$(jq -n --arg p "$update_progress" --arg u "$updating_to" \
|
||||||
'{custom_fields: {update_progress: $p, updating_to: $u}}')"
|
'{custom_fields: {update_progress: $p, updating_to: $u}}')"
|
||||||
@@ -81,6 +102,12 @@ nb_patch_update_wo_restart() {
|
|||||||
# PATCH NetBox custom field: wifidebug (deploy_wifidebug)
|
# PATCH NetBox custom field: wifidebug (deploy_wifidebug)
|
||||||
nb_patch_wifidebug() {
|
nb_patch_wifidebug() {
|
||||||
local dev_id="$1" value="$2"
|
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
|
local body
|
||||||
body="$(jq -n --arg v "$value" '{custom_fields: {wifidebug: $v}}')"
|
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
|
# PATCH custom field: multiple_ssids = "yes" — used for task_notify path
|
||||||
nb_set_multiple_ssids_yes() {
|
nb_set_multiple_ssids_yes() {
|
||||||
local dev_id="$1"
|
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 body='{"custom_fields":{"multiple_ssids":"yes"}}'
|
||||||
|
|
||||||
local code
|
local code
|
||||||
@@ -319,6 +352,12 @@ nb_remove_tag_by_slug() {
|
|||||||
# --- clear only custom_field update_progress (set to null) ---
|
# --- clear only custom_field update_progress (set to null) ---
|
||||||
nb_clear_update_progress() {
|
nb_clear_update_progress() {
|
||||||
local dev_id="$1"
|
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 body='{"custom_fields":{"update_progress":null}}'
|
||||||
local code
|
local code
|
||||||
code="$(curl -sS -o /dev/null -w "%{http_code}" \
|
code="$(curl -sS -o /dev/null -w "%{http_code}" \
|
||||||
@@ -338,6 +377,12 @@ nb_clear_update_progress() {
|
|||||||
# --- NEW: generic single custom field patch ---
|
# --- NEW: generic single custom field patch ---
|
||||||
nb_patch_custom_field() {
|
nb_patch_custom_field() {
|
||||||
local dev_id="$1" key="$2" value="$3"
|
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>" }}
|
# Build {"custom_fields": { "<key>": "<value>" }}
|
||||||
local body
|
local body
|
||||||
body="$(jq -n --arg k "$key" --arg v "$value" '{custom_fields: {($k): $v}}')"
|
body="$(jq -n --arg k "$key" --arg v "$value" '{custom_fields: {($k): $v}}')"
|
||||||
|
|||||||
Reference in New Issue
Block a user