mirror of
https://github.com/hashicorp/packer.git
synced 2026-05-19 08:25:21 -04:00
Support for local HTTP server
This commit is contained in:
parent
5b8be459ed
commit
7cafcf5879
3 changed files with 35 additions and 0 deletions
|
|
@ -63,6 +63,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
Datastore: b.config.Datastore,
|
||||
Host: b.config.Host,
|
||||
},
|
||||
&packerCommon.StepHTTPServer{
|
||||
HTTPDir: b.config.HTTPDir,
|
||||
HTTPPortMin: b.config.HTTPPortMin,
|
||||
HTTPPortMax: b.config.HTTPPortMax,
|
||||
},
|
||||
&common.StepRun{
|
||||
Config: &b.config.RunConfig,
|
||||
SetOrder: true,
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
type Config struct {
|
||||
packerCommon.PackerConfig `mapstructure:",squash"`
|
||||
packerCommon.HTTPConfig `mapstructure:",squash"`
|
||||
|
||||
common.ConnectConfig `mapstructure:",squash"`
|
||||
CreateConfig `mapstructure:",squash"`
|
||||
|
|
@ -46,6 +47,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
|||
errs = packer.MultiErrorAppend(errs, c.CreateConfig.Prepare()...)
|
||||
errs = packer.MultiErrorAppend(errs, c.LocationConfig.Prepare()...)
|
||||
errs = packer.MultiErrorAppend(errs, c.HardwareConfig.Prepare()...)
|
||||
errs = packer.MultiErrorAppend(errs, c.HTTPConfig.Prepare(&c.ctx)...)
|
||||
|
||||
errs = packer.MultiErrorAppend(errs, c.CDRomConfig.Prepare()...)
|
||||
errs = packer.MultiErrorAppend(errs, c.BootConfig.Prepare()...)
|
||||
|
|
|
|||
|
|
@ -3,10 +3,13 @@ package iso
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
packerCommon "github.com/hashicorp/packer/common"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/jetbrains-infra/packer-builder-vsphere/common"
|
||||
"github.com/jetbrains-infra/packer-builder-vsphere/driver"
|
||||
"net"
|
||||
"os"
|
||||
)
|
||||
|
||||
type CreateConfig struct {
|
||||
|
|
@ -23,6 +26,29 @@ type CreateConfig struct {
|
|||
USBController bool `mapstructure:"usb_controller"`
|
||||
|
||||
Notes string `mapstructure:"notes"`
|
||||
|
||||
HTTPIP string `mapstructure:"http_ip"`
|
||||
}
|
||||
|
||||
func getHostIP(s string) string {
|
||||
if net.ParseIP(s) != nil {
|
||||
return s
|
||||
}
|
||||
|
||||
var ipaddr string
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
for _, a := range addrs {
|
||||
if ip, ok := a.(*net.IPNet); ok && !ip.IP.IsLoopback() {
|
||||
ipaddr = ip.IP.String()
|
||||
break
|
||||
}
|
||||
}
|
||||
return ipaddr
|
||||
}
|
||||
|
||||
func (c *CreateConfig) Prepare() []error {
|
||||
|
|
@ -66,6 +92,8 @@ func (s *StepCreateVM) Run(_ context.Context, state multistep.StateBag) multiste
|
|||
}
|
||||
}
|
||||
|
||||
packerCommon.SetHTTPIP(getHostIP(s.Config.HTTPIP))
|
||||
|
||||
ui.Say("Creating VM...")
|
||||
vm, err := d.CreateVM(&driver.CreateConfig{
|
||||
DiskThinProvisioned: s.Config.DiskThinProvisioned,
|
||||
|
|
|
|||
Loading…
Reference in a new issue