Class: VGH::EC2::Volume
- Inherits:
-
Object
- Object
- VGH::EC2::Volume
- Defined in:
- lib/vgh/ec2/volume.rb
Overview
Collects information about the EBS volumes attached to the current instance.
Usage
volumes = Volume.new
puts volumes.list
puts volumes.list_tagged('MyTag')
Instance Method Summary collapse
-
#instance ⇒ Instance
The current instance object.
-
#list ⇒ Array
Creates an array with the IDs of all the volumes attached to the current instance.
-
#list_tagged(tag_key) ⇒ Array
Creates an array with the IDs of all the volumes attached to the current instance, that contain a specific tag key.
-
#mappings ⇒ Hash
Returns a Hash containing the block device mappings of the current instance.
-
#name_tag(volume_id) ⇒ String
Get volume’s Name tag.
-
#volume_tags(volume_id) ⇒ TagsCollection
Returns a collection of tags for the specified volume.
Instance Method Details
#instance ⇒ Instance
The current instance object
44 45 46 |
# File 'lib/vgh/ec2/volume.rb', line 44 def instance @instance ||= ec2.instances[instance_id] end |
#list ⇒ Array
Creates an array with the IDs of all the volumes attached to the current instance
15 16 17 18 19 |
# File 'lib/vgh/ec2/volume.rb', line 15 def list @list = [] mappings.map {|device, info| @list.push(info.volume.id)} return @list end |
#list_tagged(tag_key) ⇒ Array
Creates an array with the IDs of all the volumes attached to the current instance, that contain a specific tag key
25 26 27 28 29 30 31 32 33 |
# File 'lib/vgh/ec2/volume.rb', line 25 def list_tagged(tag_key) @list_tagged = [] list.each {|vid| (vid).map {|volume_tag| @list_tagged.push(vid) if volume_tag.key == tag_key } } return @list_tagged end |
#mappings ⇒ Hash
Returns a Hash containing the block device mappings of the current instance.
37 38 39 40 |
# File 'lib/vgh/ec2/volume.rb', line 37 def mappings .info "Creating a list of volumes..." @mappings ||= instance.block_device_mappings end |
#name_tag(volume_id) ⇒ String
Get volume’s Name tag
51 52 53 54 55 56 57 |
# File 'lib/vgh/ec2/volume.rb', line 51 def name_tag(volume_id) @name_tag = 'NOTAG' (volume_id).each {|tag| @name_tag = tag.value if tag.key == 'Name' } return @name_tag end |
#volume_tags(volume_id) ⇒ TagsCollection
Returns a collection of tags for the specified volume.
62 63 64 65 66 |
# File 'lib/vgh/ec2/volume.rb', line 62 def (volume_id) @volume_tags = ec2.. filter('resource-type', 'volume'). filter('resource-id', volume_id) end |