github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/controller/removeblocks.go (about)

     1  // Copyright 2015 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  // NewRemoveBlocksCommand returns a command that allows a controller admin
    14  // to remove blocks from the controller.
    15  func NewRemoveBlocksCommand() cmd.Command {
    16  	return modelcmd.WrapController(&removeBlocksCommand{})
    17  }
    18  
    19  type removeBlocksCommand struct {
    20  	modelcmd.ControllerCommandBase
    21  	api removeBlocksAPI
    22  }
    23  
    24  type removeBlocksAPI interface {
    25  	Close() error
    26  	RemoveBlocks() error
    27  }
    28  
    29  var removeBlocksDoc = `
    30  Remove all blocks in the Juju controller.
    31  
    32  A controller administrator is able to remove all the blocks that have been added
    33  in a Juju controller.
    34  
    35  See Also:
    36      juju help block
    37      juju help unblock
    38  `
    39  
    40  // Info implements Command.Info
    41  func (c *removeBlocksCommand) Info() *cmd.Info {
    42  	return &cmd.Info{
    43  		Name:    "remove-all-blocks",
    44  		Purpose: "remove all blocks in the Juju controller",
    45  		Doc:     removeBlocksDoc,
    46  	}
    47  }
    48  
    49  func (c *removeBlocksCommand) getAPI() (removeBlocksAPI, error) {
    50  	if c.api != nil {
    51  		return c.api, nil
    52  	}
    53  	return c.NewControllerAPIClient()
    54  }
    55  
    56  // Run implements Command.Run
    57  func (c *removeBlocksCommand) Run(ctx *cmd.Context) error {
    58  	client, err := c.getAPI()
    59  	if err != nil {
    60  		return errors.Trace(err)
    61  	}
    62  	defer client.Close()
    63  	return errors.Annotatef(client.RemoveBlocks(), "cannot remove blocks")
    64  }