Add network card customization and fix iso builder acceptance tests
This commit is contained in:
parent
65b98a57cf
commit
6235ecc129
12
driver/vm.go
12
driver/vm.go
|
@ -49,6 +49,7 @@ type CreateConfig struct {
|
||||||
GuestOS string // example: otherGuest
|
GuestOS string // example: otherGuest
|
||||||
Network string // "" for default network
|
Network string // "" for default network
|
||||||
Overwrite bool
|
Overwrite bool
|
||||||
|
NetworkCard string // example: vmxnet3
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) NewVM(ref *types.ManagedObjectReference) *VirtualMachine {
|
func (d *Driver) NewVM(ref *types.ManagedObjectReference) *VirtualMachine {
|
||||||
|
@ -153,6 +154,15 @@ func (vm *VirtualMachine) Info(params ...string) (*mo.VirtualMachine, error) {
|
||||||
return &info, nil
|
return &info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (vm *VirtualMachine) Devices() (object.VirtualDeviceList, error) {
|
||||||
|
vmInfo, err := vm.Info("config.hardware.device")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return vmInfo.Config.Hardware.Device, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (template *VirtualMachine) Clone(config *CloneConfig) (*VirtualMachine, error) {
|
func (template *VirtualMachine) Clone(config *CloneConfig) (*VirtualMachine, error) {
|
||||||
folder, err := template.driver.FindFolder(config.Folder)
|
folder, err := template.driver.FindFolder(config.Folder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -406,7 +416,7 @@ func addNetwork(d *Driver, devices object.VirtualDeviceList, config *CreateConfi
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
device, err := object.EthernetCardTypes().CreateEthernetCard("", backing)
|
device, err := object.EthernetCardTypes().CreateEthernetCard(config.NetworkCard, backing)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ func TestISOBuilderAcc_default(t *testing.T) {
|
||||||
builderT.Test(t, builderT.TestCase{
|
builderT.Test(t, builderT.TestCase{
|
||||||
Builder: &Builder{},
|
Builder: &Builder{},
|
||||||
Template: commonT.RenderConfig(config),
|
Template: commonT.RenderConfig(config),
|
||||||
Check: checkDefault(t, config["vm_name"].(string), config["host"].(string), "datastore1"),
|
Check: checkDefault(t, config["vm_name"].(string), config["host"].(string), "datastore1"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ func defaultConfig() map[string]interface{} {
|
||||||
"ssh_password": "jetbrains",
|
"ssh_password": "jetbrains",
|
||||||
|
|
||||||
"vm_name": commonT.NewVMName(),
|
"vm_name": commonT.NewVMName(),
|
||||||
|
"communicator": "none", // do not start the VM without any bootable devices
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
@ -159,3 +160,37 @@ func cdromConfig() string {
|
||||||
config["iso_path"] = "[datastore1] alpine-standard-3.6.2-x86_64.iso"
|
config["iso_path"] = "[datastore1] alpine-standard-3.6.2-x86_64.iso"
|
||||||
return commonT.RenderConfig(config)
|
return commonT.RenderConfig(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestISOBuilderAcc_networkCard(t *testing.T) {
|
||||||
|
builderT.Test(t, builderT.TestCase{
|
||||||
|
Builder: &Builder{},
|
||||||
|
Template: networkCardConfig(),
|
||||||
|
Check: checkNetworkCard(t),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func networkCardConfig() string {
|
||||||
|
config := defaultConfig()
|
||||||
|
config["network_card"] = "vmxnet3"
|
||||||
|
return commonT.RenderConfig(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkNetworkCard(t *testing.T) builderT.TestCheckFunc {
|
||||||
|
return func(artifacts []packer.Artifact) error {
|
||||||
|
d := commonT.TestConn(t)
|
||||||
|
|
||||||
|
vm := commonT.GetVM(t, d, artifacts)
|
||||||
|
devices, err := vm.Devices()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Cannot read VM properties: %v", err)
|
||||||
|
}
|
||||||
|
for _, device := range devices {
|
||||||
|
if devices.TypeName(device) == "VirtualVmxnet3" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
t.Errorf("Cannot find selected network card")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ type CreateConfig struct {
|
||||||
Datastore string `mapstructure:"datastore"`
|
Datastore string `mapstructure:"datastore"`
|
||||||
GuestOSType string `mapstructure:"guest_os_type"`
|
GuestOSType string `mapstructure:"guest_os_type"`
|
||||||
Network string `mapstructure:"network"`
|
Network string `mapstructure:"network"`
|
||||||
|
NetworkCard string `mapstructure:"network_card"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CreateConfig) Prepare() []error {
|
func (c *CreateConfig) Prepare() []error {
|
||||||
|
@ -77,6 +78,7 @@ func (s *StepCreateVM) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
Datastore: s.config.Datastore,
|
Datastore: s.config.Datastore,
|
||||||
GuestOS: s.config.GuestOSType,
|
GuestOS: s.config.GuestOSType,
|
||||||
Network: s.config.Network,
|
Network: s.config.Network,
|
||||||
|
NetworkCard: s.config.NetworkCard,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue