-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxmox_template.vm_id.convert_to_template.to.jsons.sh
More file actions
executable file
·120 lines (89 loc) · 2.76 KB
/
proxmox_template.vm_id.convert_to_template.to.jsons.sh
File metadata and controls
executable file
·120 lines (89 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
# ISSUE - 105
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
set -euo pipefail
ACTION="template_convert_vm_to_template"
DEFAULT_OUTPUT_JSON=true
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
show_example() {
echo " :: WITH VALUES FROM STDIN (as plain text) "
echo
echo " echo \"url\" | $(basename "$0") "
echo " echo \"url\" | $(basename "$0") --json"
echo " echo \"url\" | $(basename "$0") --text"
echo
echo " cat /tmp/url.text | $(basename "$0")"
echo
echo " :: WITH VALUEs FROM STDIN (as JSON lines)"
echo
local STDIN_JSON_DATA=(
'{ "vm_id": 2222, "proxmox_node": "px-testing"}'
)
for json in "${STDIN_JSON_DATA[@]}"; do
devkit_utils.text.echo_json_helper.to.text.sh "$json"
done | sed '$ s/$/ | '"$(basename "$0")"'/'
echo ""
}
if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
echo
echo
echo NAME
echo
echo " $(basename "$0") - convert VM to template - Execute the specified $ACTION action via Ansible "
echo
echo OPTIONS
echo
echo " $(basename "$0") [-h|--help]"
echo " echo [STORAGE_NAME] | $(basename "$0") [--json] - force output as json "
echo " echo [STORAGE_NAME] | $(basename "$0") [--text] - force output as text (debug purpose)"
echo
echo EXAMPLE
echo
echo "$(show_example)"
echo
echo
exit 1
fi
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
proxmox__inc.warmup_checks.sh
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
OUTPUT_JSON="$DEFAULT_OUTPUT_JSON"
while [[ $# -gt 0 ]]; do
case "$1" in
--json)
OUTPUT_JSON=true
shift
;;
--text)
OUTPUT_JSON=false
shift
;;
-*)
devkit_utils.text.echo_error.to.text.to.stderr.sh "wrong number of arguments."
show_example
exit 1
;;
*) ;;
esac
done
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
JSON_LINE_REQ=$(
devkit_proxmox.STDIN.stdin_or_jsons.to.jsons.sh "STR::vm_id" "STR::proxmox_node" "STR::action"
)
echo $JSON_LINE_REQ
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
printf '%s\n' "$JSON_LINE_REQ" | while IFS=$'\n' read -r CURRENT_JSON_LINE; do
#
# CURRENT_JSON_LINE=$NEW_CURRENT_JSON_LINE
devkit_utils.text.echo_trace.to.text.to.stderr.sh "$CURRENT_JSON_LINE"
# exit 1
if [[ "$OUTPUT_JSON" == true ]]; then # JSON output mode.
printf '%s\n' "$CURRENT_JSON_LINE" |
proxmox__inc.jsons.basic_vm_actions.to.jsons.sh "$ACTION" | jq -c "."
# jq -c '.[]'
else
# text output mode - debug
printf '%s\n' "$CURRENT_JSON_LINE" |
proxmox__inc.jsons.basic_vm_actions.to.text.sh "$ACTION"
fi
done