VM::EC2::Volume - Object describing an Amazon EBS volume
use VM::EC2; $ec2 = VM::EC2->new(...); @vol = $ec2->describe_volumes; for my $vol (@vols) { $id = $vol->volumeId; $size = $vol->size; $snap = $vol->snapshotId; $zone = $vol->availabilityZone; $status = $vol->status; $ctime = $vol->createTime; @attachments = $vol->attachments; $attachment = $vol->attachment; $origin = $vol->from_snapshot; @snapshots = $vol->to_snapshots; } $vols[0]->attach('i-12345','/dev/sdg1'); $vols[0]->detach; $vols[0]->create_snapshot('automatic snapshot')
This object is used to describe an Amazon EBS volume. It is returned by VM::EC2->describe_volumes().
The following object methods are supported:
volumeId -- ID of this volume. size -- Size of this volume (in GB). snapshotId -- ID of snapshot this availabilityZone -- Availability zone in which this volume resides. status -- Volume state, one of "creating", "available", "in-use", "deleting", "deleted", "error" createTime -- Timestamp for when volume was created. tags -- Hashref containing tags associated with this group. See L<VM::EC2::Generic>.
In addition, this class provides several convenience functions:
The attachment() method returns a VM::EC2::BlockDevice::Attachment object describing the attachment of this volume to an instance. If the volume is unused, then this returns undef.
The attachments() method is similar, except that it returns a list of the attachments. Currently an EBS volume can only be attached to one instance at a time, but the Amazon call syntax supports multiple attachments and this method is provided for future compatibility.
Attach this volume to an instance using virtual device $device. Both arguments are required. The result is a VM::EC2::BlockDevice::Attachment object which you can monitor by calling current_status():
my $a = $volume->attach('i-12345','/dev/sdg'); while ($a->current_status ne 'attached') { sleep 2; } print "volume is ready to go\n";
Detaches this volume. With no arguments, will detach the volume from whatever instance it is currently attached to. Provide -instance_id and/or -device as a check that you are detaching the volume from the expected instance and device.
Optional arguments:
-instance_id -- ID of the instance to detach from. -device -- How the device is exposed to the instance. -force -- Force detachment, even if previous attempts were unsuccessful.
The result is a VM::EC2::BlockDevice::Attachment object which you can monitor by calling current_status():
my $a = $volume->detach; while ($a->current_status ne 'detached') { sleep 2; } print "volume is ready to go\n";
Returns the VM::EC2::Snapshot object that this volume was originally derived from. It will return undef if the resource no longer exists, or if the volume was created from scratch.
If this volume has been used to create one or more snapshots, this method will return them as a list of VM::EC2::Snapshot objects.
Create a snapshot of the volume and return a VM::EC2::Snapshot object. To ensure a consistent snapshot, you should unmount the volume before snapshotting it. The optional argument allows you to add a description to the snapshot.
Here is an example:
$s = $volume->create_snapshot("Backed up at ".localtime); while ($s->current_status eq 'pending') { print "Progress: ",$s->progress,"% done\n"; } print "Snapshot status: ",$s->current_status,"\n";
This returns the up-to-date status of the volume. It works by calling refresh() and then returning status().
When used in a string context, this object will interpolate the volumeId.
VM::EC2 VM::EC2::Generic VM::EC2::Snapshot VM::EC2::BlockDevice VM::EC2::BlockDevice::Attachment
Lincoln Stein <lincoln.stein@gmail.com>.
Copyright (c) 2011 Ontario Institute for Cancer Research
This package and its accompanying libraries is free software; you can redistribute it and/or modify it under the terms of the GPL (either version 1, or at your option, any later version) or the Artistic License 2.0. Refer to LICENSE for the full license text. In addition, please see DISCLAIMER.txt for disclaimers of warranty.
To install VM::EC2, copy and paste the appropriate command in to your terminal.
cpanm
cpanm VM::EC2
CPAN shell
perl -MCPAN -e shell install VM::EC2
For more information on module installation, please visit the detailed CPAN module installation guide.