Merge pull request #2635 from wanyaoqi/bugfix/wyq/fix-vnc-connect

bugfix: vnc connect
This commit is contained in:
yunion-ci-robot
2019-08-29 22:45:17 +08:00
committed by GitHub
2 changed files with 30 additions and 18 deletions
+17 -10
View File
@@ -122,10 +122,15 @@ func findVNCPort(results string) int {
func findVNCPort2(results string) int {
vncInfo := strings.Split(results, "\n")
addrParts := strings.Split(vncInfo[3], ":")
v := addrParts[len(addrParts)-1]
port, _ := strconv.Atoi(v[0 : len(v)-7])
return port
for i := 0; i < len(vncInfo); i++ {
if strings.HasSuffix(vncInfo[i], "(ipv4)") {
addrParts := strings.Split(vncInfo[3], ":")
v := addrParts[len(addrParts)-1]
port, _ := strconv.Atoi(v[0 : len(v)-7])
return port
}
}
return -1
}
func (self *SKVMGuestDriver) GetGuestVncInfo(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, host *models.SHost) (*jsonutils.JSONDict, error) {
@@ -152,15 +157,17 @@ func (self *SKVMGuestDriver) GetGuestVncInfo(ctx context.Context, userCred mccli
// info_vnc = result['results'].split('\n')
// port = int(info_vnc[1].split(':')[-1].split()[0])
/* QEMU 2.9.1
info spice QEMU 2.12.1 monitor Server:
/* $ QEMU 2.9.1
info spice $ QEMU 2.12.1 monitor Server:
Server: (qemu) info vnc address: 0.0.0.0:5901
address: *:5921 info vnc auth: none
migrated: false default: Client: none
auth: spice Server: :::5902 (ipv6)
compiled: 0.13.3 Auth: none (Sub: none)
mouse-mode: server Server: 0.0.0.0:5902 (ipv4)
Channels: none Auth: none (Sub: none)
auth: spice Server: :::5902 (ipv6) $ QEMU 2.12.1 monitor without ipv6
compiled: 0.13.3 Auth: none (Sub: none) (qemu) info vnc
mouse-mode: server Server: 0.0.0.0:5902 (ipv4) info vnc
Channels: none Auth: none (Sub: none) default:
Server: 0.0.0.0:5902 (ipv4)
Auth: none (Sub: none)
*/
var port int
if guest.CheckQemuVersion(guest.GetMetadata("__qemu_version", userCred), "2.12.1") && strings.HasSuffix(cmd, "vnc") {
+13 -8
View File
@@ -39,6 +39,7 @@ const (
OS_NAME_MACOS = "macOS"
OS_NAME_ANDROID = "Android"
OS_NAME_VMWARE = "VMWare"
OS_NAME_CIRROS = "Cirros"
MODE_READLINE = "readline"
MODE_CONTROL = "control"
@@ -69,14 +70,16 @@ func (s *SKVMGuestInstance) getMonitorDesc(idstr string, port int, mode string)
}
func (s *SKVMGuestInstance) getOsname() string {
if s.Desc.Contains("metadata") {
metadata, _ := s.Desc.Get("metadata")
if metadata.Contains("os_name") {
osname, _ := metadata.GetString("os_name")
return osname
}
osName, err := s.Desc.GetString("metadata", "os_name")
if err != nil {
return OS_NAME_LINUX
}
return OS_NAME_LINUX
return osName
}
func (s *SKVMGuestInstance) getOsDistribution() string {
osDis, _ := s.Desc.GetString("metadata", "os_distribution")
return osDis
}
func (s *SKVMGuestInstance) getMachine() string {
@@ -468,7 +471,9 @@ func (s *SKVMGuestInstance) generateStartScript(data *jsonutils.JSONDict) (strin
cmd += " -device virtio-serial"
cmd += " -usb"
// cmd += " -device usb-kbd"
if s.getOsDistribution() != OS_NAME_CIRROS {
cmd += " -device usb-kbd"
}
// # if osname == self.OS_NAME_ANDROID:
// # cmd += " -device usb-mouse"
// # else: