github.com/vmware/govmomi@v0.37.2/govc/cluster/draft/component/info.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  	"io"
    23  
    24  	"github.com/vmware/govmomi/govc/cli"
    25  	"github.com/vmware/govmomi/govc/flags"
    26  	"github.com/vmware/govmomi/vapi/esx/settings/clusters"
    27  )
    28  
    29  type infoResult clusters.SettingsComponentInfo
    30  
    31  func (r infoResult) Write(w io.Writer) error {
    32  	return nil
    33  }
    34  
    35  type info struct {
    36  	*flags.ClientFlag
    37  	*flags.OutputFlag
    38  
    39  	clusterId   string
    40  	draftId     string
    41  	componentId string
    42  }
    43  
    44  func init() {
    45  	cli.Register("cluster.draft.component.info", &info{})
    46  }
    47  
    48  func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) {
    49  	cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
    50  	cmd.ClientFlag.Register(ctx, f)
    51  	cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
    52  
    53  	f.StringVar(&cmd.clusterId, "cluster-id", "", "The identifier of the cluster.")
    54  	f.StringVar(&cmd.draftId, "draft-id", "", "The identifier of the software draft.")
    55  	f.StringVar(&cmd.componentId, "component-id", "", "The identifier of the software component.")
    56  }
    57  
    58  func (cmd *info) Process(ctx context.Context) error {
    59  	if err := cmd.ClientFlag.Process(ctx); err != nil {
    60  		return err
    61  	}
    62  	if err := cmd.OutputFlag.Process(ctx); err != nil {
    63  		return err
    64  	}
    65  
    66  	return nil
    67  }
    68  
    69  func (cmd *info) Usage() string {
    70  	return "CLUSTER"
    71  }
    72  
    73  func (cmd *info) Description() string {
    74  	return `Displays the details of a component in a software draft.  
    75  
    76  Examples:
    77    govc cluster.draft.component.info -cluster-id=domain-c21 -draft-id=13 -component-id=NVD-AIE-800`
    78  }
    79  
    80  func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
    81  	rc, err := cmd.RestClient()
    82  
    83  	if err != nil {
    84  		return err
    85  	}
    86  
    87  	dm := clusters.NewManager(rc)
    88  
    89  	if d, err := dm.GetSoftwareDraftComponent(cmd.clusterId, cmd.draftId, cmd.componentId); err != nil {
    90  		return err
    91  	} else {
    92  		if !cmd.All() {
    93  			cmd.JSON = true
    94  		}
    95  		return cmd.WriteResult(infoResult(d))
    96  	}
    97  }