Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support BlockDeviceMapping into create_image method #19

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 48 additions & 4 deletions lib/Net/Amazon/EC2.pm
Expand Up @@ -733,6 +733,19 @@ instance before image creation and reboots the instance afterwards. When set to
does not shut down the instance before creating the image. When this option is used, file system
integrity on the created image cannot be guaranteed.

=item BlockDeviceMapping (optional)

Array ref of the device names exposed to the instance.

You can specify device names as '<device>=<block_device>' similar to ec2-create-image command. (L<http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-CreateImage.html>)

BlockDeviceMapping => [
'/dev/sda=:256:true:standard',
'/dev/sdb=none',
'/dev/sdc=ephemeral0',
'/dev/sdd=ephemeral1',
],

=back

Returns the ID of the AMI created.
Expand All @@ -742,12 +755,43 @@ Returns the ID of the AMI created.
sub create_image {
my $self = shift;
my %args = validate( @_, {
InstanceId => { type => SCALAR },
Name => { type => SCALAR },
Description => { type => SCALAR, optional => 1 },
NoReboot => { type => SCALAR, optional => 1 },
InstanceId => { type => SCALAR },
Name => { type => SCALAR },
Description => { type => SCALAR, optional => 1 },
NoReboot => { type => SCALAR, optional => 1 },
BlockDeviceMapping => { type => ARRAYREF, optional => 1 },
});


if (my $bdm = delete $args{BlockDeviceMapping}) {
my $n = 0;
for my $bdme (@$bdm) {
my($device, $block_device) = split /=/, $bdme, 2;
$args{"BlockDeviceMapping.${n}.DeviceName"} = $device;

if ($block_device =~ /^ephemeral[0-9]+$/) {
$args{"BlockDeviceMapping.${n}.VirtualName"} = $block_device;
} elsif ($block_device eq 'none') {
$args{"BlockDeviceMapping.${n}.NoDevice"} = '';
} else {
my @keys = qw(
Ebs.SnapshotId
Ebs.VolumeSize
Ebs.DeleteOnTermination
Ebs.VolumeType
Ebs.Iops
);
for my $bde (split /:/, $block_device) {
my $key = shift @keys;
next unless $bde;
$args{"BlockDeviceMapping.${n}.${key}"} = $bde;
}
}

$n++;
}
}

my $xml = $self->_sign(Action => 'CreateImage', %args);

if ( grep { defined && length } $xml->{Errors} ) {
Expand Down