add image transfer for DigitalOcean
This commit is contained in:
parent
cdbce0f8a9
commit
8ed50608b1
|
@ -29,6 +29,7 @@ type Config struct {
|
|||
PrivateNetworking bool `mapstructure:"private_networking"`
|
||||
Monitoring bool `mapstructure:"monitoring"`
|
||||
SnapshotName string `mapstructure:"snapshot_name"`
|
||||
SnapshotRegions []string `mapstructure:"snapshot_regions"`
|
||||
StateTimeout time.Duration `mapstructure:"state_timeout"`
|
||||
DropletName string `mapstructure:"droplet_name"`
|
||||
UserData string `mapstructure:"user_data"`
|
||||
|
|
|
@ -60,6 +60,44 @@ func (s *stepSnapshot) Run(state multistep.StateBag) multistep.StepAction {
|
|||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
if len(c.SnapshotRegions) > 0 {
|
||||
regionSet := make(map[string]struct{})
|
||||
regions := make([]string, 0, len(c.SnapshotRegions))
|
||||
|
||||
for _, region := range c.SnapshotRegions {
|
||||
// If we already saw the region, then don't look again
|
||||
if _, ok := regionSet[region]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
// Mark that we saw the region
|
||||
regionSet[region] = struct{}{}
|
||||
|
||||
regions = append(regions, region)
|
||||
}
|
||||
c.SnapshotRegions = regions
|
||||
for transfer := range c.SnapshotRegions {
|
||||
transferRequest := &godo.ActionRequest{
|
||||
"type": "transfer",
|
||||
"region": c.SnapshotRegions[transfer],
|
||||
}
|
||||
imageTransfer, _, err := client.ImageActions.Transfer(context.TODO(), images[0].ID, transferRequest)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error transfering snapshot: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
ui.Say(fmt.Sprintf("Transfering Snapshot ID: %d", imageTransfer.ID))
|
||||
|
||||
}
|
||||
|
||||
ui.Say(fmt.Sprintf("Snapshot region: %d", len(regions)))
|
||||
// ui.Say(fmt.Sprintf("Snapshot regions: %s", strings.Join(c.SnapshotRegions[:], ",")))
|
||||
|
||||
//client.ImageActions.Transfer(context.TODO(), )
|
||||
}
|
||||
|
||||
var imageId int
|
||||
if len(images) == 1 {
|
||||
imageId = images[0].ID
|
||||
|
|
Loading…
Reference in New Issue