github.com/vmware/govmomi@v0.51.0/cli/vm/markastemplate.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 vm
     6  
     7  import (
     8  	"context"
     9  	"flag"
    10  
    11  	"github.com/vmware/govmomi/cli"
    12  	"github.com/vmware/govmomi/cli/flags"
    13  )
    14  
    15  type markastemplate struct {
    16  	*flags.SearchFlag
    17  }
    18  
    19  func init() {
    20  	cli.Register("vm.markastemplate", &markastemplate{})
    21  }
    22  
    23  func (cmd *markastemplate) Register(ctx context.Context, f *flag.FlagSet) {
    24  	cmd.SearchFlag, ctx = flags.NewSearchFlag(ctx, flags.SearchVirtualMachines)
    25  	cmd.SearchFlag.Register(ctx, f)
    26  }
    27  
    28  func (cmd *markastemplate) Process(ctx context.Context) error {
    29  	if err := cmd.SearchFlag.Process(ctx); err != nil {
    30  		return err
    31  	}
    32  	return nil
    33  }
    34  
    35  func (cmd *markastemplate) Usage() string {
    36  	return "VM..."
    37  }
    38  
    39  func (cmd *markastemplate) Description() string {
    40  	return `Mark VM as a virtual machine template.
    41  
    42  Examples:
    43    govc vm.markastemplate $name`
    44  }
    45  
    46  func (cmd *markastemplate) Run(ctx context.Context, f *flag.FlagSet) error {
    47  	vms, err := cmd.VirtualMachines(f.Args())
    48  	if err != nil {
    49  		return err
    50  	}
    51  
    52  	for _, vm := range vms {
    53  		err := vm.MarkAsTemplate(ctx)
    54  		if err != nil {
    55  			return err
    56  		}
    57  	}
    58  
    59  	return nil
    60  }