github.com/vmware/govmomi@v0.37.2/govc/vlcm/depot/offline/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 offline
    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/depots"
    27  )
    28  
    29  type infoResult depots.SettingsDepotsOfflineContentInfo
    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  	depotId string
    40  }
    41  
    42  func init() {
    43  	cli.Register("vlcm.depot.offline.info", &info{})
    44  }
    45  
    46  func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) {
    47  	cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
    48  	cmd.ClientFlag.Register(ctx, f)
    49  	cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
    50  
    51  	f.StringVar(&cmd.depotId, "depot-id", "", "The identifier of the depot. Use the 'ls' command to see the list of depots.")
    52  }
    53  
    54  func (cmd *info) Process(ctx context.Context) error {
    55  	if err := cmd.ClientFlag.Process(ctx); err != nil {
    56  		return err
    57  	}
    58  	if err := cmd.OutputFlag.Process(ctx); err != nil {
    59  		return err
    60  	}
    61  
    62  	return nil
    63  }
    64  
    65  func (cmd *info) Usage() string {
    66  	return "VLCM"
    67  }
    68  
    69  func (cmd *info) Description() string {
    70  	return `Displays the contents of an offline image depot. 
    71  
    72  Examples:
    73    govc vlcm.depot.offline.info -depot-id=<your depot's identifier>`
    74  }
    75  
    76  func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
    77  	rc, err := cmd.RestClient()
    78  
    79  	if err != nil {
    80  		return err
    81  	}
    82  
    83  	dm := depots.NewManager(rc)
    84  
    85  	if d, err := dm.GetOfflineDepotContent(cmd.depotId); err != nil {
    86  		return err
    87  	} else {
    88  		if !cmd.All() {
    89  			cmd.JSON = true
    90  		}
    91  
    92  		return cmd.WriteResult(infoResult(d))
    93  	}
    94  }