~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/juju/controller/destroy.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
        "github.com/juju/cmd"
15
15
        "github.com/juju/errors"
16
16
        "github.com/juju/gnuflag"
 
17
        "github.com/juju/utils/clock"
17
18
        "gopkg.in/juju/names.v2"
18
19
 
19
20
        "github.com/juju/juju/api/base"
75
76
type destroyControllerAPI interface {
76
77
        Close() error
77
78
        ModelConfig() (map[string]interface{}, error)
 
79
        HostedModelConfigs() ([]controller.HostedConfig, error)
78
80
        CloudSpec(names.ModelTag) (environs.CloudSpec, error)
79
81
        DestroyController(destroyModels bool) error
80
82
        ListBlockedModels() ([]params.ModelBlockInfo, error)
125
127
        defer api.Close()
126
128
 
127
129
        // Obtain controller environ so we can clean up afterwards.
128
 
        controllerEnviron, err := c.getControllerEnviron(store, controllerName, api)
 
130
        controllerEnviron, err := c.getControllerEnviron(ctx, store, controllerName, api)
129
131
        if err != nil {
130
132
                return errors.Annotate(err, "getting controller environ")
131
133
        }
146
148
                        }
147
149
                }
148
150
 
149
 
                updateStatus := newTimedStatusUpdater(ctx, api, controllerEnviron.Config().UUID())
 
151
                updateStatus := newTimedStatusUpdater(ctx, api, controllerEnviron.Config().UUID(), clock.WallClock)
150
152
                ctrStatus, modelsStatus := updateStatus(0)
151
153
                if !c.destroyModels {
152
154
                        if err := c.checkNoAliveHostedModels(ctx, modelsStatus); err != nil {
186
188
        // and there are models still alive.
187
189
        var buf bytes.Buffer
188
190
        for _, model := range models {
189
 
                if model.Life != params.Alive {
 
191
                if model.Life != string(params.Alive) {
190
192
                        continue
191
193
                }
192
194
                buf.WriteString(fmtModelStatus(model))
308
310
// Environ by first checking the config store, then querying the
309
311
// API if the information is not in the store.
310
312
func (c *destroyCommandBase) getControllerEnviron(
 
313
        ctx *cmd.Context,
311
314
        store jujuclient.ClientStore,
312
315
        controllerName string,
313
316
        sysAPI destroyControllerAPI,
314
317
) (environs.Environ, error) {
315
 
        env, err := c.getControllerEnvironFromStore(store, controllerName)
 
318
        env, err := c.getControllerEnvironFromStore(ctx, store, controllerName)
316
319
        if errors.IsNotFound(err) {
317
320
                return c.getControllerEnvironFromAPI(sysAPI, controllerName)
318
321
        } else if err != nil {
322
325
}
323
326
 
324
327
func (c *destroyCommandBase) getControllerEnvironFromStore(
 
328
        ctx *cmd.Context,
325
329
        store jujuclient.ClientStore,
326
330
        controllerName string,
327
331
) (environs.Environ, error) {
328
 
        bootstrapConfig, params, err := modelcmd.NewGetBootstrapConfigParamsFunc(store)(controllerName)
 
332
        bootstrapConfig, params, err := modelcmd.NewGetBootstrapConfigParamsFunc(ctx, store)(controllerName)
329
333
        if err != nil {
330
334
                return nil, errors.Trace(err)
331
335
        }