Пример #1
0
func (cloug *Cloug) VmVnc(vm *lobster.VirtualMachine) (string, error) {
	if cloug.vncService == nil {
		return "", fmt.Errorf("operation not supported")
	}
	rawurl, err := cloug.vncService.GetVNC(vm.Identification)
	if err != nil {
		return "", err
	}

	// decode URL, depending on protocol we may want to start websockify/wssh
	u, err := url.Parse(rawurl)
	if err != nil {
		return "", fmt.Errorf("failed to parse returned URL: %v", err)
	}

	if u.Scheme == "vnc" {
		return lobster.HandleWebsockify(u.Host, u.Query().Get("password")), nil
	} else if u.Scheme == "ssh" {
		if u.User == nil {
			return "", fmt.Errorf("got URL with ssh scheme, but user info not set")
		}
		username := u.User.Username()
		password, isSet := u.User.Password()
		if !isSet {
			return "", fmt.Errorf("got URL with ssh scheme, but user info does not specify password")
		}
		return lobster.HandleWssh(u.Host, username, password), nil
	} else {
		return rawurl, nil
	}
}
Пример #2
0
func (this *SolusVM) VmVnc(vm *lobster.VirtualMachine) (string, error) {
	vmIdentificationInt, _ := strconv.Atoi(vm.Identification)

	if this.VirtType == "kvm" || this.VirtType == "xen" {
		vncInfo, err := this.Api.VmVnc(vmIdentificationInt)
		if err != nil {
			return "", err
		} else {
			return lobster.HandleWebsockify(vncInfo.Ip+":"+vncInfo.Port, vncInfo.Password), nil
		}
	} else {
		consoleInfo, err := this.Api.VmConsole(vmIdentificationInt)
		if err != nil {
			return "", err
		} else {
			return lobster.HandleWssh(consoleInfo.Ip+":"+consoleInfo.Port, consoleInfo.Username, consoleInfo.Password), nil
		}
	}
}