github.com/vmware/govmomi@v0.51.0/cli/host/option/set.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 option
     6  
     7  import (
     8  	"context"
     9  	"flag"
    10  
    11  	"github.com/vmware/govmomi/cli"
    12  	"github.com/vmware/govmomi/cli/flags"
    13  	"github.com/vmware/govmomi/cli/option"
    14  )
    15  
    16  type set struct {
    17  	*option.Set
    18  	*flags.HostSystemFlag
    19  }
    20  
    21  func init() {
    22  	cli.Register("host.option.set", &set{})
    23  }
    24  
    25  func (cmd *set) Register(ctx context.Context, f *flag.FlagSet) {
    26  	cmd.Set = &option.Set{}
    27  	cmd.Set.ClientFlag, ctx = flags.NewClientFlag(ctx)
    28  	cmd.Set.ClientFlag.Register(ctx, f)
    29  
    30  	cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
    31  	cmd.HostSystemFlag.Register(ctx, f)
    32  }
    33  
    34  func (cmd *set) Process(ctx context.Context) error {
    35  	if err := cmd.Set.Process(ctx); err != nil {
    36  		return err
    37  	}
    38  	if err := cmd.HostSystemFlag.Process(ctx); err != nil {
    39  		return err
    40  	}
    41  	return nil
    42  }
    43  
    44  func (cmd *set) Description() string {
    45  	return option.SetDescription + `
    46  
    47  Examples:
    48    govc host.option.set Config.HostAgent.plugins.solo.enableMob true
    49    govc host.option.set Config.HostAgent.log.level verbose
    50    govc host.option.set Config.HostAgent.vmacore.soap.sessionTimeout 90`
    51  }
    52  
    53  func (cmd *set) Run(ctx context.Context, f *flag.FlagSet) error {
    54  	host, err := cmd.HostSystem()
    55  	if err != nil {
    56  		return err
    57  	}
    58  
    59  	m, err := host.ConfigManager().OptionManager(ctx)
    60  	if err != nil {
    61  		return err
    62  	}
    63  
    64  	return cmd.Update(ctx, f, m)
    65  }