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

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package controller
     5  
     6  import (
     7  	"github.com/juju/cmd"
     8  	"github.com/juju/errors"
     9  
    10  	"github.com/juju/juju/cmd/modelcmd"
    11  )
    12  
    13  // NewEnableDestroyControllerCommand returns a command that allows a controller admin
    14  // to remove blocks from the controller.
    15  func NewEnableDestroyControllerCommand() cmd.Command {
    16  	return modelcmd.WrapController(&enableDestroyController{})
    17  }
    18  
    19  type enableDestroyController struct {
    20  	modelcmd.ControllerCommandBase
    21  	api removeBlocksAPI
    22  }
    23  
    24  type removeBlocksAPI interface {
    25  	Close() error
    26  	RemoveBlocks() error
    27  }
    28  
    29  var enableDestroyDoc = `
    30  Any model in the controller that has disabled commands will block a controller
    31  from being destroyed.
    32  
    33  A controller administrator is able to enable all the commands across all the models
    34  in a Juju controller so that the controller can be destoyed if desired.
    35  
    36  See also:
    37      disable-command
    38      disabled-commands
    39      enable-command
    40  `
    41  
    42  // Info implements Command.Info
    43  func (c *enableDestroyController) Info() *cmd.Info {
    44  	return &cmd.Info{
    45  		Name:    "enable-destroy-controller",
    46  		Purpose: "Enable destroy-controller by removing disabled commands in the controller.",
    47  		Doc:     enableDestroyDoc,
    48  	}
    49  }
    50  
    51  func (c *enableDestroyController) getAPI() (removeBlocksAPI, error) {
    52  	if c.api != nil {
    53  		return c.api, nil
    54  	}
    55  	return c.NewControllerAPIClient()
    56  }
    57  
    58  // Run implements Command.Run
    59  func (c *enableDestroyController) Run(ctx *cmd.Context) error {
    60  	client, err := c.getAPI()
    61  	if err != nil {
    62  		return errors.Trace(err)
    63  	}
    64  	defer client.Close()
    65  	return errors.Trace(client.RemoveBlocks())
    66  }