/ Published in: Bash
                    
                                        
CloudStack create API signature
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
##
# api.sh
#
# Public API port
address="https://"
# API key
api_key="<apikey>"
# Secret key
secret_key="<secretkey>"
# API entry point
api_path="/client/api"
# DATE
date=$(date '+%Y%m%d-%H%M')
# OUTPUT file
output="${HOME}/reports/capacity_${date}.csv"
echo '"Zone","Resource","Used","Available","Percent","Allocated Used","Available(Oversub)","Percent"' > ${output}
# Management Server
dbserver="<server>"
###
### create signature
###
generate_string(){
local strings=$(echo -n $@ | tr " " "&")
local pre_encoded_request=$(python -c "import urllib; print urllib.quote('''${strings}''','''=& ''').replace('''+''','''%20''')")
local sorted_request=$(echo -n ${pre_encoded_request[@]} | tr "&" "\n" | \
sort -fd -t'=' | tr "\n" "&" | sed -e 's/\&$//' )
encoded_query=$(python -c "import urllib; print urllib.quote('''${sorted_request}''','''=&:+-^''').replace('''''','''''').lower()")
}
generate_signature(){
signature=$(echo -n $@ | \
openssl sha1 -binary -hmac ${secret_key} | \
openssl base64 )
signature=$(python -c "import urllib; print urllib.quote('''${signature}''').replace('''/''','''%2F''')")
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                