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
|
||||
Network string // "" for default network
|
||||
Overwrite bool
|
||||
NetworkCard string // example: vmxnet3
|
||||
}
|
||||
|
||||
func (d *Driver) NewVM(ref *types.ManagedObjectReference) *VirtualMachine {
|
||||
|
@ -153,6 +154,15 @@ func (vm *VirtualMachine) Info(params ...string) (*mo.VirtualMachine, error) {
|
|||
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) {
|
||||
folder, err := template.driver.FindFolder(config.Folder)
|
||||
if err != nil {
|
||||
|
@ -406,7 +416,7 @@ func addNetwork(d *Driver, devices object.VirtualDeviceList, config *CreateConfi
|
|||
return nil, err
|
||||
}
|
||||
|
||||
device, err := object.EthernetCardTypes().CreateEthernetCard("", backing)
|
||||
device, err := object.EthernetCardTypes().CreateEthernetCard(config.NetworkCard, backing)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ func defaultConfig() map[string]interface{} {
|
|||
"ssh_password": "jetbrains",
|
||||
|
||||
"vm_name": commonT.NewVMName(),
|
||||
"communicator": "none", // do not start the VM without any bootable devices
|
||||
}
|
||||
|
||||
return config
|
||||
|
@ -159,3 +160,37 @@ func cdromConfig() string {
|
|||
config["iso_path"] = "[datastore1] alpine-standard-3.6.2-x86_64.iso"
|
||||
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"`
|
||||
GuestOSType string `mapstructure:"guest_os_type"`
|
||||
Network string `mapstructure:"network"`
|
||||
NetworkCard string `mapstructure:"network_card"`
|
||||
}
|
||||
|
||||
func (c *CreateConfig) Prepare() []error {
|
||||
|
@ -77,6 +78,7 @@ func (s *StepCreateVM) Run(state multistep.StateBag) multistep.StepAction {
|
|||
Datastore: s.config.Datastore,
|
||||
GuestOS: s.config.GuestOSType,
|
||||
Network: s.config.Network,
|
||||
NetworkCard: s.config.NetworkCard,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue