~juju-qa/ubuntu/yakkety/juju/2.0-beta12

« back to all changes in this revision

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

  • Committer: Nicholas Skaggs
  • Date: 2016-07-18 18:41:24 UTC
  • mfrom: (1.4.5)
  • Revision ID: nicholas.skaggs@canonical.com-20160718184124-76sg7nr3zf2o6o63
* New upstream release 2.0-beta12
* Update debian/copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
var usageShowControllerDetails = `
22
22
Shows extended information about a controller(s) as well as related models
23
 
and accounts. The active model and user accounts are also displayed.
 
23
and user login details.
24
24
 
25
25
Examples:
26
26
    juju show-controller
57
57
// SetFlags implements Command.SetFlags.
58
58
func (c *showControllerCommand) SetFlags(f *gnuflag.FlagSet) {
59
59
        c.JujuCommandBase.SetFlags(f)
60
 
        f.BoolVar(&c.showPasswords, "show-passwords", false, "Show passwords for displayed accounts")
 
60
        f.BoolVar(&c.showPasswords, "show-password", false, "Show password for logged in user")
61
61
        c.out.AddFlags(f, "yaml", map[string]cmd.Formatter{
62
62
                "yaml": cmd.FormatYaml,
63
63
                "json": cmd.FormatJson,
91
91
        // Details contains the same details that client store caches for this controller.
92
92
        Details ControllerDetails `yaml:"details,omitempty" json:"details,omitempty"`
93
93
 
94
 
        // Accounts is a collection of accounts for this controller.
95
 
        Accounts map[string]*AccountDetails `yaml:"accounts,omitempty" json:"accounts,omitempty"`
96
 
 
97
 
        // CurrentAccount is the name of the current account for this controller.
98
 
        CurrentAccount string `yaml:"current-account,omitempty" json:"current-account,omitempty"`
 
94
        // Models is a collection of all models for this controller.
 
95
        Models map[string]ModelDetails `yaml:"models,omitempty" json:"models,omitempty"`
 
96
 
 
97
        // CurrentModel is the name of the current model for this controller
 
98
        CurrentModel string `yaml:"current-model,omitempty" json:"current-model,omitempty"`
 
99
 
 
100
        // Account is the account details for the user logged into this controller.
 
101
        Account *AccountDetails `yaml:"account,omitempty" json:"account,omitempty"`
99
102
 
100
103
        // BootstrapConfig contains the bootstrap configuration for this controller.
101
104
        // This is only available on the client that bootstrapped the controller.
136
139
 
137
140
        // Password is the password for the account.
138
141
        Password string `yaml:"password,omitempty" json:"password,omitempty"`
139
 
 
140
 
        // Models is a collection of all models for this controller.
141
 
        Models map[string]ModelDetails `yaml:"models,omitempty" json:"models,omitempty"`
142
 
 
143
 
        // CurrentModel is the name of the current model for this controller
144
 
        CurrentModel string `yaml:"current-model,omitempty" json:"current-model,omitempty"`
145
142
}
146
143
 
147
144
// BootstrapConfig holds the configuration used to bootstrap a controller.
165
162
                        CloudRegion:    details.CloudRegion,
166
163
                },
167
164
        }
 
165
        c.convertModelsForShow(controllerName, &controller)
168
166
        c.convertAccountsForShow(controllerName, &controller)
169
167
        c.convertBootstrapConfigForShow(controllerName, &controller)
170
168
        return controller
171
169
}
172
170
 
173
171
func (c *showControllerCommand) convertAccountsForShow(controllerName string, controller *ShowControllerDetails) {
174
 
        accounts, err := c.store.AllAccounts(controllerName)
175
 
        if err != nil && !errors.IsNotFound(err) {
176
 
                controller.Errors = append(controller.Errors, err.Error())
177
 
        }
178
 
 
179
 
        if len(accounts) > 0 {
180
 
                controller.Accounts = make(map[string]*AccountDetails)
181
 
                for accountName, account := range accounts {
182
 
                        details := &AccountDetails{User: account.User}
183
 
                        controller.Accounts[accountName] = details
184
 
                        if c.showPasswords {
185
 
                                details.Password = account.Password
186
 
                        }
187
 
                        if err := c.convertModelsForShow(controllerName, accountName, details); err != nil {
188
 
                                controller.Errors = append(controller.Errors, err.Error())
189
 
                        }
190
 
                }
191
 
        }
192
 
 
193
 
        controller.CurrentAccount, err = c.store.CurrentAccount(controllerName)
194
 
        if err != nil && !errors.IsNotFound(err) {
195
 
                controller.Errors = append(controller.Errors, err.Error())
196
 
        }
 
172
        storeDetails, err := c.store.AccountDetails(controllerName)
 
173
        if err != nil && !errors.IsNotFound(err) {
 
174
                controller.Errors = append(controller.Errors, err.Error())
 
175
        }
 
176
        if storeDetails == nil {
 
177
                return
 
178
        }
 
179
        details := &AccountDetails{
 
180
                User: storeDetails.User,
 
181
        }
 
182
        if c.showPasswords {
 
183
                details.Password = storeDetails.Password
 
184
        }
 
185
        controller.Account = details
197
186
}
198
187
 
199
 
func (c *showControllerCommand) convertModelsForShow(controllerName, accountName string, account *AccountDetails) error {
200
 
        models, err := c.store.AllModels(controllerName, accountName)
 
188
func (c *showControllerCommand) convertModelsForShow(controllerName string, controller *ShowControllerDetails) {
 
189
        models, err := c.store.AllModels(controllerName)
201
190
        if errors.IsNotFound(err) {
202
 
                return nil
 
191
                return
203
192
        } else if err != nil {
204
 
                return err
 
193
                controller.Errors = append(controller.Errors, err.Error())
 
194
                return
205
195
        }
206
196
        if len(models) > 0 {
207
 
                account.Models = make(map[string]ModelDetails)
 
197
                controller.Models = make(map[string]ModelDetails)
208
198
                for modelName, model := range models {
209
 
                        account.Models[modelName] = ModelDetails{model.ModelUUID}
 
199
                        controller.Models[modelName] = ModelDetails{model.ModelUUID}
210
200
                }
211
201
        }
212
 
        account.CurrentModel, err = c.store.CurrentModel(controllerName, accountName)
 
202
        controller.CurrentModel, err = c.store.CurrentModel(controllerName)
213
203
        if err != nil && !errors.IsNotFound(err) {
214
 
                return err
 
204
                controller.Errors = append(controller.Errors, err.Error())
 
205
                return
215
206
        }
216
 
        return nil
217
207
}
218
208
 
219
209
func (c *showControllerCommand) convertBootstrapConfigForShow(controllerName string, controller *ShowControllerDetails) {