Attach volume¶
Overview¶
Attaches a volume to the specified server.
Classification¶
- Attach
API Operation Object¶
- os-volume_attachments
Synchronous / Asynchronous¶
- asynchronous
Request¶
HTTP Request Method¶
- POST
HTTP Request Path¶
{api_endpoint}/v2/{project_id}/servers/{server_id}/os-volume_attachments
HTTP Request Header¶
Format¶
Accept-Encoding: gzip, deflate, compress (optional)
Accept: application/json
X-Auth-Token: <token_id>
Content-Type: application/json
HTTP Request Body¶
Format¶
{
"volumeAttachment": {
"device": "<device_name>",
"volumeId": "<volume_id>"
}
}
Request Parameter¶
name | style | format | description | required/optional | default value | action for invalid parameter | response code for invalid parameter |
---|---|---|---|---|---|---|---|
project_id | URL | UUID(3) | Project id | required | - | Terminate | 400, 404 |
server_id | URL | UUID String | instance id | required | - | Terminate | 404 |
token_id | Header | authentication token string | keystone authentication token | required | - | Terminate | 401 |
device_name | Body | String(^/dev/x{0,1}[a-z]{0,1}d{0,1})([a-z]+)[0-9]*$) | device name | optional | - | Terminate | 400 |
volume_id | Body | UUID String | volume id | required | - | Terminate | 400, 404 |
Response¶
HTTP Response Header¶
Format¶
HTTP/1.1 <response_code> <message> (ex. 200 OK)
<response_code>: see "HTTP Responses" section
<message>: message based on the response code
- skip auto insert field such as "X-Compute-Request-Id" and "Content-Length", "Date"
Response Code¶
response code | condition |
---|---|
200 | normal end |
400 | not found volumeAttachment entity in body |
- | not found voumeId attribute in body |
- | invalid device_name |
- | invalid volume_id |
- | invalid the project_id |
- | volume status != available |
401 | unauthorized |
404 | not found a specified instance |
- | not found a specified volume |
409 | vm_state isn't ACTIVE, PAUSED, STOPPED, RESIZED, SOFT_DELETED |
- | Specified the device name that already exists |
500 | Unable to find host for instance |
Sample API Request and Response¶
Sample API Request¶
Request URI¶
https://example.com/v2/{project_id}/servers/{server_id}/os-volume_attachments
Request Header¶
Accept-Encoding: gzip, deflate, compress (optional)
Accept: application/json
X-Auth-Token: ajk3adjiown02
Content-Type: application/json
Request Body¶
{
"volumeAttachment": {
"device": "<device_name>",
"volumeId": "<volume_id>"
}
}
Sample API Response¶
Response Header¶
HTTP/1.1 200 OK
<response_code>: see "HTTP Responses" section
<message>: message based on the response code
- skip auto insert field such as "X-Compute-Request-Id" and "Content-Length", "Date"
Response Body¶
{
"volumeAttachment": {
"device": "<device_name>",
"id": "<attachment_id>",
"serverId": "<instance_id>",
"volumeId": "<volume_id>"
}
}
Execution Example¶
HTTP Request¶
POST /v2/b7a7b63e92174a95a999c95da856f143/servers/da5834e0-31d2-40f9-b271-6592f9f68370/os-volume_attachments HTTP/1.1
User-Agent: curl/7.35.0
Host: 192.168.150.51:8774
Accept-Encoding: gzip, deflate, compress
Accept: application/json
X-Auth-Token: b3a07ef1f2954424a9c56876d88f6751
Content-Type: application/json
Content-Length: 119
{ "volumeAttachment": { "volumeId": "eef897c2-e61b-4a18-84e9-ac44ebb34c7b", "device": "/dev/vdd" }}
HTTP Response¶
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 194
X-Compute-Request-Id: req-0550641e-fe65-4566-a16c-7ab798208daa
Date: Tue, 19 Aug 2014 09:21:02 GMT
{"volumeAttachment": {"device": "/dev/vdd", "serverId": "da5834e0-31d2-40f9-b271-6592f9f68370", "id": "eef897c2-e61b-4a18-84e9-ac44ebb34c7b", "volumeId": "eef897c2-e61b-4a18-84e9-ac44ebb34c7b"}}
Error Execution Example¶
HTTP Request¶
POST /v2/b7a7b63e92174a95a999c95da856f143/servers/da5834e0-31d2-40f9-b271-6592f9f68370/os-volume_attachments HTTP/1.1
User-Agent: curl/7.35.0
Host: 192.168.56.250:8774
X-Auth-Token: d9bd7697eb5b4d2c9594b2156475faf0
Content-type: application/json
Accept: application/json
Content-Length: 99
{ "volumeAttachment": { "volumeId": "eef897c2-e61b-4a18-84e9-ac44ebb34c7b", "device": "/dev/vdd" }}
HTTP Response¶
HTTP/1.1 400 Bad Request
Content-Length: 188
Content-Type: application/json; charset=UTF-8
X-Compute-Request-Id: req-91f31db5-408d-44e3-a7e2-1258ff50155a
Date: Tue, 13 Oct 2015 05:16:57 GMT
{"badRequest": {"message": "Malformed request URL: URL's project_id 'b7a7b63e92174a95a999c95da856f143' doesn't match Context's project_id '9e691df1813f4737a5c505b4cab89a96'", "code": 400}}