Created
May 11, 2017 13:35
-
-
Save rayhassan/2f98bed9220b940898a67533676b8976 to your computer and use it in GitHub Desktop.
REST API notes for Athens Tech Summit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
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
create a string containing 2 keys and their values
/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)"'
"Foundation 3.1.1 fc97f57a-9828-4d4c-aa30-0fc8ebbd0d78"
"Nutanix Openstack HA-Liberty dbb95757-8593-412b-8607-f0c57e344f8b"
"Ubuntu 14.04 010d692a-7aaa-4de9-aefa-af8829f20d1f"
"Calm.IO 1.8.2 Image 02469c37-f5db-4c21-82e7-0bd3cf699253"
"CentOS 7 x86_64 Generic Cloud 04a18eb0-a3ed-4ff7-aa43-bdbb055a96ef"
"Prism Central 4.6.0.1 1555ee39-b427-4467-8f7a-7bb8e3aa0946"
"cirros-0.3.2-x86_64 260cf7a7-cb84-4a2f-a4d1-eeb9af2937a9"
"Container-Host-Image 2a66603f-6570-43a8-a5d2-8839bea6e7e2"
"CentOS 7 - Tech Summit 33bab7d2-02ce-459c-8e68-f80c9a49ec10"
"Nutanix Openstack Liberty 361aee79-a03c-4197-86b4-68e0d19929d5"
"Nutanix Openstack Image 1.0.2 389181b0-c93f-4ef0-a907-11f7f914be10"
"Prism Central 4.6.0.1 43fa1803-10ce-465b-8c9f-7fa858e34d12"
"Mirantis Openstack 8.0 4a59bd81-35c0-445a-ba33-5a5e84e29b4f"
"CalmIO 1.83 5bb7ee1b-cf2f-4614-bc7d-949f0d017421"
"Windows Server 2012 R2 661cd354-33dc-4cdd-8874-9875fc7834b3"
"Prism Central 4.6.0.1 7ed9c3ec-06e0-4d24-a883-ef737da0e6d2"
"Fedora 23 8fbc77b9-67c7-4735-82f2-fe0c892582b4"
"Nutanix VirtIO 1.0.1 a375c1dc-5a39-4192-8186-d9422fdebd76"
"Mirantis Openstack 7.0 bd624aff-72c7-4740-8146-2975a63da171"