Skip to content

Instantly share code, notes, and snippets.

@malston
Last active May 31, 2016 16:40
Show Gist options
  • Save malston/8a895f8c59ced8cbf42fca94b20e7360 to your computer and use it in GitHub Desktop.
Save malston/8a895f8c59ced8cbf42fca94b20e7360 to your computer and use it in GitHub Desktop.
upload_pivnet_product
upload_product() {
PRODUCT_FILE=$1
OPSMGR_HOST=$2
OPSMGR_USER=$3
OPSMGR_PASSWORD=$4
OPSMGR_IP=$5
LOG_FILE=upload.txt
if [ -z $OPSMGR_IP ]; then
curl -k -XPOST -H "Application/json" -H "Host: $OPSMGR_HOST" -u "opsman:" \
--data "username=$OPSMGR_USER&password=$OPSMGR_PASSWORD&client_id=opsman&grant_type=password&response_type=token" \
https://$OPSMGR_HOST/uaa/oauth/token > access_token
UAA_ACCESS_TOKEN=$(jq '.access_token' access_token | tr -d '"')
curl -k "https://$OPSMGR_HOST/api/v0/available_products" -F "product[file]=@${PRODUCT_FILE}" \
-X POST -H "Host: $OPSMGR_HOST" -H "Authorization: Bearer $UAA_ACCESS_TOKEN" \
| tee -a "${LOG_FILE}" ; test ${PIPESTATUS[0]} -eq 0
else
curl -k -XPOST -H "Application/json" -H "Host: $OPSMGR_HOST" -u "opsman:" \
--data "username=$OPSMGR_USER&password=$OPSMGR_PASSWORD&client_id=opsman&grant_type=password&response_type=token" \
--resolve $OPSMGR_HOST:443:$OPSMGR_IP https://$OPSMGR_HOST/uaa/oauth/token > access_token
UAA_ACCESS_TOKEN=$(jq '.access_token' access_token | tr -d '"')
curl -k "https://$OPSMGR_HOST/api/v0/available_products" -F "product[file]=@${PRODUCT_FILE}" \
-X POST -H "Host: $OPSMGR_HOST" -H "Authorization: Bearer $UAA_ACCESS_TOKEN" \
--resolve $OPSMGR_HOST:443:$OPSMGR_IP | tee -a "${LOG_FILE}" ; test ${PIPESTATUS[0]} -eq 0
fi
rm $LOG_FILE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment