A command-line utility to manage ExtraConfig key-value pairs for virtual machines (VMs) in VMware vCloud Director. This tool allows you to find VMs, retrieve VM information (including ExtraConfig), set ExtraConfig entries, and delete ExtraConfig entries using the go-vcloud-director SDK.
The vcd-vm-extraconfig utility is designed for vCloud Director administrators and automation engineers who need to programmatically manage ExtraConfig settings for VMs. ExtraConfig entries (e.g., guestinfo.mykey) are stored in the VM's virtual hardware section and are accessible inside the VM via VMware Tools. The tool supports vCloud Director API version 36.3 and is built with the go-vcloud-director/v2@main library.
- Find VMs: Locate a VM by organization, VDC, vApp, and VM name.
- Get VM Info: Retrieve VM details, including CPU, memory, and ExtraConfig entries.
- Set ExtraConfig: Add or update ExtraConfig key-value pairs.
- Delete ExtraConfig: Remove ExtraConfig entries by key.
- Configuration: Uses a JSON configuration file for vCloud Director credentials and endpoint.
- Docker Support: Can be built and run as a Docker container.
- Go: Version 1.23 or later (1.24.2 recommended for building locally).
- Docker: Required for building and running the Docker image.
- vCloud Director: Access to a vCloud Director instance (API version 36.3 recommended).
- Permissions: The user must have
Virtual Machine: ViewandVirtual Machine: Editrights. - Git: For cloning the repository.
-
Clone the repository:
git clone https://github.com/clsv/vcd-vm-extraconfig cd vcd-vm-extraconfig -
Install dependencies: Install the
go-vcloud-directorlibrary (main branch):go mod download
-
Build the tool:
go build -o vcd-vm-extraconfig vcd-vm-extraconfig.go
-
Build the Docker image:
docker build -t vcd-vm-extraconfig:latest . -
Run the tool in a container: Mount a
config.jsonfile and run the desired command (see Usage below). Example:docker run --rm -v $(pwd)/config.json:/app/config.json vcd-vm-extraconfig:latest -config /app/config.json -action get -org my-org -vdc my-vdc -vapp my-vapp -vm my-vm
Create a config.json file in the repository root with your vCloud Director credentials:
{
"api": "36.3", //37.2, 37.1, 37.0, 36.3, 36.2, 36.1, 36.0
"url": "https://vcd.example.com/api",
"org": "your-org",
"vdc": "vdc",
"vapp": "vapp",
"user": "your-user",
"password": "your-password"
}Replace the placeholder values with your vCloud Director endpoint, organization, username, and password.
The tool supports four actions: find, get, set, and delete. Run the tool with the appropriate flags to perform these actions.
./vcd-vm-extraconfig -config config.json -action <action> -org <org> -vdc <vdc> -vapp <vapp> -vm <vm> [-key <key>] [-value <value>]-config: Path to the configuration file (default:config.json).-action: Action to perform (find,get,set, ordelete).-org: Organization name.-vdc: Virtual Data Center name.-vapp: vApp name.-vm: VM name.-key: ExtraConfig key (required forsetanddelete).-value: ExtraConfig value (required forset).
-
Find a VM:
./vcd-vm-extraconfig -config config.json -action find -org my-org -vdc my-vdc -vapp my-vapp -vm my-vm
Output:
VM found: my-vm -
Get VM Information (including ExtraConfig):
./vcd-vm-extraconfig -config config.json -action get -org my-org -vdc my-vdc -vapp my-vapp -vm my-vm
Output:
VM Name: my-vm CPU: 2 Memory: 4096 MB ExtraConfig: guestinfo.mykey: myvalue -
Set an ExtraConfig Entry:
./vcd-vm-extraconfig -config config.json -action set -org my-org -vdc my-vdc -vapp my-vapp -vm my-vm -key disk.enableUUID -value 1Output:
ExtraConfig disk.enableUUID=1 set -
Delete an ExtraConfig Entry:
./vcd-vm-extraconfig -config config.json -action delete -org my-org -vdc my-vdc -vapp my-vapp -vm my-vm -key guestinfo.mykey
Output:
ExtraConfig guestinfo.mykey deleted
Run the same commands using Docker by mounting the config.json file:
docker run --rm -v $(pwd)/config.json:/app/config.json vcd-vm-extraconfig:latest -config /app/config.json -action set -org my-org -vdc my-vdc -vapp my-vapp -vm my-vm -key guestinfo.mykey -value myvalueThe tool supports debug logging via environment variables provided by the go-vcloud-director library. Set these variables to enable detailed output for troubleshooting:
-
GOVCD_SHOW_RESP: Set totrueto log vCloud Director API responses.export GOVCD_SHOW_RESP=true export GOVCD_LOG=true ./vcd-vm-extraconfig -config config.json -action get -org my-org -vdc my-vdc -vapp my-vapp -vm my-vm
-
GOVCD_SHOW_REQ: Set totrueto log vCloud Director API requests.export GOVCD_SHOW_REQ=true export GOVCD_LOG=true ./vcd-vm-extraconfig -config config.json -action get -org my-org -vdc my-vdc -vapp my-vapp -vm my-vm
For Docker, pass the environment variables using the -e flag:
docker run --rm -v $(pwd)/config.json:/app/config.json -e GOVCD_SHOW_RESP=true -e GOVCD_LOG=true -e GOVCD_SHOW_REQ=true vcd-vm-extraconfig:latest -config /app/config.json -action get -org my-org -vdc my-vdc -vapp my-vapp -vm my-vm- ExtraConfig Keys: Keys like
guestinfo.mykeyare accessible inside the VM via VMware Tools (e.g.,vmtoolsd --cmd "info-get guestinfo.mykey"). Avoid using spaces in keys, as they are invalid. - Library Version: The tool uses the
mainbranch ofgo-vcloud-director, which may include unstable changes. For a stable release, replacego get github.com/vmware/go-vcloud-director/v2@mainwith a specific version (e.g.,v2.26.1). - Error Handling: The tool provides basic error messages. For production use, consider adding logging (e.g., with
logrus). - Cloud-Init Integration: To pass ExtraConfig to cloud-init, use
vm.SetGuestCustomizationSection. Open an issue or contribute to add this feature. - Docker: The Docker image is built with Go 1.24.2 and uses a minimal
scratchbase for the final image, reducing size.