mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #272 in YUNIONIO/onecloud from ~QUXUAN/onecloud:release/2.2.0 to release/2.2.0
* commit '7c217bc49d7525050f73a87ec73866a642849be4': 避免/tmp目录容量不够
This commit is contained in:
@@ -26,6 +26,7 @@ type Options struct {
|
||||
AdminProject string `help:"Admin project" default:"system" alias:"admin-tenant-name"`
|
||||
CorsHosts []string `help:"List of hostname that allow CORS"`
|
||||
AuthTokenCacheSize uint32 `help:"Auth token Cache Size" default:"2048"`
|
||||
TempPath string `help:"Path for store temp file, at least 40G space" default:"/opt/yunion/tmp"`
|
||||
|
||||
ApplicationID string `help:"Application ID"`
|
||||
RequestWorkerCount int `default:"4" help:"Request worker thread count, default is 4"`
|
||||
|
||||
@@ -81,7 +81,7 @@ type ICloudStoragecache interface {
|
||||
|
||||
CreateIImage(snapshotId, imageName, osType, imageDesc string) (ICloudImage, error)
|
||||
|
||||
DownloadImage(userCred mcclient.TokenCredential, imageId string, extId string) (jsonutils.JSONObject, error)
|
||||
DownloadImage(userCred mcclient.TokenCredential, imageId string, extId string, path string) (jsonutils.JSONObject, error)
|
||||
|
||||
UploadImage(userCred mcclient.TokenCredential, imageId string, osArch, osType, osDist string, extId string, isForce bool) (string, error)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package hostdrivers
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -96,7 +98,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 {
|
||||
|
||||
@@ -3,6 +3,7 @@ package hostdrivers
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -169,7 +171,12 @@ func (self *SAzureHostDriver) 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 {
|
||||
|
||||
@@ -2,6 +2,7 @@ package aliyun
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -253,8 +254,8 @@ func (self *SRegion) createIImage(snapshoutId, imageName, imageDesc string) (str
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SStoragecache) DownloadImage(userCred mcclient.TokenCredential, imageId string, extId string) (jsonutils.JSONObject, error) {
|
||||
return self.downloadImage(userCred, imageId, extId)
|
||||
func (self *SStoragecache) DownloadImage(userCred mcclient.TokenCredential, imageId string, extId string, path string) (jsonutils.JSONObject, error) {
|
||||
return self.downloadImage(userCred, imageId, extId, path)
|
||||
}
|
||||
|
||||
// 定义进度条监听器。
|
||||
@@ -280,9 +281,12 @@ func (listener *OssProgressListener) ProgressChanged(event *oss.ProgressEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SStoragecache) downloadImage(userCred mcclient.TokenCredential, imageId string, extId string) (jsonutils.JSONObject, error) {
|
||||
tmpImageFile := fmt.Sprintf("/opt/cloud/workspace/data/glance/image-cache/%s", extId)
|
||||
defer os.Remove(tmpImageFile)
|
||||
func (self *SStoragecache) downloadImage(userCred mcclient.TokenCredential, imageId string, extId string, path string) (jsonutils.JSONObject, error) {
|
||||
tmpImageFile, err := ioutil.TempFile(path, extId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer os.Remove(tmpImageFile.Name())
|
||||
bucketName := strings.ToLower(fmt.Sprintf("imgcache-%s", self.region.GetId()))
|
||||
if bucket, err := self.region.checkBucket(bucketName); err != nil {
|
||||
return nil, err
|
||||
@@ -296,12 +300,12 @@ func (self *SStoragecache) downloadImage(userCred mcclient.TokenCredential, imag
|
||||
return nil, err
|
||||
} else if len(imageList.Objects) != 1 {
|
||||
return nil, httperrors.NewResourceNotFoundError("exported image not find")
|
||||
} else if err := bucket.DownloadFile(imageList.Objects[0].Key, tmpImageFile, 12*1024*1024, oss.Routines(3), oss.Progress(&OssProgressListener{})); err != nil {
|
||||
} else if err := bucket.DownloadFile(imageList.Objects[0].Key, tmpImageFile.Name(), 12*1024*1024, oss.Routines(3), oss.Progress(&OssProgressListener{})); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
s := auth.GetAdminSession(options.Options.Region, "")
|
||||
params := jsonutils.Marshal(map[string]string{"image_id": imageId, "disk-format": "raw"})
|
||||
if file, err := os.Open(tmpImageFile); err != nil {
|
||||
if file, err := os.Open(tmpImageFile.Name()); err != nil {
|
||||
return nil, err
|
||||
} else if result, err := modules.Images.Upload(s, params, file, imageList.Objects[0].Size); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -3,6 +3,7 @@ package azure
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -172,11 +173,11 @@ func (self *SStoragecache) CreateIImage(snapshotId, imageName, osType, imageDesc
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SStoragecache) DownloadImage(userCred mcclient.TokenCredential, imageId string, extId string) (jsonutils.JSONObject, error) {
|
||||
return self.downloadImage(userCred, imageId, extId)
|
||||
func (self *SStoragecache) DownloadImage(userCred mcclient.TokenCredential, imageId string, extId string, path string) (jsonutils.JSONObject, error) {
|
||||
return self.downloadImage(userCred, imageId, extId, path)
|
||||
}
|
||||
|
||||
func (self *SStoragecache) downloadImage(userCred mcclient.TokenCredential, imageId string, extId string) (jsonutils.JSONObject, error) {
|
||||
func (self *SStoragecache) downloadImage(userCred mcclient.TokenCredential, imageId string, extId string, path string) (jsonutils.JSONObject, error) {
|
||||
if image, err := self.region.GetImage(extId); err != nil {
|
||||
return nil, err
|
||||
} else if snapshotId := image.Properties.StorageProfile.OsDisk.Snapshot.ID; len(snapshotId) == 0 {
|
||||
@@ -187,9 +188,12 @@ func (self *SStoragecache) downloadImage(userCred mcclient.TokenCredential, imag
|
||||
return nil, err
|
||||
} else {
|
||||
_, _, snapshot := pareResourceGroupWithName(snapshotId, SNAPSHOT_RESOURCE)
|
||||
tmpImageFile := fmt.Sprintf("/opt/cloud/workspace/data/glance/image-cache/%s", snapshot)
|
||||
defer os.Remove(tmpImageFile)
|
||||
if f, err := os.Create(tmpImageFile); err != nil {
|
||||
tmpImageFile, err := ioutil.TempFile(path, snapshot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer os.Remove(tmpImageFile.Name())
|
||||
if f, err := os.Open(tmpImageFile.Name()); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
readed, writed, skiped := 0, 0, 0
|
||||
@@ -230,7 +234,7 @@ func (self *SStoragecache) downloadImage(userCred mcclient.TokenCredential, imag
|
||||
|
||||
s := auth.GetAdminSession(options.Options.Region, "")
|
||||
params := jsonutils.Marshal(map[string]string{"image_id": imageId, "disk-format": "raw"})
|
||||
if file, err := os.Open(tmpImageFile); err != nil {
|
||||
if file, err := os.Open(tmpImageFile.Name()); err != nil {
|
||||
return nil, err
|
||||
} else if result, err := modules.Images.Upload(s, params, file, resp.ContentLength); err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user