github.com/vmware/govmomi@v0.51.0/object/option_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/types"
    13  )
    14  
    15  type OptionManager struct {
    16  	Common
    17  }
    18  
    19  func NewOptionManager(c *vim25.Client, ref types.ManagedObjectReference) *OptionManager {
    20  	return &OptionManager{
    21  		Common: NewCommon(c, ref),
    22  	}
    23  }
    24  
    25  func (m OptionManager) Query(ctx context.Context, name string) ([]types.BaseOptionValue, error) {
    26  	req := types.QueryOptions{
    27  		This: m.Reference(),
    28  		Name: name,
    29  	}
    30  
    31  	res, err := methods.QueryOptions(ctx, m.Client(), &req)
    32  	if err != nil {
    33  		return nil, err
    34  	}
    35  
    36  	return res.Returnval, nil
    37  }
    38  
    39  func (m OptionManager) Update(ctx context.Context, value []types.BaseOptionValue) error {
    40  	req := types.UpdateOptions{
    41  		This:         m.Reference(),
    42  		ChangedValue: value,
    43  	}
    44  
    45  	_, err := methods.UpdateOptions(ctx, m.Client(), &req)
    46  	return err
    47  }