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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for http_interface and http_bind_address #431

Merged
merged 1 commit into from
Aug 12, 2024

Conversation

tenthirtyam
Copy link
Collaborator

@tenthirtyam tenthirtyam commented May 12, 2024

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.
  • If http_ip is provided and the IP address does not exist on any interface, the build will exit.

Testing

Basic

packer-plugin-vsphere on  feat/http-interface [!] via 🐹 v1.22.6 
➜ go fmt ./...

packer-plugin-vsphere on  feat/http-interface [!] via 🐹 v1.22.6 
➜ make generate
2024/08/09 10:23:36 Copying "docs" to ".docs/"
2024/08/09 10:23:36 Replacing @include '...' calls in .docs/
Compiling MDX docs in '.docs' to Markdown in '.web-docs'...

packer-plugin-vsphere on  feat/http-interface [!] via 🐹 v1.22.6 took 16.6s 
➜ make build

packer-plugin-vsphere on  feat/http-interface [!] via 🐹 v1.22.6 took 6.5s 
➜ make test

?       github.com/hashicorp/packer-plugin-vsphere      [no test files]
?       github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/common/testing       [no test files]
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/clone        1.664s
?       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/common       3.108s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/driver       6.676s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/iso  2.554s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/supervisor   5.676s
ok      github.com/hashicorp/packer-plugin-vsphere/post-processor/vsphere       1.746s
ok      github.com/hashicorp/packer-plugin-vsphere/post-processor/vsphere-template      3.037s

packer-plugin-vsphere took 1m 3.7s …
➜ 

packer-plugin-vsphere on  feat/http-interface [!] via 🐹 v1.22.6 
➜ make dev                       
packer plugins install --path packer-plugin-vsphere "github.com/hashicorp/vsphere"
Successfully installed plugin github.com/hashicorp/vsphere from /Users/ryan/Library/Mobile Documents/com~apple~CloudDocs/Code/Personal/packer-plugin-vsphere/packer-plugin-vsphere to /Users/ryan/.packer.d/plugins/github.com/hashicorp/vsphere/packer-plugin-vsphere_v1.3.1-dev_x5.0_darwin_arm64

PASS : http_ip not provided. (Default)

