-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPI_Guide.txt
107 lines (74 loc) · 5.04 KB
/
API_Guide.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
API Consumption Guide
October 2014 V1.1
OneCloud Consulting
Openstack Using the OpenStack APIs for Application Deployment
Overview
The API interface is not usually used "manaully" for consuming cloud resources, but it can be informative to walk through the steps that an application would use to accomplish a task like spinning up a virtual machine. The following lab will walk you through those concepts.
The API itself is a ReSTful interface into the OpenStack system, and each project has it's own API endpoint, which is cataloged by Keystone. The initial token request to Keystone (which then provides authorization for the rest of the processes) also returns the list of endpoints a particular tenant has access to.
NOTE: If you are running this on DevStack, you can run these commands nearly as is, so long as the IDs required are exported as described. If you are running this against a remote system (like Cisco Cloud Service), you'll want to replace the endpoint IP address (127.0.0.1) with the appropriate address or dns name.
# Get token, manually copy token and tenant info into export commands. These allow these identifiers to be called in later curl commands with the ${NAME} syntax rather than being added each time.
export endpoint=${REPLACE_WITH_ENDPOINT_ADDRESS:-dnvrco-api.os.cloud.twc.net}
curl -i "https://${endpoint}:5000/v2.0/tokens" -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{"auth": {"tenantName": "admin", "passwordCredentials": {"username": "admin", "password": "ubuntu"}}}' | python -mjson.tool
export token=REPLACE_WITH_ACCESS_TOKEN_ID
export tenant_id=REPLACE_WITH_ACCESS_TENANT_ID
# List servers, should be empty
curl -v -H "X-Auth-Token:${token}" https://${endpoint}:8774/v2/${tenant_id}/servers | tail -n 1 | python -mjson.tool
# Get service list— seem to get service list with prior command…
curl -s \ -H "X-Auth-Token: ${token}" \ https://${endpoint}:5000/v3/services | python -mjson.tool
# keystone service-list --debug
curl -i -X GET https://${endpoint}:35357/v2.0/OS-KSADM/services -H "User-Agent: python-keystoneclient" -H "X-Auth-Token: ${token}" | python -mjson.tool
#Use service id from prior command to find service endpoint for glance and nova. First five alpha-numeric characters should be enough to differentiate from other listed endpoints in following step. For example:
{
"id": "5c817e2087cb43859516a0757b27d339",
"enabled": true,
"type": "compute",
"name": "nova",
"description": "Nova Compute Service"
},
{
"id": "5cf44d44abc54fc08ca23211d0ecc391",
"enabled": true,
"type": "image",
"name": "glance",
"description": "Glance Image Service"
},
So glance= 5cf44… and nova= 5c817…
# Get endpoints list
curl -i -X GET https://${endpoint}:35357/v2.0/endpoints -H "User-Agent: python-keystoneclient" -H "X-Auth-Token: ${token}" | python -mjson.tool
For Example: NOVA ENDPOINT
{
"internalurl": "https://${endpoint}:8774/v2/$(tenant_id)s",
"adminurl": "https://${endpoint}:8774/v2/$(tenant_id)s",
"service_id": "5c817e2087cb43859516a0757b27d339",
"region": "RegionOne",
"enabled": true,
"id": "265765fe58fc4fd6ab1c6fe4ae662420",
"publicurl": "https://${endpoint}:8774/v2/$(tenant_id)s"
},
For example: GLANCE ENDPOINT
{
"internalurl": "https://${endpoint}:9292",
"adminurl": "https://${endpoint}:9292",
"service_id": "5cf44d44abc54fc08ca23211d0ecc391",
"region": "RegionOne",
"enabled": true,
"id": "30df89def7ee4e6d9283b430e3aa4b54",
"publicurl": "https://${endpoint}:9292"
},
# Get image list from glance
curl -s https://${endpoint}:8774/v2/${tenant_id}/images -X GET -H "X-Auth-Project-Id: admin" -H "Accept: application/json" -H "X-Auth-Token: ${token} | python -mjson.tool
export image_id=REPLACE_WITH_IMAGE_ID
# Get flavor list from nova
curl -s https://${endpoint}:8774/v2/${tenant_id}/flavors -X GET -H "X-Auth-Project-Id: admin" -H "Accept: application/json" -H "X-Auth-Token: ${token}" | python -mjson.tool
export flavor_id= REPLACE_WITH_FLAVOR_ID
#get keypair
curl -i -X 'POST' -H "Content-type: application/json" -H "X-Auth-Token: ${Auth_Token}" -d '{"keypair": {"name": "keypair_1"}}' https://${endpoint}:8774/v2/${tenant_id}/os-keypairs'
export keypair=REPLACE_WITH_KEYPAIR
# build server
curl -i https://${endpoint}:8774/v2/${tenant_id}/servers -X POST -H "X-Auth-Project-Id: admin" -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: ${token}" -d \'{"server": {"name": "instance1", "imageRef": "${image_id}", "key_name": “keypair_1“, "flavorRef": “${flavor_id}", "max_count": 1, "min_count": 1}}\'
#alternative to python -mjson.tool
# do following as root at start
#apt-get install npm -y
#npm install node.js
#npm install -g json
#sed -e ’s/env node/env nodejs/‘ -i /usr/local/bin/json