terraform-provider-google/google/container_operation.go

63 lines
1.4 KiB
Go
Raw Normal View History

package google
import (
"fmt"
2018-12-27 01:42:37 +00:00
"google.golang.org/api/container/v1beta1"
)
type ContainerOperationWaiter struct {
2018-12-27 01:42:37 +00:00
Service *container.Service
Op *container.Operation
Project string
Location string
}
2018-12-27 01:42:37 +00:00
func (w *ContainerOperationWaiter) State() string {
return w.Op.Status
}
2018-12-27 01:42:37 +00:00
func (w *ContainerOperationWaiter) Error() error {
if w.Op.StatusMessage != "" {
return fmt.Errorf(w.Op.StatusMessage)
}
2018-12-27 01:42:37 +00:00
return nil
}
2018-12-27 01:42:37 +00:00
func (w *ContainerOperationWaiter) SetOp(op interface{}) error {
w.Op = op.(*container.Operation)
return nil
}
2018-12-27 01:42:37 +00:00
func (w *ContainerOperationWaiter) QueryOp() (interface{}, error) {
name := fmt.Sprintf("projects/%s/locations/%s/operations/%s",
w.Project, w.Location, w.Op.Name)
return w.Service.Projects.Locations.Operations.Get(name).Do()
}
2018-12-27 01:42:37 +00:00
func (w *ContainerOperationWaiter) OpName() string {
return w.Op.Name
}
2018-12-27 01:42:37 +00:00
func (w *ContainerOperationWaiter) PendingStates() []string {
return []string{"PENDING", "RUNNING"}
}
2018-12-27 01:42:37 +00:00
func (w *ContainerOperationWaiter) TargetStates() []string {
return []string{"DONE"}
}
2018-12-27 01:42:37 +00:00
func containerOperationWait(config *Config, op *container.Operation, project, location, activity string, timeoutMinutes int) error {
w := &ContainerOperationWaiter{
Service: config.clientContainerBeta,
Op: op,
Project: project,
Location: location,
}
2018-12-27 01:42:37 +00:00
if err := w.SetOp(op); err != nil {
return err
}
2018-12-27 01:42:37 +00:00
return OperationWait(w, activity, timeoutMinutes)
}