github.com/vmware/govmomi@v0.51.0/object/host_vsan_system.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 HostVsanSystem struct {
    17  	Common
    18  }
    19  
    20  func NewHostVsanSystem(c *vim25.Client, ref types.ManagedObjectReference) *HostVsanSystem {
    21  	return &HostVsanSystem{
    22  		Common: NewCommon(c, ref),
    23  	}
    24  }
    25  
    26  func (s HostVsanSystem) Update(ctx context.Context, config types.VsanHostConfigInfo) (*Task, error) {
    27  	req := types.UpdateVsan_Task{
    28  		This:   s.Reference(),
    29  		Config: config,
    30  	}
    31  
    32  	res, err := methods.UpdateVsan_Task(ctx, s.Client(), &req)
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  
    37  	return NewTask(s.Client(), res.Returnval), nil
    38  }
    39  
    40  // updateVnic in support of the HostVirtualNicManager.{SelectVnic,DeselectVnic} methods
    41  func (s HostVsanSystem) updateVnic(ctx context.Context, device string, enable bool) error {
    42  	var vsan mo.HostVsanSystem
    43  
    44  	err := s.Properties(ctx, s.Reference(), []string{"config.networkInfo.port"}, &vsan)
    45  	if err != nil {
    46  		return err
    47  	}
    48  
    49  	info := vsan.Config
    50  
    51  	var port []types.VsanHostConfigInfoNetworkInfoPortConfig
    52  
    53  	for _, p := range info.NetworkInfo.Port {
    54  		if p.Device == device {
    55  			continue
    56  		}
    57  
    58  		port = append(port, p)
    59  	}
    60  
    61  	if enable {
    62  		port = append(port, types.VsanHostConfigInfoNetworkInfoPortConfig{
    63  			Device: device,
    64  		})
    65  	}
    66  
    67  	info.NetworkInfo.Port = port
    68  
    69  	task, err := s.Update(ctx, info)
    70  	if err != nil {
    71  		return err
    72  	}
    73  
    74  	_, err = task.WaitForResult(ctx, nil)
    75  	return err
    76  }