2013-12-08 14:37:36 -08:00
|
|
|
package googlecompute
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"log"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Artifact represents a GCE image as the result of a Packer build.
|
|
|
|
|
type Artifact struct {
|
2016-09-07 19:00:30 -07:00
|
|
|
image *Image
|
2016-07-07 17:50:46 -04:00
|
|
|
driver Driver
|
|
|
|
|
config *Config
|
2020-01-30 11:27:58 +01:00
|
|
|
// StateData should store data such as GeneratedData
|
|
|
|
|
// to be shared with post-processors
|
|
|
|
|
StateData map[string]interface{}
|
2013-12-08 14:37:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BuilderId returns the builder Id.
|
|
|
|
|
func (*Artifact) BuilderId() string {
|
|
|
|
|
return BuilderId
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Destroy destroys the GCE image represented by the artifact.
|
|
|
|
|
func (a *Artifact) Destroy() error {
|
2016-05-24 17:13:36 -07:00
|
|
|
log.Printf("Destroying image: %s", a.image.Name)
|
|
|
|
|
errCh := a.driver.DeleteImage(a.image.Name)
|
2013-12-13 19:07:10 -08:00
|
|
|
return <-errCh
|
2013-12-08 14:37:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Files returns the files represented by the artifact.
|
|
|
|
|
func (*Artifact) Files() []string {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Id returns the GCE image name.
|
|
|
|
|
func (a *Artifact) Id() string {
|
2016-05-24 17:13:36 -07:00
|
|
|
return a.image.Name
|
2013-12-08 14:37:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// String returns the string representation of the artifact.
|
|
|
|
|
func (a *Artifact) String() string {
|
2016-05-24 17:13:36 -07:00
|
|
|
return fmt.Sprintf("A disk image was created: %v", a.image.Name)
|
2013-12-08 14:37:36 -08:00
|
|
|
}
|
2014-01-19 18:32:44 +00:00
|
|
|
|
|
|
|
|
func (a *Artifact) State(name string) interface{} {
|
2020-01-30 11:27:58 +01:00
|
|
|
if _, ok := a.StateData[name]; ok {
|
|
|
|
|
return a.StateData[name]
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-07 17:50:46 -04:00
|
|
|
switch name {
|
2016-09-29 14:13:04 -07:00
|
|
|
case "ImageName":
|
|
|
|
|
return a.image.Name
|
|
|
|
|
case "ImageSizeGb":
|
|
|
|
|
return a.image.SizeGb
|
|
|
|
|
case "AccountFilePath":
|
|
|
|
|
return a.config.AccountFile
|
|
|
|
|
case "ProjectId":
|
|
|
|
|
return a.config.ProjectId
|
|
|
|
|
case "BuildZone":
|
|
|
|
|
return a.config.Zone
|
2016-07-07 17:50:46 -04:00
|
|
|
}
|
2014-01-19 18:32:44 +00:00
|
|
|
return nil
|
|
|
|
|
}
|