add oci/classic artifact

This commit is contained in:
Matthew Hooker 2018-01-23 18:13:51 -08:00
parent 44befb0857
commit 603881d990
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
3 changed files with 30 additions and 15 deletions

View File

@ -1,7 +1,15 @@
package classic
// Artifact is an artifact implementation that contains a built Custom Image.
import (
"fmt"
"github.com/hashicorp/go-oracle-terraform/compute"
)
// Artifact is an artifact implementation that contains a Snapshot.
type Artifact struct {
Snapshot *compute.Snapshot
driver *compute.ComputeClient
}
// BuilderId uniquely identifies the builder.
@ -15,13 +23,17 @@ func (a *Artifact) Files() []string {
return nil
}
// Id returns the OCID of the associated Image.
func (a *Artifact) Id() string {
return ""
return a.Snapshot.Name
}
func (a *Artifact) String() string {
return ""
return fmt.Sprintf("A Snapshot was created: \n"+
"Name: %s\n"+
"Instance: %s\n"+
"MachineImage: %s\n"+
"URI: %s",
a.Snapshot.Name, a.Snapshot.Instance, a.Snapshot.MachineImage, a.Snapshot.URI)
}
func (a *Artifact) State(name string) interface{} {
@ -30,5 +42,11 @@ func (a *Artifact) State(name string) interface{} {
// Destroy deletes the custom image associated with the artifact.
func (a *Artifact) Destroy() error {
return nil
client := a.driver.Snapshots()
mic := a.driver.MachineImages()
input := &compute.DeleteSnapshotInput{
Snapshot: a.Snapshot.Name,
MachineImage: a.Snapshot.MachineImage,
}
return client.DeleteSnapshot(mic, input)
}

View File

@ -89,17 +89,13 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
return nil, rawErr.(error)
}
/*
// Build the artifact and return it
artifact := &Artifact{
Image: state.Get("image").(client.Image),
Region: b.config.AccessCfg.Region,
driver: driver,
}
// Build the artifact and return it
artifact := &Artifact{
Snapshot: state.Get("snapshot").(*compute.Snapshot),
driver: client,
}
return artifact, nil
*/
return nil, nil
return artifact, nil
}
// Cancel terminates a running build.

View File

@ -35,6 +35,7 @@ func (s *stepSnapshot) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}
state.Put("snapshot", snap)
ui.Say(fmt.Sprintf("Created snapshot (%s).", snap.Name))
return multistep.ActionContinue
}