mirror of https://github.com/hashicorp/packer
parent
c0721bc3ef
commit
91670cea07
@ -0,0 +1,46 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/mitchellh/goamz/ec2"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BlockDevice
|
||||||
|
type BlockDevice struct {
|
||||||
|
DeviceName string `mapstructure:"device_name"`
|
||||||
|
VirtualName string `mapstructure:"virtual_name"`
|
||||||
|
SnapshotId string `mapstructure:"snapshot_id"`
|
||||||
|
VolumeType string `mapstructure:"volume_type"`
|
||||||
|
VolumeSize int64 `mapstructure:"volume_size"`
|
||||||
|
DeleteOnTermination bool `mapstructure:"delete_on_termination"`
|
||||||
|
IOPS int64 `mapstructure:"iops"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type BlockDevices struct {
|
||||||
|
AMIMappings []BlockDevice `mapstructure:"ami_block_device_mappings,squash"`
|
||||||
|
LaunchMappings []BlockDevice `mapstructure:"launch_block_device_mappings,squash"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildBlockDevices(b []BlockDevice) []ec2.BlockDeviceMapping {
|
||||||
|
var blockDevices []ec2.BlockDeviceMapping
|
||||||
|
|
||||||
|
for _, blockDevice := range b {
|
||||||
|
blockDevices = append(blockDevices, ec2.BlockDeviceMapping{
|
||||||
|
DeviceName: blockDevice.DeviceName,
|
||||||
|
VirtualName: blockDevice.VirtualName,
|
||||||
|
SnapshotId: blockDevice.SnapshotId,
|
||||||
|
VolumeType: blockDevice.VolumeType,
|
||||||
|
VolumeSize: blockDevice.VolumeSize,
|
||||||
|
DeleteOnTermination: blockDevice.DeleteOnTermination,
|
||||||
|
IOPS: blockDevice.IOPS,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return blockDevices
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BlockDevices) BuildAMIDevices() []ec2.BlockDeviceMapping {
|
||||||
|
return buildBlockDevices(b.AMIMappings)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BlockDevices) BuildLaunchDevices() []ec2.BlockDeviceMapping {
|
||||||
|
return buildBlockDevices(b.LaunchMappings)
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"cgl.tideland.biz/asserts"
|
||||||
|
"github.com/mitchellh/goamz/ec2"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBlockDevice(t *testing.T) {
|
||||||
|
assert := asserts.NewTestingAsserts(t, true)
|
||||||
|
|
||||||
|
ec2Mapping := []ec2.BlockDeviceMapping{
|
||||||
|
ec2.BlockDeviceMapping{
|
||||||
|
DeviceName: "/dev/sdb",
|
||||||
|
VirtualName: "ephemeral0",
|
||||||
|
SnapshotId: "snap-1234",
|
||||||
|
VolumeType: "standard",
|
||||||
|
VolumeSize: 8,
|
||||||
|
DeleteOnTermination: true,
|
||||||
|
IOPS: 1000,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
blockDevice := BlockDevice{
|
||||||
|
DeviceName: "/dev/sdb",
|
||||||
|
VirtualName: "ephemeral0",
|
||||||
|
SnapshotId: "snap-1234",
|
||||||
|
VolumeType: "standard",
|
||||||
|
VolumeSize: 8,
|
||||||
|
DeleteOnTermination: true,
|
||||||
|
IOPS: 1000,
|
||||||
|
}
|
||||||
|
|
||||||
|
blockDevices := BlockDevices{
|
||||||
|
AMIMappings: []BlockDevice{blockDevice},
|
||||||
|
LaunchMappings: []BlockDevice{blockDevice},
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(ec2Mapping, blockDevices.BuildAMIDevices(), "should match output")
|
||||||
|
assert.Equal(ec2Mapping, blockDevices.BuildLaunchDevices(), "should match output")
|
||||||
|
}
|
||||||
Loading…
Reference in new issue