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