Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions builder/xenserver/common/common_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ type CommonConfig struct {

ToolsIsoName string `mapstructure:"tools_iso_name"`

HTTPDir string `mapstructure:"http_directory"`
HTTPPortMin uint `mapstructure:"http_port_min"`
HTTPPortMax uint `mapstructure:"http_port_max"`
HTTPContent map[string]string `mapstructure:"http_content"`
HTTPDir string `mapstructure:"http_directory"`
HTTPPortMin uint `mapstructure:"http_port_min"`
HTTPPortMax uint `mapstructure:"http_port_max"`

// SSHHostPortMin uint `mapstructure:"ssh_host_port_min"`
// SSHHostPortMax uint `mapstructure:"ssh_host_port_max"`
Expand Down Expand Up @@ -133,7 +134,6 @@ func (c *CommonConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig
c.Comm.SSHPort = 22
}


if c.OutputDir == "" {
c.OutputDir = fmt.Sprintf("output-%s", pc.PackerBuildName)
}
Expand Down
2 changes: 2 additions & 0 deletions builder/xenserver/common/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions builder/xenserver/common/step_http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"

"github.com/hashicorp/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
"github.com/hashicorp/packer-plugin-sdk/packer"
)

Expand Down Expand Up @@ -48,12 +49,20 @@ func (snooper IPSnooper) ServeHTTP(resp http.ResponseWriter, req *http.Request)
snooper.handler.ServeHTTP(resp, req)
}

func (s *StepHTTPServer) Handler(config *CommonConfig) http.Handler {
if config.HTTPDir != "" {
return http.FileServer(http.Dir(config.HTTPDir))
}

return commonsteps.MapServer(config.HTTPContent)
}
Comment on lines +52 to +58
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

As this type largely appears to be a fork of packer-plugin-sdk's StepHTTPServer type, I opted to approximately mirror that package's Handler() function.


func (s *StepHTTPServer) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("commonconfig").(CommonConfig)
ui := state.Get("ui").(packer.Ui)

var httpPort uint = 0
if config.HTTPDir == "" {
if config.HTTPDir == "" && len(config.HTTPContent) == 0 {
// the packer provision steps assert this type is an int
// so this cannot be a uint like the rest of the code
state.Put("http_port", int(httpPort))
Expand All @@ -70,12 +79,11 @@ func (s *StepHTTPServer) Run(ctx context.Context, state multistep.StateBag) mult
ui.Say(fmt.Sprintf("Starting HTTP server on port %d", httpPort))

// Start the HTTP server and run it in the background
fileServer := http.FileServer(http.Dir(config.HTTPDir))
server := &http.Server{
Addr: fmt.Sprintf(":%d", httpPort),
Handler: IPSnooper{
ch: s.Chan,
handler: fileServer,
handler: s.Handler(&config),
},
}
go server.Serve(s.l)
Expand Down
15 changes: 15 additions & 0 deletions docs/builders/iso/xenserver-iso.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,21 @@ If you want to add multiple disk, you can do it like this:
"vdi_raw" to export just the raw disk image. Set to "none" to export nothing;
this is only useful with "keep_vm" set to "always" or "on_success".

- `http_content` (map[string]string) - Key/Values to serve using an HTTP server.
`http_content` works like and conflicts with `http_directory`. The keys
represent the paths and the values contents, the keys must start with a slash,
ex: `/path/to/file`. `http_content` is useful for hosting kickstart files and
so on. By default this is empty, which means no HTTP server will be started.
The address and port of the HTTP server will be available as variables in
`boot_command`. This is covered in more detail below.
Example:
```hcl
http_content = {
"/a/b" = file("http/b")
"/foo/bar" = templatefile("${path.root}/preseed.cfg", { packages = ["nginx"] })
}
```

* `http_directory` (string) - Path to a directory to serve using an HTTP
server. The files in this directory will be available over HTTP which will
be requestable from the virtual machine. This is useful for hosting
Expand Down