mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): cloudpods esxi disk create (#19390)
This commit is contained in:
@@ -15,12 +15,16 @@
|
||||
package guestdrivers
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/rbacscope"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/compute/options"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -56,6 +60,14 @@ func (self *SCloudpodsGuestDriver) GetGuestInitialStateAfterCreate() string {
|
||||
return api.VM_READY
|
||||
}
|
||||
|
||||
func (self *SCloudpodsGuestDriver) DoGuestCreateDisksTask(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
|
||||
subtask, err := taskman.TaskManager.NewTask(ctx, "CloudpodsGuestCreateDiskTask", guest, task.GetUserCred(), task.GetParams(), task.GetTaskId(), "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "NewTask")
|
||||
}
|
||||
return subtask.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SCloudpodsGuestDriver) GetDetachDiskStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
@@ -1835,10 +1835,9 @@ func (self *SGuest) StartGuestCreateDiskTask(ctx context.Context, userCred mccli
|
||||
data.Add(jsonutils.Marshal(disks), "disks")
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "GuestCreateDiskTask", self, userCred, data, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrapf(err, "NewTask")
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SGuest) PerformDetachdisk(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.ServerDetachDiskInput) (jsonutils.JSONObject, error) {
|
||||
|
||||
@@ -439,6 +439,10 @@ func (self *NutanixGuestCreateDiskTask) OnInit(ctx context.Context, obj db.IStan
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
type CloudpodsGuestCreateDiskTask struct {
|
||||
NutanixGuestCreateDiskTask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(GuestCreateBackupDisksTask{})
|
||||
taskman.RegisterTask(GuestCreateDiskTask{})
|
||||
@@ -447,4 +451,5 @@ func init() {
|
||||
taskman.RegisterTask(ESXiGuestCreateDiskTask{})
|
||||
taskman.RegisterTask(ProxmoxGuestCreateDiskTask{})
|
||||
taskman.RegisterTask(NutanixGuestCreateDiskTask{})
|
||||
taskman.RegisterTask(CloudpodsGuestCreateDiskTask{})
|
||||
}
|
||||
|
||||
@@ -67,6 +67,13 @@ func (self *SInstance) Refresh() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
self.DisksInfo = nil
|
||||
self.Nics = nil
|
||||
self.Secgroups = nil
|
||||
self.SubIPs = nil
|
||||
self.IsolatedDevices = nil
|
||||
self.Cdrom = nil
|
||||
self.Floppy = nil
|
||||
return jsonutils.Update(self, ins)
|
||||
}
|
||||
|
||||
@@ -584,3 +591,42 @@ func (cli *SCloudpodsClient) GetMetrics(opts *cloudprovider.MetricListOptions) (
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (self *SInstance) CreateDisk(ctx context.Context, opts *cloudprovider.GuestDiskCreateOptions) (string, error) {
|
||||
diskIds := []string{}
|
||||
for _, disk := range self.DisksInfo {
|
||||
diskIds = append(diskIds, disk.Id)
|
||||
}
|
||||
input := jsonutils.Marshal(map[string]interface{}{
|
||||
"disks": []map[string]interface{}{
|
||||
{
|
||||
"size": opts.SizeMb,
|
||||
"storage_id": opts.StorageId,
|
||||
"preallocation": opts.Preallocation,
|
||||
},
|
||||
},
|
||||
})
|
||||
_, err := self.host.zone.region.perform(&modules.Servers, self.Id, "createdisk", input)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
ret := ""
|
||||
cloudprovider.Wait(time.Second*3, time.Minute*3, func() (bool, error) {
|
||||
err = self.Refresh()
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "Refresh")
|
||||
}
|
||||
|
||||
for _, disk := range self.DisksInfo {
|
||||
if !utils.IsInStringArray(disk.Id, diskIds) {
|
||||
ret = disk.Id
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
if len(ret) > 0 {
|
||||
return ret, nil
|
||||
}
|
||||
return "", errors.Wrapf(cloudprovider.ErrNotFound, "after disk created")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user