Add support for custom networks

This commit is contained in:
Andrei Tonkikh 2018-01-30 23:15:30 +03:00
parent 19713ca20d
commit 65b98a57cf
2 changed files with 6 additions and 3 deletions

View File

@ -47,6 +47,7 @@ type CreateConfig struct {
ResourcePool string
Datastore string
GuestOS string // example: otherGuest
Network string // "" for default network
Overwrite bool
}
@ -109,7 +110,7 @@ func (d *Driver) CreateVM(config *CreateConfig) (*VirtualMachine, error) {
if err != nil {
return nil, err
}
devices, err = addNetwork(d, devices)
devices, err = addNetwork(d, devices, config)
if err != nil {
return nil, err
}
@ -394,8 +395,8 @@ func addDisk(d *Driver, devices object.VirtualDeviceList, config *CreateConfig)
return devices, nil
}
func addNetwork(d *Driver, devices object.VirtualDeviceList) (object.VirtualDeviceList, error) {
network, err := d.finder.DefaultNetwork(d.ctx)
func addNetwork(d *Driver, devices object.VirtualDeviceList, config *CreateConfig) (object.VirtualDeviceList, error) {
network, err := d.finder.NetworkOrDefault(d.ctx, config.Network)
if err != nil {
return nil, err
}

View File

@ -20,6 +20,7 @@ type CreateConfig struct {
ResourcePool string `mapstructure:"resource_pool"`
Datastore string `mapstructure:"datastore"`
GuestOSType string `mapstructure:"guest_os_type"`
Network string `mapstructure:"network"`
}
func (c *CreateConfig) Prepare() []error {
@ -75,6 +76,7 @@ func (s *StepCreateVM) Run(state multistep.StateBag) multistep.StepAction {
ResourcePool: s.config.ResourcePool,
Datastore: s.config.Datastore,
GuestOS: s.config.GuestOSType,
Network: s.config.Network,
})
if err != nil {