Class: Elbas::AWS::AMI
Constant Summary
collapse
- DEPLOY_ID_TAG =
'ELBAS-Deploy-id'.freeze
- DEPLOY_GROUP_TAG =
'ELBAS-Deploy-group'.freeze
Instance Attribute Summary collapse
Attributes inherited from Base
#aws_counterpart
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Taggable
#tag, #tags
Methods inherited from Base
#aws_access_key, #aws_client, aws_client, #aws_credentials, #aws_region, #aws_secret_key
Constructor Details
#initialize(id, snapshots = []) ⇒ AMI
Returns a new instance of AMI.
11
12
13
14
15
16
17
18
|
# File 'lib/elbas/aws/ami.rb', line 11
def initialize(id, snapshots = [])
@id = id
@aws_counterpart = ::Aws::EC2::Image.new id
@snapshots = snapshots.map do |snapshot|
Elbas::AWS::Snapshot.new snapshot&.ebs&.snapshot_id
end
end
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
9
10
11
|
# File 'lib/elbas/aws/ami.rb', line 9
def id
@id
end
|
#snapshots ⇒ Object
Returns the value of attribute snapshots.
9
10
11
|
# File 'lib/elbas/aws/ami.rb', line 9
def snapshots
@snapshots
end
|
Class Method Details
.create(instance, no_reboot: true) ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/elbas/aws/ami.rb', line 41
def self.create(instance, no_reboot: true)
ami = instance.aws_counterpart.create_image({
name: "ELBAS-ami-#{Time.now.to_i}",
instance_id: instance.id,
no_reboot: no_reboot
})
new ami.id
end
|
Instance Method Details
#ancestors ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/elbas/aws/ami.rb', line 28
def ancestors
aws_amis_in_deploy_group.select { |aws_ami|
deploy_id_from_aws_tags(aws_ami.tags) != deploy_id
}.map { |aws_ami|
self.class.new aws_ami.image_id, aws_ami.block_device_mappings
}
end
|
#delete ⇒ Object
36
37
38
39
|
# File 'lib/elbas/aws/ami.rb', line 36
def delete
aws_client.deregister_image image_id: id
snapshots.each(&:delete)
end
|
#deploy_group ⇒ Object
24
25
26
|
# File 'lib/elbas/aws/ami.rb', line 24
def deploy_group
tags[DEPLOY_GROUP_TAG]
end
|
#deploy_id ⇒ Object
20
21
22
|
# File 'lib/elbas/aws/ami.rb', line 20
def deploy_id
tags[DEPLOY_ID_TAG]
end
|