Hey! So, today I was playing around with Cloud Networking API and thought I would document the basic process of creating a network. It’s simple enough and follows the precise same logic as many of my other tutorials on cloud files, load balancers and etc.
#!/bin/bash
USERNAME='mycloudusername'
APIKEY='mycloudapikey'
ACCOUNT_NUMBER=10010101
API_ENDPOINT="https://lon.networks.api.rackspacecloud.com/v2.0/"
TOKEN=`curl 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 -mjson.tool | grep -A5 token | grep id | cut -d '"' -f4`
curl -s -v \
-H "X-Auth-Token: $TOKEN" \
-H "X-Project-Id: $ACCOUNT_NUMBER" \
-H "Accept: application/json" \
-X POST -d @create-network.json "$API_ENDPOINT/networks" | python -mjson.tool
For the above code to create a new network you need to create the create-network.json markup file, it needs to look like and be in this format:
{
"network":
{
"name": "Isolatednet",
"shared": false,
"tenant_id": "10010101"
}
}
It’s important to note you need to define the tenant_id, thats your account number that appears in the URL when you login to mycloud control panel.
Output looks like
* Connection #0 to host lon.networks.api.rackspacecloud.com left intact
{
"network": {
"admin_state_up": true,
"id": "ae36972f-5cba-4327-8bff-15d8b05dc3ee",
"name": "Isolatednet",
"shared": false,
"status": "ACTIVE",
"subnets": [],
"tenant_id": "10045567"
}
}