==> vsphere-iso.appliance: Starting HTTP server on port 8091
==> vsphere-iso.appliance: Setting boot order...
==> vsphere-iso.appliance: Powering on virtual machine...
==> vsphere-iso.appliance: Waiting 2s for boot...
==> vsphere-iso.appliance: Serving HTTP requests at http://192.168.86.58:8091/.
==> vsphere-iso.appliance: Typing boot command...
2024/08/09 10:30:06 ui: �[1;32m==> vsphere-iso.appliance: Starting HTTP server on port 8950�[0m
2024/08/09 10:30:06 ui: �[1;32m==> vsphere-iso.appliance: Setting boot order...�[0m
2024/08/09 10:30:06 ui: �[1;32m==> vsphere-iso.appliance: Powering on virtual machine...�[0m
2024/08/09 10:30:07 ui: �[1;32m==> vsphere-iso.appliance: Waiting 2s for boot...�[0m
2024/08/09 10:30:09 packer-plugin-vsphere_v1.3.1-dev_x5.0_darwin_arm64 plugin: 2024/08/09 10:30:09 Using IP address 192.168.86.58 from http_ip.
2024/08/09 10:30:09 ui: �[1;32m==> vsphere-iso.appliance: Serving HTTP requests at http://192.168.86.58:8950/.�[0m
2024/08/09 10:30:09 ui: �[1;32m==> vsphere-iso.appliance: Typing boot command...�[0m

PASS : http_ip provided with a valid IP address.

==> vsphere-iso.appliance: Starting HTTP server on port 8457
==> vsphere-iso.appliance: Setting boot order...
==> vsphere-iso.appliance: Powering on virtual machine...
==> vsphere-iso.appliance: Waiting 2s for boot...
==> vsphere-iso.appliance: Serving HTTP requests at http://192.168.86.58:8457/.
==> vsphere-iso.appliance: Typing boot command...
2024/08/09 10:31:21 ui: �[1;32m==> vsphere-iso.appliance: Starting HTTP server on port 8457�[0m
2024/08/09 10:31:21 ui: �[1;32m==> vsphere-iso.appliance: Setting boot order...�[0m
2024/08/09 10:31:21 ui: �[1;32m==> vsphere-iso.appliance: Powering on virtual machine...�[0m
2024/08/09 10:31:21 ui: �[1;32m==> vsphere-iso.appliance: Waiting 2s for boot...�[0m
2024/08/09 10:31:23 packer-plugin-vsphere_v1.3.1-dev_x5.0_darwin_arm64 plugin: 2024/08/09 10:31:23 Using IP address 192.168.86.58 from http_ip.
2024/08/09 10:31:23 ui: �[1;32m==> vsphere-iso.appliance: Serving HTTP requests at http://192.168.86.58:8457/.�[0m
2024/08/09 10:31:23 ui: �[1;32m==> vsphere-iso.appliance: Typing boot command...�[0m

PASS : http_ip provided with an invalid IP address.

--> vsphere-iso.appliance: error using IP address 192.168.86.57: 192.168.86.57 is not assigned to an interface
2024/08/09 10:32:14 ui error: �[1;31m==> vsphere-iso.appliance: error using IP address 192.168.86.57: 192.168.86.57 is not assigned to an interface�[0m

PASS : http_bind_address provided with matching interface.

==> vsphere-iso.appliance: Starting HTTP server on port 8996
==> vsphere-iso.appliance: Setting boot order...
==> vsphere-iso.appliance: Powering on virtual machine...
==> vsphere-iso.appliance: Waiting 2s for boot...
==> vsphere-iso.appliance: Serving HTTP requests at http://192.168.86.58:8996/.
==> vsphere-iso.appliance: Typing boot command...
2024/08/09 10:36:50 ui: �[1;32m==> vsphere-iso.appliance: Starting HTTP server on port 8996�[0m
2024/08/09 10:36:50 ui: �[1;32m==> vsphere-iso.appliance: Setting boot order...�[0m
2024/08/09 10:36:51 ui: �[1;32m==> vsphere-iso.appliance: Powering on virtual machine...�[0m
2024/08/09 10:36:51 ui: �[1;32m==> vsphere-iso.appliance: Waiting 2s for boot...�[0m
2024/08/09 10:36:53 packer-plugin-vsphere_v1.3.1-dev_x5.0_darwin_arm64 plugin: 2024/08/09 10:36:53 Using IP address 192.168.86.58 from http_bind_address.
2024/08/09 10:36:53 ui: �[1;32m==> vsphere-iso.appliance: Serving HTTP requests at http://192.168.86.58:8996/.�[0m
2024/08/09 10:36:53 ui: �[1;32m==> vsphere-iso.appliance: Typing boot command...�[0m

PASS : http_bind_address provided with non-matching interface.

--> vsphere-iso.appliance: 192.168.86.57 is not assigned to an interface
2024/08/09 10:35:33 ui error: �[1;31m==> vsphere-iso.appliance: error validating IP address for HTTP server: 192.168.86.57 is not assigned to an interface�[0m

PASS : http_bind_address provided with http_interface.

Error: 1 error(s) occurred:

* either http_interface or http_bind_address can be specified
2024/08/09 10:37:58 ui error: Error: 1 error(s) occurred:

* either http_interface or http_bind_address can be specified

PASS : http_bind_address provided with http_ip. http_bind_address takes precedence.

==> vsphere-iso.appliance: Starting HTTP server on port 8665
==> vsphere-iso.appliance: Setting boot order...
==> vsphere-iso.appliance: Powering on virtual machine...
==> vsphere-iso.appliance: Waiting 2s for boot...
==> vsphere-iso.appliance: Serving HTTP requests at http://192.168.86.58:8665/.
==> vsphere-iso.appliance: Typing boot command...
2024/08/09 10:39:17 ui: �[1;32m==> vsphere-iso.appliance: Starting HTTP server on port 8665�[0m
2024/08/09 10:39:17 ui: �[1;32m==> vsphere-iso.appliance: Setting boot order...�[0m
2024/08/09 10:39:17 ui: �[1;32m==> vsphere-iso.appliance: Powering on virtual machine...�[0m
2024/08/09 10:39:18 ui: �[1;32m==> vsphere-iso.appliance: Waiting 2s for boot...�[0m
2024/08/09 10:39:20 packer-plugin-vsphere_v1.3.1-dev_x5.0_darwin_arm64 plugin: 2024/08/09 10:39:20 Using IP address 192.168.86.58 from http_bind_address.
2024/08/09 10:39:20 ui: �[1;32m==> vsphere-iso.appliance: Serving HTTP requests at http://192.168.86.58:8665/.�[0m
2024/08/09 10:39:20 ui: �[1;32m==> vsphere-iso.appliance: Typing boot command...�[0m

PASS : http_interface provided.

🟢 Interface en0:

==> vsphere-iso.appliance: Starting HTTP server on port 8259
==> vsphere-iso.appliance: Setting boot order...
==> vsphere-iso.appliance: Powering on virtual machine...
==> vsphere-iso.appliance: Waiting 2s for boot...
==> vsphere-iso.appliance: Serving HTTP requests at http://192.168.86.58:8259/.
==> vsphere-iso.appliance: Typing boot command...
2024/08/09 10:40:41 ui: �[1;32m==> vsphere-iso.appliance: Starting HTTP server on port 8259�[0m
2024/08/09 10:40:41 packer-plugin-vsphere_v1.3.1-dev_x5.0_darwin_arm64 plugin: 2024/08/09 10:40:41 Found available port: 8259 on IP: 0.0.0.0
2024/08/09 10:40:41 ui: �[1;32m==> vsphere-iso.appliance: Setting boot order...�[0m
2024/08/09 10:40:41 ui: �[1;32m==> vsphere-iso.appliance: Powering on virtual machine...�[0m
2024/08/09 10:40:41 ui: �[1;32m==> vsphere-iso.appliance: Waiting 2s for boot...�[0m
2024/08/09 10:40:43 packer-plugin-vsphere_v1.3.1-dev_x5.0_darwin_arm64 plugin: 2024/08/09 10:40:43 Using IP address 192.168.86.58 from http_interface en0.
2024/08/09 10:40:43 ui: �[1;32m==> vsphere-iso.appliance: Serving HTTP requests at http://192.168.86.58:8259/.�[0m
2024/08/09 10:40:43 ui: �[1;32m==> vsphere-iso.appliance: Typing boot command...�[0m

🟢 Interface en1:

==> vsphere-iso.appliance: Starting HTTP server on port 8186
==> vsphere-iso.appliance: Setting boot order...
==> vsphere-iso.appliance: Powering on virtual machine...
==> vsphere-iso.appliance: Waiting 2s for boot...
==> vsphere-iso.appliance: Serving HTTP requests at http://192.168.87.57:8186/.
==> vsphere-iso.appliance: Typing boot command...
2024/08/09 10:41:24 ui: �[1;32m==> vsphere-iso.appliance: Starting HTTP server on port 8186�[0m
2024/08/09 10:41:24 ui: �[1;32m==> vsphere-iso.appliance: Setting boot order...�[0m
2024/08/09 10:41:24 ui: �[1;32m==> vsphere-iso.appliance: Powering on virtual machine...�[0m
2024/08/09 10:41:24 ui: �[1;32m==> vsphere-iso.appliance: Waiting 2s for boot...�[0m
2024/08/09 10:41:26 ui: �[1;32m==> vsphere-iso.appliance: Serving HTTP requests at http://192.168.213.1:8186/.�[0m
2024/08/09 10:41:26 packer-plugin-vsphere_v1.3.1-dev_x5.0_darwin_arm64 plugin: 2024/08/09 10:41:26 Using IP address 192.168.87.57 from http_interface en1.
2024/08/09 10:41:26 ui: �[1;32m==> vsphere-iso.appliance: Typing boot command...�[0m

PASS : http_interface provided with no matching interface.

--> vsphere-iso.appliance: error using interface foo: route ip+net: no such network interface
2024/08/09 10:43:02 ui error: �[1;31mBuild 'vsphere-iso.appliance' errored after 3 seconds 808 milliseconds: error using interface foo: route ip+net: no such network interface�[0m

PASS : http_interface provided with http_ip. http_interface takes precedence.

==> vsphere-iso.appliance: Starting HTTP server on port 8564
==> vsphere-iso.appliance: Setting boot order...
==> vsphere-iso.appliance: Powering on virtual machine...
==> vsphere-iso.appliance: Waiting 2s for boot...
==> vsphere-iso.appliance: Serving HTTP requests at http://192.168.86.58:8564/.
==> vsphere-iso.appliance: Typing boot command...
2024/08/09 10:44:23 ui: �[1;32m==> vsphere-iso.appliance: Starting HTTP server on port 8564�[0m
2024/08/09 10:44:23 ui: �[1;32m==> vsphere-iso.appliance: Setting boot order...�[0m
2024/08/09 10:44:23 ui: �[1;32m==> vsphere-iso.appliance: Powering on virtual machine...�[0m
2024/08/09 10:44:23 ui: �[1;32m==> vsphere-iso.appliance: Waiting 2s for boot...�[0m
2024/08/09 10:44:25 packer-plugin-vsphere_v1.3.1-dev_x5.0_darwin_arm64 plugin: 2024/08/09 10:44:25 Using IP address 192.168.86.58 from http_interface en0.
2024/08/09 10:44:25 ui: �[1;32m==> vsphere-iso.appliance: Serving HTTP requests at http://192.168.86.58:8564/.�[0m
2024/08/09 10:44:25 ui: �[1;32m==> vsphere-iso.appliance: Typing boot command...�[0m

@tenthirtyam tenthirtyam added this to the On Deck milestone May 12, 2024
@tenthirtyam tenthirtyam self-assigned this May 12, 2024
@tenthirtyam tenthirtyam linked an issue May 12, 2024 that may be closed by this pull request
1 task
@tenthirtyam tenthirtyam modified the milestones: On Deck, v1.3.1 May 13, 2024
@tenthirtyam tenthirtyam force-pushed the feat/http-interface branch 12 times, most recently from 523b817 to 86f59d3 Compare May 18, 2024 01:28
@tenthirtyam tenthirtyam force-pushed the feat/http-interface branch 2 times, most recently from dd847dc to 6075355 Compare May 30, 2024 15:54
@tenthirtyam tenthirtyam changed the title feat: add support for http_interface feat: add support for http_interface and http_bind_address May 30, 2024
@tenthirtyam tenthirtyam marked this pull request as ready for review May 30, 2024 17:01
@tenthirtyam tenthirtyam requested a review from a team as a code owner May 30, 2024 17:01
Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of comments on the new code, but overall LGTM, thanks for taking the time to delve into this @tenthirtyam

builder/vsphere/clone/builder.go Outdated Show resolved Hide resolved
builder/vsphere/common/step_http_ip_discover.go Outdated Show resolved Hide resolved
builder/vsphere/common/step_boot_command.go Outdated Show resolved Hide resolved
builder/vsphere/clone/builder.go Outdated Show resolved Hide resolved
@tenthirtyam tenthirtyam marked this pull request as ready for review July 1, 2024 16:33
@tenthirtyam
Copy link
Collaborator Author

@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
Copy link
Contributor

nywilken commented Jul 1, 2024

@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
Copy link
Collaborator Author

tenthirtyam commented Jul 1, 2024

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

Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few suggestions on the code. But the approach looks good.

builder/vsphere/clone/builder.go Outdated Show resolved Hide resolved
builder/vsphere/clone/builder.go Outdated Show resolved Hide resolved
builder/vsphere/clone/builder.go Outdated Show resolved Hide resolved
builder/vsphere/common/http_address.go Outdated Show resolved Hide resolved
builder/vsphere/common/step_boot_command.go Outdated Show resolved Hide resolved
builder/vsphere/common/step_boot_command.go Show resolved Hide resolved
builder/vsphere/common/step_boot_command.go Outdated Show resolved Hide resolved
@tenthirtyam tenthirtyam force-pushed the feat/http-interface branch 4 times, most recently from 2cccb46 to 4242f44 Compare July 24, 2024 22:12
@tenthirtyam
Copy link
Collaborator Author

@nywilken and @lbajolet-hashicorp - this one has been updated but I still need to run another round of testing before any merge. Let me know how the updates look to you both.

Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the rerolls @tenthirtyam, LGTM!

@tenthirtyam tenthirtyam marked this pull request as draft July 27, 2024 15:37
@tenthirtyam
Copy link
Collaborator Author

Marked as draft pending e2e testing post refactor.

@tenthirtyam tenthirtyam force-pushed the feat/http-interface branch 3 times, most recently from 6574850 to bca604f Compare August 9, 2024 14:25
@tenthirtyam tenthirtyam marked this pull request as ready for review August 9, 2024 14:45
@tenthirtyam
Copy link
Collaborator Author

@lbajolet-hashicorp @nywilken - all comments have been addressed and implemented.

I've tested various scenarios above with the console and log outputs. Note that the log will also show from where the IP address is used.

Ryan

Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left a small nit/question on the hostIP function, but aside from that, LGTM!

Pre-approving so not to be a blocker later

}
for _, addr := range addrs {
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we only supporting IPv4 here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Resolved in 4f68e62..

Adds support for `http_interface` and `http_bind_address`.

Signed-off-by: Ryan Johnson <ryan@tenthirtyam.org>
@lbajolet-hashicorp lbajolet-hashicorp merged commit bf146ab into main Aug 12, 2024
12 checks passed
@lbajolet-hashicorp lbajolet-hashicorp deleted the feat/http-interface branch August 12, 2024 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for http_interface and http_bind_address
3 participants