Skip to content

Commit 552a4b7

Browse files
committed
Had it probably handle bad output from the API.
1 parent daacb22 commit 552a4b7

File tree

4 files changed

+56
-8
lines changed

4 files changed

+56
-8
lines changed

Management-Utilities/Workload-Factory-API-Samples/list_credentials

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,25 @@ if [ -z "$token" ]; then
106106
fi
107107

108108
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/credentials/v1/credentials?$filter" $tmpout $tmperr
109-
jq -r '.items[] | if(.type == "ONTAP") then "\(.metadata.fileSystemId) \(.type) \(.accountId) \(.id)" else "\(.metadata.name) \(.type) \(.credentials | split(":") | .[4]) \(.id)" end' $tmpout > $tmpout2
109+
if jq -r '.items[] | if(.type == "ONTAP") then "\(.metadata.fileSystemId) \(.type) \(.accountId) \(.id)" else "\(.metadata.name) \(.type) \(.credentials | split(":") | .[4]) \(.id)" end' $tmpout > $tmpout2 2> $tmperr; then
110+
:
111+
else
112+
echo "Failed to parse the output from the API."
113+
cat $tmperr >&2
114+
exit 1
115+
fi
110116
#
111117
# Check to see if there are more.
112118
nextToken=$(jq -r '.nextToken' $tmpout)
113119
while [ "$nextToken" != "null" ]; do
114120
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/credentials/v1/credentials?nextToken=$nextToken&$filter" $tmpout $tmperr
115-
jq -r '.items[] | if(.type == "ONTAP") then "\(.metadata.fileSystemId) \(.type) \(.accountId) \(.id)" else "\(.metadata.name) \(.type) \(.credentials | split(":") | .[4]) \(.id)" end' $tmpout >> $tmpout2
121+
if jq -r '.items[] | if(.type == "ONTAP") then "\(.metadata.fileSystemId) \(.type) \(.accountId) \(.id)" else "\(.metadata.name) \(.type) \(.credentials | split(":") | .[4]) \(.id)" end' $tmpout >> $tmpout2 2> $tmperr; then
122+
:
123+
else
124+
echo "Failed to parse the output from the API."
125+
cat $tmperr >&2
126+
exit 1
127+
fi
116128
nextToken=$(jq -r '.nextToken' $tmpout)
117129
done
118130

Management-Utilities/Workload-Factory-API-Samples/list_filesystems

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,25 @@ if [ -z "$token" ]; then
135135
fi
136136

137137
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems" $tmpout $tmperr
138-
jq -r '.items[] | "\(.id),\(.name),\(.region),\(.deploymentType),\(.status.status)"' $tmpout > $tmpout2
138+
if jq -r '.items[] | "\(.id),\(.name),\(.region),\(.deploymentType),\(.status.status)"' $tmpout > $tmpout2 2> $tmperr; then
139+
:
140+
else
141+
echo "Error: Failed to parse the output from the API." >&2
142+
cat $tmperr >&2
143+
exit 1
144+
fi
139145
#
140146
# Check to see if there are more.
141147
nextToken=$(jq -r '.nextToken' $tmpout)
142148
while [ "$nextToken" != "null" ]; do
143149
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems"
144-
jq -r '.items[] | "\(.id),\(.name),\(.region),\(.deploymentType),\(.status.status)"' $tmpout >> $tmpout2
150+
if jq -r '.items[] | "\(.id),\(.name),\(.region),\(.deploymentType),\(.status.status)"' $tmpout >> $tmpout2 2> $tmperr; then
151+
:
152+
else
153+
echo "Error: Failed to parse the output from the API." >&2
154+
cat $tmperr >&2
155+
exit 1
156+
fi
145157
nextToken=$(jq -r '.nextToken' $tmpout)
146158
done
147159
sort -t, -f -k 2,2 $tmpout2 | column -t -s, -N ID,Name,Region,Deployment_Type,Status

Management-Utilities/Workload-Factory-API-Samples/list_snapmirrors

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,25 @@ if [ -z "$token" ]; then
146146
fi
147147

