mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 01:35:56 +08:00
webconsole: use external frontend
This commit is contained in:
@@ -6,6 +6,6 @@ admin_user = 'regionadmin'
|
||||
admin_password = 'iygPtGX6r7NZ_tW_'
|
||||
admin_tenant_name = 'system'
|
||||
|
||||
frontend_url = "http://10.168.222.245:8899"
|
||||
api_server = "http://webconsole.yunion.io"
|
||||
|
||||
log_level = "debug"
|
||||
|
||||
@@ -1,12 +1,36 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
o "yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
handleResult := func(opt o.WebConsoleFrontendOptions, obj jsonutils.JSONObject) error {
|
||||
if opt.WebUrl == "" {
|
||||
printObject(obj)
|
||||
return nil
|
||||
}
|
||||
u, err := url.Parse(opt.WebUrl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
connParams, err := obj.GetString("connect_params")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u.Path = "index.html"
|
||||
u.RawQuery = connParams
|
||||
fmt.Println(u.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
R(&o.PodShellOptions{}, "webconsole-k8s-pod", "Show TTY console of given pod", func(s *mcclient.ClientSession, args *o.PodShellOptions) error {
|
||||
params, err := args.Params()
|
||||
if err != nil {
|
||||
@@ -16,7 +40,7 @@ func init() {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(ret)
|
||||
handleResult(args.WebConsoleFrontendOptions, ret)
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -29,7 +53,7 @@ func init() {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(ret)
|
||||
handleResult(args.WebConsoleFrontendOptions, ret)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,7 +4,12 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
)
|
||||
|
||||
type WebConsoleFrontendOptions struct {
|
||||
WebUrl string `help:"Frontend terminal HTML web url" short-token:"w"`
|
||||
}
|
||||
|
||||
type PodBaseOptions struct {
|
||||
WebConsoleFrontendOptions
|
||||
NAME string `help:"Name of k8s pod to connect"`
|
||||
Namespace string `help:"Namespace of this pod"`
|
||||
Container string `help:"Container in this pod"`
|
||||
|
||||
@@ -124,12 +124,13 @@ func handleK8sCommand(
|
||||
return
|
||||
}
|
||||
data := jsonutils.NewDict()
|
||||
url, err := cmdSession.GetConnectUrl()
|
||||
params, err := cmdSession.GetConnectParams()
|
||||
if err != nil {
|
||||
httperrors.GeneralServerError(w, err)
|
||||
return
|
||||
}
|
||||
data.Add(jsonutils.NewString(url), "url")
|
||||
data.Add(jsonutils.NewString(params), "connect_params")
|
||||
data.Add(jsonutils.NewString(cmdSession.Id), "session")
|
||||
sendJSON(w, data)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,5 @@ var (
|
||||
type WebConsoleOptions struct {
|
||||
cloudcommon.Options
|
||||
|
||||
FrontendUrl string `help:"Frontend url to display web console page" default:"http://127.0.0.1:8899"`
|
||||
TtyStaticPath string `help:"TTY static HTML render pages" default:"./tty"`
|
||||
ApiServer string `help:"API server url to handle websocket connection, usually with public access" default:"http://webconsole.yunion.io"`
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -14,7 +13,6 @@ import (
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon"
|
||||
"yunion.io/x/onecloud/pkg/webconsole"
|
||||
"yunion.io/x/onecloud/pkg/webconsole/command"
|
||||
o "yunion.io/x/onecloud/pkg/webconsole/options"
|
||||
"yunion.io/x/onecloud/pkg/webconsole/server"
|
||||
)
|
||||
@@ -22,12 +20,12 @@ import (
|
||||
func StartService() {
|
||||
cloudcommon.ParseOptions(&o.Options, &o.Options.Options, os.Args, "webconsole.conf")
|
||||
|
||||
if o.Options.FrontendUrl == "" {
|
||||
log.Fatalf("--frontend-url must specified")
|
||||
if o.Options.ApiServer == "" {
|
||||
log.Fatalf("--api-server must specified")
|
||||
}
|
||||
_, err := url.Parse(o.Options.FrontendUrl)
|
||||
_, err := url.Parse(o.Options.ApiServer)
|
||||
if err != nil {
|
||||
log.Fatalf("invalid --frontend-url %s", o.Options.FrontendUrl)
|
||||
log.Fatalf("invalid --api-server %s", o.Options.ApiServer)
|
||||
}
|
||||
|
||||
cloudcommon.InitAuth(&o.Options.Options, func() {
|
||||
@@ -49,10 +47,6 @@ func start() {
|
||||
// websocket related console handler
|
||||
root.Handle(webconsole.ConnectPathPrefix, server.NewConnectionServer())
|
||||
|
||||
p1 := fmt.Sprintf("/%s/", command.PROTOCOL_TTY)
|
||||
// static file handler
|
||||
root.PathPrefix(p1).Handler(http.FileServer(http.Dir(o.Options.TtyStaticPath)))
|
||||
|
||||
addr := net.JoinHostPort(o.Options.Address, strconv.Itoa(o.Options.Port))
|
||||
log.Infof("Start listen on %s", addr)
|
||||
err := http.ListenAndServe(addr, root)
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
"yunion.io/x/onecloud/pkg/webconsole/command"
|
||||
o "yunion.io/x/onecloud/pkg/webconsole/options"
|
||||
)
|
||||
@@ -75,23 +74,13 @@ type SSession struct {
|
||||
AccessToken string
|
||||
}
|
||||
|
||||
func (s SSession) GetConnectUrl() (string, error) {
|
||||
FrontendUrl := o.Options.FrontendUrl
|
||||
endpointUrl, err := auth.AdminCredential().GetServiceURL("webconsole", o.Options.Region, "", "internalURL")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if endpointUrl == "" {
|
||||
return "", fmt.Errorf("Not found service URL for webconsole")
|
||||
}
|
||||
u, _ := url.Parse(FrontendUrl)
|
||||
func (s SSession) GetConnectParams() (string, error) {
|
||||
params := url.Values{
|
||||
"api_server": {endpointUrl},
|
||||
"api_server": {o.Options.ApiServer},
|
||||
"access_token": {s.AccessToken},
|
||||
"protocol": {s.GetProtocol()},
|
||||
}
|
||||
u.Path = fmt.Sprintf("%s/", s.GetProtocol())
|
||||
u.RawQuery = params.Encode()
|
||||
return u.String(), nil
|
||||
return params.Encode(), nil
|
||||
}
|
||||
|
||||
func (s *SSession) Close() error {
|
||||
|
||||
Reference in New Issue
Block a user