packer-cn/builder/vmware/iso/driver.go

42 lines
1005 B
Go
Raw Normal View History

2013-12-24 00:58:41 -05:00
package iso
2013-06-06 15:19:38 -04:00
import (
2013-06-08 00:46:59 -04:00
"fmt"
2013-06-06 15:19:38 -04:00
2013-12-24 13:31:57 -05:00
vmwcommon "github.com/mitchellh/packer/builder/vmware/common"
)
2013-06-06 15:19:38 -04:00
// NewDriver returns a new driver implementation for this operating
// system, or an error if the driver couldn't be initialized.
2013-12-24 13:31:57 -05:00
func NewDriver(config *config) (vmwcommon.Driver, error) {
drivers := []vmwcommon.Driver{}
2013-06-08 00:46:59 -04:00
if config.RemoteType == "" {
return vmwcommon.NewDriver(&config.DriverConfig, &config.SSHConfig)
}
drivers = []vmwcommon.Driver{
&ESX5Driver{
Host: config.RemoteHost,
Port: config.RemotePort,
Username: config.RemoteUser,
Password: config.RemotePassword,
Datastore: config.RemoteDatastore,
},
2013-06-08 00:46:59 -04:00
}
errs := ""
for _, driver := range drivers {
err := driver.Verify()
if err == nil {
return driver, nil
}
errs += "* " + err.Error() + "\n"
2013-06-08 00:46:59 -04:00
}
return nil, fmt.Errorf(
"Unable to initialize any driver for this platform. The errors\n"+
"from each driver are shown below. Please fix at least one driver\n"+
"to continue:\n%s", errs)
}