@@ -30,12 +30,20 @@ import (
3030 "github.com/flatcar/mantle/util"
3131)
3232
33+ type MachineState int
34+
35+ const (
36+ READY MachineState = iota
37+ PROVISIONING
38+ )
39+
3340type Machine struct {
3441 ID string
3542 PublicIPAddress string
3643 PrivateIPAddress string
3744 InterfaceName string
3845 PublicIPName string
46+ State MachineState
3947}
4048
4149func (a * API ) getAvset () string {
@@ -239,7 +247,7 @@ func (a *API) CreateInstance(name, sshkey, resourceGroup, storageAccount string,
239247 defer cancel ()
240248 _ , err = poller .PollUntilDone (ctx , nil )
241249 if err != nil {
242- return & Machine {ID : name }, fmt .Errorf ("PollUntilDone: %w" , err )
250+ return & Machine {ID : name , State : PROVISIONING }, fmt .Errorf ("PollUntilDone: %w" , err )
243251 }
244252 plog .Infof ("Instance %s created" , name )
245253
@@ -300,6 +308,38 @@ func (a *API) TerminateInstance(machine *Machine, resourceGroup string) error {
300308 return err
301309}
302310
311+ func (a * API ) GetScreenshot (name , resourceGroup string , output io.Writer ) error {
312+ vmResourceGroup := a .getVMRG (resourceGroup )
313+ param := & armcompute.VirtualMachinesClientRetrieveBootDiagnosticsDataOptions {
314+ SasURIExpirationTimeInMinutes : to.Ptr [int32 ](5 ),
315+ }
316+ resp , err := a .compClient .RetrieveBootDiagnosticsData (context .TODO (), vmResourceGroup , name , param )
317+ if err != nil {
318+ return fmt .Errorf ("could not get VM: %v" , err )
319+ }
320+ if resp .ConsoleScreenshotBlobURI == nil {
321+ return fmt .Errorf ("console screenshot URI is nil" )
322+ }
323+
324+ var data io.ReadCloser
325+ err = util .Retry (6 , 10 * time .Second , func () error {
326+ reply , err := http .Get (* resp .ConsoleScreenshotBlobURI )
327+ if err != nil {
328+ return fmt .Errorf ("could not GET console screenshot: %v" , err )
329+ }
330+ data = reply .Body
331+ return nil
332+ })
333+ if err != nil {
334+ return err
335+ }
336+ written , err := io .Copy (output , data )
337+ if err == nil {
338+ plog .Debugf ("wrote %d bytes to screenshot" , written )
339+ }
340+ return err
341+ }
342+
303343func (a * API ) GetConsoleOutput (name , resourceGroup , storageAccount string ) ([]byte , error ) {
304344 vmResourceGroup := a .getVMRG (resourceGroup )
305345 param := & armcompute.VirtualMachinesClientRetrieveBootDiagnosticsDataOptions {
0 commit comments