Class: Bosh::AwsCloud::Stemcell
- Inherits:
-
Object
- Object
- Bosh::AwsCloud::Stemcell
show all
- Includes:
- Helpers
- Defined in:
- lib/cloud/aws/stemcell.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helpers
#cloud_error, #default_ephemeral_disk_mapping, #ebs_ephemeral_disk_mapping, #extract_security_groups
Constructor Details
#initialize(region, image) ⇒ Stemcell
Returns a new instance of Stemcell.
13
14
15
16
17
|
# File 'lib/cloud/aws/stemcell.rb', line 13
def initialize(region, image)
@region = region
@ami = image
@snapshots = []
end
|
Instance Attribute Details
#ami ⇒ Object
Returns the value of attribute ami.
5
6
7
|
# File 'lib/cloud/aws/stemcell.rb', line 5
def ami
@ami
end
|
#snapshots ⇒ Object
Returns the value of attribute snapshots.
5
6
7
|
# File 'lib/cloud/aws/stemcell.rb', line 5
def snapshots
@snapshots
end
|
Class Method Details
.find(region, id) ⇒ Object
7
8
9
10
11
|
# File 'lib/cloud/aws/stemcell.rb', line 7
def self.find(region, id)
image = region.images[id]
raise Bosh::Clouds::CloudError, "could not find AMI '#{id}'" unless image.exists?
new(region, image)
end
|
Instance Method Details
#delete ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/cloud/aws/stemcell.rb', line 19
def delete
memoize_snapshots
ami.deregister
ResourceWait.for_image(image: ami, state: :deleted)
delete_snapshots
logger.info("deleted stemcell '#{id}'")
rescue AWS::EC2::Errors::AuthFailure => e
logger.info("deleted fake stemcell '#{id}")
end
|
#delete_snapshots ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/cloud/aws/stemcell.rb', line 63
def delete_snapshots
snapshots.each do |id|
logger.info("cleaning up snapshot '#{id}'")
snapshot = @region.snapshots[id]
snapshot.delete
end
end
|
#id ⇒ Object
39
40
41
|
# File 'lib/cloud/aws/stemcell.rb', line 39
def id
ami.id
end
|
#image_id ⇒ Object
43
44
45
|
# File 'lib/cloud/aws/stemcell.rb', line 43
def image_id
ami.id
end
|
#logger ⇒ Object
71
72
73
|
# File 'lib/cloud/aws/stemcell.rb', line 71
def logger
Bosh::Clouds::Config.logger
end
|
#memoize_snapshots ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/cloud/aws/stemcell.rb', line 51
def memoize_snapshots
ami.block_device_mappings.to_hash.each do |device, map|
snapshot_id = map[:snapshot_id]
if id
logger.debug("queuing snapshot '#{snapshot_id}' for deletion")
snapshots << snapshot_id
end
end
end
|
#root_device_name ⇒ Object
47
48
49
|
# File 'lib/cloud/aws/stemcell.rb', line 47
def root_device_name
ami.root_device_name
end
|