Skip to content

Instantly share code, notes, and snippets.

@pratikmallya
Created September 29, 2015 14:48
Show Gist options
  • Save pratikmallya/71562b7afc643b20e0be to your computer and use it in GitHub Desktop.
Save pratikmallya/71562b7afc643b20e0be to your computer and use it in GitHub Desktop.
#cloud-config
write_files:
- path: /root/hello-world.txt
content: |
#!/bin/bash
username=XXXXXX
APIkey=XXXXXX
dc=hkg
container=dn-container
file=xyz.tar.gz
token() {
token=`curl -s "https://identity.api.rackspacecloud.com/v2.0/tokens" -X POST \
-d '{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"'$username'", "apiKey":"'$APIkey'"}}}' \
-H "Content-Type: application/json" | python -m json.tool | sed -n '/expires/{n;p;}' |sed -e 's/^.*"id": "\(.*\)",/\1/'`
echo "Your API Token is ----> $token" > /root/token.txt
}
token
Output (in cloud server):
root@test-server:~# cat hello-world.txt
username=XXXXXX
APIkey=XXXXXX
dc=hkg
container=dn-container
file=xyz.tar.gz
token() {
token=`curl -s "https://identity.api.rackspacecloud.com/v2.0/tokens" -X POST undefined
-d '{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"'$username'", "apiKey":"'$APIkey'"}}}' undefined
-H "Content-Type: application/json" | python -m json.tool | sed -n '/expires/{n;p;}' |sed -e 's/^.*"id": "undefined(.*undefined)",/undefined1/'`
echo "Your API Token is ----> $token" > /root/token.txt
}
token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment