github.com/hernad/nomad@v1.6.112/command/quota.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package command
     5  
     6  import (
     7  	"strings"
     8  
     9  	"github.com/hernad/nomad/api/contexts"
    10  	"github.com/mitchellh/cli"
    11  	"github.com/posener/complete"
    12  )
    13  
    14  type QuotaCommand struct {
    15  	Meta
    16  }
    17  
    18  func (f *QuotaCommand) Help() string {
    19  	helpText := `
    20  Usage: nomad quota <subcommand> [options] [args]
    21  
    22    This command groups subcommands for interacting with resource quotas. Resource
    23    quotas allow operators to restrict the aggregate resource usage of namespaces.
    24    Users can inspect existing quota specifications, create new quotas, delete and
    25    list existing quotas, and more. For a full guide on resource quotas see:
    26    https://www.nomadproject.io/guides/quotas.html
    27  
    28    Examine a quota's status:
    29  
    30        $ nomad quota status <name>
    31  
    32    List existing quotas:
    33  
    34        $ nomad quota list
    35  
    36    Create a new quota specification:
    37  
    38        $ nomad quota apply <path>
    39  
    40    Please see the individual subcommand help for detailed usage information.
    41  `
    42  
    43  	return strings.TrimSpace(helpText)
    44  }
    45  
    46  func (f *QuotaCommand) Synopsis() string {
    47  	return "Interact with quotas"
    48  }
    49  
    50  func (f *QuotaCommand) Name() string { return "quota" }
    51  
    52  func (f *QuotaCommand) Run(args []string) int {
    53  	return cli.RunResultHelp
    54  }
    55  
    56  // QuotaPredictor returns a quota predictor
    57  func QuotaPredictor(factory ApiClientFactory) complete.Predictor {
    58  	return complete.PredictFunc(func(a complete.Args) []string {
    59  		client, err := factory()
    60  		if err != nil {
    61  			return nil
    62  		}
    63  
    64  		resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Quotas, nil)
    65  		if err != nil {
    66  			return []string{}
    67  		}
    68  		return resp.Matches[contexts.Quotas]
    69  	})
    70  }