github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/cmd/juju/commands/resolved.go (about)

     1  // Copyright 2012, 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package commands
     5  
     6  import (
     7  	"github.com/juju/cmd"
     8  	"github.com/juju/errors"
     9  	"github.com/juju/gnuflag"
    10  	"gopkg.in/juju/names.v2"
    11  
    12  	"github.com/juju/juju/cmd/juju/block"
    13  	"github.com/juju/juju/cmd/modelcmd"
    14  )
    15  
    16  func newResolvedCommand() cmd.Command {
    17  	return modelcmd.Wrap(&resolvedCommand{})
    18  }
    19  
    20  // resolvedCommand marks a unit in an error state as ready to continue.
    21  type resolvedCommand struct {
    22  	modelcmd.ModelCommandBase
    23  	UnitName string
    24  	NoRetry  bool
    25  }
    26  
    27  func (c *resolvedCommand) Info() *cmd.Info {
    28  	return &cmd.Info{
    29  		Name:    "resolved",
    30  		Args:    "<unit>",
    31  		Purpose: "Marks unit errors resolved and re-executes failed hooks",
    32  	}
    33  }
    34  
    35  func (c *resolvedCommand) SetFlags(f *gnuflag.FlagSet) {
    36  	c.ModelCommandBase.SetFlags(f)
    37  	f.BoolVar(&c.NoRetry, "no-retry", false, "Do not re-execute failed hooks on the unit")
    38  }
    39  
    40  func (c *resolvedCommand) Init(args []string) error {
    41  	if len(args) > 0 {
    42  		c.UnitName = args[0]
    43  		if !names.IsValidUnit(c.UnitName) {
    44  			return errors.Errorf("invalid unit name %q", c.UnitName)
    45  		}
    46  		args = args[1:]
    47  	} else {
    48  		return errors.Errorf("no unit specified")
    49  	}
    50  	return cmd.CheckEmpty(args)
    51  }
    52  
    53  func (c *resolvedCommand) Run(_ *cmd.Context) error {
    54  	client, err := c.NewAPIClient()
    55  	if err != nil {
    56  		return err
    57  	}
    58  	defer client.Close()
    59  	return block.ProcessBlockedError(client.Resolved(c.UnitName, c.NoRetry), block.BlockChange)
    60  }