github.com/jrxfive/nomad@v0.6.1-0.20170802162750-1fef470e89bf/command/deployment_resume.go (about)

     1  package command
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  type DeploymentResumeCommand struct {
     9  	Meta
    10  }
    11  
    12  func (c *DeploymentResumeCommand) Help() string {
    13  	helpText := `
    14  Usage: nomad deployment resume [options] <deployment id>
    15  
    16  Resume is used to unpause a paused deployment. Resuming a deployment will
    17  resume the placement of new allocations as part of rolling deployment.
    18  
    19  General Options:
    20  
    21    ` + generalOptionsUsage() + `
    22  
    23  Resume Options:
    24  
    25    -detach
    26      Return immediately instead of entering monitor mode. After deployment
    27      resume, the evaluation ID will be printed to the screen, which can be used
    28      to examine the evaluation using the eval-status command.
    29  
    30    -verbose
    31      Display full information.
    32  `
    33  	return strings.TrimSpace(helpText)
    34  }
    35  
    36  func (c *DeploymentResumeCommand) Synopsis() string {
    37  	return "Resume a paused deployment"
    38  }
    39  
    40  func (c *DeploymentResumeCommand) Run(args []string) int {
    41  	var detach, verbose bool
    42  
    43  	flags := c.Meta.FlagSet("deployment resume", FlagSetClient)
    44  	flags.Usage = func() { c.Ui.Output(c.Help()) }
    45  	flags.BoolVar(&detach, "detach", false, "")
    46  	flags.BoolVar(&verbose, "verbose", false, "")
    47  
    48  	if err := flags.Parse(args); err != nil {
    49  		return 1
    50  	}
    51  
    52  	// Check that we got no arguments
    53  	args = flags.Args()
    54  	if l := len(args); l != 1 {
    55  		c.Ui.Error(c.Help())
    56  		return 1
    57  	}
    58  
    59  	dID := args[0]
    60  
    61  	// Truncate the id unless full length is requested
    62  	length := shortId
    63  	if verbose {
    64  		length = fullId
    65  	}
    66  
    67  	// Get the HTTP client
    68  	client, err := c.Meta.Client()
    69  	if err != nil {
    70  		c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
    71  		return 1
    72  	}
    73  
    74  	// Do a prefix lookup
    75  	deploy, possible, err := getDeployment(client.Deployments(), dID)
    76  	if err != nil {
    77  		c.Ui.Error(fmt.Sprintf("Error retrieving deployment: %s", err))
    78  		return 1
    79  	}
    80  
    81  	if len(possible) != 0 {
    82  		c.Ui.Error(fmt.Sprintf("Prefix matched multiple deployments\n\n%s", formatDeployments(possible, length)))
    83  		return 1
    84  	}
    85  
    86  	u, _, err := client.Deployments().Pause(deploy.ID, false, nil)
    87  	if err != nil {
    88  		c.Ui.Error(fmt.Sprintf("Error resuming deployment: %s", err))
    89  		return 1
    90  	}
    91  
    92  	c.Ui.Output(fmt.Sprintf("Deployment %q resumed", deploy.ID))
    93  	evalCreated := u.EvalID != ""
    94  
    95  	// Nothing to do
    96  	if detach || !evalCreated {
    97  		return 0
    98  	}
    99  
   100  	c.Ui.Output("")
   101  	mon := newMonitor(c.Ui, client, length)
   102  	return mon.monitor(u.EvalID, false)
   103  }