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

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/api/controller/controller.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:
15
15
        "github.com/juju/juju/api/common"
16
16
        "github.com/juju/juju/api/common/cloudspec"
17
17
        "github.com/juju/juju/apiserver/params"
18
 
        "github.com/juju/juju/core/description"
 
18
        "github.com/juju/juju/environs"
 
19
        "github.com/juju/juju/permission"
19
20
)
20
21
 
21
22
// Client provides methods that the Juju client command uses to interact
75
76
        return values, err
76
77
}
77
78
 
 
79
// HostedConfig contains the model config and the cloud spec for that
 
80
// model such that direct access to the provider can be used.
 
81
type HostedConfig struct {
 
82
        Name      string
 
83
        Owner     names.UserTag
 
84
        Config    map[string]interface{}
 
85
        CloudSpec environs.CloudSpec
 
86
        Error     error
 
87
}
 
88
 
 
89
// HostedModelsConfig returns all model settings for the
 
90
// controller model.
 
91
func (c *Client) HostedModelConfigs() ([]HostedConfig, error) {
 
92
        result := params.HostedModelConfigsResults{}
 
93
        err := c.facade.FacadeCall("HostedModelConfigs", nil, &result)
 
94
        if err != nil {
 
95
                return nil, errors.Trace(err)
 
96
        }
 
97
        // If we get to here, we have some values. Each value may or
 
98
        // may not have an error, but it should at least have a name
 
99
        // and owner.
 
100
        hostedConfigs := make([]HostedConfig, len(result.Models))
 
101
        for i, modelConfig := range result.Models {
 
102
                hostedConfigs[i].Name = modelConfig.Name
 
103
                tag, err := names.ParseUserTag(modelConfig.OwnerTag)
 
104
                if err != nil {
 
105
                        hostedConfigs[i].Error = errors.Trace(err)
 
106
                        continue
 
107
                }
 
108
                hostedConfigs[i].Owner = tag
 
109
                if modelConfig.Error != nil {
 
110
                        hostedConfigs[i].Error = errors.Trace(modelConfig.Error)
 
111
                        continue
 
112
                }
 
113
                hostedConfigs[i].Config = modelConfig.Config
 
114
                spec, err := c.MakeCloudSpec(modelConfig.CloudSpec)
 
115
                if err != nil {
 
116
                        hostedConfigs[i].Error = errors.Trace(err)
 
117
                        continue
 
118
                }
 
119
                hostedConfigs[i].CloudSpec = spec
 
120
        }
 
121
        return hostedConfigs, err
 
122
}
 
123
 
78
124
// DestroyController puts the controller model into a "dying" state,
79
125
// and removes all non-manager machine instances. Underlying DestroyModel
80
126
// calls will fail if there are any manually-provisioned non-manager machines
137
183
 
138
184
                results[i] = base.ModelStatus{
139
185
                        UUID:               model.Id(),
140
 
                        Life:               r.Life,
 
186
                        Life:               string(r.Life),
141
187
                        Owner:              owner.Canonical(),
142
188
                        HostedMachineCount: r.HostedMachineCount,
143
189
                        ServiceCount:       r.ApplicationCount,
197
243
}
198
244
 
199
245
// GetControllerAccess returns the access level the user has on the controller.
200
 
func (c *Client) GetControllerAccess(user string) (description.Access, error) {
 
246
func (c *Client) GetControllerAccess(user string) (permission.Access, error) {
201
247
        if !names.IsValidUser(user) {
202
248
                return "", errors.Errorf("invalid username: %q", user)
203
249
        }
213
259
        if err := results.Results[0].Error; err != nil {
214
260
                return "", errors.Trace(err)
215
261
        }
216
 
        return description.Access(results.Results[0].Result.Access), nil
 
262
        return permission.Access(results.Results[0].Result.Access), nil
217
263
}
218
264
 
219
265
// MigrationSpec holds the details required to start the migration of
220
266
// a single model.
221
267
type MigrationSpec struct {
222
268
        ModelUUID            string
223
 
        ExternalControl      bool
224
269
        TargetControllerUUID string
225
270
        TargetAddrs          []string
226
271
        TargetCACert         string
227
272
        TargetUser           string
228
273
        TargetPassword       string
229
274
        TargetMacaroons      []macaroon.Slice
 
275
        ExternalControl      bool
 
276
        SkipInitialPrechecks bool
230
277
}
231
278
 
232
279
// Validate performs sanity checks on the migration configuration it
273
320
                Specs: []params.MigrationSpec{{
274
321
                        ModelTag: names.NewModelTag(spec.ModelUUID).String(),
275
322
                        TargetInfo: params.MigrationTargetInfo{
276
 
                                ControllerTag: names.NewModelTag(spec.TargetControllerUUID).String(),
 
323
                                ControllerTag: names.NewControllerTag(spec.TargetControllerUUID).String(),
277
324
                                Addrs:         spec.TargetAddrs,
278
325
                                CACert:        spec.TargetCACert,
279
326
                                AuthTag:       names.NewUserTag(spec.TargetUser).String(),
280
327
                                Password:      spec.TargetPassword,
281
328
                                Macaroons:     string(macsJSON),
282
329
                        },
283
 
                        ExternalControl: spec.ExternalControl,
 
330
                        ExternalControl:      spec.ExternalControl,
 
331
                        SkipInitialPrechecks: spec.SkipInitialPrechecks,
284
332
                }},
285
333
        }
286
334
        response := params.InitiateMigrationResults{}