packer-cn/builder/oracle/oci/artifact.go

58 lines
1.2 KiB
Go
Raw Normal View History

package oci
import (
2018-06-26 05:05:56 -04:00
"context"
"fmt"
2018-01-22 20:21:10 -05:00
2018-04-11 05:20:40 -04:00
"github.com/oracle/oci-go-sdk/core"
)
// Artifact is an artifact implementation that contains a built Custom Image.
type Artifact struct {
2018-04-11 05:20:40 -04:00
Image core.Image
Region string
driver Driver
// StateData should store data such as GeneratedData
// to be shared with post-processors
StateData map[string]interface{}
}
// BuilderId uniquely identifies the builder.
func (a *Artifact) BuilderId() string {
return BuilderId
}
// Files lists the files associated with an artifact. We don't have any files
// as the custom image is stored server side.
func (a *Artifact) Files() []string {
return nil
}
// Id returns the OCID of the associated Image.
func (a *Artifact) Id() string {
2018-04-11 05:20:40 -04:00
return *a.Image.Id
}
func (a *Artifact) String() string {
2018-04-11 05:20:40 -04:00
var displayName string
if a.Image.DisplayName != nil {
displayName = *a.Image.DisplayName
}
return fmt.Sprintf(
"An image was created: '%v' (OCID: %v) in region '%v'",
2018-04-11 05:20:40 -04:00
displayName, *a.Image.Id, a.Region,
)
}
2018-06-26 05:05:56 -04:00
// State ...
func (a *Artifact) State(name string) interface{} {
return a.StateData[name]
}
// Destroy deletes the custom image associated with the artifact.
func (a *Artifact) Destroy() error {
2018-06-26 05:05:56 -04:00
return a.driver.DeleteImage(context.TODO(), *a.Image.Id)
}