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