Class: CloudProviders::ElasticBlockStoreGroup
- Inherits:
-
Ec2Helper
- Object
- CloudProvider
- Ec2Helper
- CloudProviders::ElasticBlockStoreGroup
- Defined in:
- lib/cloud_providers/ec2/helpers/elastic_block_store_group.rb
Overview
ElasticBlockStoreGroup class allows easy manipulation of EBS volumes matching defined criterias. Existing volumes in cloud’s availability zones that match the criterias will be selected for the group. When cloud instances need to attach EBS volumes from the group, the attach method should called. When attaching volumes the ElasticBlockStoreGroup will select existing (unattached) volumes until there are non, afterwhich the group will create new volumes according to the criterias given as needed.
Currently, EBS volumes will not be deleted when tearing down a cloud. This is because poolparty is stateless and thus deleting drives from it will probably result in catastroph (deletions will be too general and delete stuff you don’t want deleted). Hopefully, we will come up with a scheme for a deletion flag of some sort to solve this situation.
Instance Attribute Summary
Attributes inherited from CloudProvider
Instance Method Summary collapse
- #after_initialized ⇒ Object
- #attach(nodes) ⇒ Object
-
#create(availability_zone) ⇒ Object
Create new volume on availability_zone.
-
#free_volumes(availability_zone) ⇒ Object
get volumes that are not attached.
-
#get_free_volume(availability_zone) ⇒ Object
Get a free volume from existing volumes in group or create a new one.
-
#initialize(name = cloud.proper_name, init_opts = {}, &block) ⇒ ElasticBlockStoreGroup
constructor
A new instance of ElasticBlockStoreGroup.
- #verify_attachments(nodes) ⇒ Object
- #volumes(*volume_ids) ⇒ Object
- #volumes_attached_to(instanceId) ⇒ Object
Methods inherited from Ec2Helper
#as, #ec2, #elb, #pool, property, #rds
Methods inherited from CloudProvider
#bootstrap_nodes!, #default_keypair_path, default_keypair_path, #method_missing, #run
Constructor Details
#initialize(name = cloud.proper_name, init_opts = {}, &block) ⇒ ElasticBlockStoreGroup
Returns a new instance of ElasticBlockStoreGroup.
14 15 16 17 |
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store_group.rb', line 14 def initialize(name=cloud.proper_name, init_opts={}, &block) @volumes=[] super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class CloudProviders::CloudProvider
Instance Method Details
#after_initialized ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store_group.rb', line 18 def after_initialized unless @volumes.size > 0 filters={:size => size, :availabilityZone => availability_zones} filters[:snapshotId]=snapshot_id if snapshot_id @volumes=cloud.list_ec2_volumes filters end end |
#attach(nodes) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store_group.rb', line 55 def attach(nodes) nodes.each{|node| # Check no volumes are attached to node on device skip_node=false cloud.list_ec2_volumes.each{|vol| if vol.attached?(node.instance_id) and vol.device == device warn "A volume is allready attached to device #{device} of instance #{node.instance_id}" skip_node = true end } unless skip_node vol=get_free_volume(node.zone) vol.attach(node,device) end } end |
#create(availability_zone) ⇒ Object
Create new volume on availability_zone
47 48 49 50 51 52 53 |
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store_group.rb', line 47 def create(availability_zone) ={:availability_zone => availability_zone, :size => size.to_s} [:snapshot_id]=snapshot_id if snapshot_id vol=ElasticBlockStore.new(ec2.create_volume(),:cloud => cloud) @volumes<<vol vol end |
#free_volumes(availability_zone) ⇒ Object
get volumes that are not attached
34 35 36 |
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store_group.rb', line 34 def free_volumes(availability_zone) @volumes.flatten.select{|vol| vol.available? and vol.availability_zone == availability_zone} end |
#get_free_volume(availability_zone) ⇒ Object
Get a free volume from existing volumes in group or create a new one
38 39 40 41 42 43 44 |
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store_group.rb', line 38 def get_free_volume(availability_zone) free=free_volumes(availability_zone) if free.size>=1 return free[0] end create(availability_zone) end |
#verify_attachments(nodes) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store_group.rb', line 72 def (nodes) nodes_without_volume=nodes.select do |node| volumes_attached_to(node.id).size=0 end attach nodes_without_volume if nodes_without_volume.any? end |
#volumes(*volume_ids) ⇒ Object
25 26 27 28 |
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store_group.rb', line 25 def volumes(*volume_ids) return @volumes if volume_ids.size==0 volume_ids.each{|volume_id| @volumes << cloud.list_ec2_volumes(:volumeId => volume_id)} end |
#volumes_attached_to(instanceId) ⇒ Object
29 30 31 |
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store_group.rb', line 29 def volumes_attached_to(instanceId) @volumes.select {|vol| vol.attached?(instanceId)} end |