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

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/api/controller/controller.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
133
133
        }
134
134
        return results, nil
135
135
}
 
136
 
 
137
// ModelMigrationSpec holds the details required to start the
 
138
// migration of a single model.
 
139
type ModelMigrationSpec struct {
 
140
        ModelUUID            string
 
141
        TargetControllerUUID string
 
142
        TargetAddrs          []string
 
143
        TargetCACert         string
 
144
        TargetUser           string
 
145
        TargetPassword       string
 
146
}
 
147
 
 
148
// Validate performs sanity checks on the migration configuration it
 
149
// holds.
 
150
func (s *ModelMigrationSpec) Validate() error {
 
151
        if !names.IsValidModel(s.ModelUUID) {
 
152
                return errors.NotValidf("model UUID")
 
153
        }
 
154
        if !names.IsValidModel(s.TargetControllerUUID) {
 
155
                return errors.NotValidf("controller UUID")
 
156
        }
 
157
        if len(s.TargetAddrs) < 1 {
 
158
                return errors.NotValidf("empty target API addresses")
 
159
        }
 
160
        if s.TargetCACert == "" {
 
161
                return errors.NotValidf("empty target CA cert")
 
162
        }
 
163
        if !names.IsValidUser(s.TargetUser) {
 
164
                return errors.NotValidf("target user")
 
165
        }
 
166
        if s.TargetPassword == "" {
 
167
                return errors.NotValidf("empty target password")
 
168
        }
 
169
        return nil
 
170
}
 
171
 
 
172
// InitiateModelMigration attempts to start a migration for the
 
173
// specified model, returning the migration's ID.
 
174
//
 
175
// The API server supports starting multiple migrations in one request
 
176
// but we don't need that at the client side yet (and may never) so
 
177
// this call just supports starting one migration at a time.
 
178
func (c *Client) InitiateModelMigration(spec ModelMigrationSpec) (string, error) {
 
179
        if err := spec.Validate(); err != nil {
 
180
                return "", errors.Trace(err)
 
181
        }
 
182
        args := params.InitiateModelMigrationArgs{
 
183
                Specs: []params.ModelMigrationSpec{{
 
184
                        ModelTag: names.NewModelTag(spec.ModelUUID).String(),
 
185
                        TargetInfo: params.ModelMigrationTargetInfo{
 
186
                                ControllerTag: names.NewModelTag(spec.TargetControllerUUID).String(),
 
187
                                Addrs:         spec.TargetAddrs,
 
188
                                CACert:        spec.TargetCACert,
 
189
                                AuthTag:       names.NewUserTag(spec.TargetUser).String(),
 
190
                                Password:      spec.TargetPassword,
 
191
                        },
 
192
                }},
 
193
        }
 
194
        response := params.InitiateModelMigrationResults{}
 
195
        if err := c.facade.FacadeCall("InitiateModelMigration", args, &response); err != nil {
 
196
                return "", errors.Trace(err)
 
197
        }
 
198
        if len(response.Results) != 1 {
 
199
                return "", errors.New("unexpected number of results returned")
 
200
        }
 
201
        result := response.Results[0]
 
202
        if result.Error != nil {
 
203
                return "", errors.Trace(result.Error)
 
204
        }
 
205
        return result.Id, nil
 
206
}