use the ip_wait_address range to determine the default for the http server IP
This commit is contained in:
parent
aa50b2185f
commit
aaf9103330
|
@ -12,11 +12,12 @@ import (
|
|||
// which guests use to reach the vm host
|
||||
// To make sure the IP is set before boot command and http server steps
|
||||
type StepHTTPIPDiscover struct {
|
||||
HTTPIP string
|
||||
HTTPIP string
|
||||
Network *net.IPNet
|
||||
}
|
||||
|
||||
func (s *StepHTTPIPDiscover) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
ip, err := getHostIP(s.HTTPIP)
|
||||
ip, err := getHostIP(s.HTTPIP, s.Network)
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
return multistep.ActionHalt
|
||||
|
@ -28,7 +29,7 @@ func (s *StepHTTPIPDiscover) Run(ctx context.Context, state multistep.StateBag)
|
|||
|
||||
func (s *StepHTTPIPDiscover) Cleanup(state multistep.StateBag) {}
|
||||
|
||||
func getHostIP(s string) (string, error) {
|
||||
func getHostIP(s string, network *net.IPNet) (string, error) {
|
||||
if s != "" {
|
||||
if net.ParseIP(s) != nil {
|
||||
return s, nil
|
||||
|
@ -45,7 +46,7 @@ func getHostIP(s string) (string, error) {
|
|||
for _, a := range addrs {
|
||||
ipnet, ok := a.(*net.IPNet)
|
||||
if ok && !ipnet.IP.IsLoopback() {
|
||||
if ipnet.IP.To4() != nil {
|
||||
if network.Contains(ipnet.IP) {
|
||||
return ipnet.IP.String(), nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ type WaitIpConfig struct {
|
|||
// this network range. Defaults to "0.0.0.0/0" for any ipv4 address. Examples include:
|
||||
//
|
||||
// * empty string ("") - remove all filters
|
||||
// * "0:0:0:0:0:0:0:0/0" - allow only ipv6 addresses
|
||||
// * "192.168.1.0/24 - only allow ipv4 addresses from 192.168.1.1 to 192.168.1.254
|
||||
// * `0:0:0:0:0:0:0:0/0` - allow only ipv6 addresses
|
||||
// * `192.168.1.0/24` - only allow ipv4 addresses from 192.168.1.1 to 192.168.1.254
|
||||
WaitAddress *string `mapstructure:"ip_wait_address"`
|
||||
ipnet *net.IPNet
|
||||
|
||||
|
@ -69,6 +69,10 @@ func (c *WaitIpConfig) Prepare() []error {
|
|||
return errs
|
||||
}
|
||||
|
||||
func (c *WaitIpConfig) GetIPNet() *net.IPNet {
|
||||
return c.ipnet
|
||||
}
|
||||
|
||||
func (s *StepWaitForIp) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
vm := state.Get("vm").(*driver.VirtualMachine)
|
||||
|
|
|
@ -91,7 +91,8 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
|
|||
SetHostForDatastoreUploads: b.config.SetHostForDatastoreUploads,
|
||||
},
|
||||
&common.StepHTTPIPDiscover{
|
||||
HTTPIP: b.config.BootConfig.HTTPIP,
|
||||
HTTPIP: b.config.BootConfig.HTTPIP,
|
||||
Network: b.config.WaitIpConfig.GetIPNet(),
|
||||
},
|
||||
&packerCommon.StepHTTPServer{
|
||||
HTTPDir: b.config.HTTPDir,
|
||||
|
|
|
@ -16,6 +16,6 @@
|
|||
this network range. Defaults to "0.0.0.0/0" for any ipv4 address. Examples include:
|
||||
|
||||
* empty string ("") - remove all filters
|
||||
* "0:0:0:0:0:0:0:0/0" - allow only ipv6 addresses
|
||||
* "192.168.1.0/24 - only allow ipv4 addresses from 192.168.1.1 to 192.168.1.254
|
||||
* `0:0:0:0:0:0:0:0/0` - allow only ipv6 addresses
|
||||
* `192.168.1.0/24` - only allow ipv4 addresses from 192.168.1.1 to 192.168.1.254
|
||||
|
Loading…
Reference in New Issue