Find local IP automatically

This commit is contained in:
Cheng Sun 2015-01-02 15:08:51 +00:00
parent d619e751e3
commit 27819cd51f
2 changed files with 14 additions and 11 deletions

View File

@ -37,8 +37,6 @@ type CommonConfig struct {
HTTPPortMin uint `mapstructure:"http_port_min"`
HTTPPortMax uint `mapstructure:"http_port_max"`
LocalIp string `mapstructure:"local_ip"`
// SSHHostPortMin uint `mapstructure:"ssh_host_port_min"`
// SSHHostPortMax uint `mapstructure:"ssh_host_port_max"`
SSHKeyPath string `mapstructure:"ssh_key_path"`
@ -136,7 +134,6 @@ func (c *CommonConfig) Prepare(t *packer.ConfigTemplate, pc *common.PackerConfig
"boot_wait": &c.RawBootWait,
"tools_iso_name": &c.ToolsIsoName,
"http_directory": &c.HTTPDir,
"local_ip": &c.LocalIp,
"ssh_key_path": &c.SSHKeyPath,
"ssh_password": &c.SSHPassword,
"ssh_username": &c.SSHUser,
@ -227,12 +224,6 @@ func (c *CommonConfig) Prepare(t *packer.ConfigTemplate, pc *common.PackerConfig
errs = append(errs, errors.New("keep_vm must be one of 'always', 'never', 'on_success'"))
}
/*
if c.LocalIp == "" {
errs = append(errs, errors.New("A local IP visible to XenServer's mangement interface is required to serve files."))
}
*/
return errs
}

View File

@ -60,10 +60,22 @@ func (self *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAct
log.Printf("Connected to the VNC console: %s", c.DesktopName)
// @todo - include http port/ip so kickstarter files can be grabbed
// find local ip
envVar, err := execute_ssh_cmd("echo $SSH_CLIENT", config.HostIp, "22", config.Username, config.Password)
if err != nil {
ui.Error(fmt.Sprintf("Error detecting local IP: %s", err))
return multistep.ActionHalt
}
if envVar == "" {
ui.Error("Error detecting local IP: $SSH_CLIENT was empty")
return multistep.ActionHalt
}
localIp := strings.Split(envVar, " ")[0]
ui.Message(fmt.Sprintf("Found local IP: %s", localIp))
tplData := &bootCommandTemplateData{
config.VMName,
config.LocalIp,
localIp,
http_port,
}