mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
避免/tmp目录容量不够
This commit is contained in:
+17
-16
@@ -4,11 +4,12 @@ import (
|
||||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
|
||||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
|
||||
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -205,11 +206,11 @@ func (self *SAliyunClient) GetIStoragecacheById(id string) (cloudprovider.ICloud
|
||||
}
|
||||
|
||||
type SAccountBalance struct {
|
||||
AvailableAmount float64
|
||||
AvailableAmount float64
|
||||
AvailableCashAmount float64
|
||||
CreditAmount float64
|
||||
MybankCreditAmount float64
|
||||
Currency string
|
||||
CreditAmount float64
|
||||
MybankCreditAmount float64
|
||||
Currency string
|
||||
}
|
||||
|
||||
type SCashCoupon struct {
|
||||
@@ -226,15 +227,15 @@ type SCashCoupon struct {
|
||||
}
|
||||
|
||||
type SPrepaidCard struct {
|
||||
PrepaidCardId string
|
||||
PrepaidCardNo string
|
||||
GrantedTime time.Time
|
||||
EffectiveTime time.Time
|
||||
ExpiryTime time.Time
|
||||
NominalValue float64
|
||||
Balance float64
|
||||
ApplicableProducts string
|
||||
ApplicableScenarios string
|
||||
PrepaidCardId string
|
||||
PrepaidCardNo string
|
||||
GrantedTime time.Time
|
||||
EffectiveTime time.Time
|
||||
ExpiryTime time.Time
|
||||
NominalValue float64
|
||||
Balance float64
|
||||
ApplicableProducts string
|
||||
ApplicableScenarios string
|
||||
}
|
||||
|
||||
func (self *SAliyunClient) QueryAccountBalance() (*SAccountBalance, error) {
|
||||
@@ -272,7 +273,7 @@ func (self *SAliyunClient) QueryCashCoupons() ([]SCashCoupon, error) {
|
||||
func (self *SAliyunClient) QueryPrepaidCards() ([]SPrepaidCard, error) {
|
||||
params := make(map[string]string)
|
||||
params["EffectiveOrNot"] = "True"
|
||||
body, err := self.businessRequest("QueryPrepaidCards", params)
|
||||
body, err := self.businessRequest("QueryPrepaidCards", params)
|
||||
if err != nil {
|
||||
log.Errorf("QueryPrepaidCards fail %s", err)
|
||||
return nil, err
|
||||
@@ -284,4 +285,4 @@ func (self *SAliyunClient) QueryPrepaidCards() ([]SPrepaidCard, error) {
|
||||
return nil, err
|
||||
}
|
||||
return cards, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package aliyun
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
@@ -252,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)
|
||||
}
|
||||
|
||||
// 定义进度条监听器。
|
||||
@@ -279,8 +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("/tmp/%s", extId)
|
||||
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
|
||||
@@ -294,17 +300,16 @@ 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
|
||||
} else {
|
||||
os.Remove(tmpImageFile)
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user