-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxmox_network.node_name.add_interfaces_node.to.jsons.sh
More file actions
executable file
·145 lines (113 loc) · 4.44 KB
/
proxmox_network.node_name.add_interfaces_node.to.jsons.sh
File metadata and controls
executable file
·145 lines (113 loc) · 4.44 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
# ISSUE -101
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
set -euo pipefail
ACTION="network_add_interfaces_node"
DEFAULT_OUTPUT_JSON=true
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
show_example() {
echo " :: WITH VALUES FROM STDIN (as plain text) "
echo
echo " echo \"px-testing\" | $(basename "$0") "
echo " echo \"px-testing\" | $(basename "$0") --json"
echo " echo \"px-testing\" | $(basename "$0") --text"
echo
echo " cat /tmp/px_nodes.text | $(basename "$0")"
echo
echo " :: WITH VALUEs FROM STDIN (as JSON lines)"
echo
local STDIN_JSON_DATA=(
'{"proxmox_node":"px-testing","iface_name":"vmbr42","iface_type":"bridge","bridge_ports":"enp87s0"}'
'{"proxmox_node":"px-testing","iface_name":"vmbr42","iface_type":"bridge","bridge_ports":"enp87s0", "iface_autostart":1,"ip_address":"192.168.88.2", "ip_netmask":"255.255.255.0" }'
'{"proxmox_node":"px-testing","iface_name":"vmbr42","iface_type":"bridge","bridge_ports":"enp87s0", "iface_autostart":1,"ip_address":"192.168.88.2", "ip_netmask":"255.255.255.0", "ip_gateway":"192.168.88.1" }'
'{"proxmox_node":"px-testing","iface_name":"vmbr42","iface_type":"OVSBridge","ovs_bridge":"enp87s0","iface_autostart":1,"ip_address":"192.168.88.2","ip_netmask":"255.255.255.0"}'
#
''
'{"iface_name":"bridge42","iface_type":"bridge","iface_autostart":1}'
'{"iface_name":"bond","iface_type":"bond","iface_autostart":1}'
'{"iface_name":"alias","iface_type":"alias","iface_autostart":1}'
'{"iface_name":"vlan","iface_type":"vlan","iface_autostart":1}'
'{"iface_name":"ovsbridge42","iface_type":"OVSBridge","iface_autostart":1}'
'{"iface_name":"ovsbond42","iface_type":"OVSBond","iface_autostart":1}'
'{"iface_name":"ovsport42","iface_type":"OVSPort","iface_autostart":1}'
'{"iface_name":"ovintport42","iface_type":"OVSIntPort","iface_autostart":1}'
'{"iface_name":"vmnet42","iface_type":"vnet","iface_autostart":1}'
)
for json in "${STDIN_JSON_DATA[@]}"; do
devkit_utils.text.echo_json_helper.to.text.sh "$json"
done | sed '$ s/$/ | '"$(basename "$0")"'/'
printf '%s | %s\n' "$(devkit_utils.text.echo_json_helper.to.text.sh "${STDIN_JSON_DATA[-1]}")" "$(basename "$0") --text"
echo ""
echo " cat /tmp/px_nodes.json | $(basename "$0")"
}
if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
echo
echo
echo NAME
echo
echo " $(basename "$0") - list NODE network interfaces - Execute the specified $ACTION action via Ansible "
echo
echo OPTIONS
echo
echo " $(basename "$0") [-h|--help] "
echo " $(basename "$0") [--json] - force output as json "
echo " $(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
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
#
# browse provided arugments :
#
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
;;
*) ;;
# if [[ -z "$ARG_VM_BRIDGE_NAME_FILTER" ]]; then
# ARG_VM_BRIDGE_NAME_FILTER="$1"
# shift
# else
# devkit_utils.text.echo_error.to.text.to.stderr.sh "wrong number of arguments."
# show_example
# exit 1
# fi
# ;;
esac
done
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
JSON_LINE_REQ=$(devkit_proxmox.STDIN.stdin_or_jsons.to.jsons.sh "STR::iface_name" "STR::iface_type" "STR::proxmox_node" "STR::action")
#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####
# IFS=$'\n'
printf '%s\n' "$JSON_LINE_REQ" | while IFS=$'\n' read -r CURRENT_JSON_LINE; do
devkit_utils.text.echo_trace.to.text.to.stderr.sh "$CURRENT_JSON_LINE"
# exit 1
if [[ "$OUTPUT_JSON" == true ]]; then # json mode.
printf '%s\n' "$CURRENT_JSON_LINE" |
proxmox__inc.jsons.basic_vm_actions.to.jsons.sh "$ACTION"
# jq ".[]"
# fi
else # text output mode - debug
printf '%s\n' "$CURRENT_JSON_LINE" |
proxmox__inc.jsons.basic_vm_actions.to.text.sh "$ACTION"
fi
done