Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/migration-managerd/internal/api/api_1.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var api10 = []APIEndpoint{
instanceCmd,
instanceOverrideCmd,
instanceResetBackgroundImportCmd,
instanceEnableBackgroundImportCmd,
instancePowerCmd,
instancesCmd,
networkCmd,
networkInstancesCmd,
Expand Down
81 changes: 0 additions & 81 deletions cmd/migration-managerd/internal/api/api_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/FuturFusion/migration-manager/internal/server/auth"
"github.com/FuturFusion/migration-manager/internal/server/response"
"github.com/FuturFusion/migration-manager/internal/server/util"
"github.com/FuturFusion/migration-manager/internal/source"
"github.com/FuturFusion/migration-manager/internal/transaction"
"github.com/FuturFusion/migration-manager/shared/api"
"github.com/FuturFusion/migration-manager/shared/api/event"
Expand All @@ -40,12 +39,6 @@ var instanceOverrideCmd = APIEndpoint{
Put: APIEndpointAction{Handler: instanceOverridePut, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
}

var instanceResetBackgroundImportCmd = APIEndpoint{
Path: "instances/{uuid}/:reset-background-import",

Post: APIEndpointAction{Handler: instanceResetBackgroundImport, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
}

// swagger:operation GET /1.0/instances instances instances_get
//
// Get the instances
Expand Down Expand Up @@ -456,77 +449,3 @@ func instanceOverrideDelete(d *Daemon, r *http.Request) response.Response {

return response.EmptySyncResponse
}

// swagger:operation POST /1.0/instances/{uuid}/:reset-background-import instances instance_reset_background_import
//
// Reactivates instance background import support
//
// Resets background import verification for an instance whose source reports background import support, but could not be verified..
//
// ---
// produces:
// - application/json
// responses:
// "200":
// $ref: "#/responses/EmptySyncResponse"
// "400":
// $ref: "#/responses/BadRequest"
// "403":
// $ref: "#/responses/Forbidden"
// "500":
// $ref: "#/responses/InternalServerError"
func instanceResetBackgroundImport(d *Daemon, r *http.Request) response.Response {
uuidString := r.PathValue("uuid")

instanceUUID, err := uuid.Parse(uuidString)
if err != nil {
return response.BadRequest(err)
}

var apiInstance api.Instance
err = transaction.Do(r.Context(), func(ctx context.Context) error {
inst, err := d.instance.GetByUUID(ctx, instanceUUID)
if err != nil {
return err
}

src, err := d.source.GetByName(ctx, inst.Source)
if err != nil {
return err
}

is, err := source.NewVMSource(src.ToAPI())
if err != nil {
return err
}

err = is.Connect(ctx)
if err != nil {
return err
}

supported, err := is.GetBackgroundImport(ctx, inst.UUID)
if err != nil {
return err
}

if !supported {
return fmt.Errorf("Instance %q (%q) on source %q does not have background import support", inst.UUID, inst.Properties.Location, src.Name)
}

err = d.instance.ResetBackgroundImport(ctx, inst)
if err != nil {
return err
}

apiInstance = inst.ToAPI()
return nil
})
if err != nil {
return response.SmartError(err)
}

d.logHandler.SendLifecycle(r.Context(), event.NewInstanceEvent(event.InstanceModified, r, apiInstance, apiInstance.UUID))

return response.EmptySyncResponse
}
Loading
Loading