github.com/vmware/govmomi@v0.51.0/cli/namespace/update.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 namespace
     6  
     7  import (
     8  	"context"
     9  	"flag"
    10  
    11  	"github.com/vmware/govmomi/cli"
    12  	"github.com/vmware/govmomi/vapi/namespace"
    13  )
    14  
    15  type update struct {
    16  	*namespaceFlag
    17  
    18  	spec namespace.NamespacesInstanceUpdateSpec
    19  }
    20  
    21  func init() {
    22  	cli.Register("namespace.update", &update{})
    23  }
    24  
    25  func (cmd *update) Register(ctx context.Context, f *flag.FlagSet) {
    26  	cmd.namespaceFlag = &namespaceFlag{}
    27  	cmd.namespaceFlag.Register(ctx, f)
    28  }
    29  
    30  func (cmd *update) Process(ctx context.Context) error {
    31  	if err := cmd.namespaceFlag.Process(ctx); err != nil {
    32  		return err
    33  	}
    34  
    35  	cmd.spec.StorageSpecs = cmd.storageSpec()
    36  	cmd.spec.VmServiceSpec = cmd.vmServiceSpec()
    37  
    38  	return nil
    39  }
    40  
    41  func (cmd *update) Usage() string {
    42  	return "NAME"
    43  }
    44  
    45  func (cmd *update) Description() string {
    46  	return `Modifies an existing vSphere Namespace on a Supervisor.
    47  
    48  Examples:
    49    govc namespace.update -library vmsvc test-namespace
    50    govc namespace.update -library vmsvc -library tkgs -storage wcp-policy test-namespace
    51    govc namespace.update -vmclass best-effort-2xlarge test-namespace
    52    govc namespace.update -vmclass best-effort-2xlarge -vmclass best-effort-4xlarge test-namespace
    53    govc namespace.update -library vmsvc -library tkgs -vmclass best-effort-2xlarge -vmclass best-effort-4xlarge test-namespace`
    54  }
    55  
    56  func (cmd *update) Run(ctx context.Context, f *flag.FlagSet) error {
    57  	if f.NArg() != 1 {
    58  		return flag.ErrHelp
    59  	}
    60  
    61  	rc, err := cmd.RestClient()
    62  	if err != nil {
    63  		return err
    64  	}
    65  
    66  	nm := namespace.NewManager(rc)
    67  
    68  	return nm.UpdateNamespace(ctx, f.Arg(0), cmd.spec)
    69  }