Commit 637968f2 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/googlecompute: artifact uses Driver, no more api

parent 33a84c09
package googlecompute
import (
"code.google.com/p/google-api-go-client/compute/v1beta16"
)
// GoogleComputeClient represents a GCE client.
type GoogleComputeClient struct {
ProjectId string
Service *compute.Service
Zone string
clientSecrets *clientSecrets
}
// DeleteImage deletes the named image. Returns a Global Operation.
func (g *GoogleComputeClient) DeleteImage(name string) (*compute.Operation, error) {
imagesDeleteCall := g.Service.Images.Delete(g.ProjectId, name)
operation, err := imagesDeleteCall.Do()
if err != nil {
return nil, err
}
return operation, nil
}
......@@ -19,14 +19,8 @@ func (*Artifact) BuilderId() string {
// Destroy destroys the GCE image represented by the artifact.
func (a *Artifact) Destroy() error {
log.Printf("Destroying image: %s", a.imageName)
/*
// Ignore the operation result as we are not waiting until it completes.
_, err := a.client.DeleteImage(a.imageName)
if err != nil {
return err
}
*/
return nil
errCh := a.driver.DeleteImage(a.imageName)
return <-errCh
}
// Files returns the files represented by the artifact.
......
......@@ -7,6 +7,9 @@ type Driver interface {
// CreateImage creates an image with the given URL in Google Storage.
CreateImage(name, description, url string) <-chan error
// DeleteImage deletes the image with the given name.
DeleteImage(name string) <-chan error
// DeleteInstance deletes the given instance.
DeleteInstance(zone, name string) (<-chan error, error)
......
......@@ -81,6 +81,18 @@ func (d *driverGCE) CreateImage(name, description, url string) <-chan error {
return errCh
}
func (d *driverGCE) DeleteImage(name string) <-chan error {
errCh := make(chan error, 1)
op, err := d.service.Images.Delete(d.projectId, name).Do()
if err != nil {
errCh <- err
} else {
go waitForState(errCh, "DONE", d.refreshGlobalOp(op))
}
return errCh
}
func (d *driverGCE) DeleteInstance(zone, name string) (<-chan error, error) {
op, err := d.service.Instances.Delete(d.projectId, zone, name).Do()
if err != nil {
......
......@@ -8,6 +8,9 @@ type DriverMock struct {
CreateImageURL string
CreateImageErrCh <-chan error
DeleteImageName string
DeleteImageErrCh <-chan error
DeleteInstanceZone string
DeleteInstanceName string
DeleteInstanceErrCh <-chan error
......@@ -43,6 +46,19 @@ func (d *DriverMock) CreateImage(name, description, url string) <-chan error {
return resultCh
}
func (d *DriverMock) DeleteImage(name string) <-chan error {
d.DeleteImageName = name
resultCh := d.DeleteImageErrCh
if resultCh == nil {
ch := make(chan error)
close(ch)
resultCh = ch
}
return resultCh
}
func (d *DriverMock) DeleteInstance(zone, name string) (<-chan error, error) {
d.DeleteInstanceZone = zone
d.DeleteInstanceName = name
......
package googlecompute
import (
"time"
)
// waitForInstanceState.
func waitForInstanceState(desiredState string, zone string, name string, client *GoogleComputeClient, timeout time.Duration) error {
return nil
/*
f := func() (string, error) {
return client.InstanceStatus(zone, name)
}
return waitForState("instance", desiredState, f, timeout)
*/
}
// waitForZoneOperationState.
func waitForZoneOperationState(desiredState string, zone string, name string, client *GoogleComputeClient, timeout time.Duration) error {
return nil
/*
f := func() (string, error) {
return client.ZoneOperationStatus(zone, name)
}
return waitForState("operation", desiredState, f, timeout)
*/
}
// waitForGlobalOperationState.
func waitForGlobalOperationState(desiredState string, name string, client *GoogleComputeClient, timeout time.Duration) error {
/*
f := func() (string, error) {
return client.GlobalOperationStatus(name)
}
return waitForState("operation", desiredState, f, timeout)
*/
return nil
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment