1
// Copyright 2014, 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
10
"github.com/juju/errors"
11
"gopkg.in/juju/names.v2"
13
"github.com/juju/juju/apiserver/params"
14
"github.com/juju/juju/cmd/juju/block"
15
"github.com/juju/juju/cmd/modelcmd"
18
func NewRetryProvisioningCommand() cmd.Command {
19
return modelcmd.Wrap(&retryProvisioningCommand{})
22
// retryProvisioningCommand updates machines' error status to tell
23
// the provisoner that it should try to re-provision the machine.
24
type retryProvisioningCommand struct {
25
modelcmd.ModelCommandBase
26
Machines []names.MachineTag
27
api RetryProvisioningAPI
30
// RetryProvisioningAPI defines methods on the client API
31
// that the retry-provisioning command calls.
32
type RetryProvisioningAPI interface {
34
RetryProvisioning(machines ...names.MachineTag) ([]params.ErrorResult, error)
37
func (c *retryProvisioningCommand) Info() *cmd.Info {
39
Name: "retry-provisioning",
40
Args: "<machine> [...]",
41
Purpose: "Retries provisioning for failed machines.",
45
func (c *retryProvisioningCommand) Init(args []string) error {
47
return errors.Errorf("no machine specified")
49
c.Machines = make([]names.MachineTag, len(args))
50
for i, arg := range args {
51
if !names.IsValidMachine(arg) {
52
return errors.Errorf("invalid machine %q", arg)
54
if names.IsContainerMachine(arg) {
55
return errors.Errorf("invalid machine %q retry-provisioning does not support containers", arg)
57
c.Machines[i] = names.NewMachineTag(arg)
62
func (c *retryProvisioningCommand) getAPI() (RetryProvisioningAPI, error) {
66
return c.NewAPIClient()
69
func (c *retryProvisioningCommand) Run(context *cmd.Context) error {
70
client, err := c.getAPI()
76
results, err := client.RetryProvisioning(c.Machines...)
78
return block.ProcessBlockedError(err, block.BlockChange)
80
for _, result := range results {
81
if result.Error != nil {
82
fmt.Fprintf(context.Stderr, "%v\n", result.Error)