RemoteCommand Implement of native
(option *ami.DebugOptions, pipe ami.Pipe)
| 99 | |
| 100 | // RemoteCommand Implement of native |
| 101 | func (impl *nativeImpl) RemoteCommand(option *ami.DebugOptions, pipe ami.Pipe) error { |
| 102 | cfg := &ssh.ClientConfig{ |
| 103 | User: option.Username, |
| 104 | Auth: []ssh.AuthMethod{ |
| 105 | ssh.Password(option.Password), |
| 106 | }, |
| 107 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), |
| 108 | } |
| 109 | server := fmt.Sprintf("%s:%s", option.IP, option.Port) |
| 110 | conn, err := ssh.Dial(Network, server, cfg) |
| 111 | if err != nil { |
| 112 | return errors.Trace(err) |
| 113 | } |
| 114 | defer conn.Close() |
| 115 | |
| 116 | session, err := conn.NewSession() |
| 117 | if err != nil { |
| 118 | return errors.Trace(err) |
| 119 | } |
| 120 | defer session.Close() |
| 121 | |
| 122 | session.Stdout = pipe.OutWriter |
| 123 | session.Stderr = pipe.OutWriter |
| 124 | session.Stdin = pipe.InReader |
| 125 | |
| 126 | modes := ssh.TerminalModes{ |
| 127 | ssh.ECHO: 1, // enable echo |
| 128 | ssh.TTY_OP_ISPEED: TtySpeed, // input speed = 14.4kbaud |
| 129 | ssh.TTY_OP_OSPEED: TtySpeed, // output speed = 14.4kbaud |
| 130 | } |
| 131 | |
| 132 | // TODO: support window resize |
| 133 | if err = session.RequestPty(Term, Rows, Cols, modes); err != nil { |
| 134 | return errors.Trace(err) |
| 135 | } |
| 136 | // Start remote shell |
| 137 | if err = session.Shell(); err != nil { |
| 138 | return errors.Trace(err) |
| 139 | } |
| 140 | err = session.Wait() |
| 141 | if err != nil { |
| 142 | impl.log.Warn("ssh session log out with exception") |
| 143 | } |
| 144 | return nil |
| 145 | } |
| 146 | |
| 147 | // TODO: impl native RemoteLogs |
| 148 | func (impl *nativeImpl) RemoteLogs(*ami.LogsOptions, ami.Pipe) error { |