1// Copyright 2018 Google LLC. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package main
6
7import (
8	"context"
9	"log"
10
11	"golang.org/x/oauth2/google"
12	compute "google.golang.org/api/compute/v1"
13)
14
15const (
16	projectID   = "some-project-id"
17	zone        = "some-zone"
18	operationID = "some-operation-id"
19)
20
21func operationProgressMain() {
22	ctx := context.Background()
23
24	client, err := google.DefaultClient(ctx, compute.CloudPlatformScope)
25	if err != nil {
26		log.Fatal(err)
27	}
28	svc, err := compute.New(client)
29	if err != nil {
30		log.Fatal(err)
31	}
32
33	for {
34		resp, err := svc.ZoneOperations.Get(projectID, zone, operationID).Do()
35		if err != nil {
36			log.Fatal(err)
37		}
38		// Note: the response Status may differ between APIs. The string values
39		// checked here may need to be changed depending on the API.
40		if resp.Status != "WORKING" && resp.Status != "QUEUED" {
41			break
42		}
43	}
44	log.Println("operation complete")
45}
46