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

     1  package scaleway
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"log"
     7  
     8  	"github.com/hashicorp/packer/helper/multistep"
     9  	"github.com/hashicorp/packer/packer"
    10  	"github.com/scaleway/scaleway-cli/pkg/api"
    11  )
    12  
    13  type stepSnapshot struct{}
    14  
    15  func (s *stepSnapshot) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
    16  	client := state.Get("client").(*api.ScalewayAPI)
    17  	ui := state.Get("ui").(packer.Ui)
    18  	c := state.Get("config").(*Config)
    19  	volumeID := state.Get("root_volume_id").(string)
    20  
    21  	ui.Say(fmt.Sprintf("Creating snapshot: %v", c.SnapshotName))
    22  	snapshot, err := client.PostSnapshot(volumeID, c.SnapshotName)
    23  	if err != nil {
    24  		err := fmt.Errorf("Error creating snapshot: %s", err)
    25  		state.Put("error", err)
    26  		ui.Error(err.Error())
    27  		return multistep.ActionHalt
    28  	}
    29  
    30  	log.Printf("Snapshot ID: %s", snapshot)
    31  	state.Put("snapshot_id", snapshot)
    32  	state.Put("snapshot_name", c.SnapshotName)
    33  	state.Put("region", c.Region)
    34  
    35  	return multistep.ActionContinue
    36  }
    37  
    38  func (s *stepSnapshot) Cleanup(state multistep.StateBag) {
    39  	// no cleanup
    40  }