diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index dca0995b64..a78aa91d39 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -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" { diff --git a/pkg/compute/tasks/guest_convert_esxi_to_kvm_task.go b/pkg/compute/tasks/guest_convert_esxi_to_kvm_task.go index 56b564c0b5..b6931030e8 100644 --- a/pkg/compute/tasks/guest_convert_esxi_to_kvm_task.go +++ b/pkg/compute/tasks/guest_convert_esxi_to_kvm_task.go @@ -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) diff --git a/pkg/hostman/guestman/esxi.go b/pkg/hostman/guestman/esxi.go index 1810c10595..76b48cddac 100644 --- a/pkg/hostman/guestman/esxi.go +++ b/pkg/hostman/guestman/esxi.go @@ -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 { diff --git a/pkg/hostman/guestman/libvirt.go b/pkg/hostman/guestman/libvirt.go index 7176dc6230..c4a47e257f 100644 --- a/pkg/hostman/guestman/libvirt.go +++ b/pkg/hostman/guestman/libvirt.go @@ -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 {