mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-29 03:51:54 +08:00
fix(region): add device for disk (#23691)
This commit is contained in:
@@ -97,7 +97,7 @@ require (
|
||||
k8s.io/cri-api v0.28.15
|
||||
k8s.io/klog/v2 v2.20.0
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20251031063552-483d6c724492
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20251105060649-53dbf73add2c
|
||||
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0
|
||||
yunion.io/x/jsonutils v1.0.1-0.20250507052344-1abcf4f443b1
|
||||
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
|
||||
|
||||
@@ -1470,8 +1470,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.20251031063552-483d6c724492 h1:cDmRCZ1z9QABdLYrpZ4e9CV4IWPLuI7cMPgopflzof4=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20251031063552-483d6c724492/go.mod h1:MeA5UnvNhLXMvy+xPMOzRqjWMWMkZ3QXZP0u1bYEM0M=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20251105060649-53dbf73add2c h1:0OPSeH93GcwWeVuwD26EZMdgmf9xnhtDuHGlBWAg7X8=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20251105060649-53dbf73add2c/go.mod h1:MeA5UnvNhLXMvy+xPMOzRqjWMWMkZ3QXZP0u1bYEM0M=
|
||||
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0 h1:msG4SiDSVU7CrXH06WuHlNEZXIooTcmNbfrIGHuIHBU=
|
||||
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
@@ -459,6 +459,12 @@ func (drv *SManagedVirtualizedGuestDriver) RequestAttachDisk(ctx context.Context
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "RequestAttachDisk.iVM.WaitStatus")
|
||||
}
|
||||
if device := iDisks[i].GetDeviceName(); len(device) > 0 {
|
||||
db.Update(disk, func() error {
|
||||
disk.Device = device
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
@@ -1226,6 +1232,7 @@ func (drv *SManagedVirtualizedGuestDriver) OnGuestDeployTaskDataReceived(ctx con
|
||||
disk.ExternalId = diskInfo[i].Uuid
|
||||
disk.DiskType = diskInfo[i].DiskType
|
||||
disk.Status = api.DISK_READY
|
||||
disk.Device = diskInfo[i].Device
|
||||
|
||||
disk.FsFormat = diskInfo[i].FsFromat
|
||||
if diskInfo[i].AutoDelete {
|
||||
|
||||
@@ -41,6 +41,7 @@ type SDiskInfo struct {
|
||||
CacheMode string
|
||||
ExpiredAt time.Time
|
||||
StorageExternalId string
|
||||
Device string
|
||||
|
||||
Metadata map[string]string
|
||||
}
|
||||
@@ -97,6 +98,7 @@ func fetchIVMinfo(desc cloudprovider.SManagedVMCreateConfig, iVM cloudprovider.I
|
||||
dinfo.TemplateId = idisks[i].GetTemplateId()
|
||||
dinfo.FsFromat = idisks[i].GetFsFormat()
|
||||
dinfo.ExpiredAt = idisks[i].GetExpiredAt()
|
||||
dinfo.Device = idisks[i].GetDeviceName()
|
||||
dinfo.StorageExternalId = idisks[i].GetIStorageId()
|
||||
diskSysTags := idisks[i].GetSysTags()
|
||||
diskTags, _ := idisks[i].GetTags()
|
||||
|
||||
@@ -114,6 +114,9 @@ type SDisk struct {
|
||||
// 备份Id
|
||||
BackupId string `width:"256" charset:"ascii" nullable:"true" list:"user" json:"backup_id"`
|
||||
|
||||
// 设备名称
|
||||
Device string `width:"32" charset:"ascii" nullable:"true" get:"user" list:"user"`
|
||||
|
||||
// 文件系统
|
||||
FsFormat string `width:"32" charset:"ascii" nullable:"true" list:"user" json:"fs_format"`
|
||||
// 文件系统特性
|
||||
@@ -1927,6 +1930,9 @@ func (self *SDisk) syncWithCloudDisk(ctx context.Context, userCred mcclient.Toke
|
||||
if extDisk.GetIsAutoDelete() {
|
||||
self.AutoDelete = true
|
||||
}
|
||||
if device := extDisk.GetDeviceName(); len(device) > 0 {
|
||||
self.Device = device
|
||||
}
|
||||
// self.TemplateId = extDisk.GetTemplateId() no sync template ID
|
||||
if templateId := extDisk.GetTemplateId(); len(templateId) > 0 {
|
||||
cachedImage, err := db.FetchByExternalId(CachedimageManager, templateId)
|
||||
@@ -2011,6 +2017,7 @@ func (manager *SDiskManager) newFromCloudDisk(ctx context.Context, userCred mccl
|
||||
disk.DiskType = api.DISK_TYPE_SYS
|
||||
}
|
||||
disk.Nonpersistent = extDisk.GetIsNonPersistent()
|
||||
disk.Device = extDisk.GetDeviceName()
|
||||
|
||||
disk.IsEmulated = extDisk.IsEmulated()
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -2039,7 +2039,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.20251031063552-483d6c724492
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20251105060649-53dbf73add2c
|
||||
## explicit; go 1.24
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+1
@@ -547,6 +547,7 @@ type ICloudDisk interface {
|
||||
// GetStatus() string
|
||||
GetDiskFormat() string
|
||||
GetDiskSizeMB() int // MB
|
||||
GetDeviceName() string
|
||||
GetIsAutoDelete() bool
|
||||
GetTemplateId() string
|
||||
GetDiskType() string
|
||||
|
||||
+4
@@ -168,6 +168,10 @@ func (self *SDisk) SetTags(tags map[string]string, replace bool) error {
|
||||
return self.storage.zone.region.SetResourceTags(ALIYUN_SERVICE_ECS, "disk", self.DiskId, tags, replace)
|
||||
}
|
||||
|
||||
func (self *SDisk) GetDeviceName() string {
|
||||
return self.Device
|
||||
}
|
||||
|
||||
func (self *SRegion) ChangeDiskChargeType(vmId, diskId string, billingType string) error {
|
||||
params := make(map[string]string)
|
||||
params["RegionId"] = self.RegionId
|
||||
|
||||
+4
@@ -157,6 +157,10 @@ func (self *SDisk) GetTemplateId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SDisk) GetDeviceName() string {
|
||||
return self.getDevice()
|
||||
}
|
||||
|
||||
func (self *SDisk) getDevice() string {
|
||||
for _, dev := range self.Attachments {
|
||||
if len(dev.Device) > 0 {
|
||||
|
||||
+9
@@ -147,6 +147,15 @@ func (disk *SDisk) GetName() string {
|
||||
return disk.Name
|
||||
}
|
||||
|
||||
func (disk *SDisk) GetDeviceName() string {
|
||||
for _, attachment := range disk.Attachments {
|
||||
if len(attachment.Device) > 0 {
|
||||
return attachment.Device
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (disk *SDisk) GetStatus() string {
|
||||
switch disk.Status {
|
||||
case "Available", "InUse", "Recharging":
|
||||
|
||||
+4
@@ -42,3 +42,7 @@ func (disk *SDisk) GetPreallocation() string {
|
||||
func (disk *SDisk) ChangeStorage(ctx context.Context, opts *cloudprovider.ChangeStorageOptions) error {
|
||||
return errors.Wrapf(cloudprovider.ErrNotImplemented, "ChangeStorage")
|
||||
}
|
||||
|
||||
func (disk *SDisk) GetDeviceName() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
+8
-3
@@ -205,6 +205,10 @@ func (self *SDisk) GetExpiredAt() time.Time {
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func (self *SDisk) GetDeviceName() string {
|
||||
return self.GetMountpoint()
|
||||
}
|
||||
|
||||
func (self *SDisk) GetIStorage() (cloudprovider.ICloudStorage, error) {
|
||||
return self.storage, nil
|
||||
}
|
||||
@@ -275,10 +279,11 @@ func (self *SDisk) GetCacheMode() string {
|
||||
}
|
||||
|
||||
func (self *SDisk) GetMountpoint() string {
|
||||
if len(self.Attachments) > 0 {
|
||||
return self.Attachments[0].Device
|
||||
for _, attachment := range self.Attachments {
|
||||
if len(attachment.Device) > 0 {
|
||||
return attachment.Device
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -92,6 +92,9 @@ func (region *SRegion) CreateVM(opts *cloudprovider.SManagedVMCreateConfig) (*SI
|
||||
"SystemDisk.DiskSize": fmt.Sprintf("%d", opts.SysDisk.SizeGB),
|
||||
"SyncTag": "true",
|
||||
}
|
||||
if len(opts.Hostname) > 0 {
|
||||
params["HostName"] = opts.Hostname
|
||||
}
|
||||
if len(opts.Password) > 0 {
|
||||
params["InstancePassword"] = opts.Password
|
||||
}
|
||||
|
||||
+31
@@ -319,6 +319,37 @@ func (cli *SKsyunClient) vpcRequest(regionId, apiName string, params map[string]
|
||||
}
|
||||
|
||||
func (cli *SKsyunClient) request(service, regionId, apiName, apiVersion string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
isQueryApi := strings.HasPrefix(apiName, "Get") || strings.HasPrefix(apiName, "Describe") || strings.HasPrefix(apiName, "List")
|
||||
if !isQueryApi {
|
||||
return cli._request(service, regionId, apiName, apiVersion, params)
|
||||
}
|
||||
for i := 0; i < 2; i++ {
|
||||
resp, err := cli._request(service, regionId, apiName, apiVersion, params)
|
||||
if err != nil {
|
||||
retry := false
|
||||
for _, key := range []string{
|
||||
"EOF",
|
||||
"i/o timeout",
|
||||
"TLS handshake timeout",
|
||||
"connection reset by peer",
|
||||
} {
|
||||
if strings.Contains(err.Error(), key) {
|
||||
retry = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !retry {
|
||||
return nil, errors.Wrapf(err, "request")
|
||||
}
|
||||
time.Sleep(time.Second * 10)
|
||||
continue
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
return cli._request(service, regionId, apiName, apiVersion, params)
|
||||
}
|
||||
|
||||
func (cli *SKsyunClient) _request(service, regionId, apiName, apiVersion string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri, err := cli.getUrl(service, regionId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "getUrl")
|
||||
|
||||
+4
@@ -139,3 +139,7 @@ func (disk *SDisk) SetStorage(storage SStorage) {
|
||||
func (disk *SDisk) ChangeStorage(ctx context.Context, opts *cloudprovider.ChangeStorageOptions) error {
|
||||
return errors.Wrapf(cloudprovider.ErrNotImplemented, "ChangeStorage")
|
||||
}
|
||||
|
||||
func (disk *SDisk) GetDeviceName() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user