134
134
return results, nil
137
// ModelMigrationSpec holds the details required to start the
138
// migration of a single model.
139
type ModelMigrationSpec struct {
141
TargetControllerUUID string
145
TargetPassword string
148
// Validate performs sanity checks on the migration configuration it
150
func (s *ModelMigrationSpec) Validate() error {
151
if !names.IsValidModel(s.ModelUUID) {
152
return errors.NotValidf("model UUID")
154
if !names.IsValidModel(s.TargetControllerUUID) {
155
return errors.NotValidf("controller UUID")
157
if len(s.TargetAddrs) < 1 {
158
return errors.NotValidf("empty target API addresses")
160
if s.TargetCACert == "" {
161
return errors.NotValidf("empty target CA cert")
163
if !names.IsValidUser(s.TargetUser) {
164
return errors.NotValidf("target user")
166
if s.TargetPassword == "" {
167
return errors.NotValidf("empty target password")
172
// InitiateModelMigration attempts to start a migration for the
173
// specified model, returning the migration's ID.
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)
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,
194
response := params.InitiateModelMigrationResults{}
195
if err := c.facade.FacadeCall("InitiateModelMigration", args, &response); err != nil {
196
return "", errors.Trace(err)
198
if len(response.Results) != 1 {
199
return "", errors.New("unexpected number of results returned")
201
result := response.Results[0]
202
if result.Error != nil {
203
return "", errors.Trace(result.Error)
205
return result.Id, nil