From ab9846d942f99a51238554ad2d7e4c4d0826e2e4 Mon Sep 17 00:00:00 2001 From: William Lam Date: Thu, 16 Nov 2023 17:21:59 -0800 Subject: [PATCH] VI/JSON Examples --- shell/create_snapshot_for_vm.sh | 28 ++++++++++++++++++++++++++ shell/list_advanced_settings_for_vm.sh | 18 +++++++++++++++++ shell/list_custom_attributes_for_vm.sh | 22 ++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 shell/create_snapshot_for_vm.sh create mode 100644 shell/list_advanced_settings_for_vm.sh create mode 100644 shell/list_custom_attributes_for_vm.sh diff --git a/shell/create_snapshot_for_vm.sh b/shell/create_snapshot_for_vm.sh new file mode 100644 index 0000000..2963196 --- /dev/null +++ b/shell/create_snapshot_for_vm.sh @@ -0,0 +1,28 @@ +VC='vcsa.primp-industries.local' +VC_USERNAME='administrator@vsphere.local' +VC_PASSWORD='VMware1!' +VC_API_RELEASE='8.0.1.0' +VM_NAME="esx-1.0" + +# vCenter REST API +VCREST_API_SESSION_ID=$(curl -s -u "${VC_USERNAME}:${VC_PASSWORD}" -X POST "https://${VC}/api/session" | jq -j) +VM_MOREF=$(curl -s -H "vmware-api-session-id: ${VCREST_API_SESSION_ID}" -X GET "https://${VC}/api/vcenter/vm?names=${VM_NAME}" | jq -r '.[0].vm') + +# vCenter VI JSON API +SESSION_MANAGER_MOID=$(curl -s https://$VC/sdk/vim25/${VC_API_RELEASE}/ServiceInstance/ServiceInstance/content | jq -j .sessionManager.value) +VIJSON_API_SESSION_ID=$(curl -s -o /dev/null -D - "https://$VC/sdk/vim25/${VC_API_RELEASE}/SessionManager/$SESSION_MANAGER_MOID/Login" -H 'Content-Type: application/json' -d "{\"userName\":\"${VC_USERNAME}\", \"password\": \"${VC_PASSWORD}\"}" | awk 'BEGIN {FS=": "}/^vmware-api-session-id/{print $2}') + +# Create Snapshot spec +cat > snapshot_spec.json <