mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
华为云快照回滚bugfix
This commit is contained in:
@@ -3,6 +3,7 @@ package models
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -380,6 +381,11 @@ func (manager *SCloudregionManager) ListItemFilter(ctx context.Context, q *sqlch
|
||||
}
|
||||
manager := managerObj.(*SCloudprovider)
|
||||
q = q.Equals("provider", manager.Provider)
|
||||
if manager.Provider == CLOUD_PROVIDER_HUAWEI {
|
||||
region := strings.Split(manager.Name, "_")[0]
|
||||
prefix := CLOUD_PROVIDER_HUAWEI + "/" + region
|
||||
q = q.Startswith("external_id", prefix)
|
||||
}
|
||||
}
|
||||
accountStr, _ := query.GetString("account")
|
||||
if len(accountStr) > 0 {
|
||||
|
||||
+26
-5
@@ -95,7 +95,6 @@ type SDisk struct {
|
||||
ConsistencygroupID string `json:"consistencygroup_id"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
|
||||
/*下面这些字段也许不需要*/
|
||||
ExpiredTime time.Time
|
||||
}
|
||||
|
||||
@@ -183,7 +182,17 @@ func (self *SDisk) GetBillingType() string {
|
||||
}
|
||||
|
||||
func (self *SDisk) GetExpiredAt() time.Time {
|
||||
return self.ExpiredTime
|
||||
var expiredTime time.Time
|
||||
if self.Metadata.Billing == "1" {
|
||||
res, err := self.storage.zone.region.GetOrderResourceDetail(self.GetId())
|
||||
if err != nil {
|
||||
log.Debugf(err.Error())
|
||||
}
|
||||
|
||||
expiredTime = res.ExpireTime
|
||||
}
|
||||
|
||||
return expiredTime
|
||||
}
|
||||
|
||||
func (self *SDisk) GetIStorage() (cloudprovider.ICloudStorage, error) {
|
||||
@@ -340,7 +349,19 @@ func (self *SDisk) Detach() error {
|
||||
return err
|
||||
}
|
||||
|
||||
return cloudprovider.WaitStatus(self, models.DISK_READY, 5*time.Second, 60*time.Second)
|
||||
return cloudprovider.WaitCreated(5*time.Second, 60*time.Second, func() bool {
|
||||
err := self.Refresh()
|
||||
if err != nil {
|
||||
log.Debugf(err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
if self.Status == "available" {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
func (self *SDisk) Attach(device string) error {
|
||||
@@ -357,7 +378,7 @@ func (self *SDisk) Attach(device string) error {
|
||||
// 对于挂载在系统盘盘位(也就是“/dev/sda”或“/dev/vda”挂载点)上的磁盘,当前仅支持离线卸载
|
||||
func (self *SDisk) Reset(ctx context.Context, snapshotId string) (string, error) {
|
||||
mountpoint := self.GetMountpoint()
|
||||
if mountpoint == "/dev/sda" || mountpoint == "/dev/vda" {
|
||||
if len(mountpoint) > 0 {
|
||||
err := self.Detach()
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -374,7 +395,7 @@ func (self *SDisk) Reset(ctx context.Context, snapshotId string) (string, error)
|
||||
return "", err
|
||||
}
|
||||
|
||||
if mountpoint == "/dev/sda" || mountpoint == "/dev/vda" {
|
||||
if len(mountpoint) > 0 {
|
||||
err := self.Attach(mountpoint)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/util/billing"
|
||||
"yunion.io/x/onecloud/pkg/util/huawei/client/modules"
|
||||
"yunion.io/x/pkg/util/osprofile"
|
||||
"yunion.io/x/pkg/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -555,9 +556,28 @@ func (self *SInstance) GetVNCInfo() (jsonutils.JSONObject, error) {
|
||||
return self.host.zone.region.GetInstanceVNCUrl(self.GetId())
|
||||
}
|
||||
|
||||
func (self *SInstance) NextDeviceName() (string, error) {
|
||||
currents := []string{}
|
||||
for _, item := range self.OSExtendedVolumesVolumesAttached {
|
||||
currents = append(currents, strings.ToLower(item.Device))
|
||||
}
|
||||
|
||||
for i := 0; i < 25; i++ {
|
||||
device := fmt.Sprintf("/dev/sd%s", string(98+i))
|
||||
if ok, _ := utils.InStringArray(device, currents); !ok {
|
||||
return device, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("disk devicename out of index, current deivces: %s", currents)
|
||||
}
|
||||
|
||||
func (self *SInstance) AttachDisk(ctx context.Context, diskId string) error {
|
||||
// todo: calc device
|
||||
return self.host.zone.region.AttachDisk(self.GetId(), diskId, "")
|
||||
device, err := self.NextDeviceName()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return self.host.zone.region.AttachDisk(self.GetId(), diskId, device)
|
||||
}
|
||||
|
||||
func (self *SInstance) DetachDisk(ctx context.Context, diskId string) error {
|
||||
@@ -1073,12 +1093,15 @@ func (self *SRegion) GetInstanceVNCUrl(instanceId string) (jsonutils.JSONObject,
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-ecs/zh-cn_topic_0022472987.html
|
||||
// todo: 指定device
|
||||
// XEN平台虚拟机device为必选参数。
|
||||
func (self *SRegion) AttachDisk(instanceId string, diskId string, device string) error {
|
||||
params := jsonutils.NewDict()
|
||||
volumeObj := jsonutils.NewDict()
|
||||
volumeObj.Add(jsonutils.NewString(diskId), "volumeId")
|
||||
if len(device) > 0 {
|
||||
volumeObj.Add(jsonutils.NewString(device), "device")
|
||||
}
|
||||
|
||||
params.Add(volumeObj, "volumeAttachment")
|
||||
|
||||
_, err := self.ecsClient.Servers.PerformAction2("attachvolume", instanceId, params, "")
|
||||
|
||||
Reference in New Issue
Block a user