hashicorp / packer-plugin-vsphere

Packer plugin for VMware vSphere Builder
https://www.packer.io/docs/builders/vsphere
Mozilla Public License 2.0
93 stars 91 forks source link

feat: add support for `http_interface` and `http_bind_address` #431

Open tenthirtyam opened 1 month ago

tenthirtyam commented 1 month ago

Summary

Adds support for http_interface and http_bind_interface from the SDK.

[!NOTE]

  • The options http_bind_address and http_interface are mutually exclusive, per the SDK.
  • Both http_bind_address and http_interface have higher priority than http_ip.
  • The http_bind_address is matched against the IP addresses of the host's network interfaces. If no match is found, the plugin will terminate.
  • Similarly, http_interface is compared with the host's network interfaces. If there's no corresponding network interface, the plugin will also terminate.
  • If neither http_bind_address, http_interface, and http_ip are provided, the plugin will automatically find and use the IP address of the first non-loopback interface for http_ip.

Testing

Basic

➜  packer-plugin-vsphere git:(feat/http-interface) ✗ go fmt ./...

➜  packer-plugin-vsphere git:(feat/http-interface) ✗ make generate
2024/05/30 11:20:22 Copying "docs" to ".docs/"
2024/05/30 11:20:22 Replacing @include '...' calls in .docs/
Compiling MDX docs in '.docs' to Markdown in '.web-docs'...
➜  packer-plugin-vsphere git:(feat/http-interface) ✗ make build   
➜  packer-plugin-vsphere git:(feat/http-interface) ✗ make test    
?       github.com/hashicorp/packer-plugin-vsphere      [no test files]
?       github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/common/testing       [no test files]
?       github.com/hashicorp/packer-plugin-vsphere/examples/driver      [no test files]
?       github.com/hashicorp/packer-plugin-vsphere/version      [no test files]
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/clone        2.051s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/common       3.525s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/driver       8.058s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/iso  3.659s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/supervisor   8.502s
ok      github.com/hashicorp/packer-plugin-vsphere/post-processor/vsphere       4.054s
ok      github.com/hashicorp/packer-plugin-vsphere/post-processor/vsphere-template      4.876s

Test Scenarios

packer@packer:~/packer-plugin-vsphere$ make dev
packer plugins install --path packer-plugin-vsphere "github.com/hashicorp/vsphere"
Successfully installed plugin github.com/hashicorp/vsphere from /home/packer/packer-plugin-vsphere/packer-plugin-vsphere to /home/packer/.config/packer/plugins/github.com/hashicorp/vsphere/packer-plugin-vsphere_v1.3.1-dev_x5.0_linux_amd64

PASS: http_ip not provided.

Initializing HashiCorp Packer and the required plugins...
Starting the build of VMware Photon OS 5...

vsphere-iso.linux-photon: output will be in this color.

==> vsphere-iso.linux-photon: Creating virtual machine...
==> vsphere-iso.linux-photon: Customizing hardware...
==> vsphere-iso.linux-photon: Adding SATA controller...
==> vsphere-iso.linux-photon: Mounting ISO images...
==> vsphere-iso.linux-photon: Adding configuration parameters...
==> vsphere-iso.linux-photon: Starting HTTP server on port 8016
==> vsphere-iso.linux-photon: Setting boot order...
==> vsphere-iso.linux-photon: Powering on virtual machine...
==> vsphere-iso.linux-photon: Waiting 2s for boot...
==> vsphere-iso.linux-photon: Using IP address 172.16.11.253 from first non-loopback interface.
==> vsphere-iso.linux-photon: Serving HTTP requests at http://172.16.11.253:8016/.
==> vsphere-iso.linux-photon: Typing boot command...

PASS: http_ip provided.

Initializing HashiCorp Packer and the required plugins...
Starting the build of VMware Photon OS 5...

vsphere-iso.linux-photon: output will be in this color.

==> vsphere-iso.linux-photon: the vm/template Templates/linux-photon-5.0-test already exists, but deleting it due to -force flag
==> vsphere-iso.linux-photon: Creating virtual machine...
==> vsphere-iso.linux-photon: Customizing hardware...
==> vsphere-iso.linux-photon: Adding SATA controller...
==> vsphere-iso.linux-photon: Mounting ISO images...
==> vsphere-iso.linux-photon: Adding configuration parameters...
==> vsphere-iso.linux-photon: Starting HTTP server on port 8005
==> vsphere-iso.linux-photon: Setting boot order...
==> vsphere-iso.linux-photon: Powering on virtual machine...
==> vsphere-iso.linux-photon: Waiting 2s for boot...
==> vsphere-iso.linux-photon: Using IP address 172.16.11.253 from 'http_ip'.
==> vsphere-iso.linux-photon: Serving HTTP requests at http://172.16.11.253:8005/.
==> vsphere-iso.linux-photon: Typing boot command...

PASS: http_bind_address provided with matching interface.

