Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the VMware Workstation Pro API with the vmware-vmx builder #157

Open
niwamo opened this issue Nov 12, 2023 · 1 comment 路 May be fixed by #161
Open

Add support for the VMware Workstation Pro API with the vmware-vmx builder #157

niwamo opened this issue Nov 12, 2023 · 1 comment 路 May be fixed by #161

Comments

@niwamo
Copy link

niwamo commented Nov 12, 2023

Community Note

Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request.
Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request.
If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

Create a new "driver" for vmrest, the API that ships with VMWare Workstation Pro. Due to API limitations, only the vmware-vmx builder can be implemented.

Use Case(s)

Implement the vmware-vmx functionality using the API. Enables using Packer from a remote host or from a container.

Potential configuration

Already implemented and ready for a PR. See https://github.com/niwamo/packer-plugin-vmware.

I also updated /docs/builders/vmx.mdx and ran .web-docs/scripts/compile-to-webdocs.sh.

Opening an issue for discussion prior to making the PR, as directed in the README.

The code is reasonably well-commented, and I endeavored to limit changes outside of the new driver file to the greatest extent possible. Please take a look and lmk if/when you're ready for a PR.

Potential References

If you'd like to repeat my tests:

  • Set the API credentials on the VMWare host
  • Run the API
  • Install the updated plugin in a WSL container
  • Create a new VM using the "New Virtual Machine" menu in VMWare
    • Assign a Debian .iso for the installer, but don't run the VM
  • Use the created .vmx filepath in a configuration like the following:
packer {
  required_plugins {
    vmware = {
      version = ">= 1.0"
      source = "github.com/niwamo/vmware"
    }
  }
}

source "vmware-vmx" "vmrest" {
  remote_type     = "vmrest"
  remote_host     = // the VMWare host's WSL interface IP
  remote_port     = 8697
  remote_username = // username you set for the API
  remote_password = // password you set for the API
  skip_export     = true

  source_path = // vmx filepath - make sure all backslashes are doubled/escaped, e.g. "C:\\Users\\test.vmx"

  vnc_bind_address  = "0.0.0.0"

  http_content = {
    "/preseed.cfg" = file("./preseed.cfg")
  }

  boot_wait    = "10s"
  boot_command = [
    "<esc><wait>",
    "auto url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg",
    "<enter>"
  ]

  ssh_username      = // user created by the preseed
  ssh_password      = // pwd for user created by the preseed
  ssh_timeout       = "30m"
  shutdown_command  = "shutdown -P now"
}

build {
  sources = ["sources.vmware-vmx.vmrest"]
  provisioner "shell" {
    script = "./scripts/test-1.sh"
  }
}

Note that this test config requires

  • a valid "preseed.cfg" to be present
  • a valid "./scripts/test-1.sh" to be present
  • your Windows firewall to allow all inbound connections from your WSL distro
@niwamo
Copy link
Author

niwamo commented Nov 14, 2023

Thought of a couple things to add --

First, if you want to follow my testing methodology as described above, you'll need to proxy incoming connections, as the VMRest API only listens on localhost (127.0.0.1). You can achieve this with a port proxy: netsh interface portproxy add v4tov4 listenport=8697 listenaddress=0.0.0.0 connectport=8697 connectaddress=127.0.0.1.

Secondly, the WSL firewall rule I mentioned can be accomplished with: New-NetFirewallRule -DisplayName "Allow all WSL inbound" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow

Finally, I added more details to my documentation updates in https://github.com/niwamo/packer-plugin-vmware

@tenthirtyam tenthirtyam changed the title (PR Ready) Add support for the VMWare Workstation Pro API with the vmware-vmx builder Add support for the VMware Workstation Pro API with the vmware-vmx builder Dec 7, 2023
@tenthirtyam tenthirtyam added this to the Backlog milestone May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants