Cloud Panel

Attach to a server

POST/api/v1/volumes/{disk_uuid}/attach

Attaches the volume to a running server without a restart. The server sees a new disk, usually /dev/vdb; format and mount it the first time. A volume is on one server at a time.

Parameters

NameInDescription
disk_uuidpath, stringrequiredVolume id, from Create a volume or List volumes

Request body

FieldTypeDescription
vm_uuidstringrequiredServer id, from List VMs of the cloud VM API

Example request

curl -X POST "https://platform.serverscamp.com/api/v1/volumes/$DISK_UUID/attach" \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "vm_uuid": "6f1c2a9e-4b3d-4e8a-9c71-2d5e8f0a1b34"
  }'

Answer

Status 200 with this body.

FieldTypeDescription
disk_uuidstringrequired
vm_uuidstringrequiredThe server it goes to
statusstringrequiredattach_queued: poll Get a volume until vm_uuid is set and the state settles
{
  "disk_uuid": "c7a1e3f9-52b8-4d06-9e41-8b3f2a6d0c75",
  "vm_uuid": "6f1c2a9e-4b3d-4e8a-9c71-2d5e8f0a1b34",
  "status": "attach_queued"
}

Wait until it is ready

The answer comes at once and the work runs in the background, usually for a few seconds. Get a volume shows how far it got in its state field.

Check the state

Ask Get a volume with the volume's id; the field to watch is state:

curl "https://platform.serverscamp.com/api/v1/volumes/$DISK_UUID" \
  -H "Authorization: Bearer $API_TOKEN"
stateWhat it means
creatingThe volume is being made; one from a backup also shows provision_phase and provision_pct
createdReady. With vm_uuid set it is attached to that server, without it the volume is free
attaching, detaching, resizingThe change runs
failedSomething went wrong. Write to support with the volume id

Wait in a loop

Ask every few seconds until the state is no longer one of the busy ones, and stop on failed.

# DISK_UUID: disk_uuid of the volume, from the answer above
BUSY=" pending queued creating provisioning attaching attach_queued detaching detach_queued resizing deleting deprovisioning delete_queued "
while true; do
  VOL=$(curl -s "https://platform.serverscamp.com/api/v1/volumes/$DISK_UUID" -H "Authorization: Bearer $API_TOKEN")
  STATE=$(echo "$VOL" | jq -r .state)
  echo "$STATE"
  case "$STATE" in failed|error) echo "volume $STATE"; exit 1;; esac
  case "$BUSY" in *" $STATE "*) ;; *) [ "$(echo "$VOL" | jq -r '.provision_phase // "ready"')" = ready ] && break;; esac
  sleep 5
done

The bash version needs jq.

Errors

StatusWhen
401No token, or a token that is not valid
404No such volume or server in your account
409The volume is attached already, or busy
422The body or a parameter is not what the operation takes

Every operation can also answer 401 without a valid token. All errors