github.phpd.cn/hashicorp/packer@v1.3.2/builder/googlecompute/artifact.go (about) 1 package googlecompute 2 3 import ( 4 "fmt" 5 "log" 6 ) 7 8 // Artifact represents a GCE image as the result of a Packer build. 9 type Artifact struct { 10 image *Image 11 driver Driver 12 config *Config 13 } 14 15 // BuilderId returns the builder Id. 16 func (*Artifact) BuilderId() string { 17 return BuilderId 18 } 19 20 // Destroy destroys the GCE image represented by the artifact. 21 func (a *Artifact) Destroy() error { 22 log.Printf("Destroying image: %s", a.image.Name) 23 errCh := a.driver.DeleteImage(a.image.Name) 24 return <-errCh 25 } 26 27 // Files returns the files represented by the artifact. 28 func (*Artifact) Files() []string { 29 return nil 30 } 31 32 // Id returns the GCE image name. 33 func (a *Artifact) Id() string { 34 return a.image.Name 35 } 36 37 // String returns the string representation of the artifact. 38 func (a *Artifact) String() string { 39 return fmt.Sprintf("A disk image was created: %v", a.image.Name) 40 } 41 42 func (a *Artifact) State(name string) interface{} { 43 switch name { 44 case "ImageName": 45 return a.image.Name 46 case "ImageSizeGb": 47 return a.image.SizeGb 48 case "AccountFilePath": 49 return a.config.AccountFile 50 case "ProjectId": 51 return a.config.ProjectId 52 case "BuildZone": 53 return a.config.Zone 54 } 55 return nil 56 }