github.com/vmware/govmomi@v0.51.0/object/network.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package object
     6  
     7  import (
     8  	"context"
     9  
    10  	"github.com/vmware/govmomi/vim25"
    11  	"github.com/vmware/govmomi/vim25/types"
    12  )
    13  
    14  type Network struct {
    15  	Common
    16  }
    17  
    18  func NewNetwork(c *vim25.Client, ref types.ManagedObjectReference) *Network {
    19  	return &Network{
    20  		Common: NewCommon(c, ref),
    21  	}
    22  }
    23  
    24  func (n Network) GetInventoryPath() string {
    25  	return n.InventoryPath
    26  }
    27  
    28  // EthernetCardBackingInfo returns the VirtualDeviceBackingInfo for this Network
    29  func (n Network) EthernetCardBackingInfo(ctx context.Context) (types.BaseVirtualDeviceBackingInfo, error) {
    30  	name, err := n.ObjectName(ctx)
    31  	if err != nil {
    32  		return nil, err
    33  	}
    34  
    35  	backing := &types.VirtualEthernetCardNetworkBackingInfo{
    36  		VirtualDeviceDeviceBackingInfo: types.VirtualDeviceDeviceBackingInfo{
    37  			DeviceName: name,
    38  		},
    39  	}
    40  
    41  	return backing, nil
    42  }