Return to Snippet

Revision: 67555
at October 6, 2014 23:09 by tonyjameshart


Initial Code
##
# 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''')")

}

Initial URL

                                

Initial Description
CloudStack create API signature

Initial Title
CloudStack create API signature

Initial Tags

                                

Initial Language
Bash