Skip to content

Instantly share code, notes, and snippets.

@rayhassan
Created May 11, 2017 13:35
Show Gist options
  • Save rayhassan/2f98bed9220b940898a67533676b8976 to your computer and use it in GitHub Desktop.
Save rayhassan/2f98bed9220b940898a67533676b8976 to your computer and use it in GitHub Desktop.
REST API notes for Athens Tech Summit
2048afa6-a785-4aa8-b2b1-6124114ab91d
"uuid": "661cd354-33dc-4cdd-8874-9875fc7834b3",
"name": "Windows Server 2012 R2",
"deleted": false,
"storage_container_id": 1023,
"storage_container_uuid": "c99819f0-bb38-4a5e-b473-48371ef8561c",
"logical_timestamp": 2,
"image_type": "DISK_IMAGE",
"vm_disk_id": "7eb94d44-8d8d-4da0-82cd-6da4103a14af",
"uuid": "a375c1dc-5a39-4192-8186-d9422fdebd76",
"name": "Nutanix VirtIO 1.0.1",
"annotation": "Windows",
"deleted": false,
"storage_container_id": 1023,
"storage_container_uuid": "c99819f0-bb38-4a5e-b473-48371ef8561c",
"logical_timestamp": 2,
"image_type": "ISO_IMAGE",
"vm_disk_id": "a8ba92da-8c3d-4a2c-a03e-592fc6a99cf6",
json body :
{
"description":"Tech Summit - 2017",
"guest_os":"Windows Server 2012 R2",
"memory_mb":4096,
"name":"W2K12 Server VM-1",
"num_cores_per_vcpu":2,
"num_vcpus":1,
"vm_disks":[
{
"disk_address":{
"device_bus":"ide",
"device_index":0
},
"is_cdrom":true,
"is_empty":false,
"vm_disk_clone":{
"disk_address":{
"vmdisk_uuid":"7eb94d44-8d8d-4da0-82cd-6da4103a14af"
}
}
},
{
"disk_address":{
"device_bus":"scsi",
"device_index":0
},
"vm_disk_create":{
"storage_container_uuid":"2048afa6-a785-4aa8-b2b1-6124114ab91d",
"size":10737418240
}
},
{
"disk_address":{
"device_bus":"ide",
"device_index":1
},
"is_cdrom":true,
"is_empty":false,
"vm_disk_clone":{
"disk_address":{
"vmdisk_uuid":"a8ba92da-8c3d-4a2c-a03e-592fc6a99cf6"
}
}
}
],
"hypervisor_type":"ACROPOLIS",
"affinity":null
}
cURL
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
"description":"Tech Summit - 2017",
"guest_os":"Windows Server 2012 R2",
"memory_mb":4096,
"name":"W2K12 Server VM-1",
"num_cores_per_vcpu":2,
"num_vcpus":1,
"vm_disks":[
{
"disk_address":{
"device_bus":"ide",
"device_index":0
},
"is_cdrom":true,
"is_empty":false,
"vm_disk_clone":{
"disk_address":{
"vmdisk_uuid":"7eb94d44-8d8d-4da0-82cd-6da4103a14af"
}
}
},
{
"disk_address":{
"device_bus":"scsi",
"device_index":0
},
"vm_disk_create":{
"storage_container_uuid":"2048afa6-a785-4aa8-b2b1-6124114ab91d",
"size":10737418240
}
},
{
"disk_address":{
"device_bus":"ide",
"device_index":1
},
"is_cdrom":true,
"is_empty":false,
"vm_disk_clone":{
"disk_address":{
"vmdisk_uuid":"a8ba92da-8c3d-4a2c-a03e-592fc6a99cf6"
}
}
}
],
"hypervisor_type":"ACROPOLIS",
"affinity":null
}
' 'https://10.68.64.55:9440/PrismGateway/services/rest/v2.0/vms/'
Request URL
https://10.68.64.55:9440/PrismGateway/services/rest/v2.0/vms/
i. Read the Storage Containers using - GET storage_containers
ii. Read the images using - GET images
REST Gateway
curl --user admin:nutanix/4u -k -X GET --header 'Accept: application/json' 'https://10.68.64.50:9440/PrismGateway/services/rest/v2.0/images/' | jq -r .
Postman
curl --insecure -X GET \
https://10.68.64.50:9440/PrismGateway/services/rest/v2.0/images/ \
-H 'authorization: Basic YWRtaW46bnV0YW5peC80dQ==' \
-H 'cache-control: no-cache' \
-H 'postman-token: b9b5f512-ea40-7e4e-ceb7-b057651a58a4'
iii. Read the VM’s using - GET vms
Rest Gateway
curl --user admin:nutanix/4u -k -X GET --header 'Accept: application/json' 'https://10.68.64.50:9440/PrismGateway/services/rest/v2.0/vms/' | jq -r .
Postman
curl --insecure -X GET https://10.68.64.55:9440/PrismGateway/services/rest/v2.0/vms/ -H 'authorization: Basic YWRtaW46bnV0YW5peC80dQ==' -H 'cache-control: no-cache' -H 'postman-token: e21be3c4-6e83-c104-4af1-10e92a57a543' -H 'uuid: 9f6c128f-daa6-4daf-92b4-8a4acf9e15ab' | jq -r .
iv. Create a VM using - POST vms
Rest Gateway
Postman
v. Power ON/OFF a VM using - POST vms/(uuid}/set_power_state [on|off]
vi. Delete a VM using - DEL vms/{uuid}
@rayhassan
Copy link
Author

rayhassan commented May 16, 2017

Create a string as above from the array of images but select based on name criteria:

/usr/bin/curl --insecure -s -H Content-Type:application/json -X GET -u user:password https://10.68.64.55:9440/PrismGateway/services/rest/v2.0/images/ | jq '.entities[] | "(.name) (.uuid) (.vm_disk_id)"| select(. and contains("CentOS"))'

"CentOS 7 x86_64 Generic Cloud 04a18eb0-a3ed-4ff7-aa43-bdbb055a96ef bb907470-a885-494d-840c-bc67c4420066"
"CentOS 7 - Tech Summit 33bab7d2-02ce-459c-8e68-f80c9a49ec10 2ec6918a-9cb1-487c-991d-5322dad5dee6"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment