detect default network per host (#180)
This commit is contained in:
parent
ebcd6174d4
commit
d7fcff025f
26
driver/vm.go
26
driver/vm.go
|
@ -445,9 +445,29 @@ func addDisk(_ *Driver, devices object.VirtualDeviceList, config *CreateConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func addNetwork(d *Driver, devices object.VirtualDeviceList, config *CreateConfig) (object.VirtualDeviceList, error) {
|
func addNetwork(d *Driver, devices object.VirtualDeviceList, config *CreateConfig) (object.VirtualDeviceList, error) {
|
||||||
network, err := d.finder.NetworkOrDefault(d.ctx, config.Network)
|
var network object.NetworkReference
|
||||||
if err != nil {
|
if config.Network == "" {
|
||||||
return nil, err
|
h, err := d.FindHost(config.Host)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
i, err := h.Info("network")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(i.Network) > 1 {
|
||||||
|
return nil, fmt.Errorf("Host has multiple networks. Specify it explicitly")
|
||||||
|
}
|
||||||
|
|
||||||
|
network = object.NewNetwork(d.client.Client, i.Network[0])
|
||||||
|
} else {
|
||||||
|
var err error
|
||||||
|
network, err = d.finder.Network(d.ctx, config.Network)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
backing, err := network.EthernetCardBackingInfo(d.ctx)
|
backing, err := network.EthernetCardBackingInfo(d.ctx)
|
||||||
|
|
Loading…
Reference in New Issue