Automatic merge from release/2.6.0 -> master

* commit 'cd5b0b9781a53cfe31ee4dd0e63c6b5e66d271df':
  修复: webconsole 连接vnc设置 password 的虚拟机
This commit is contained in:
邱剑
2019-01-21 20:29:01 +08:00
3 changed files with 26 additions and 14 deletions
+5 -4
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"yunion.io/x/jsonutils"
@@ -191,7 +192,7 @@ func handleServerRemoteConsole(ctx context.Context, w http.ResponseWriter, r *ht
case session.ALIYUN, session.QCLOUD:
responsePublicCloudConsole(info, w)
case session.VNC, session.SPICE, session.WMKS:
handleDataSession(info, w)
handleDataSession(info, w, url.Values{"password": {info.GetPassword()}})
default:
httperrors.NotAcceptableError(w, "Unspported remote console protocol: %s", info.Protocol)
}
@@ -208,14 +209,14 @@ func responsePublicCloudConsole(info *session.RemoteConsoleInfo, w http.Response
sendJSON(w, data)
}
func handleDataSession(sData session.ISessionData, w http.ResponseWriter) {
func handleDataSession(sData session.ISessionData, w http.ResponseWriter, connParams url.Values) {
s, err := session.Manager.Save(sData)
if err != nil {
httperrors.GeneralServerError(w, err)
return
}
data := jsonutils.NewDict()
params, err := s.GetConnectParams()
params, err := s.GetConnectParams(connParams)
if err != nil {
httperrors.GeneralServerError(w, err)
return
@@ -226,7 +227,7 @@ func handleDataSession(sData session.ISessionData, w http.ResponseWriter) {
}
func handleCommandSession(cmd command.ICommand, w http.ResponseWriter) {
handleDataSession(cmd, w)
handleDataSession(cmd, w, nil)
}
func sendJSON(w http.ResponseWriter, body jsonutils.JSONObject) {
+15 -5
View File
@@ -19,11 +19,12 @@ const (
)
type RemoteConsoleInfo struct {
Host string `json:"host"`
Port int64 `json:"port"`
Protocol string `json:"protocol"`
Id string `json:"id"`
OsName string `json:"osName"`
Host string `json:"host"`
Port int64 `json:"port"`
Protocol string `json:"protocol"`
Id string `json:"id"`
OsName string `json:"osName"`
VncPassword string `json:"vncPassword"`
// used by aliyun server
InstanceId string `json:"instance_id"`
@@ -37,6 +38,7 @@ func NewRemoteConsoleInfoByCloud(s *mcclient.ClientSession, serverId string) (*R
return nil, err
}
osName, _ := metadata.GetString("os_name")
vncPasswd, _ := metadata.GetString("__vnc_password")
ret, err := modules.Servers.GetSpecific(s, serverId, "vnc", nil)
if err != nil {
return nil, err
@@ -47,6 +49,7 @@ func NewRemoteConsoleInfoByCloud(s *mcclient.ClientSession, serverId string) (*R
return nil, err
}
vncInfo.OsName = osName
vncInfo.VncPassword = vncPasswd
return &vncInfo, nil
}
@@ -93,6 +96,13 @@ func (info *RemoteConsoleInfo) GetConnectParams() (string, error) {
}
}
func (info *RemoteConsoleInfo) GetPassword() string {
if len(info.Password) != 0 {
return info.Password
}
return info.VncPassword
}
func (info *RemoteConsoleInfo) getOpenStackURL() (string, error) {
return info.Url, nil
}
+6 -5
View File
@@ -87,12 +87,13 @@ type SSession struct {
AccessedAt time.Time
}
func (s SSession) GetConnectParams() (string, error) {
params := url.Values{
"api_server": {o.Options.ApiServer},
"access_token": {s.AccessToken},
"protocol": {s.GetProtocol()},
func (s SSession) GetConnectParams(params url.Values) (string, error) {
if params == nil {
params = url.Values(make(map[string][]string))
}
params.Set("api_server", o.Options.ApiServer)
params.Set("access_token", s.AccessToken)
params.Set("protocol", s.GetProtocol())
return params.Encode(), nil
}