mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #3979 from rainzm/feature/guest_suspend_vmware
feat(region): Add suspend feature for vmware guest
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -29,6 +30,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/compute/options"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/multicloud/esxi"
|
||||
"yunion.io/x/onecloud/pkg/util/billing"
|
||||
"yunion.io/x/onecloud/pkg/util/httputils"
|
||||
)
|
||||
@@ -186,6 +188,30 @@ func (self *SESXiGuestDriver) RequestDeployGuestOnHost(ctx context.Context, gues
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) RqeuestSuspendOnHost(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
host := guest.GetHost()
|
||||
if host == nil {
|
||||
return nil, errors.Error("fail to get host of guest")
|
||||
}
|
||||
ihost, err := host.GetIHost()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ivm, err := ihost.GetIVMById(guest.GetExternalId())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vm := ivm.(*esxi.SVirtualMachine)
|
||||
err = vm.SuspendVM(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "VM.SuspendVM for vmware")
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) OnGuestDeployTaskDataReceived(ctx context.Context, guest *models.SGuest, task taskman.ITask, data jsonutils.JSONObject) error {
|
||||
|
||||
if data.Contains("host_ip") {
|
||||
|
||||
@@ -430,6 +430,15 @@ func (self *SVirtualMachine) StopVM(ctx context.Context, isForce bool) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SVirtualMachine) SuspendVM(ctx context.Context) error {
|
||||
vm := self.getVmObj()
|
||||
task, err := vm.Suspend(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return task.Wait(ctx)
|
||||
}
|
||||
|
||||
func (self *SVirtualMachine) poweroffVM(ctx context.Context) error {
|
||||
vm := self.getVmObj()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user