github.phpd.cn/hashicorp/packer@v1.3.2/builder/scaleway/artifact.go (about)

     1  package scaleway
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  
     7  	"github.com/scaleway/scaleway-cli/pkg/api"
     8  )
     9  
    10  type Artifact struct {
    11  	// The name of the image
    12  	imageName string
    13  
    14  	// The ID of the image
    15  	imageID string
    16  
    17  	// The name of the snapshot
    18  	snapshotName string
    19  
    20  	// The ID of the snapshot
    21  	snapshotID string
    22  
    23  	// The name of the region
    24  	regionName string
    25  
    26  	// The client for making API calls
    27  	client *api.ScalewayAPI
    28  }
    29  
    30  func (*Artifact) BuilderId() string {
    31  	return BuilderId
    32  }
    33  
    34  func (*Artifact) Files() []string {
    35  	// No files with Scaleway
    36  	return nil
    37  }
    38  
    39  func (a *Artifact) Id() string {
    40  	return fmt.Sprintf("%s:%s", a.regionName, a.imageID)
    41  }
    42  
    43  func (a *Artifact) String() string {
    44  	return fmt.Sprintf("An image was created: '%v' (ID: %v) in region '%v' based on snapshot '%v' (ID: %v)",
    45  		a.imageName, a.imageID, a.regionName, a.snapshotName, a.snapshotID)
    46  }
    47  
    48  func (a *Artifact) State(name string) interface{} {
    49  	return nil
    50  }
    51  
    52  func (a *Artifact) Destroy() error {
    53  	log.Printf("Destroying image: %s (%s)", a.imageID, a.imageName)
    54  	if err := a.client.DeleteImage(a.imageID); err != nil {
    55  		return err
    56  	}
    57  	log.Printf("Destroying snapshot: %s (%s)", a.snapshotID, a.snapshotName)
    58  	if err := a.client.DeleteSnapshot(a.snapshotID); err != nil {
    59  		return err
    60  	}
    61  	return nil
    62  }