mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #17090 from ioito/hotfix/qx-disk-reset
fix(region): openstack disk reset
This commit is contained in:
@@ -320,3 +320,8 @@ type DiskDeleteInput struct {
|
||||
SkipRecycle *bool
|
||||
EsxiFlatFilePath string
|
||||
}
|
||||
|
||||
type DiskResetInput struct {
|
||||
SnapshotId string `json:"snapshot_id"`
|
||||
AutoStart bool `json:"auto_start"`
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -69,11 +68,11 @@ func (self *SAliyunHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SAliyunHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (self *SAliyunHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
for _, guest := range guests {
|
||||
if !utils.IsInStringArray(guest.Status, []string{api.VM_RUNNING, api.VM_READY}) {
|
||||
return nil, httperrors.NewBadGatewayError("Aliyun reset disk required guest status is running or ready")
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -67,6 +66,6 @@ func (self *SAwsHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb in
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SAwsHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (self *SAwsHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
return nil, httperrors.NewBadRequestError("Aws not support reset disk, you can create new disk with snapshot")
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -52,7 +51,7 @@ func (self *SAzureHostDriver) ValidateUpdateDisk(ctx context.Context, userCred m
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SAzureHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (self *SAzureHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
return nil, httperrors.NewBadRequestError("Azure not support reset disk, you can create new disk with snapshot")
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ func (self *SBaseHostDriver) ValidateUpdateDisk(ctx context.Context, userCred mc
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SBaseHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (self *SBaseHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
return nil, httperrors.NewNotImplementedError("Not Implement ValidateResetDisk")
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -57,9 +55,9 @@ func (self *SCtyunHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCtyunHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (self *SCtyunHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
if len(guests) >= 1 {
|
||||
return nil, httperrors.NewBadRequestError("Disk must be dettached")
|
||||
}
|
||||
return data, nil
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -59,11 +58,11 @@ func (self *SGoogleHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SGoogleHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (self *SGoogleHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
for _, guest := range guests {
|
||||
if !utils.IsInStringArray(guest.Status, []string{api.VM_RUNNING, api.VM_READY}) {
|
||||
return nil, httperrors.NewBadGatewayError("%s reset disk required guest status is running or ready", self.GetHostType())
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -51,7 +49,7 @@ func (self *SH3CHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb in
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SH3CHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (self *SH3CHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
if len(guests) >= 1 {
|
||||
if disk.DiskType == api.DISK_TYPE_SYS {
|
||||
for _, g := range guests {
|
||||
@@ -63,5 +61,5 @@ func (self *SH3CHostDriver) ValidateResetDisk(ctx context.Context, userCred mccl
|
||||
return nil, httperrors.NewBadRequestError("Disk must be detached")
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -51,7 +49,7 @@ func (self *SHCSHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb in
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHCSHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (self *SHCSHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
if len(guests) >= 1 {
|
||||
if disk.DiskType == api.DISK_TYPE_SYS {
|
||||
for _, g := range guests {
|
||||
@@ -63,5 +61,5 @@ func (self *SHCSHostDriver) ValidateResetDisk(ctx context.Context, userCred mccl
|
||||
return nil, httperrors.NewBadRequestError("Disk must be detached")
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -51,7 +49,7 @@ func (self *SHCSOPHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHCSOPHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (self *SHCSOPHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
if len(guests) >= 1 {
|
||||
if disk.DiskType == api.DISK_TYPE_SYS {
|
||||
for _, g := range guests {
|
||||
@@ -63,5 +61,5 @@ func (self *SHCSOPHostDriver) ValidateResetDisk(ctx context.Context, userCred mc
|
||||
return nil, httperrors.NewBadRequestError("Disk must be detached")
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -57,7 +55,7 @@ func (self *SHuaweiHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHuaweiHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (self *SHuaweiHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
if len(guests) >= 1 {
|
||||
if disk.DiskType == api.DISK_TYPE_SYS {
|
||||
for _, g := range guests {
|
||||
@@ -69,5 +67,5 @@ func (self *SHuaweiHostDriver) ValidateResetDisk(ctx context.Context, userCred m
|
||||
return nil, httperrors.NewBadRequestError("Disk must be detached")
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -57,7 +55,7 @@ func (self *SHCSOHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb i
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHCSOHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (self *SHCSOHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
if len(guests) >= 1 {
|
||||
if disk.DiskType == api.DISK_TYPE_SYS {
|
||||
for _, g := range guests {
|
||||
@@ -69,5 +67,5 @@ func (self *SHCSOHostDriver) ValidateResetDisk(ctx context.Context, userCred mcc
|
||||
return nil, httperrors.NewBadRequestError("Disk must be detached")
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@ package hostdrivers
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -49,6 +47,6 @@ func (self *SInCloudSphereHostDriver) GetStoragecacheQuota(host *models.SHost) i
|
||||
return 100
|
||||
}
|
||||
|
||||
func (self *SInCloudSphereHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
return data, nil
|
||||
func (self *SInCloudSphereHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -45,7 +43,7 @@ func (self *SJDcloudHostDriver) GetHypervisor() string {
|
||||
|
||||
// ValidateResetDisk 仅可用状态的云硬盘支持恢复
|
||||
// 卸载硬盘需要停止云主机
|
||||
func (self *SJDcloudHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (self *SJDcloudHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
return nil, httperrors.NewNotSupportedError("not supported")
|
||||
}
|
||||
|
||||
|
||||
@@ -385,7 +385,7 @@ func (self *SKVMHostDriver) RequestDeleteSnapshotsWithStorage(ctx context.Contex
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SKVMHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (self *SKVMHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
if len(guests) > 1 {
|
||||
return nil, httperrors.NewBadRequestError("Disk attach muti guests")
|
||||
} else if len(guests) == 1 {
|
||||
@@ -396,7 +396,7 @@ func (self *SKVMHostDriver) ValidateResetDisk(ctx context.Context, userCred mccl
|
||||
return nil, httperrors.NewBadRequestError("Disk dosen't attach guest")
|
||||
}
|
||||
|
||||
return data, nil
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SKVMHostDriver) RequestResetDisk(ctx context.Context, host *models.SHost, disk *models.SDisk, params *jsonutils.JSONDict, task taskman.ITask) error {
|
||||
|
||||
@@ -357,24 +357,46 @@ func (self *SManagedVirtualizationHostDriver) RequestDeallocateDiskOnHost(ctx co
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
return data, nil
|
||||
func (self *SManagedVirtualizationHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationHostDriver) RequestResetDisk(ctx context.Context, host *models.SHost, disk *models.SDisk, params *jsonutils.JSONDict, task taskman.ITask) error {
|
||||
iDisk, err := disk.GetIDisk(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
snapshotId, err := params.GetString("snapshot_id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
exteranlDiskId, err := iDisk.Reset(ctx, snapshotId)
|
||||
data := jsonutils.NewDict()
|
||||
data.Set("exteranl_disk_id", jsonutils.NewString(exteranlDiskId))
|
||||
return data, err
|
||||
iDisk, err := disk.GetIDisk(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetIDisk")
|
||||
}
|
||||
snapshotId, err := params.GetString("snapshot_id")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "get snapshot_id")
|
||||
}
|
||||
|
||||
exteranlId, err := iDisk.Reset(ctx, snapshotId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Reset")
|
||||
}
|
||||
_, err = db.Update(disk, func() error {
|
||||
if len(exteranlId) > 0 {
|
||||
disk.ExternalId = exteranlId
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "db.Update")
|
||||
}
|
||||
iDisk, err = disk.GetIDisk(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetIDisk")
|
||||
}
|
||||
_, err = db.Update(disk, func() error {
|
||||
if len(exteranlId) > 0 {
|
||||
disk.DiskSize = iDisk.GetDiskSizeMB()
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return nil, err
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@ package hostdrivers
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -50,6 +48,9 @@ func (driver *SOpenStackHostDriver) GetStoragecacheQuota(host *models.SHost) int
|
||||
return 100
|
||||
}
|
||||
|
||||
func (self *SOpenStackHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
return nil, httperrors.NewBadRequestError("OpenStack not support reset disk, you can create new disk with snapshot")
|
||||
func (self *SOpenStackHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
if len(guests) > 0 {
|
||||
return nil, httperrors.NewBadRequestError("can not reset with disk associate with guests")
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -68,13 +67,13 @@ func (self *SQcloudHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SQcloudHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (self *SQcloudHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
for _, guest := range guests {
|
||||
if !utils.IsInStringArray(guest.Status, []string{api.VM_RUNNING, api.VM_READY}) {
|
||||
return nil, httperrors.NewBadGatewayError("Qcloud reset disk required guest status is running or read")
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SQcloudHostDriver) RequestDeleteSnapshotWithStorage(ctx context.Context, host *models.SHost, snapshot *models.SSnapshot, task taskman.ITask) error {
|
||||
|
||||
@@ -18,8 +18,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -71,12 +69,12 @@ func (self *SUCloudHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SUCloudHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (self *SUCloudHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
if len(guests) > 0 {
|
||||
return nil, httperrors.NewInputParameterError("Ucloud reset disk operation required disk not be attached")
|
||||
}
|
||||
if disk.DiskType != api.DISK_TYPE_DATA {
|
||||
return nil, httperrors.NewInputParameterError("Ucloud only support data disk reset operation")
|
||||
}
|
||||
return data, nil
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@ package hostdrivers
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -46,11 +44,11 @@ func (self *SZStackHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SZStackHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (self *SZStackHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
|
||||
for _, guest := range guests {
|
||||
if guest.Status != api.VM_READY {
|
||||
return nil, httperrors.NewBadRequestError("ZStack reset disk operation requried guest status is ready")
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
return input, nil
|
||||
}
|
||||
|
||||
+18
-22
@@ -916,7 +916,7 @@ func (self *SDisk) CleanUpDiskSnapshots(ctx context.Context, userCred mcclient.T
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SDisk) PerformDiskReset(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
func (self *SDisk) PerformDiskReset(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input *api.DiskResetInput) (jsonutils.JSONObject, error) {
|
||||
err := self.ValidateEncryption(ctx, userCred)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "ValidateEncryption")
|
||||
@@ -924,22 +924,21 @@ func (self *SDisk) PerformDiskReset(ctx context.Context, userCred mcclient.Token
|
||||
if !utils.IsInStringArray(self.Status, []string{api.DISK_READY}) {
|
||||
return nil, httperrors.NewInputParameterError("Cannot reset disk in status %s", self.Status)
|
||||
}
|
||||
storage, _ := self.GetStorage()
|
||||
if storage == nil {
|
||||
return nil, httperrors.NewNotFoundError("failed to find storage for disk %s", self.Name)
|
||||
}
|
||||
|
||||
host, _ := storage.GetMasterHost()
|
||||
if host == nil {
|
||||
return nil, httperrors.NewNotFoundError("failed to find host for storage %s with disk %s", storage.Name, self.Name)
|
||||
}
|
||||
|
||||
snapshotV := validators.NewModelIdOrNameValidator("snapshot", "snapshot", userCred)
|
||||
err = snapshotV.Validate(data.(*jsonutils.JSONDict))
|
||||
storage, err := self.GetStorage()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "snapshotV.Validate")
|
||||
return nil, httperrors.NewGeneralError(errors.Wrapf(err, "GetStorage"))
|
||||
}
|
||||
snapshot := snapshotV.Model.(*SSnapshot)
|
||||
|
||||
host, err := storage.GetMasterHost()
|
||||
if err != nil {
|
||||
return nil, httperrors.NewGeneralError(errors.Wrapf(err, "GetMasterHost"))
|
||||
}
|
||||
|
||||
snapshotObj, err := validators.ValidateModel(userCred, SnapshotManager, &input.SnapshotId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
snapshot := snapshotObj.(*SSnapshot)
|
||||
if snapshot.Status != api.SNAPSHOT_READY {
|
||||
return nil, httperrors.NewBadRequestError("Cannot reset disk with snapshot in status %s", snapshot.Status)
|
||||
}
|
||||
@@ -949,17 +948,16 @@ func (self *SDisk) PerformDiskReset(ctx context.Context, userCred mcclient.Token
|
||||
}
|
||||
|
||||
guests := self.GetGuests()
|
||||
data, err = host.GetHostDriver().ValidateResetDisk(ctx, userCred, self, snapshot, guests, data.(*jsonutils.JSONDict))
|
||||
input, err = host.GetHostDriver().ValidateResetDisk(ctx, userCred, self, snapshot, guests, input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
autoStart := jsonutils.QueryBoolean(data, "auto_start", false)
|
||||
var guest *SGuest = nil
|
||||
if len(guests) > 0 {
|
||||
guest = &guests[0]
|
||||
}
|
||||
return nil, self.StartResetDisk(ctx, userCred, snapshot.Id, autoStart, guest, "")
|
||||
return nil, self.StartResetDisk(ctx, userCred, snapshot.Id, input.AutoStart, guest, "")
|
||||
}
|
||||
|
||||
func (self *SDisk) StartResetDisk(
|
||||
@@ -975,11 +973,9 @@ func (self *SDisk) StartResetDisk(
|
||||
params.Set("auto_start", jsonutils.NewBool(autoStart))
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "DiskResetTask", self, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
task.ScheduleRun(nil)
|
||||
return errors.Wrapf(err, "NewTask")
|
||||
}
|
||||
return nil
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (disk *SDisk) PerformResize(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.DiskResizeInput) (jsonutils.JSONObject, error) {
|
||||
|
||||
@@ -33,7 +33,7 @@ type IHostDriver interface {
|
||||
RequestUncacheImage(ctx context.Context, host *SHost, storageCache *SStoragecache, task taskman.ITask) error
|
||||
|
||||
ValidateUpdateDisk(ctx context.Context, userCred mcclient.TokenCredential, input api.DiskUpdateInput) (api.DiskUpdateInput, error)
|
||||
ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *SDisk, snapshot *SSnapshot, guests []SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error)
|
||||
ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *SDisk, snapshot *SSnapshot, guests []SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error)
|
||||
ValidateDiskSize(storage *SStorage, sizeGb int) error
|
||||
RequestPrepareSaveDiskOnHost(ctx context.Context, host *SHost, disk *SDisk, imageId string, task taskman.ITask) error
|
||||
RequestSaveUploadImageOnHost(ctx context.Context, host *SHost, disk *SDisk, imageId string, task taskman.ITask, data jsonutils.JSONObject) error
|
||||
|
||||
@@ -1191,34 +1191,6 @@ func (self *SManagedVirtualizationRegionDriver) GetDiskResetParams(snapshot *mod
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) OnDiskReset(ctx context.Context, userCred mcclient.TokenCredential,
|
||||
disk *models.SDisk, snapshot *models.SSnapshot, data jsonutils.JSONObject) error {
|
||||
|
||||
externalId, _ := data.GetString("exteranl_disk_id")
|
||||
if len(externalId) > 0 {
|
||||
_, err := db.Update(disk, func() error {
|
||||
disk.ExternalId = externalId
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
iDisk, err := disk.GetIDisk(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = iDisk.Refresh()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if disk.DiskSize != iDisk.GetDiskSizeMB() {
|
||||
_, err := db.Update(disk, func() error {
|
||||
disk.DiskSize = iDisk.GetDiskSizeMB()
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user