-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20023 from zexi/container-save-vm-image
feat(container): save volume_mount to image
- Loading branch information
Showing
11 changed files
with
294 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
pkg/compute/tasks/container_save_volume_mount_image_task.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package tasks | ||
|
||
import ( | ||
"context" | ||
|
||
"yunion.io/x/jsonutils" | ||
|
||
api "yunion.io/x/onecloud/pkg/apis/compute" | ||
"yunion.io/x/onecloud/pkg/cloudcommon/db" | ||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" | ||
"yunion.io/x/onecloud/pkg/compute/models" | ||
) | ||
|
||
func init() { | ||
taskman.RegisterTask(ContainerSaveVolumeMountImageTask{}) | ||
} | ||
|
||
type ContainerSaveVolumeMountImageTask struct { | ||
ContainerBaseTask | ||
} | ||
|
||
func (t *ContainerSaveVolumeMountImageTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) { | ||
t.requestSaveImage(ctx, obj.(*models.SContainer)) | ||
} | ||
|
||
func (t *ContainerSaveVolumeMountImageTask) requestSaveImage(ctx context.Context, container *models.SContainer) { | ||
t.SetStage("OnImageSaved", nil) | ||
if err := t.GetPodDriver().RequestSaveVolumeMountImage(ctx, t.GetUserCred(), t); err != nil { | ||
t.OnImageSavedFailed(ctx, container, jsonutils.NewString(err.Error())) | ||
return | ||
} | ||
} | ||
|
||
func (t *ContainerSaveVolumeMountImageTask) OnImageSaved(ctx context.Context, container *models.SContainer, data jsonutils.JSONObject) { | ||
t.SetStage("OnSyncStatus", nil) | ||
container.StartSyncStatusTask(ctx, t.GetUserCred(), t.GetTaskId()) | ||
} | ||
|
||
func (t *ContainerSaveVolumeMountImageTask) OnImageSavedFailed(ctx context.Context, container *models.SContainer, reason jsonutils.JSONObject) { | ||
container.SetStatus(ctx, t.GetUserCred(), api.CONTAINER_STATUS_SAVE_IMAGE_FAILED, reason.String()) | ||
t.SetStageFailed(ctx, reason) | ||
} | ||
|
||
func (t *ContainerSaveVolumeMountImageTask) OnSyncStatus(ctx context.Context, container *models.SContainer, data jsonutils.JSONObject) { | ||
t.SetStageComplete(ctx, nil) | ||
} | ||
func (t *ContainerSaveVolumeMountImageTask) OnSyncStatusFailed(ctx context.Context, container *models.SContainer, reason jsonutils.JSONObject) { | ||
t.SetStageFailed(ctx, reason) | ||
} |
Oops, something went wrong.