github.com/hernad/nomad@v1.6.112/command/scaling_policy.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package command 5 6 import ( 7 "fmt" 8 "strings" 9 10 "github.com/mitchellh/cli" 11 ) 12 13 // Ensure ScalingPolicyCommand satisfies the cli.Command interface. 14 var _ cli.Command = &ScalingPolicyCommand{} 15 16 // ScalingPolicyCommand implements cli.Command. 17 type ScalingPolicyCommand struct { 18 Meta 19 } 20 21 // Help satisfies the cli.Command Help function. 22 func (s *ScalingPolicyCommand) Help() string { 23 helpText := ` 24 Usage: nomad scaling policy <subcommand> [options] 25 26 This command groups subcommands for interacting with scaling policies. Scaling 27 policies can be used by an external autoscaler to perform scaling actions on 28 Nomad targets. 29 30 List policies: 31 32 $ nomad scaling policy list 33 34 Detail an individual scaling policy: 35 36 $ nomad scaling policy info <policy_id> 37 38 Please see the individual subcommand help for detailed usage information. 39 ` 40 return strings.TrimSpace(helpText) 41 } 42 43 // Synopsis satisfies the cli.Command Synopsis function. 44 func (s *ScalingPolicyCommand) Synopsis() string { 45 return "Interact with Nomad scaling policies" 46 } 47 48 // Name returns the name of this command. 49 func (s *ScalingPolicyCommand) Name() string { return "scaling policy" } 50 51 // Run satisfies the cli.Command Run function. 52 func (s *ScalingPolicyCommand) Run(_ []string) int { return cli.RunResultHelp } 53 54 // formatScalingPolicyTarget is a command helper that correctly formats a 55 // scaling policy target map into a command string output. 56 func formatScalingPolicyTarget(t map[string]string) string { 57 var ns, j, g string 58 var other []string 59 60 for k, v := range t { 61 62 s := fmt.Sprintf("%s:%s", k, v) 63 64 switch strings.ToLower(k) { 65 case "namespace": 66 ns = s 67 case "job": 68 j = s 69 case "group": 70 g = s 71 default: 72 other = append(other, s) 73 } 74 } 75 76 out := []string{ns, j, g} 77 78 if len(other) > 0 { 79 out = append(out, other...) 80 } 81 return strings.Trim(strings.Join(out, ","), ",") 82 }