This guide covers essential operations for managing a VM in OpenStack, including stopping, shelving, starting, and deleting a VM.
1. Listing VMs
To list all available VMs in your project:
curl -ks -X GET \
-H 'X-Auth-Token: YOUR_AUTH_TOKEN' \
https://in-west3.controlcloud.app:8774/v2.1/YOUR_PROJECT_ID/servers | jq '.servers[] | {id, name, status}'

2. Stopping a VM
To gracefully shut down a running VM, use the following API request:
curl -ks -X POST -H 'Content-Type: application/json' \ -H 'X-Auth-Token: your-token' \ -H "Accept: application/json" \ -d '{"os-stop": {}}' https://in-west3.controlcloud.app:8774/v2.1/your-project-id/servers/your-vm-id/action
To check if the VM has stopped:
curl -ks -H 'X-Auth-Token: your-token' \ https://in-west3.controlcloud.app:8774/v2.1/your-project-id/servers/your-vm-id | jq '.server["OS-EXT-STS:vm_state"]'

3. Starting a VM
To start a previously stopped VM:
curl -ks -X POST \
-H 'Content-Type: application/json' \
-H 'X-Auth-Token: YOUR_AUTH_TOKEN' \
-d '{"os-start": {}}' \
https://in-west3.controlcloud.app:8774/v2.1/YOUR_PROJECT_ID/servers/YOUR_VM_ID/action
To check if the VM has started:
curl -ks -H 'X-Auth-Token: your-token' \
https://in-west3.controlcloud.app:8774/v2.1/your-project-id/servers/your-vm-id | jq '.server["OS-EXT-STS:vm_state"]'

4. Shelving a VM
Shelving a VM saves its state while freeing up resources.
curl -ks -X POST \
-H 'Content-Type: application/json' \
-H 'X-Auth-Token: YOUR_AUTH_TOKEN' \
-d '{"shelve": null}' \
https://in-west3.controlcloud.app:8774/v2.1/YOUR_PROJECT_ID/servers/YOUR_VM_ID/action
To check if the VM is shelved:
curl -ks -H 'X-Auth-Token: your-token' \
https://in-west3.controlcloud.app:8774/v2.1/your-project-id/servers/your-vm-id | jq '.server["OS-EXT-STS:vm_state"]'

5. Unshelving a VM
To restore a shelved VM and bring it back online:
curl -ks -X POST \
-H 'Content-Type: application/json' \
-H 'X-Auth-Token: YOUR_AUTH_TOKEN' \
-d '{"unshelve": null}' \
https://in-west3.controlcloud.app:8774/v2.1/YOUR_PROJECT_ID/servers/YOUR_VM_ID/action
And check the VM status:
curl -ks -H 'X-Auth-Token: your-token' \
https://in-west3.controlcloud.app:8774/v2.1/your-project-id/servers/your-vm-id | jq '.server["OS-EXT-STS:vm_state"]'

6. Deleting a VM
To permanently delete a VM:
curl -ks -X DELETE -H 'Content-Type: application/json' -H 'X-Auth-Token: gAAAAA<...>' \
https://in-west3.controlcloud.app:8774/v2.1/your-project-id/servers/your-vm-id

These API commands help in efficiently managing VMs in OpenStack.