-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenable-ctk.sh
More file actions
51 lines (39 loc) · 1.73 KB
/
enable-ctk.sh
File metadata and controls
51 lines (39 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
VM_PATH="${1:?ERROR: VM path required. Usage: $0 <vm-path>}"
echo "Fetching VMs from path: $VM_PATH"
VMS=$(govc ls "$VM_PATH" | grep -v '/$')
for VM in $VMS; do
echo "==> Processing: $VM"
govc vm.change -vm "$VM" -e ctkEnabled=TRUE
if [ $? -eq 0 ]; then
echo " CTK enabled on VM"
else
echo " WARNING: Failed to enable CTK on VM"
continue
fi
# Get disk controller key and unit number as "controllerKey unitNumber"
DISKS=$(govc device.info -vm "$VM" -json | jq -r '.devices[] | select(.type=="VirtualDisk") | "\(.controllerKey) \(.unitNumber)"')
if [ -z "$DISKS" ]; then
echo " No disks found"
else
# Build a map of controllerKey -> scsiX index
SCSI_MAP=$(govc device.info -vm "$VM" -json | jq -r '.devices[] | select(.type | test("VirtualLsiLogic|VirtualSCSI|ParaVirtualSCSIController|VirtualBusLogic")) | "\(.key) \(.busNumber)"')
while IFS= read -r DISK; do
CTRL_KEY=$(echo "$DISK" | awk '{print $1}')
UNIT=$(echo "$DISK" | awk '{print $2}')
BUS=$(echo "$SCSI_MAP" | awk -v key="$CTRL_KEY" '$1==key {print $2}')
if [ -z "$BUS" ]; then
echo " WARNING: Could not resolve controller for disk (controllerKey=$CTRL_KEY)"
continue
fi
SCSI="scsi${BUS}:${UNIT}"
govc vm.change -vm "$VM" -e "${SCSI}.ctkEnabled=TRUE"
if [ $? -eq 0 ]; then
echo " CTK enabled on disk: $SCSI"
else
echo " WARNING: Failed to enable CTK on disk: $SCSI"
fi
done <<< "$DISKS"
fi
echo " Done. Remember to power-cycle and take a snapshot to initialize CTK."
done