2020# The script will automatically generate a new API key if
2121# no key is found, or if a saved key has expired or is invalid.
2222
23-
24-
23+ _COMMIT_WAIT_INTERVAL=30 # query commit status every 30 seconds
24+ _COMMIT_WAIT_ITERATIONS=20 # query commit status 20 times (20*30 = 600 seconds = 10 minutes)
2525
2626# This function is to parse the XML response from the firewall
2727parse_response () {
@@ -59,11 +59,11 @@ deployer() {
5959 content=" "
6060 type=$1 # Types are keytest, keygen, cert, key, commit, job_status, push
6161 panos_url=" https://$_panos_host /api/"
62+ export _H1=" Content-Type: application/x-www-form-urlencoded"
6263
6364 # Test API Key by performing a lookup
6465 if [ " $type " = ' keytest' ]; then
6566 _debug " **** Testing saved API Key ****"
66- _H1=" Content-Type: application/x-www-form-urlencoded"
6767 # Get Version Info to test key
6868 content=" type=version&key=$_panos_key "
6969 # # Exclude all scopes for the empty commit
@@ -74,7 +74,6 @@ deployer() {
7474 # Generate API Key
7575 if [ " $type " = ' keygen' ]; then
7676 _debug " **** Generating new API Key ****"
77- _H1=" Content-Type: application/x-www-form-urlencoded"
7877 content=" type=keygen&user=$_panos_user &password=$_panos_pass "
7978 # content="$content${nl}--$delim${nl}Content-Disposition: form-data; type=\"keygen\"; user=\"$_panos_user\"; password=\"$_panos_pass\"${nl}Content-Type: application/octet-stream${nl}${nl}"
8079 fi
@@ -99,7 +98,7 @@ deployer() {
9998 fi
10099 if [ " $_panos_vsys " ]; then
101100 content=" $content ${nl} --$delim ${nl} Content-Disposition: form-data; name=\" target-tpl-vsys\" \r\n\r\n$_panos_vsys "
102- fi
101+ fi
103102 fi
104103 if [ " $type " = ' key' ]; then
105104 panos_url=" ${panos_url} ?type=import"
@@ -114,7 +113,7 @@ deployer() {
114113 fi
115114 if [ " $_panos_vsys " ]; then
116115 content=" $content ${nl} --$delim ${nl} Content-Disposition: form-data; name=\" target-tpl-vsys\" \r\n\r\n$_panos_vsys "
117- fi
116+ fi
118117 fi
119118 # Close multipart
120119 content=" $content ${nl} --$delim --${nl}${nl} "
@@ -125,7 +124,6 @@ deployer() {
125124 # Commit changes
126125 if [ " $type " = ' commit' ]; then
127126 _debug " **** Committing changes ****"
128- export _H1=" Content-Type: application/x-www-form-urlencoded"
129127 # Check for force commit - will commit ALL uncommited changes to the firewall. Use with caution!
130128 if [ " $FORCE " ]; then
131129 _debug " Force switch detected. Committing ALL changes to the firewall."
@@ -140,15 +138,13 @@ deployer() {
140138 # Query job status
141139 if [ " $type " = ' job_status' ]; then
142140 echo " **** Querying job $_commit_job_id status ****"
143- H1=" Content-Type: application/x-www-form-urlencoded"
144141 cmd=$( printf " %s" " <show><jobs><id>$_commit_job_id </id></jobs></show>" | _url_encode)
145142 content=" type=op&key=$_panos_key &cmd=$cmd "
146143 fi
147144
148145 # Push changes
149146 if [ " $type " = ' push' ]; then
150147 echo " **** Pushing changes ****"
151- H1=" Content-Type: application/x-www-form-urlencoded"
152148 cmd=$( printf " %s" " <commit-all><template-stack><name>$_panos_template_stack </name><admin><member>$_panos_user </member></admin></template-stack></commit-all>" | _url_encode)
153149 content=" type=commit&action=all&key=$_panos_key &cmd=$cmd "
154150 fi
@@ -288,13 +284,15 @@ panos_deploy() {
288284 deployer commit
289285 if [ " $_panos_template_stack " ]; then
290286 # try to get job status for 20 times in 30 sec interval
291- for (( i = 0 ; i < 20 ; i++ )) ; do
292- deployer job_status
293- if [[ " $_commit_job_status " == " OK" ]]; then
294- echo " Commit finished!"
295- break
296- fi
297- sleep 30
287+ i=0
288+ while [ " $i " -lt $_COMMIT_WAIT_ITERATIONS ]; do
289+ deployer job_status
290+ if [ " $_commit_job_status " = " OK" ]; then
291+ echo " Commit finished!"
292+ break
293+ fi
294+ sleep $_COMMIT_WAIT_INTERVAL
295+ i=$(( i + 1 ))
298296 done
299297 deployer push
300298 fi
0 commit comments