github.com/vmware/govmomi@v0.37.2/govc/cluster/draft/component/add.go (about)

     1  /*
     2  Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package component
    18  
    19  import (
    20  	"context"
    21  	"flag"
    22  
    23  	"github.com/vmware/govmomi/govc/cli"
    24  	"github.com/vmware/govmomi/govc/flags"
    25  	"github.com/vmware/govmomi/vapi/esx/settings/clusters"
    26  )
    27  
    28  type add struct {
    29  	*flags.ClientFlag
    30  	*flags.OutputFlag
    31  
    32  	clusterId        string
    33  	draftId          string
    34  	componentId      string
    35  	componentVersion string
    36  }
    37  
    38  func init() {
    39  	cli.Register("cluster.draft.component.add", &add{})
    40  }
    41  
    42  func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
    43  	cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
    44  	cmd.ClientFlag.Register(ctx, f)
    45  	cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
    46  
    47  	f.StringVar(&cmd.clusterId, "cluster-id", "", "The identifier of the cluster.")
    48  	f.StringVar(&cmd.draftId, "draft-id", "", "The identifier of the software draft.")
    49  	f.StringVar(&cmd.componentId, "component-id", "", "The identifier of the software component.")
    50  	f.StringVar(&cmd.componentVersion, "component-version", "", "The version of the software component.")
    51  }
    52  
    53  func (cmd *add) Process(ctx context.Context) error {
    54  	return cmd.ClientFlag.Process(ctx)
    55  }
    56  
    57  func (cmd *add) Usage() string {
    58  	return "CLUSTER"
    59  }
    60  
    61  func (cmd *add) Description() string {
    62  	return `Adds a new component to the software draft.  
    63  
    64  Examples:
    65    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`
    66  }
    67  
    68  func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error {
    69  	rc, err := cmd.RestClient()
    70  
    71  	if err != nil {
    72  		return err
    73  	}
    74  
    75  	dm := clusters.NewManager(rc)
    76  
    77  	spec := clusters.SoftwareComponentsUpdateSpec{}
    78  	spec.ComponentsToSet = make(map[string]string)
    79  	spec.ComponentsToSet[cmd.componentId] = cmd.componentVersion
    80  	return dm.UpdateSoftwareDraftComponents(cmd.clusterId, cmd.draftId, spec)
    81  }