Merge pull request #8753 from jhawk28/bug_8743

fix #8743 by using interface instead of Network object
This commit is contained in:
Megan Marsh 2020-02-18 10:12:34 -08:00 committed by GitHub
commit 5846c0cdd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 3 deletions

View File

@ -1,6 +1,8 @@
package driver package driver
import ( import (
"fmt"
"github.com/vmware/govmomi/object" "github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/vim25/mo" "github.com/vmware/govmomi/vim25/mo"
"github.com/vmware/govmomi/vim25/types" "github.com/vmware/govmomi/vim25/types"
@ -8,7 +10,7 @@ import (
type Network struct { type Network struct {
driver *Driver driver *Driver
network *object.Network network object.NetworkReference
} }
func (d *Driver) NewNetwork(ref *types.ManagedObjectReference) *Network { func (d *Driver) NewNetwork(ref *types.ManagedObjectReference) *Network {
@ -24,7 +26,7 @@ func (d *Driver) FindNetwork(name string) (*Network, error) {
return nil, err return nil, err
} }
return &Network{ return &Network{
network: n.(*object.Network), network: n,
driver: d, driver: d,
}, nil }, nil
} }
@ -37,7 +39,13 @@ func (n *Network) Info(params ...string) (*mo.Network, error) {
p = params p = params
} }
var info mo.Network var info mo.Network
err := n.network.Properties(n.driver.ctx, n.network.Reference(), p, &info)
network, ok := n.network.(*object.Network)
if !ok {
return nil, fmt.Errorf("unexpected %t network object type", n.network)
}
err := network.Properties(n.driver.ctx, network.Reference(), p, &info)
if err != nil { if err != nil {
return nil, err return nil, err
} }