Atšķirības starp "Hostnet OpenStack Cloud Compute API" versijām
No ''Hostnet Wiki''
| (13 starpversijas, ko mainījis viens dalībnieks, nav parādītas) | |||
| 1. rindiņa: | 1. rindiņa: | ||
| − | + | Example with using curl. | |
| − | # {username}, { | + | Once you have these pieces of information, you can pass them into the SDK by replacing {username}, {password} and {projectID} with your info: |
| + | |||
| + | # {username}, {password} below are placeholders, do not enclose '{}' when you replace them with actual credentials. | ||
<syntaxhighlight lang=bash> | <syntaxhighlight lang=bash> | ||
| − | + | curl -i \ | |
-H "Content-Type: application/json" \ | -H "Content-Type: application/json" \ | ||
-d ' | -d ' | ||
| 16. rindiņa: | 18. rindiņa: | ||
"name": "{username}", | "name": "{username}", | ||
"domain": { | "domain": { | ||
| − | "id": " | + | "id": "default" |
}, | }, | ||
"password": "{password}" | "password": "{password}" | ||
| 30. rindiņa: | 32. rindiņa: | ||
}' \ | }' \ | ||
https://identity.api.cloud.hostnet.lv/v3/auth/tokens | https://identity.api.cloud.hostnet.lv/v3/auth/tokens | ||
| + | |||
| + | # From the resulting, set environment variable as X-Subject-Token value: | ||
| + | export OS_TOKEN="{X-Subject-Token}" | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | # Get service endpoints: | ||
| + | |||
| + | <syntaxhighlight lang=bash> | ||
| + | curl -s -X GET https://identity.api.cloud.hostnet.lv/v3/auth/catalog \ | ||
| + | -H "X-Auth-Token: $OS_TOKEN" | python -m json.tool | ||
| + | |||
| + | # Set env variable for public compute, image and network endpoints: | ||
| + | export ENDPOINT="{computeURL}" | ||
| + | export IMG_ENDPOINT="{imageURL}" | ||
| + | export NET_ENDPOINT="{networkURL}" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | # | + | # List available flavors: |
| + | |||
| + | <syntaxhighlight lang=bash> | ||
| + | curl -s -X GET $ENDPOINT/flavors \ | ||
| + | -H "X-Auth-Token: $OS_TOKEN" | python -m json.tool | ||
| + | |||
| + | # Choose a flavor from the list and note its id. | ||
| + | export FLAVOR_ID="{flavorId}" | ||
| + | </syntaxhighlight> | ||
| − | + | Or get flavor there [[Hostnet_OpenStack_Cloud_Flavors|Hostnet OpenStack Cloud Flavors]] | |
| − | # | + | # List available images: |
<syntaxhighlight lang=bash> | <syntaxhighlight lang=bash> | ||
| − | curl -s -X GET | + | curl -s -X GET $IMG_ENDPOINT/v2/images \ |
| − | -H "X-Auth-Token: $OS_TOKEN" | python -m json.tool | + | -H "X-Auth-Token: $OS_TOKEN" | python -m json.tool |
| + | |||
| + | # Choose an image from the list and note its id. | ||
| + | export IMAGE_ID="{imageId}" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | # | + | # List available networks: |
| − | export | + | <syntaxhighlight lang=bash> |
| + | curl -s -X GET $NET_ENDPOINT/v2.0/networks \ | ||
| + | -H "X-Auth-Token: $OS_TOKEN" | python -m json.tool | ||
| + | |||
| + | # Choose an network from the list and note its id. | ||
| + | export NET_ID="{networkId}" | ||
| + | </syntaxhighlight> | ||
| − | # | + | # Create server: |
<syntaxhighlight lang=bash> | <syntaxhighlight lang=bash> | ||
| − | curl -s | + | curl -s $ENDPOINT/servers \ |
| − | -H "X-Auth-Token: $OS_TOKEN" | python -m json.tool | + | -X POST \ |
| + | -H "X-Auth-Token: $OS_TOKEN" \ | ||
| + | -H "Content-Type: application/json" \ | ||
| + | -d '{"server": {"name": "MyNewServer", "imageRef": "e689ffc1-3cd5-4e9e-be6f-240fdaac83fd", "flavorRef": "687f86d4-c227-421e-9c32-43519a2b4363"}}' | python -m json.tool | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | Response: | ||
| + | <syntaxhighlight lang="json"> | ||
| + | { | ||
| + | "server": { | ||
| + | "OS-DCF:diskConfig": "MANUAL", | ||
| + | "adminPass": "iH5oE7DSDzwz", | ||
| + | "id": "57037ac4-4478-4708-bd17-46273bcc3b06", | ||
| + | "links": [ | ||
| + | { | ||
| + | "href": "https://compute.api.cloud.hostnet.lv/v2.1/86320c4cde114196a211b49d3ba9c5f3/servers/57037ac4-4478-4708-bd17-46273bcc3b06", | ||
| + | "rel": "self" | ||
| + | }, | ||
| + | { | ||
| + | "href": "https://compute.api.cloud.hostnet.lv/86320c4cde114196a211b49d3ba9c5f3/servers/57037ac4-4478-4708-bd17-46273bcc3b06", | ||
| + | "rel": "bookmark" | ||
| + | } | ||
| + | ], | ||
| + | "security_groups": [ | ||
| + | { | ||
| + | "name": "default" | ||
| + | } | ||
| + | ] | ||
| + | } | ||
| + | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | + | # Nova API documentation: https://developer.openstack.org/api-ref/compute/ | |
| + | # Nova Python client: https://github.com/openstack/python-novaclient | ||
| + | |||
| + | [[Category:Hostnet OpenStack Cloud]] | ||
Pašreizējā versija, 2017. gada 6. jūnijs, plkst. 14.03
Example with using curl.
Once you have these pieces of information, you can pass them into the SDK by replacing {username}, {password} and {projectID} with your info:
- {username}, {password} below are placeholders, do not enclose '{}' when you replace them with actual credentials.
curl -i \
-H "Content-Type: application/json" \
-d '
{ "auth": {
"identity": {
"methods": [
"password"
],
"password": {
"user": {
"name": "{username}",
"domain": {
"id": "default"
},
"password": "{password}"
}
}
},
"scope": {
"project": {
"id": "{projectID}"
}
}
}
}' \
https://identity.api.cloud.hostnet.lv/v3/auth/tokens
# From the resulting, set environment variable as X-Subject-Token value:
export OS_TOKEN="{X-Subject-Token}"
- Get service endpoints:
curl -s -X GET https://identity.api.cloud.hostnet.lv/v3/auth/catalog \
-H "X-Auth-Token: $OS_TOKEN" | python -m json.tool
# Set env variable for public compute, image and network endpoints:
export ENDPOINT="{computeURL}"
export IMG_ENDPOINT="{imageURL}"
export NET_ENDPOINT="{networkURL}"
- List available flavors:
curl -s -X GET $ENDPOINT/flavors \
-H "X-Auth-Token: $OS_TOKEN" | python -m json.tool
# Choose a flavor from the list and note its id.
export FLAVOR_ID="{flavorId}"
Or get flavor there Hostnet OpenStack Cloud Flavors
- List available images:
curl -s -X GET $IMG_ENDPOINT/v2/images \
-H "X-Auth-Token: $OS_TOKEN" | python -m json.tool
# Choose an image from the list and note its id.
export IMAGE_ID="{imageId}"
- List available networks:
curl -s -X GET $NET_ENDPOINT/v2.0/networks \
-H "X-Auth-Token: $OS_TOKEN" | python -m json.tool
# Choose an network from the list and note its id.
export NET_ID="{networkId}"
- Create server:
curl -s $ENDPOINT/servers \
-X POST \
-H "X-Auth-Token: $OS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"server": {"name": "MyNewServer", "imageRef": "e689ffc1-3cd5-4e9e-be6f-240fdaac83fd", "flavorRef": "687f86d4-c227-421e-9c32-43519a2b4363"}}' | python -m json.tool
Response:
{
"server": {
"OS-DCF:diskConfig": "MANUAL",
"adminPass": "iH5oE7DSDzwz",
"id": "57037ac4-4478-4708-bd17-46273bcc3b06",
"links": [
{
"href": "https://compute.api.cloud.hostnet.lv/v2.1/86320c4cde114196a211b49d3ba9c5f3/servers/57037ac4-4478-4708-bd17-46273bcc3b06",
"rel": "self"
},
{
"href": "https://compute.api.cloud.hostnet.lv/86320c4cde114196a211b49d3ba9c5f3/servers/57037ac4-4478-4708-bd17-46273bcc3b06",
"rel": "bookmark"
}
],
"security_groups": [
{
"name": "default"
}
]
}
}
- Nova API documentation: https://developer.openstack.org/api-ref/compute/
- Nova Python client: https://github.com/openstack/python-novaclient