@@ -2,16 +2,18 @@ package google
22
33import (
44 "bytes"
5+ "encoding/json"
56 "fmt"
67 "time"
78
8- "google.golang.org/api/compute/v1 "
9+ computeBeta "google.golang.org/api/compute/v0.beta "
910)
1011
1112type ComputeOperationWaiter struct {
12- Service * compute .Service
13- Op * compute .Operation
13+ Service * computeBeta .Service
14+ Op * computeBeta .Operation
1415 Project string
16+ Parent string
1517}
1618
1719func (w * ComputeOperationWaiter ) State () string {
@@ -42,7 +44,7 @@ func (w *ComputeOperationWaiter) IsRetryable(err error) bool {
4244
4345func (w * ComputeOperationWaiter ) SetOp (op interface {}) error {
4446 var ok bool
45- w .Op , ok = op .(* compute .Operation )
47+ w .Op , ok = op .(* computeBeta .Operation )
4648 if ! ok {
4749 return fmt .Errorf ("Unable to set operation. Bad type!" )
4850 }
@@ -59,6 +61,8 @@ func (w *ComputeOperationWaiter) QueryOp() (interface{}, error) {
5961 } else if w .Op .Region != "" {
6062 region := GetResourceNameFromSelfLink (w .Op .Region )
6163 return w .Service .RegionOperations .Get (w .Project , region , w .Op .Name ).Do ()
64+ } else if w .Parent != "" {
65+ return w .Service .GlobalOrganizationOperations .Get (w .Op .Name ).ParentId (w .Parent ).Do ()
6266 }
6367 return w .Service .GlobalOperations .Get (w .Project , w .Op .Name ).Do ()
6468}
@@ -80,14 +84,14 @@ func (w *ComputeOperationWaiter) TargetStates() []string {
8084}
8185
8286func computeOperationWaitTime (config * Config , res interface {}, project , activity string , timeout time.Duration ) error {
83- op := & compute .Operation {}
87+ op := & computeBeta .Operation {}
8488 err := Convert (res , op )
8589 if err != nil {
8690 return err
8791 }
8892
8993 w := & ComputeOperationWaiter {
90- Service : config .clientCompute ,
94+ Service : config .clientComputeBeta ,
9195 Op : op ,
9296 Project : project ,
9397 }
@@ -98,9 +102,35 @@ func computeOperationWaitTime(config *Config, res interface{}, project, activity
98102 return OperationWait (w , activity , timeout , config .PollInterval )
99103}
100104
105+ func computeOrgOperationWaitTimeWithResponse (config * Config , res interface {}, response * map [string ]interface {}, parent , activity string , timeout time.Duration ) error {
106+ op := & computeBeta.Operation {}
107+ err := Convert (res , op )
108+ if err != nil {
109+ return err
110+ }
111+
112+ w := & ComputeOperationWaiter {
113+ Service : config .clientComputeBeta ,
114+ Op : op ,
115+ Parent : parent ,
116+ }
117+
118+ if err := w .SetOp (op ); err != nil {
119+ return err
120+ }
121+ if err := OperationWait (w , activity , timeout , config .PollInterval ); err != nil {
122+ return err
123+ }
124+ e , err := json .Marshal (w .Op )
125+ if err != nil {
126+ return err
127+ }
128+ return json .Unmarshal (e , response )
129+ }
130+
101131// ComputeOperationError wraps compute.OperationError and implements the
102132// error interface so it can be returned.
103- type ComputeOperationError compute .OperationError
133+ type ComputeOperationError computeBeta .OperationError
104134
105135func (e ComputeOperationError ) Error () string {
106136 var buf bytes.Buffer
0 commit comments