# Get the VM Path from the DNS Name
vm_path=$(./govc vm.info -vm.dns=$vm | grep Path | awk '{print $2}')
echo $vm_path
# Get the VM JSON Parameters
vm_json=$(./govc vm.info -vm.dns=$vm -json=true)
# Get the number of attached disks
disk_num=$(echo $vm_json | jq .VirtualMachines[0].Layout.Disk[].DiskFile[0] | awk '{print $2}' | wc -l)
# Get the last disk number
next_disk_num=$((disk_num - 1))
# Get the base disk path/name
base_disk=$(echo $vm_json | jq -r .VirtualMachines[0].Layout.Disk[].DiskFile[0] | awk '{print $2}' | head -1 | sed 's/.vmdk//')
# Get the next disk name
next_disk_name=$base_disk\_$next_disk_num
echo $next_disk_name
#### DS
# Get the Datastore
ds=$(echo $vm_json | jq -r .VirtualMachines[0].Layout.Disk[].DiskFile[0] | head -1 | awk '{print $1}' | tr -d '[]')
echo $ds
# Get the Datastore Path
ds_path=$(./govc ls -t datastore '*/*' | grep $ds)
echo $ds_path
# Add disk
./govc vm.disk.create -vm.dns=${vm} -name={$next_disk_name} -ds=${ds_path} -size ${size}
Workaround:
Add machines manually with juju add-machine then attach new disks with the govc tool using this script:
#!/bin/bash
export GOVC_USERNAME=*** CA_CERTS= ***
export GOVC_PASSWORD="***"
export GOVC_TLS_
export GOVC_URL=***
vm=$1
size="1TB"
# Get the VM Path from the DNS Name
vm_path=$(./govc vm.info -vm.dns=$vm | grep Path | awk '{print $2}')
echo $vm_path
# Get the VM JSON Parameters
vm_json=$(./govc vm.info -vm.dns=$vm -json=true)
# Get the number of attached disks s[0].Layout. Disk[]. DiskFile[ 0] | awk '{print $2}' | wc -l)
disk_num=$(echo $vm_json | jq .VirtualMachine
# Get the last disk number num=$(( disk_num - 1))
next_disk_
# Get the base disk path/name s[0].Layout. Disk[]. DiskFile[ 0] | awk '{print $2}' | head -1 | sed 's/.vmdk//')
base_disk=$(echo $vm_json | jq -r .VirtualMachine
# Get the next disk name name=$base_ disk\_$ next_disk_ num
next_disk_
echo $next_disk_name
#### DS s[0].Layout. Disk[]. DiskFile[ 0] | head -1 | awk '{print $1}' | tr -d '[]')
# Get the Datastore
ds=$(echo $vm_json | jq -r .VirtualMachine
echo $ds
# Get the Datastore Path
ds_path=$(./govc ls -t datastore '*/*' | grep $ds)
echo $ds_path
# Add disk $next_disk_ name} -ds=${ds_path} -size ${size}
./govc vm.disk.create -vm.dns=${vm} -name={