Initializing HashiCorp Packer and the required plugins...
Starting the build of VMware Photon OS 5...

vsphere-iso.linux-photon: output will be in this color.

==> vsphere-iso.linux-photon: the vm/template Templates/linux-photon-5.0-test already exists, but deleting it due to -force flag
==> vsphere-iso.linux-photon: Creating virtual machine...
==> vsphere-iso.linux-photon: Customizing hardware...
==> vsphere-iso.linux-photon: Adding SATA controller...
==> vsphere-iso.linux-photon: Mounting ISO images...
==> vsphere-iso.linux-photon: Adding configuration parameters...
==> vsphere-iso.linux-photon: Starting HTTP server on port 8036
==> vsphere-iso.linux-photon: Setting boot order...
==> vsphere-iso.linux-photon: Powering on virtual machine...
==> vsphere-iso.linux-photon: Waiting 2s for boot...
==> vsphere-iso.linux-photon: Using IP address 172.16.14.200 from 'http_bind_address'.
==> vsphere-iso.linux-photon: Serving HTTP requests at http://172.16.14.200:8036/.
==> vsphere-iso.linux-photon: Typing boot command...

PASS: http_bind_address provided with non-matching interface.

Initializing HashiCorp Packer and the required plugins...
Starting the build of VMware Photon OS 5...

vsphere-iso.linux-photon: output will be in this color.

==> vsphere-iso.linux-photon: 'http_bind_address' 172.16.14.201 is not assigned to any interface
Build 'vsphere-iso.linux-photon' errored after 1 millisecond 511 microseconds: 'http_bind_address' 172.16.14.201 is not assigned to any interface

==> Wait completed after 1 millisecond 585 microseconds

==> Some builds didn't complete successfully and had errors:
--> vsphere-iso.linux-photon: 'http_bind_address' 172.16.14.201 is not assigned to any interface

PASS: http_bind_address provided with http_interface.

Initializing HashiCorp Packer and the required plugins...
Starting the build of VMware Photon OS 5...

Error: 1 error(s) occurred:

* either http_interface or http_bind_address can be specified

  on /home/<sensitive>/<sensitive>-examples-for-vsphere/builds/linux/photon/5/linux-photon.pkr.hcl line 73:
  (source code not available)

PASS: http_bind_address provided with http_ip.

Initializing HashiCorp Packer and the required plugins...
Starting the build of VMware Photon OS 5...

vsphere-iso.linux-photon: output will be in this color.

==> vsphere-iso.linux-photon: the vm/template Templates/linux-photon-5.0-test already exists, but deleting it due to -force flag
==> vsphere-iso.linux-photon: Creating virtual machine...
==> vsphere-iso.linux-photon: Customizing hardware...
==> vsphere-iso.linux-photon: Adding SATA controller...
==> vsphere-iso.linux-photon: Mounting ISO images...
==> vsphere-iso.linux-photon: Adding configuration parameters...
==> vsphere-iso.linux-photon: Starting HTTP server on port 8068
==> vsphere-iso.linux-photon: Setting boot order...
==> vsphere-iso.linux-photon: Powering on virtual machine...
==> vsphere-iso.linux-photon: Waiting 2s for boot...
==> vsphere-iso.linux-photon: Using IP address 172.16.14.200 from 'http_bind_address'.
==> vsphere-iso.linux-photon: Serving HTTP requests at http://172.16.14.200:8068/.
==> vsphere-iso.linux-photon: Typing boot command...

PASS: http_interface provided.

🟢 Interface ens160:

Initializing HashiCorp Packer and the required plugins...
Starting the build of VMware Photon OS 5...

vsphere-iso.linux-photon: output will be in this color.

==> vsphere-iso.linux-photon: the vm/template Templates/linux-photon-5.0-test already exists, but deleting it due to -force flag
==> vsphere-iso.linux-photon: Creating virtual machine...
==> vsphere-iso.linux-photon: Customizing hardware...
==> vsphere-iso.linux-photon: Adding SATA controller...
==> vsphere-iso.linux-photon: Mounting ISO images...
==> vsphere-iso.linux-photon: Adding configuration parameters...
==> vsphere-iso.linux-photon: Starting HTTP server on port 8052
==> vsphere-iso.linux-photon: Setting boot order...
==> vsphere-iso.linux-photon: Powering on virtual machine...
==> vsphere-iso.linux-photon: Waiting 2s for boot...
==> vsphere-iso.linux-photon: Using IP address 172.16.11.253 from 'http_interface' ens160.
==> vsphere-iso.linux-photon: Serving HTTP requests at http://172.16.11.253:8052/.
==> vsphere-iso.linux-photon: Typing boot command...

🟢 Interface ens192:

Initializing HashiCorp Packer and the required plugins...
Starting the build of VMware Photon OS 5...

vsphere-iso.linux-photon: output will be in this color.

