github.com/vmware/govmomi@v0.51.0/cli/namespace/vmclass/update.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 vmclass
     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/vapi/namespace"
    14  )
    15  
    16  type update struct {
    17  	*flags.ClientFlag
    18  
    19  	spec namespace.VirtualMachineClassUpdateSpec
    20  }
    21  
    22  func init() {
    23  	cli.Register("namespace.vmclass.update", &update{})
    24  }
    25  
    26  func (cmd *update) Register(ctx context.Context, f *flag.FlagSet) {
    27  	cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
    28  	cmd.ClientFlag.Register(ctx, f)
    29  
    30  	f.Int64Var(&cmd.spec.CpuCount, "cpus", 0, "The number of CPUs.")
    31  	f.Int64Var(&cmd.spec.MemoryMb, "memory", 0, "The amount of memory (in MB).")
    32  }
    33  
    34  func (cmd *update) Process(ctx context.Context) error {
    35  	return cmd.ClientFlag.Process(ctx)
    36  }
    37  
    38  func (cmd *update) Usage() string {
    39  	return "NAME"
    40  }
    41  
    42  func (cmd *update) Description() string {
    43  	return `Modifies an existing virtual machine class.
    44  
    45  Examples:
    46    govc namespace.vmclass.update -cpus=8 -memory=8192 test-class`
    47  }
    48  
    49  func (cmd *update) Run(ctx context.Context, f *flag.FlagSet) error {
    50  	rc, err := cmd.RestClient()
    51  
    52  	if err != nil {
    53  		return err
    54  	}
    55  
    56  	cmd.spec.Id = f.Arg(0)
    57  
    58  	nm := namespace.NewManager(rc)
    59  
    60  	return nm.UpdateVmClass(ctx, cmd.spec.Id, cmd.spec)
    61  }