2018-01-24 06:04:39 -05:00
|
|
|
package common
|
2017-07-01 20:52:10 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"fmt"
|
2017-08-23 15:40:57 -04:00
|
|
|
"github.com/jetbrains-infra/packer-builder-vsphere/driver"
|
2017-07-01 20:52:10 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type ConnectConfig struct {
|
|
|
|
VCenterServer string `mapstructure:"vcenter_server"`
|
|
|
|
Username string `mapstructure:"username"`
|
|
|
|
Password string `mapstructure:"password"`
|
|
|
|
InsecureConnection bool `mapstructure:"insecure_connection"`
|
2017-07-02 16:29:50 -04:00
|
|
|
Datacenter string `mapstructure:"datacenter"`
|
2017-07-01 20:52:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ConnectConfig) Prepare() []error {
|
|
|
|
var errs []error
|
|
|
|
|
|
|
|
if c.VCenterServer == "" {
|
|
|
|
errs = append(errs, fmt.Errorf("vCenter hostname is required"))
|
|
|
|
}
|
|
|
|
if c.Username == "" {
|
|
|
|
errs = append(errs, fmt.Errorf("Username is required"))
|
|
|
|
}
|
|
|
|
if c.Password == "" {
|
|
|
|
errs = append(errs, fmt.Errorf("Password is required"))
|
|
|
|
}
|
|
|
|
|
|
|
|
return errs
|
|
|
|
}
|
|
|
|
|
|
|
|
type StepConnect struct {
|
2018-01-24 06:04:39 -05:00
|
|
|
Config *ConnectConfig
|
2017-07-01 20:52:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepConnect) Run(state multistep.StateBag) multistep.StepAction {
|
2017-08-23 15:40:57 -04:00
|
|
|
d, err := driver.NewDriver(&driver.ConnectConfig{
|
2018-01-24 06:04:39 -05:00
|
|
|
VCenterServer: s.Config.VCenterServer,
|
|
|
|
Username: s.Config.Username,
|
|
|
|
Password: s.Config.Password,
|
|
|
|
InsecureConnection: s.Config.InsecureConnection,
|
|
|
|
Datacenter: s.Config.Datacenter,
|
2017-08-23 15:40:57 -04:00
|
|
|
})
|
2017-07-01 20:52:10 -04:00
|
|
|
if err != nil {
|
|
|
|
state.Put("error", err)
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2017-08-23 15:40:57 -04:00
|
|
|
state.Put("driver", d)
|
2017-07-01 20:52:10 -04:00
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepConnect) Cleanup(multistep.StateBag) {}
|