From f3ecde64cfcbdbbb68dc52be7176d5fbb7460c3d Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Mon, 29 Aug 2022 18:08:51 +0800 Subject: [PATCH] fix: add password info to server vnc info (#14861) Co-authored-by: Qiu Jian --- pkg/cloudprovider/instance.go | 32 ++++++++++++++--------------- pkg/compute/guestdrivers/kvm.go | 3 +++ pkg/compute/models/guest_actions.go | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/pkg/cloudprovider/instance.go b/pkg/cloudprovider/instance.go index afe82c3c23..0591ee3b80 100644 --- a/pkg/cloudprovider/instance.go +++ b/pkg/cloudprovider/instance.go @@ -303,29 +303,29 @@ type ServerVncInput struct { // +onecloud:model-api-gen type ServerVncOutput struct { - Id string + Id string `json:"id"` // baremetal - HostId string - Zone string + HostId string `json:"host_id"` + Zone string `json:"zone"` // kvm host ip - Host string - Protocol string - Port int64 + Host string `json:"host"` + Protocol string `json:"protocol"` + Port int64 `json:"port"` - Url string - InstanceId string - InstanceName string - Password string - VncPassword string + Url string `json:"url"` + InstanceId string `json:"instance_id"` + InstanceName string `json:"instance_name"` + Password string `json:"password"` + VncPassword string `json:"vnc_password"` - OsName string + OsName string `json:"os_name"` // cloudpods - ApiServer string - ConnectParams string - Session string + ApiServer string `json:"api_server"` + ConnectParams string `json:"connect_params"` + Session string `json:"session"` - Hypervisor string + Hypervisor string `json:"hypervisor"` } diff --git a/pkg/compute/guestdrivers/kvm.go b/pkg/compute/guestdrivers/kvm.go index f145e111f9..f251f3b129 100644 --- a/pkg/compute/guestdrivers/kvm.go +++ b/pkg/compute/guestdrivers/kvm.go @@ -204,11 +204,14 @@ func (self *SKVMGuestDriver) GetGuestVncInfo(ctx context.Context, userCred mccli port = findVNCPort(results) } + password := guest.GetMetadata(ctx, "__vnc_password", userCred) + result := &cloudprovider.ServerVncOutput{ Host: host.AccessIp, Protocol: guest.GetVdi(), Port: int64(port), Hypervisor: api.HYPERVISOR_KVM, + Password: password, } return result, nil } diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index c8a282d028..76ebe1e95d 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -71,7 +71,7 @@ import ( func (self *SGuest) GetDetailsVnc(ctx context.Context, userCred mcclient.TokenCredential, input *cloudprovider.ServerVncInput) (*cloudprovider.ServerVncOutput, error) { ret := &cloudprovider.ServerVncOutput{} - if utils.IsInStringArray(self.Status, []string{api.VM_RUNNING, api.VM_BLOCK_STREAM}) { + if utils.IsInStringArray(self.Status, []string{api.VM_RUNNING, api.VM_BLOCK_STREAM, api.VM_MIGRATING}) { host, err := self.GetHost() if err != nil { return nil, httperrors.NewInternalServerError(errors.Wrapf(err, "GetHost").Error())