@@ -96,6 +96,50 @@ func addUserData(ctx CommandContext, userdatas []string, serverID string) {
9696 }
9797}
9898
99+ func runShowBoot (ctx CommandContext , args RunArgs , serverID string , closeTimeout chan struct {}, timeoutExit chan struct {}) error {
100+ // Attach to server serial
101+ logrus .Info ("Attaching to server console ..." )
102+ gottycli , done , err := utils .AttachToSerial (serverID , ctx .API .Token )
103+ if err != nil {
104+ close (closeTimeout )
105+ return fmt .Errorf ("cannot attach to server serial: %v" , err )
106+ }
107+ utils .Quiet (true )
108+ notif , gateway , err := waitSSHConnection (ctx , args , serverID )
109+ if err != nil {
110+ close (closeTimeout )
111+ gottycli .ExitLoop ()
112+ <- done
113+ return err
114+ }
115+ select {
116+ case <- timeoutExit :
117+ gottycli .ExitLoop ()
118+ <- done
119+ utils .Quiet (false )
120+ return fmt .Errorf ("Operation timed out" )
121+ case sshConnection := <- notif :
122+ close (closeTimeout )
123+ gottycli .ExitLoop ()
124+ <- done
125+ utils .Quiet (false )
126+ if sshConnection .err != nil {
127+ return sshConnection .err
128+ }
129+ if fingerprints := ctx .API .GetSSHFingerprintFromServer (serverID ); len (fingerprints ) > 0 {
130+ for i := range fingerprints {
131+ fmt .Fprintf (ctx .Stdout , "%s\n " , fingerprints [i ])
132+ }
133+ }
134+ server := sshConnection .server
135+ logrus .Info ("Connecting to server ..." )
136+ if err = utils .SSHExec (server .PublicAddress .IP , server .PrivateIP , []string {}, false , gateway ); err != nil {
137+ return fmt .Errorf ("Connection to server failed: %v" , err )
138+ }
139+ }
140+ return nil
141+ }
142+
99143// Run is the handler for 'scw run'
100144func Run (ctx CommandContext , args RunArgs ) error {
101145 if args .Gateway == "" {
@@ -163,41 +207,7 @@ func Run(ctx CommandContext, args RunArgs) error {
163207 }()
164208 }
165209 if args .ShowBoot {
166- // Attach to server serial
167- logrus .Info ("Attaching to server console ..." )
168- gottycli , done , err := utils .AttachToSerial (serverID , ctx .API .Token )
169- if err != nil {
170- close (closeTimeout )
171- return fmt .Errorf ("cannot attach to server serial: %v" , err )
172- }
173- utils .Quiet (true )
174- notif , gateway , err := waitSSHConnection (ctx , args , serverID )
175- if err != nil {
176- close (closeTimeout )
177- gottycli .ExitLoop ()
178- <- done
179- return err
180- }
181- select {
182- case <- timeoutExit :
183- gottycli .ExitLoop ()
184- <- done
185- utils .Quiet (false )
186- return fmt .Errorf ("Operation timed out" )
187- case sshConnection := <- notif :
188- close (closeTimeout )
189- gottycli .ExitLoop ()
190- <- done
191- utils .Quiet (false )
192- if sshConnection .err != nil {
193- return sshConnection .err
194- }
195- server := sshConnection .server
196- logrus .Info ("Connecting to server ..." )
197- if err = utils .SSHExec (server .PublicAddress .IP , server .PrivateIP , []string {}, false , gateway ); err != nil {
198- return fmt .Errorf ("Connection to server failed: %v" , err )
199- }
200- }
210+ return runShowBoot (ctx , args , serverID , closeTimeout , timeoutExit )
201211 } else if args .Attach {
202212 // Attach to server serial
203213 logrus .Info ("Attaching to server console ..." )
@@ -222,6 +232,11 @@ func Run(ctx CommandContext, args RunArgs) error {
222232 if sshConnection .err != nil {
223233 return sshConnection .err
224234 }
235+ if fingerprints := ctx .API .GetSSHFingerprintFromServer (serverID ); len (fingerprints ) > 0 {
236+ for i := range fingerprints {
237+ fmt .Fprintf (ctx .Stdout , "%s\n " , fingerprints [i ])
238+ }
239+ }
225240 server := sshConnection .server
226241 // exec -w SERVER COMMAND ARGS...
227242 if len (args .Command ) < 1 {
0 commit comments