github.com/vmware/govmomi@v0.37.2/govc/vlcm/depot/offline/rm.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  
    23  	"github.com/vmware/govmomi/govc/cli"
    24  	"github.com/vmware/govmomi/govc/flags"
    25  	"github.com/vmware/govmomi/vapi/cis/tasks"
    26  	"github.com/vmware/govmomi/vapi/esx/settings/depots"
    27  )
    28  
    29  type rm struct {
    30  	*flags.ClientFlag
    31  
    32  	depotId string
    33  }
    34  
    35  func init() {
    36  	cli.Register("vlcm.depot.offline.rm", &rm{})
    37  }
    38  
    39  func (cmd *rm) Register(ctx context.Context, f *flag.FlagSet) {
    40  	cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
    41  	cmd.ClientFlag.Register(ctx, f)
    42  
    43  	f.StringVar(&cmd.depotId, "depot-id", "", "The identifier of the depot. Use the 'ls' command to see the list of depots.")
    44  }
    45  
    46  func (cmd *rm) Process(ctx context.Context) error {
    47  	return cmd.ClientFlag.Process(ctx)
    48  }
    49  
    50  func (cmd *rm) Usage() string {
    51  	return "VLCM"
    52  }
    53  
    54  func (cmd *rm) Description() string {
    55  	return `Deletes an offline image depot.
    56  
    57  Execution will block the terminal for the duration of the task. 
    58  
    59  Examples:
    60    govc vlcm.depot.offline.rm -depot-id=<your depot's identifier>`
    61  }
    62  
    63  func (cmd *rm) Run(ctx context.Context, f *flag.FlagSet) error {
    64  	rc, err := cmd.RestClient()
    65  
    66  	if err != nil {
    67  		return err
    68  	}
    69  
    70  	dm := depots.NewManager(rc)
    71  
    72  	if taskId, err := dm.DeleteOfflineDepot(cmd.depotId); err != nil {
    73  		return err
    74  	} else if _, err = tasks.NewManager(rc).WaitForCompletion(ctx, taskId); err != nil {
    75  		return err
    76  	} else {
    77  		return nil
    78  	}
    79  }