mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(climc): modify the code logic of starting "Port-Forward SSH"
This commit is contained in:
@@ -39,7 +39,7 @@ type forwardInfo struct {
|
||||
func dump(input jsonutils.JSONObject) (*forwardInfo, error) {
|
||||
ret := new(forwardInfo)
|
||||
if err := input.Unmarshal(ret); err != nil {
|
||||
return nil, errors.Wrap(err, "xxxx")
|
||||
return nil, errors.Wrap(err, "JSONObject unmarshal failed")
|
||||
}
|
||||
|
||||
if ret.ProxyAddr == "" {
|
||||
|
||||
@@ -844,12 +844,23 @@ func init() {
|
||||
port = opts.Port
|
||||
}
|
||||
|
||||
sshCli, err := ssh.NewClient(host, port, user, passwd, "")
|
||||
vpcid, err := srv.GetString("vpc_id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
forwardFlag := false
|
||||
var forwardItem *forwardInfo
|
||||
var (
|
||||
forwardItem *forwardInfo
|
||||
sshCli *ssh.Client
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
if vpcid == "default" {
|
||||
sshCli, err = ssh.NewClient(host, port, user, passwd, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
forwardFlag = true
|
||||
forwardItem, err = openForward(s, srvid)
|
||||
if err != nil {
|
||||
@@ -861,8 +872,8 @@ func init() {
|
||||
closeForward(s, srvid, forwardItem)
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
log.Infof("ssh %s:%d", host, port)
|
||||
if err := sshCli.RunTerminal(); err != nil {
|
||||
if forwardFlag {
|
||||
@@ -870,6 +881,7 @@ func init() {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if forwardFlag {
|
||||
closeForward(s, srvid, forwardItem)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user