mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): update the image status to save_fail when OnImageSavedFailed (#23140)
This commit is contained in:
@@ -18,11 +18,18 @@ import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
hostapi "yunion.io/x/onecloud/pkg/apis/host"
|
||||
imageapi "yunion.io/x/onecloud/pkg/apis/image"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/compute/options"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/image"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -51,7 +58,19 @@ func (t *ContainerSaveVolumeMountImageTask) OnImageSaved(ctx context.Context, co
|
||||
}
|
||||
|
||||
func (t *ContainerSaveVolumeMountImageTask) OnImageSavedFailed(ctx context.Context, container *models.SContainer, reason jsonutils.JSONObject) {
|
||||
input := &hostapi.ContainerSaveVolumeMountToImageInput{}
|
||||
t.GetParams().Unmarshal(input)
|
||||
container.SetStatus(ctx, t.GetUserCred(), api.CONTAINER_STATUS_SAVE_IMAGE_FAILED, reason.String())
|
||||
if input.ImageId != "" {
|
||||
s := auth.GetSession(ctx, t.GetUserCred(), options.Options.Region)
|
||||
imgStatus := apis.PerformStatusInput{
|
||||
Status: imageapi.IMAGE_STATUS_SAVE_FAIL,
|
||||
Reason: reason.String(),
|
||||
}
|
||||
if _, err := image.Images.PerformAction(s, input.ImageId, "status", jsonutils.Marshal(imgStatus)); err != nil {
|
||||
log.Warningf("update image %s status failed: %v", input.ImageId, err)
|
||||
}
|
||||
}
|
||||
t.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
|
||||
@@ -2430,7 +2430,10 @@ func (s *sPodGuestInstance) tarGzDir(input *hostapi.ContainerSaveVolumeMountToIm
|
||||
outputFp := filepath.Join(s.GetVolumesDir(), fp)
|
||||
dirPath := "."
|
||||
if len(input.VolumeMountDirs) != 0 {
|
||||
dirPath = strings.Join(input.VolumeMountDirs, " ")
|
||||
dirPath = ""
|
||||
for _, vd := range input.VolumeMountDirs {
|
||||
dirPath = fmt.Sprintf("%s '%s'", dirPath, vd)
|
||||
}
|
||||
}
|
||||
|
||||
// 计算总字节数,兼容多个目录/文件
|
||||
|
||||
Reference in New Issue
Block a user