-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
William Lam
committed
Nov 17, 2023
1 parent
5a8ff77
commit ab9846d
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
VC='vcsa.primp-industries.local' | ||
VC_USERNAME='[email protected]' | ||
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 <<EOF | ||
{ | ||
"description": "Test Snapshot", | ||
"memory": false, | ||
"name": "test-snapshot-1" | ||
} | ||
EOF | ||
|
||
# Create Snapshot | ||
curl -s -H "vmware-api-session-id: ${VIJSON_API_SESSION_ID}" -H "Content-Type: application/json" -X POST "https://$VC/sdk/vim25/${VC_API_RELEASE}/VirtualMachine/${VM_MOREF}/CreateSnapshotEx_Task" -d@snapshot_spec.json | ||
|
||
# List Snapshots | ||
curl -s -H "vmware-api-session-id: ${VIJSON_API_SESSION_ID}" -H "Content-Type: application/json" -X GET "https://$VC/sdk/vim25/${VC_API_RELEASE}/VirtualMachine/${VM_MOREF}/snapshot" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
VC='vcsa.primp-industries.local' | ||
VC_USERNAME='[email protected]' | ||
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}') | ||
|
||
# List VM Advanced Setings | ||
curl -s -H "vmware-api-session-id: ${VIJSON_API_SESSION_ID}" -X GET "https://$VC/sdk/vim25/${VC_API_RELEASE}/VirtualMachine/${VM_MOREF}/config" | jq -r .extraConfig |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
VC='vcsa.primp-industries.local' | ||
VC_USERNAME='[email protected]' | ||
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}') | ||
|
||
CUSTOM_FIELDS_MANAGER_MOID=$(curl -s https://$VC/sdk/vim25/${VC_API_RELEASE}/ServiceInstance/ServiceInstance/content | jq -j .customFieldsManager.value) | ||
|
||
# Retrieve Custom Field Key/Name for VirtualMachine definitions | ||
curl -s -H "vmware-api-session-id: ${VIJSON_API_SESSION_ID}" -X GET "https://$VC/sdk/vim25/${VC_API_RELEASE}/CustomFieldsManager/${CUSTOM_FIELDS_MANAGER_MOID}/field" | jq -r '.[] | select(.managedObjectType == "VirtualMachine") | {key, name}' | ||
|
||
curl -s -H "vmware-api-session-id: ${VIJSON_API_SESSION_ID}" -X GET "https://$VC/sdk/vim25/${VC_API_RELEASE}/VirtualMachine/${VM_MOREF}/value" |