mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): hcs image import
This commit is contained in:
@@ -84,7 +84,7 @@ require (
|
||||
k8s.io/client-go v0.19.3
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221123072358-1e847337e6bf
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221124020439-ed3f31c9fee1
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656
|
||||
yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd
|
||||
yunion.io/x/log v1.0.0
|
||||
|
||||
@@ -1176,8 +1176,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221123072358-1e847337e6bf h1:GVdFXNiKD7jkYR5ia+HLJBM9E7UoJBPM80PtHdVHDN0=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221123072358-1e847337e6bf/go.mod h1:drc/WDD65r6wI1tSejk19xcl9QwmzZlgJGXN7a9o2KQ=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221124020439-ed3f31c9fee1 h1:EvHqaa3dqrlfAjQXx5d09JbeUS8tgWbwPt3U+hyHdD4=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221124020439-ed3f31c9fee1/go.mod h1:drc/WDD65r6wI1tSejk19xcl9QwmzZlgJGXN7a9o2KQ=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656 h1:0zlZD5uhZoIHgLVAWCz2aHaYk2ZrNsACCYD7R6EIBII=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
@@ -110,10 +110,6 @@ func (self *SHCSGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *mode
|
||||
if !utils.IsInStringArray(guest.Status, []string{api.VM_RUNNING, api.VM_READY}) {
|
||||
return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status)
|
||||
}
|
||||
if !utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_HUAWEI_SATA, api.STORAGE_HUAWEI_SAS, api.STORAGE_HUAWEI_SSD}) {
|
||||
return fmt.Errorf("Cannot resize disk with unsupported volumes type %s", storage.StorageType)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -136,6 +136,7 @@ func (self *SManagedVirtualizationHostDriver) CheckAndSetCacheImage(ctx context.
|
||||
log.Debugf("UploadImage: no external ID")
|
||||
return iStorageCache.UploadImage(ctx, image, callback)
|
||||
}()
|
||||
log.Infof("upload image %s id: %s", image.ImageName, image.ExternalId)
|
||||
} else {
|
||||
_, err = iStorageCache.GetIImageById(cachedImage.ExternalId)
|
||||
if err != nil {
|
||||
@@ -143,6 +144,9 @@ func (self *SManagedVirtualizationHostDriver) CheckAndSetCacheImage(ctx context.
|
||||
}
|
||||
image.ExternalId = cachedImage.ExternalId
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// should record the externalId immediately
|
||||
// so the waiting goroutine could pick the new externalId
|
||||
|
||||
@@ -1035,13 +1035,17 @@ func (disk *SDisk) doResize(ctx context.Context, userCred mcclient.TokenCredenti
|
||||
if storage == nil {
|
||||
return httperrors.NewInternalServerError("disk has no valid storage")
|
||||
}
|
||||
var guestdriver IGuestDriver
|
||||
if host, _ := storage.GetMasterHost(); host != nil {
|
||||
if err := host.GetHostDriver().ValidateDiskSize(storage, sizeMb>>10); err != nil {
|
||||
return httperrors.NewInputParameterError("%v", err)
|
||||
}
|
||||
guestdriver = GetDriver(api.HOSTTYPE_HYPERVISOR[host.HostType])
|
||||
}
|
||||
if int64(addDisk) > storage.GetFreeCapacity() && !storage.IsEmulated {
|
||||
return httperrors.NewOutOfResourceError("Not enough free space")
|
||||
if guestdriver == nil || guestdriver.DoScheduleStorageFilter() {
|
||||
if int64(addDisk) > storage.GetFreeCapacity() && !storage.IsEmulated {
|
||||
return httperrors.NewOutOfResourceError("Not enough free space")
|
||||
}
|
||||
}
|
||||
if guest != nil {
|
||||
if err := guest.ValidateResizeDisk(disk, storage); err != nil {
|
||||
|
||||
Vendored
+1
-1
@@ -1439,7 +1439,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221123072358-1e847337e6bf
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221124020439-ed3f31c9fee1
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+29
@@ -818,3 +818,32 @@ func (self *SRegion) GetIBuckets() ([]cloudprovider.ICloudBucket, error) {
|
||||
func (region *SRegion) GetIBucketById(name string) (cloudprovider.ICloudBucket, error) {
|
||||
return cloudprovider.GetIBucketById(region, name)
|
||||
}
|
||||
|
||||
func (region *SRegion) GetIBucketByName(name string) (cloudprovider.ICloudBucket, error) {
|
||||
return region.GetIBucketById(name)
|
||||
}
|
||||
|
||||
func obsHttpCode(err error) int {
|
||||
switch httpErr := err.(type) {
|
||||
case obs.ObsError:
|
||||
return httpErr.StatusCode
|
||||
case *obs.ObsError:
|
||||
return httpErr.StatusCode
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func (region *SRegion) DeleteIBucket(name string) error {
|
||||
obsClient, err := region.getOBSClient()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "region.getOBSClient")
|
||||
}
|
||||
_, err = obsClient.DeleteBucket(name)
|
||||
if err != nil {
|
||||
if obsHttpCode(err) == 404 {
|
||||
return nil
|
||||
}
|
||||
return errors.Wrap(err, "DeleteBucket")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+1
-1
@@ -379,7 +379,7 @@ func (self *SRegion) DeleteDisk(id string) error {
|
||||
|
||||
func (self *SRegion) ResizeDisk(id string, sizeGb int64) error {
|
||||
params := map[string]interface{}{
|
||||
"os_extend": map[string]interface{}{
|
||||
"os-extend": map[string]interface{}{
|
||||
"new_size": sizeGb,
|
||||
},
|
||||
}
|
||||
|
||||
+16
-13
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/apis"
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
@@ -333,23 +334,16 @@ func (self *SRegion) GetImageByName(name string) (*SImage, error) {
|
||||
return &images[0], nil
|
||||
}
|
||||
|
||||
/*
|
||||
https://support.huaweicloud.com/api-ims/zh-cn_topic_0020092109.html
|
||||
|
||||
os version 取值范围: https://support.huaweicloud.com/api-ims/zh-cn_topic_0031617666.html
|
||||
用于创建私有镜像的源云服务器系统盘大小大于等于40GB且不超过1024GB。
|
||||
目前支持vhd,zvhd、raw,qcow2
|
||||
todo: 考虑使用镜像快速导入。 https://support.huaweicloud.com/api-ims/zh-cn_topic_0133188204.html
|
||||
使用OBS文件创建镜像
|
||||
|
||||
* openstack原生接口支持的格式:https://support.huaweicloud.com/api-ims/zh-cn_topic_0031615566.html
|
||||
*/
|
||||
func (self *SRegion) ImportImageJob(name string, osDist string, osVersion string, osArch string, bucket string, key string, minDiskGB int64) error {
|
||||
func (self *SRegion) ImportImageJob(name string, osDist string, osVersion string, osArch string, bucket string, key string, minDiskGB int64) (*SImage, error) {
|
||||
os_version, err := stdVersion(osDist, osVersion, osArch)
|
||||
log.Debugf("%s %s %s: %s.min_disk %d GB", osDist, osVersion, osArch, os_version, minDiskGB)
|
||||
if err != nil {
|
||||
log.Debugln(err)
|
||||
}
|
||||
arch := "x86_64"
|
||||
if strings.Contains(osArch, "arm") || strings.Contains(osArch, "aarch") {
|
||||
arch = "aarch64"
|
||||
}
|
||||
|
||||
image_url := fmt.Sprintf("%s:%s", bucket, key)
|
||||
params := map[string]interface{}{
|
||||
@@ -359,8 +353,17 @@ func (self *SRegion) ImportImageJob(name string, osDist string, osVersion string
|
||||
"is_config_init": true,
|
||||
"is_config": true,
|
||||
"min_disk": minDiskGB,
|
||||
"architecture": arch,
|
||||
}
|
||||
return self.imsPerform("cloudimage", "action", params, nil)
|
||||
job := &SJob{}
|
||||
err = self.imsPerform("cloudimages", "action", params, job)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "import image")
|
||||
}
|
||||
for _, id := range job.GetIds() {
|
||||
return self.GetImage(id)
|
||||
}
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, jsonutils.Marshal(job).String())
|
||||
}
|
||||
|
||||
func formatVersion(osDist string, osVersion string) (string, error) {
|
||||
|
||||
+9
@@ -386,6 +386,15 @@ func (self *SRegion) CreateElasticcache(opts *cloudprovider.SCloudElasticCacheIn
|
||||
}
|
||||
if len(opts.SecurityGroupIds) > 0 {
|
||||
params["security_group_id"] = opts.SecurityGroupIds[0]
|
||||
} else {
|
||||
secgroups, err := self.GetSecurityGroups(opts.VpcId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetSecurityGroups")
|
||||
}
|
||||
for _, secgroup := range secgroups {
|
||||
params["security_group_id"] = secgroup.Id
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if len(opts.ProjectId) > 0 {
|
||||
|
||||
-4
@@ -72,10 +72,6 @@ func (self *SRegion) GetStatus() string {
|
||||
return api.CLOUD_REGION_STATUS_INSERVER
|
||||
}
|
||||
|
||||
func (self *SRegion) GetILoadBalancerBackendGroups() ([]cloudprovider.ICloudLoadbalancerBackendGroup, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SRegion) GetI18n() cloudprovider.SModelI18nTable {
|
||||
en := fmt.Sprintf("%s %s", CLOUD_PROVIDER_HCS_EN, self.Locales.EnUS)
|
||||
table := cloudprovider.SModelI18nTable{}
|
||||
|
||||
+4
-5
@@ -172,17 +172,16 @@ func (self *SStoragecache) uploadImage(ctx context.Context, image *cloudprovider
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
break
|
||||
} else {
|
||||
return "", err
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
imageName = fmt.Sprintf("%s-%d", imageBaseName, nameIdx)
|
||||
nameIdx += 1
|
||||
log.Debugf("uploadImage Match remote name %s", imageName)
|
||||
log.Infof("uploadImage Match remote name %s", imageName)
|
||||
}
|
||||
|
||||
err = self.region.ImportImageJob(imageName, image.OsDistribution, image.OsVersion, image.OsArch, bucketName, image.ImageId, int64(minDiskGB))
|
||||
imageInfo, err := self.region.ImportImageJob(imageName, image.OsDistribution, image.OsVersion, image.OsArch, bucketName, image.ImageId, int64(minDiskGB))
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "ImportImageJob")
|
||||
}
|
||||
@@ -190,7 +189,7 @@ func (self *SStoragecache) uploadImage(ctx context.Context, image *cloudprovider
|
||||
if callback != nil {
|
||||
callback(100)
|
||||
}
|
||||
return "", cloudprovider.ErrNotImplemented
|
||||
return imageInfo.Id, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) getStoragecache() *SStoragecache {
|
||||
|
||||
Reference in New Issue
Block a user