@@ -157,47 +157,6 @@ func (s *openstackServer) ReuseData() interface{} {
157157 return & s .d
158158}
159159
160- var openstackSerialOutputTimeout = 30 * time .Second
161- var openstackSerialConsoleErr = fmt .Errorf ("cannot get console output" )
162-
163- func (s * openstackServer ) SerialOutput (ctx context.Context ) (string , error ) {
164- _ , err := s .p .computeClient .GetServer (s .d .Id )
165- if err != nil {
166- // this is when the server is removed
167- return "" , fmt .Errorf ("failed to retrieve the serial console, server removed: %s" , s )
168- }
169-
170- url := fmt .Sprintf ("servers/%s/action" , s .d .Id )
171-
172- var req struct {
173- OsGetSerialConsole struct {} `json:"os-getConsoleOutput"`
174- }
175- var resp struct {
176- Output string `json:"output"`
177- }
178- requestData := goosehttp.RequestData {ReqValue : req , RespValue : & resp , ExpectedStatus : []int {http .StatusOK }}
179- timeout := time .After (openstackSerialOutputTimeout )
180- retry := time .NewTicker (openstackServerBootRetry )
181- defer retry .Stop ()
182-
183- for {
184- err := s .p .osClient .SendRequest ("POST" , "compute" , "v2" , url , & requestData )
185- if err != nil {
186- debugf ("failed to retrieve the serial console for server %s: %v" , s , err )
187- }
188- if len (resp .Output ) > 0 {
189- return resp .Output , nil
190- }
191- select {
192- case <- retry .C :
193- case <- timeout :
194- return "" , fmt .Errorf ("failed to retrieve the serial console for instance %s: timeout reached" , s )
195- case <- ctx .Done ():
196- return "" , fmt .Errorf ("failed to retrieve the serial console for instance %s: interrupted" , s )
197- }
198- }
199- }
200-
201160const (
202161 serverStatusProvisioning = "PROVISIONING"
203162 volumeStatusAvailable = "available"
@@ -308,6 +267,47 @@ func (e *openstackError) Error() string {
308267 return msg
309268}
310269
270+ var openstackSerialOutputTimeout = 30 * time .Second
271+ var openstackSerialConsoleErr = fmt .Errorf ("cannot get console output" )
272+
273+ func (p * openstackProvider ) SerialOutput (ctx context.Context , s * openstackServer ) (string , error ) {
274+ _ , err := p .computeClient .GetServer (s .d .Id )
275+ if err != nil {
276+ // this is when the server is removed
277+ return "" , fmt .Errorf ("failed to retrieve the serial console, server removed: %s" , s )
278+ }
279+
280+ url := fmt .Sprintf ("servers/%s/action" , s .d .Id )
281+
282+ var req struct {
283+ OsGetSerialConsole struct {} `json:"os-getConsoleOutput"`
284+ }
285+ var resp struct {
286+ Output string `json:"output"`
287+ }
288+ requestData := goosehttp.RequestData {ReqValue : req , RespValue : & resp , ExpectedStatus : []int {http .StatusOK }}
289+ timeout := time .After (openstackSerialOutputTimeout )
290+ retry := time .NewTicker (openstackServerBootRetry )
291+ defer retry .Stop ()
292+
293+ for {
294+ err := s .p .osClient .SendRequest ("POST" , "compute" , "v2" , url , & requestData )
295+ if err != nil {
296+ debugf ("failed to retrieve the serial console for server %s: %v" , s , err )
297+ }
298+ if len (resp .Output ) > 0 {
299+ return resp .Output , nil
300+ }
301+ select {
302+ case <- retry .C :
303+ case <- timeout :
304+ return "" , fmt .Errorf ("failed to retrieve the serial console for instance %s: timeout reached" , s )
305+ case <- ctx .Done ():
306+ return "" , fmt .Errorf ("failed to retrieve the serial console for instance %s: interrupted" , s )
307+ }
308+ }
309+ }
310+
311311func (p * openstackProvider ) findFlavor (flavorName string ) (* nova.Entity , error ) {
312312 flavors , err := p .computeClient .ListFlavors ()
313313 if err != nil {
@@ -625,7 +625,7 @@ func (p *openstackProvider) waitServerBootSerial(ctx context.Context, s *opensta
625625
626626 var marker = openstackReadyMarker
627627 for {
628- resp , err := s .SerialOutput (ctx )
628+ resp , err := p .SerialOutput (ctx , s )
629629 if err != nil {
630630 return fmt .Errorf ("%w: %v" , openstackSerialConsoleErr , err )
631631 }
0 commit comments