fix(region): kvm convert to esxi

complete kvm guest meta info

Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
This commit is contained in:
wanyaoqi
2023-02-16 11:09:43 +08:00
parent 692b5512da
commit cacd7e61e1
4 changed files with 28 additions and 1 deletions
+4
View File
@@ -4352,6 +4352,7 @@ func (self *SGuest) createConvertedServer(
// generate guest create params
createInput := self.ToCreateInput(ctx, userCred)
createInput.Hypervisor = api.HYPERVISOR_KVM
createInput.PreferHost = ""
createInput.Vdi = api.VM_VDI_PROTOCOL_VNC
createInput.GenerateName = fmt.Sprintf("%s-%s", self.Name, api.HYPERVISOR_KVM)
// change drivers so as to bootable in KVM
@@ -4359,6 +4360,9 @@ func (self *SGuest) createConvertedServer(
if createInput.Disks[i].Driver != "ide" {
createInput.Disks[i].Driver = "ide"
}
createInput.Disks[i].Format = ""
createInput.Disks[i].Backend = ""
createInput.Disks[i].Medium = ""
}
for i := range createInput.Networks {
if createInput.Networks[i].Driver != "e1000" && createInput.Networks[i].Driver != "vmxnet3" {
@@ -51,6 +51,10 @@ func (self *GuestConvertEsxiToKvmTask) GetSchedParams() (*schedapi.ScheduleInput
preferHostId, _ := self.Params.GetString("prefer_host_id")
schedDesc.ServerConfig.PreferHost = preferHostId
}
for i := range schedDesc.Disks {
schedDesc.Disks[i].Backend = ""
schedDesc.Disks[i].Medium = ""
}
schedDesc.Hypervisor = api.HYPERVISOR_KVM
return schedDesc, nil
}
@@ -211,6 +215,12 @@ func (self *GuestConvertEsxiToKvmTask) TaskComplete(ctx context.Context, guest,
}
}
}
for _, k := range []string{api.VM_METADATA_OS_ARCH, api.VM_METADATA_OS_DISTRO, api.VM_METADATA_OS_NAME, api.VM_METADATA_OS_VERSION} {
if v := guest.GetMetadata(ctx, k, self.UserCred); len(v) > 0 {
targetGuest.SetMetadata(ctx, k, v, self.UserCred)
}
}
db.OpsLog.LogEvent(guest, db.ACT_VM_CONVERT, "", self.UserCred)
logclient.AddSimpleActionLog(guest, logclient.ACT_VM_CONVERT, "", self.UserCred, true)
self.SetStageComplete(ctx, nil)
+8 -1
View File
@@ -23,6 +23,7 @@ import (
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/onecloud/pkg/hostman/guestman/desc"
deployapi "yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
"yunion.io/x/onecloud/pkg/hostman/hostdeployer/deployclient"
hostutils "yunion.io/x/onecloud/pkg/hostman/hostutils"
@@ -40,6 +41,12 @@ func (m *SGuestManager) GuestCreateFromEsxi(
if err := guest.SaveSourceDesc(createConfig.GuestDesc); err != nil {
return nil, err
}
guest.Desc = new(desc.SGuestDesc)
jsonutils.Marshal(createConfig.GuestDesc).Unmarshal(guest.Desc)
if err := guest.SaveLiveDesc(guest.Desc); err != nil {
return nil, err
}
esxiCli, err := esxi.NewESXiClientFromAccessInfo(ctx, &createConfig.EsxiAccessInfo.Datastore)
if err != nil {
return nil, errors.Wrap(err, "new esxi client")
@@ -82,7 +89,7 @@ func (m *SGuestManager) GuestCreateFromEsxi(
log.Infof("Connection disks %v", connections.String())
var ret = jsonutils.NewDict()
disksDesc := guest.Desc.Disks
disksDesc := guest.SourceDesc.Disks
for i := 0; i < len(disksDesc); i++ {
storageId := disksDesc[i].StorageId
if storage := storageman.GetManager().GetStorage(storageId); storage == nil {
+6
View File
@@ -31,6 +31,7 @@ import (
"yunion.io/x/pkg/util/netutils"
"yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/hostman/guestman/desc"
"yunion.io/x/onecloud/pkg/hostman/hostutils"
"yunion.io/x/onecloud/pkg/hostman/storageman"
"yunion.io/x/onecloud/pkg/util/fileutils2"
@@ -70,6 +71,11 @@ func (m *SGuestManager) GuestCreateFromLibvirt(
if err := guest.SaveSourceDesc(createConfig.GuestDesc); err != nil {
return nil, err
}
guest.Desc = new(desc.SGuestDesc)
jsonutils.Marshal(createConfig.GuestDesc).Unmarshal(guest.Desc)
if err := guest.SaveLiveDesc(guest.Desc); err != nil {
return nil, err
}
if len(createConfig.MonitorPath) > 0 {
if pid := findGuestProcessPid(guest.getOriginId(), "[q]emu-kvm"); len(pid) > 0 {