Class: Capistrano::ASG::Rolling::LaunchTemplate

Inherits:
Object
  • Object
show all
Includes:
AWS
Defined in:
lib/capistrano/asg/rolling/launch_template.rb

Overview

AWS EC2 Launch Template.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AWS

#aws_autoscaling_client, #aws_ec2_client

Constructor Details

#initialize(id, version, name, default_version: false) ⇒ LaunchTemplate

Returns a new instance of LaunchTemplate.



13
14
15
16
17
18
# File 'lib/capistrano/asg/rolling/launch_template.rb', line 13

def initialize(id, version, name, default_version: false)
  @id = id
  @version = version.to_s
  @name = name
  @default_version = default_version
end

Instance Attribute Details

#default_versionObject (readonly) Also known as: default_version?

Returns the value of attribute default_version.



10
11
12
# File 'lib/capistrano/asg/rolling/launch_template.rb', line 10

def default_version
  @default_version
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/capistrano/asg/rolling/launch_template.rb', line 10

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/capistrano/asg/rolling/launch_template.rb', line 10

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



10
11
12
# File 'lib/capistrano/asg/rolling/launch_template.rb', line 10

def version
  @version
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

Object equality for Launch Templates is only by ID. Version number is deliberately not taken in account.



68
69
70
# File 'lib/capistrano/asg/rolling/launch_template.rb', line 68

def ==(other)
  id == other.id
end

#amiObject



39
40
41
# File 'lib/capistrano/asg/rolling/launch_template.rb', line 39

def ami
  @ami ||= AMI.new(image_id)
end

#create_version(image_id:, description: nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/capistrano/asg/rolling/launch_template.rb', line 20

def create_version(image_id:, description: nil)
  response = aws_ec2_client.create_launch_template_version(
    launch_template_data: { image_id: image_id },
    launch_template_id: id,
    source_version: version,
    version_description: description
  )
  version = response.launch_template_version

  self.class.new(version.launch_template_id, version.version_number, version.launch_template_name, default_version: version.default_version)
end

#deleteObject



32
33
34
35
36
37
# File 'lib/capistrano/asg/rolling/launch_template.rb', line 32

def delete
  aws_ec2_client.delete_launch_template_versions(
    launch_template_id: id,
    versions: [version]
  )
end

#hashObject



74
75
76
# File 'lib/capistrano/asg/rolling/launch_template.rb', line 74

def hash
  id.hash
end

#image_idObject



55
56
57
# File 'lib/capistrano/asg/rolling/launch_template.rb', line 55

def image_id
  aws_describe_launch_template_version.launch_template_data.image_id
end

#network_interfacesObject



59
60
61
# File 'lib/capistrano/asg/rolling/launch_template.rb', line 59

def network_interfaces
  aws_describe_launch_template_version.launch_template_data.network_interfaces
end

#previous_versionsObject



43
44
45
46
47
48
49
# File 'lib/capistrano/asg/rolling/launch_template.rb', line 43

def previous_versions
  aws_ec2_client.describe_launch_template_versions(launch_template_id: id)
                .launch_template_versions
                .sort_by { |v| -v.version_number }
                .select { |v| v.version_number < version_number }
                .map { |v| self.class.new(v.launch_template_id, v.version_number, v.launch_template_name, default_version: v.default_version) }
end

#security_group_idsObject



63
64
65
# File 'lib/capistrano/asg/rolling/launch_template.rb', line 63

def security_group_ids
  aws_describe_launch_template_version.launch_template_data.security_group_ids
end

#version_numberObject



51
52
53
# File 'lib/capistrano/asg/rolling/launch_template.rb', line 51

def version_number
  aws_describe_launch_template_version.version_number
end