detect default network per host (#180)

This commit is contained in:
Michael Kuzmin 2018-10-31 23:51:20 +03:00 committed by GitHub
parent ebcd6174d4
commit d7fcff025f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 3 deletions

View File

@ -445,11 +445,31 @@ func addDisk(_ *Driver, devices object.VirtualDeviceList, config *CreateConfig)
}
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 config.Network == "" {
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)
if err != nil {
return nil, err