148148
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/replication/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems/${FILESYSTEM_ID}/relationships" $tmpout $tmperr
149-
jq -r '.items[] | "\(.sourceCluster)::\(.sourceSvm):\(.sourceVolume) \(.destinationCluster)::\(if(.destinationSvm != null) then .destinationSvm else "Unknown" end):\(.destinationVolume) \(.id) \(if(.isHealthy != null) then .isHealthy else "Unknown" end) \(if(.mirrorState != null) then .mirrorState else "Unknown" end) \(if(.schedule != null) then .schedule else "None" end) \(if(.lagTime != null) then .lagTime else "Unknown" end)"' $tmpout > $tmpout2
149+
if jq -r '.items[] | "\(.sourceCluster)::\(.sourceSvm):\(.sourceVolume) \(.destinationCluster)::\(if(.destinationSvm != null) then .destinationSvm else "Unknown" end):\(.destinationVolume) \(.id) \(if(.isHealthy != null) then .isHealthy else "Unknown" end) \(if(.mirrorState != null) then .mirrorState else "Unknown" end) \(if(.schedule != null) then .schedule else "None" end) \(if(.lagTime != null) then .lagTime else "Unknown" end)"' $tmpout > $tmpout2 2> $tmperr; then
150+
:
151+
else
152+
echo "Error: Failed to parse the output from the API." >&2
153+
cat $tmperr >&2
154+
exit 1
155+
fi
150156
#
151157
# Check to see if there are more.
152158
nextToken=$(jq -r '.nextToken' $tmpout)
153159
while [ "$nextToken" != "null" ]; do
154160
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/replication/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems/${FILESYSTEM_ID}/relationships?nextToken=${nextToken}" $tmpout $tmperr
155-
jq -r '.items[] | "\(.sourceCluster)::\(.sourceSvm):\(.sourceVolume) \(.destinationCluster)::\(if(.destinationSvm != null) then .destinationSvm else "Unknown" end):\(.destinationVolume) \(.id) \(if(.isHealthy != null) then .isHealthy else "Unknown" end) \(if(.mirrorState != null) then .mirrorState else "Unknown" end) \(if(.schedule != null) then.schedule else "None" end) \(if(.lagTime != null) then .lagTime else "Unknown" end)"' $tmpout >> $tmpout2
161+
if jq -r '.items[] | "\(.sourceCluster)::\(.sourceSvm):\(.sourceVolume) \(.destinationCluster)::\(if(.destinationSvm != null) then .destinationSvm else "Unknown" end):\(.destinationVolume) \(.id) \(if(.isHealthy != null) then .isHealthy else "Unknown" end) \(if(.mirrorState != null) then .mirrorState else "Unknown" end) \(if(.schedule != null) then.schedule else "None" end) \(if(.lagTime != null) then .lagTime else "Unknown" end)"' $tmpout >> $tmpout2 2> $tmperr; then
162+
:
163+
else
164+
echo "Error: Failed to parse the output from the API." >&2
165+
cat $tmperr >&2
166+
exit 1
167+
fi
156168
nextToken=$(jq -r '.nextToken' $tmpout)
157169
done
158170
sort -f $tmpout2 | column -t -N Source,Destination,SnapMirror_Relationship_ID,Healthy,State,Schedule,Lag_Time

Management-Utilities/Workload-Factory-API-Samples/list_volumes

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,25 @@ if [ -z "$token" ]; then
146146
fi
147147

148148
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems/${FILESYSTEM_ID}/volumes" $tmpout $tmperr
149-
jq -r '.items[] | "\(.name) \(.id) \(.svmId) \(.lifecycle)"' $tmpout > $tmpout2
149+
if jq -r '.items[] | "\(.name) \(.id) \(.svmId) \(.lifecycle)"' $tmpout > $tmpout2 2> $tmperr; then
150+
:
151+
else
152+
echo "Error: Failed to parse the output from the API." >&2
153+
cat $tmperr >&2
154+
exit 1
155+
fi
150156
#
151157
# Check to see if there are more.
152158
nextToken=$(jq -r '.nextToken' $tmpout)
153159
while [ "$nextToken" != "null" ]; do
154160
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems/${FILESYSTEM_ID}/volumes?nextToken=${nextToken}" $tmpout $tmperr
155-
jq -r '.items[] | "\(.name) \(.id) \(.svmId) \(.lifecycle)"' $tmpout >> $tmpout2
161+
if jq -r '.items[] | "\(.name) \(.id) \(.svmId) \(.lifecycle)"' $tmpout >> $tmpout2 2> $tmperr; then
162+
:
163+
else
164+
echo "Error: Failed to parse the output from the API." >&2
165+
cat $tmperr >&2
166+
exit 1
167+
fi
156168
nextToken=$(jq -r '.nextToken' $tmpout)
157169
done
158170
sort -f $tmpout2 | column -t -N Name,ID,SVM_ID,Status

0 commit comments

Comments
 (0)