Merge pull request #238 in YUNIONIO/onecloud from ~QUXUAN/onecloud:hotfix/qx-save-image to release/2.1.0

* commit '3eea07f2791c9251da1bb504bb3d07de5216b718':
  避免/tmp目录容量不够
This commit is contained in:
邱剑
2018-09-30 12:05:40 +08:00
5 changed files with 40 additions and 27 deletions
+9 -3
View File
@@ -3,14 +3,16 @@ package hostdrivers
import (
"context"
"fmt"
"os"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/compute/options"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
)
type SAliyunHostDriver struct {
@@ -36,7 +38,6 @@ func (self *SAliyunHostDriver) CheckAndSetCacheImage(ctx context.Context, host *
osType, _ := params.GetString("os_type")
osDist, _ := params.GetString("os_distribution")
isForce := jsonutils.QueryBoolean(params, "is_force", false)
userCred := task.GetUserCred()
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
@@ -93,7 +94,12 @@ func (self *SAliyunHostDriver) RequestSaveUploadImageOnHost(ctx context.Context,
return nil, err
} else {
scimg.SetExternalId(iImage.GetId())
if result, err := iStoragecache.DownloadImage(task.GetUserCred(), imageId, iImage.GetId()); err != nil {
if _, err := os.Stat(options.Options.TempPath); os.IsNotExist(err) {
if err = os.MkdirAll(options.Options.TempPath, 0755); err != nil {
return nil, err
}
}
if result, err := iStoragecache.DownloadImage(task.GetUserCred(), imageId, iImage.GetId(), options.Options.TempPath); err != nil {
scimg.SetStatus(task.GetUserCred(), models.CACHED_IMAGE_STATUS_CACHE_FAILED, err.Error())
return nil, err
} else {