Class: CloudProviders::ElasticBlockStore

Inherits:
Ec2Helper show all
Defined in:
lib/cloud_providers/ec2/helpers/elastic_block_store.rb

Instance Attribute Summary collapse

Attributes inherited from CloudProvider

#init_opts, #name

Instance Method Summary collapse

Methods inherited from Ec2Helper

#as, #ec2, #elb, #pool, property, #rds

Methods inherited from CloudProvider

#after_initialized, #bootstrap_nodes!, #default_keypair_path, default_keypair_path, #method_missing, #run

Constructor Details

#initialize(raw_response, init_opts = {}, &block) ⇒ ElasticBlockStore

Returns a new instance of ElasticBlockStore.



21
22
23
24
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 21

def initialize(raw_response,init_opts={},&block)
  parse_raw_response(raw_response)
  super(volumeId,init_opts,&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CloudProviders::CloudProvider

Instance Attribute Details

#attachmentsObject (readonly)

instance methods



5
6
7
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 5

def attachments
  @attachments
end

#availabilityZoneObject (readonly) Also known as: availability_zone

instance methods



5
6
7
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 5

def availabilityZone
  @availabilityZone
end

#createTime(create_time) ⇒ Object (readonly)

Returns the value of attribute createTime.



6
7
8
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 6

def createTime
  @createTime
end

#deviceObject (readonly)

instance methods



5
6
7
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 5

def device
  @device
end

#instanceIdObject (readonly) Also known as: instance_id

instance methods



5
6
7
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 5

def instanceId
  @instanceId
end

#sizeObject (readonly)

instance methods



5
6
7
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 5

def size
  @size
end

#snapshotIdObject (readonly) Also known as: snapshot_id

instance methods



5
6
7
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 5

def snapshotId
  @snapshotId
end

#statusObject (readonly)

instance methods



5
6
7
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 5

def status
  @status
end

#volumeIdObject (readonly) Also known as: volume_id

instance methods



5
6
7
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 5

def volumeId
  @volumeId
end

Instance Method Details

#attach(ec2_instance, device) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 50

def attach(ec2_instance,device)
  if ec2.attach_volume(:volume_id => volume_id, :instance_id => ec2_instance.instance_id, :device => device).return=="true"
    update!
    return true
  end
  false
end

#attached?(fn_instance_id = nil) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 39

def attached?(fn_instance_id=nil)
  return false unless @status=="in-use" or @status=="attaching"
  return true if fn_instance_id.nil?
  return true if fn_instance_id == instance_id
  return false
end

#available?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 46

def available?
   @status=="available"
end

#create_timeObject

Returns the value of attribute createTime.



11
12
13
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 11

def createTime
  @createTime
end

#delete!Object



70
71
72
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 70

def delete!
  ec2.delete(:volume_id => volume_id).return == "true"
end

#detachObject



58
59
60
61
62
63
64
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 58

def detach
  if ec2.detach_volume(:volume_id => volume_id).return=="true"
    update!
    return true
  end
  false
end

#detach!Object



66
67
68
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 66

def detach!
  ec2.detach_volume(:volume_id => volume_id, :force => true).return=="true"
end

#parse_raw_response(raw_response) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 26

def parse_raw_response(raw_response)
  @raw_respons = raw_response
  raw_response.each{|k,v| instance_variable_set("@"+k,v) if respond_to?(k) }
  unless raw_response.attachmentSet.nil?
    @attachments=raw_response.attachmentSet.item 
    @attachments.each{|attch| if attch.status=="attached" or attch.status=="attaching"
        @instanceId=attch.instanceId 
        @device=attch.device
      end
    }
  end
end

#update!Object



74
75
76
# File 'lib/cloud_providers/ec2/helpers/elastic_block_store.rb', line 74

def update!
  parse_raw_response ec2.describe_volumes(:volume_id => volume_id)
end