github.com/vmware/govmomi@v0.51.0/cli/cluster/draft/component/add.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 component
     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/esx/settings/clusters"
    14  )
    15  
    16  type add struct {
    17  	*flags.ClientFlag
    18  	*flags.OutputFlag
    19  
    20  	clusterId        string
    21  	draftId          string
    22  	componentId      string
    23  	componentVersion string
    24  }
    25  
    26  func init() {
    27  	cli.Register("cluster.draft.component.add", &add{})
    28  }
    29  
    30  func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
    31  	cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
    32  	cmd.ClientFlag.Register(ctx, f)
    33  	cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
    34  
    35  	f.StringVar(&cmd.clusterId, "cluster-id", "", "The identifier of the cluster.")
    36  	f.StringVar(&cmd.draftId, "draft-id", "", "The identifier of the software draft.")
    37  	f.StringVar(&cmd.componentId, "component-id", "", "The identifier of the software component.")
    38  	f.StringVar(&cmd.componentVersion, "component-version", "", "The version of the software component.")
    39  }
    40  
    41  func (cmd *add) Process(ctx context.Context) error {
    42  	return cmd.ClientFlag.Process(ctx)
    43  }
    44  
    45  func (cmd *add) Usage() string {
    46  	return "CLUSTER"
    47  }
    48  
    49  func (cmd *add) Description() string {
    50  	return `Adds a new component to the software draft.
    51  
    52  Examples:
    53    govc cluster.draft.component.add -cluster-id=domain-c21 -draft-id=13 -component-id=NVD-AIE-800 -component-version=550.54.10-1OEM.800.1.0.20613240`
    54  }
    55  
    56  func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error {
    57  	rc, err := cmd.RestClient()
    58  
    59  	if err != nil {
    60  		return err
    61  	}
    62  
    63  	dm := clusters.NewManager(rc)
    64  
    65  	spec := clusters.SoftwareComponentsUpdateSpec{}
    66  	spec.ComponentsToSet = make(map[string]string)
    67  	spec.ComponentsToSet[cmd.componentId] = cmd.componentVersion
    68  	return dm.UpdateSoftwareDraftComponents(cmd.clusterId, cmd.draftId, spec)
    69  }