==> vsphere-iso.linux-photon: the vm/template Templates/linux-photon-5.0-test already exists, but deleting it due to -force flag
==> vsphere-iso.linux-photon: Creating virtual machine...
==> vsphere-iso.linux-photon: Customizing hardware...
==> vsphere-iso.linux-photon: Adding SATA controller...
==> vsphere-iso.linux-photon: Mounting ISO images...
==> vsphere-iso.linux-photon: Adding configuration parameters...
==> vsphere-iso.linux-photon: Starting HTTP server on port 8086
==> vsphere-iso.linux-photon: Setting boot order...
==> vsphere-iso.linux-photon: Powering on virtual machine...
==> vsphere-iso.linux-photon: Waiting 2s for boot...
==> vsphere-iso.linux-photon: Using IP address 172.16.14.200 from 'http_interface' ens192.
==> vsphere-iso.linux-photon: Serving HTTP requests at http://172.16.14.200:8086/.
==> vsphere-iso.linux-photon: Typing boot command...

🟢 Interface docker0 (for giggles):

Initializing HashiCorp Packer and the required plugins...
Starting the build of VMware Photon OS 5...

vsphere-iso.linux-photon: output will be in this color.

==> vsphere-iso.linux-photon: the vm/template Templates/linux-photon-5.0-test already exists, but deleting it due to -force flag
==> vsphere-iso.linux-photon: Creating virtual machine...
==> vsphere-iso.linux-photon: Customizing hardware...
==> vsphere-iso.linux-photon: Adding SATA controller...
==> vsphere-iso.linux-photon: Mounting ISO images...
==> vsphere-iso.linux-photon: Adding configuration parameters...
==> vsphere-iso.linux-photon: Starting HTTP server on port 8044
==> vsphere-iso.linux-photon: Setting boot order...
==> vsphere-iso.linux-photon: Powering on virtual machine...
==> vsphere-iso.linux-photon: Waiting 2s for boot...
==> vsphere-iso.linux-photon: Using IP address 172.17.0.1 from 'http_interface' docker0.
==> vsphere-iso.linux-photon: Serving HTTP requests at http://172.17.0.1:8044/.
==> vsphere-iso.linux-photon: Typing boot command...

PASS: http_interface provided with no matching interface.

Initializing HashiCorp Packer and the required plugins...
Starting the build of VMware Photon OS 5...

vsphere-iso.linux-photon: output will be in this color.

==> vsphere-iso.linux-photon: the vm/template Templates/linux-photon-5.0-test already exists, but deleting it due to -force flag
==> vsphere-iso.linux-photon: Creating virtual machine...
==> vsphere-iso.linux-photon: Customizing hardware...
==> vsphere-iso.linux-photon: Adding SATA controller...
==> vsphere-iso.linux-photon: Mounting ISO images...
==> vsphere-iso.linux-photon: Adding configuration parameters...
==> vsphere-iso.linux-photon: Starting HTTP server on port 8051
==> vsphere-iso.linux-photon: Setting boot order...
==> vsphere-iso.linux-photon: Powering on virtual machine...
==> vsphere-iso.linux-photon: Waiting 2s for boot...
==> vsphere-iso.linux-photon: error determining IP address from interface ou812: route ip+net: no such network interface
==> vsphere-iso.linux-photon: Step "StepBootCommand" failed

PASS: http_interface provided with http_ip.

Initializing HashiCorp Packer and the required plugins...
Starting the build of VMware Photon OS 5...

vsphere-iso.linux-photon: output will be in this color.

==> vsphere-iso.linux-photon: Creating virtual machine...
==> vsphere-iso.linux-photon: Customizing hardware...
==> vsphere-iso.linux-photon: Adding SATA controller...
==> vsphere-iso.linux-photon: Mounting ISO images...
==> vsphere-iso.linux-photon: Adding configuration parameters...
==> vsphere-iso.linux-photon: Starting HTTP server on port 8033
==> vsphere-iso.linux-photon: Setting boot order...
==> vsphere-iso.linux-photon: Powering on virtual machine...
==> vsphere-iso.linux-photon: Waiting 2s for boot...
==> vsphere-iso.linux-photon: Using IP address 172.16.14.200 from 'http_interface' ens192.
==> vsphere-iso.linux-photon: Serving HTTP requests at http://172.16.14.200:8033/.
==> vsphere-iso.linux-photon: Typing boot command...
tenthirtyam commented 1 week ago

@nywilken This one is ready now, but need some help with the failing est on go generate. each of the tests in the Testing section still hold true after making factorizing changes Lucas requested.

nywilken commented 1 week ago

@nywilken This one is ready now, but need some help with the failing est on go generate. each of the tests in the Testing section still hold true after making factorizing changes Lucas requested.

So looking into the failure it looks like the .web-docs were committed to this branch with a previous version of the packer-sdc. Rebasing onto the latest main doesn't fix it because your changes are being applied on top of what is on main. So in order to fix this issue you must run make generate again and commit the updated .web-doc files.

tenthirtyam commented 1 week ago

That did the trick @nywilken - update in inbound now.