github.com/vmware/govmomi@v0.51.0/object/host_virtual_nic_manager.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/methods" 12 "github.com/vmware/govmomi/vim25/mo" 13 "github.com/vmware/govmomi/vim25/types" 14 ) 15 16 type HostVirtualNicManager struct { 17 Common 18 Host *HostSystem 19 } 20 21 func NewHostVirtualNicManager(c *vim25.Client, ref types.ManagedObjectReference, host types.ManagedObjectReference) *HostVirtualNicManager { 22 return &HostVirtualNicManager{ 23 Common: NewCommon(c, ref), 24 Host: NewHostSystem(c, host), 25 } 26 } 27 28 func (m HostVirtualNicManager) Info(ctx context.Context) (*types.HostVirtualNicManagerInfo, error) { 29 var vnm mo.HostVirtualNicManager 30 31 err := m.Properties(ctx, m.Reference(), []string{"info"}, &vnm) 32 if err != nil { 33 return nil, err 34 } 35 36 return &vnm.Info, nil 37 } 38 39 func (m HostVirtualNicManager) DeselectVnic(ctx context.Context, nicType string, device string) error { 40 if nicType == string(types.HostVirtualNicManagerNicTypeVsan) { 41 // Avoid fault.NotSupported: 42 // "Error deselecting device '$device': VSAN interfaces must be deselected using vim.host.VsanSystem" 43 s, err := m.Host.ConfigManager().VsanSystem(ctx) 44 if err != nil { 45 return err 46 } 47 48 return s.updateVnic(ctx, device, false) 49 } 50 51 req := types.DeselectVnicForNicType{ 52 This: m.Reference(), 53 NicType: nicType, 54 Device: device, 55 } 56 57 _, err := methods.DeselectVnicForNicType(ctx, m.Client(), &req) 58 return err 59 } 60 61 func (m HostVirtualNicManager) SelectVnic(ctx context.Context, nicType string, device string) error { 62 if nicType == string(types.HostVirtualNicManagerNicTypeVsan) { 63 // Avoid fault.NotSupported: 64 // "Error selecting device '$device': VSAN interfaces must be selected using vim.host.VsanSystem" 65 s, err := m.Host.ConfigManager().VsanSystem(ctx) 66 if err != nil { 67 return err 68 } 69 70 return s.updateVnic(ctx, device, true) 71 } 72 73 req := types.SelectVnicForNicType{ 74 This: m.Reference(), 75 NicType: nicType, 76 Device: device, 77 } 78 79 _, err := methods.SelectVnicForNicType(ctx, m.Client(), &req) 80 return err 81 }