From c4b2b2fda245843ab23e075b99a366da97e264cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Wed, 5 Jun 2024 11:10:00 +0800 Subject: [PATCH] fix(region): cloudpods baremetal rebuild root (#20483) --- .../guestdrivers/cloudpods-baremetals.go | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkg/compute/guestdrivers/cloudpods-baremetals.go b/pkg/compute/guestdrivers/cloudpods-baremetals.go index 8477a4cd0b..6df0644030 100644 --- a/pkg/compute/guestdrivers/cloudpods-baremetals.go +++ b/pkg/compute/guestdrivers/cloudpods-baremetals.go @@ -485,6 +485,33 @@ func (self *SCloudpodsBaremetalGuestDriver) RequestDeployGuestOnHost(ctx context data := fetchIVMinfo(desc, iVM, guest.Id, desc.Account, desc.Password, desc.PublicKey, "create") return data, nil }) + case "rebuild": + taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) { + iVm, err := guest.GetIVM(ctx) + if err != nil { + return nil, errors.Wrapf(err, "GetIVM") + } + + opts := &cloudprovider.SManagedVMRebuildRootConfig{ + Account: desc.Account, + ImageId: desc.ExternalImageId, + Password: desc.Password, + PublicKey: desc.PublicKey, + } + + _, err = iVm.RebuildRoot(ctx, opts) + if err != nil { + return nil, err + } + initialState := driver.GetGuestInitialStateAfterRebuild() + err = cloudprovider.WaitStatus(iVm, initialState, time.Second*5, time.Hour*1) + if err != nil { + return nil, err + } + data := fetchIVMinfo(desc, iVm, guest.Id, desc.Account, desc.Password, desc.PublicKey, "rebuild") + return data, nil + }) + return nil default: return fmt.Errorf("Action %s not supported", val) }