Module: Cumulus::EC2

Defined in:
lib/ec2/EC2.rb,
lib/ec2/Commands.rb,
lib/ec2/IPProtocolMapping.rb,
lib/ec2/loaders/EbsLoader.rb,
lib/ec2/managers/EbsManager.rb,
lib/ec2/models/EbsGroupDiff.rb,
lib/ec2/models/InstanceDiff.rb,
lib/ec2/models/EbsGroupConfig.rb,
lib/ec2/models/InstanceConfig.rb,
lib/ec2/loaders/InstanceLoader.rb,
lib/ec2/managers/InstanceManager.rb

Defined Under Namespace

Modules: EbsGroupChange, EbsLoader, InstanceChange, InstanceLoader Classes: Commands, EbsGroupConfig, EbsGroupDiff, EbsManager, IPProtocolMapping, InstanceAttributes, InstanceConfig, InstanceDiff, InstanceManager, VolumeGroup

Constant Summary collapse

@@client =
Aws::EC2::Client.new(Configuration.instance.client)

Class Method Summary collapse

Class Method Details

.addressesObject

Public: Lazily load the addresses



227
228
229
# File 'lib/ec2/EC2.rb', line 227

def addresses
  @addresses ||= init_addresses
end

.dhcp_optionsObject

Public: Lazily load the dhcp options



191
192
193
# File 'lib/ec2/EC2.rb', line 191

def dhcp_options
  @dhcp_options ||= init_dhcp_options
end

.ebs_groupsObject

Public

Returns an array of the group names used by all ebs volumes



283
284
285
# File 'lib/ec2/EC2.rb', line 283

def ebs_groups
  @ebs_groups ||= ebs_volumes.map(&:group).reject(&:nil?).uniq
end

.ebs_volumesObject

Public: Lazily loads EBS volumes, rejecting all root-mounted volumes



295
296
297
298
299
300
301
302
# File 'lib/ec2/EC2.rb', line 295

def ebs_volumes
  @ebs_volumes ||= init_ebs_volumes.reject do |vol|
    vol.attachments.any? do |att|
      attached_instance = id_instances[att.instance_id]
      attached_instance.root_device_name == att.device
    end
  end
end

.endpointsObject

Public: Lazily load the endpoints



205
206
207
# File 'lib/ec2/EC2.rb', line 205

def endpoints
  @endpoints ||= init_endpoints
end

.group_ebs_volumesObject

Public

Returns a Hash of ebs volume group name to EbsGroupConfig



263
264
265
266
267
268
# File 'lib/ec2/EC2.rb', line 263

def group_ebs_volumes
  @group_ebs_volumes ||= Hash[ebs_groups.map do |group_name|
    vols = ebs_volumes.select { |vol| vol.group == group_name}
    [group_name, EbsGroupConfig.new(group_name).populate!(vols)]
  end]
end

.group_ebs_volumes_awsObject

Public

Returns a Hash of ebs volume group name to Aws::EC2::Types::Volume



273
274
275
276
277
278
# File 'lib/ec2/EC2.rb', line 273

def group_ebs_volumes_aws
  @group_ebs_volumes_aws ||= Hash[ebs_groups.map do |group_name|
    vols = ebs_volumes.select { |vol| vol.group == group_name}
    [group_name, vols]
  end]
end

.id_dhcp_optionsObject

Public

Returns a Hash of dhcp options id to Aws::EC2::Types::DhcpOptions



186
187
188
# File 'lib/ec2/EC2.rb', line 186

def id_dhcp_options
  @id_dhcp_options ||= Hash[dhcp_options.map { |dhcp| [dhcp.dhcp_options_id, dhcp] }]
end

.id_ebs_volumesObject

Public

Returns a Hash of ebs volume id to volume



290
291
292
# File 'lib/ec2/EC2.rb', line 290

def id_ebs_volumes
  @id_ebs_volumes ||= Hash[ebs_volumes.map { |vol| [vol.volume_id, vol] }]
end

.id_instance_attributes(instance_id) ⇒ Object

Public

Returns a Hash of instance id to attributes, lazily loading each attribute



321
322
323
324
# File 'lib/ec2/EC2.rb', line 321

def id_instance_attributes(instance_id)
  @id_instance_attributes ||= {}
  @id_instance_attributes[instance_id] ||= InstanceAttributes.new(instance_id)
end

.id_instancesObject

Public

Returns a Hash of instance id to Aws::EC2::Types::Instance



307
308
309
# File 'lib/ec2/EC2.rb', line 307

def id_instances
  @id_instances ||= Hash[instances.map { |i| [i.instance_id, i] }]
end

.id_network_interfacesObject

Public

Returns a Hash of interface id to Aws::EC2::Types::NetworkInterface



242
243
244
# File 'lib/ec2/EC2.rb', line 242

def id_network_interfaces
  @id_network_interfaces ||= Hash[network_interfaces.map { |net| [net.network_interface_id, net] }]
end

.id_route_tablesObject

Public

Returns a Hash of route table id Aws::EC2::Types::RouteTable



131
132
133
# File 'lib/ec2/EC2.rb', line 131

def id_route_tables
  @id_route_tables ||= Hash[@route_tables.map { |rt| [rt.route_table_id, rt] }]
end

.id_subnetsObject

Public

Returns a Hash of subnet id to Aws::EC2::Types::Subnet



51
52
53
# File 'lib/ec2/EC2.rb', line 51

def id_subnets
  @id_subnets ||= Hash[subnets.map { |subnet| [subnet.subnet_id, subnet] }]
end

.id_vpcsObject

Public

Returns a Hash of VPC id to Aws::EC2::Types::Vpc



88
89
90
# File 'lib/ec2/EC2.rb', line 88

def id_vpcs
  @vpc_ids ||= Hash[vpcs.map { |vpc| [vpc.vpc_id, vpc] }]
end

.init_instance_attribute(instance_id, attribute) ⇒ Object

Public: Load instance attributes

Returns the instance attribute as whatever type that attribute is



329
330
331
332
333
334
# File 'lib/ec2/EC2.rb', line 329

def init_instance_attribute(instance_id, attribute)
  @@client.describe_instance_attribute({
    instance_id: instance_id,
    attribute: attribute
  })
end

.init_tags(object_id) ⇒ Object

Public: Load tags for an ec2 object

Returns the tags as Hash



356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/ec2/EC2.rb', line 356

def init_tags(object_id)
  next_token = nil
  tags_loaded = false

  tags = []

  while !tags_loaded do
    resp = @@client.describe_tags({
      filters: [
        {
          name: "resource-id",
          values: [object_id]
        }
      ]
    })

    tags.concat(resp.tags)
    tags_loaded = resp.next_token.nil? || resp.next_token.empty?
    next_token = resp.next_token

  end

  Hash[tags.map { |tag|  [tag.key, tag.value] }]

end

.instancesObject

Public: Lazily loads instances



337
338
339
# File 'lib/ec2/EC2.rb', line 337

def instances
  @instances ||= init_instances.reject(&:terminated?)
end

.named_instancesObject

Public

Returns a Hash of instance name or id to Aws::EC2::Types::Instance



314
315
316
# File 'lib/ec2/EC2.rb', line 314

def named_instances
  @named_instances ||= Hash[instances.map { |i| [i.name || i.instance_id, i] }]
end

.named_network_aclsObject

Public

Returns a Hash of network acl name or id to Aws::EC2::Types::NetworkAcl



167
168
169
170
171
# File 'lib/ec2/EC2.rb', line 167

def named_network_acls
  @named_network_acls = Hash[network_acls.map do |acl|
    [acl.name || acl.network_acl_id, acl]
  end]
end

.named_network_interfacesObject

Public

Returns a Hash of interface name to Aws::EC2::Types::NetworkInterface



234
235
236
237
# File 'lib/ec2/EC2.rb', line 234

def named_network_interfaces
  @named_network_interfaces ||= Hash[network_interfaces.map { |net| [net.name || net.network_interface_id, net] }]
    .reject { |k, v| !k or !v }
end

.named_placement_groupsObject

Public

Returns a Hash of placement group name to Aws::EC2::Types::PlacementGroup



344
345
346
# File 'lib/ec2/EC2.rb', line 344

def named_placement_groups
  @named_placement_groups ||= Hash[placement_groups.map { |pg| [pg.group_name, pg] }]
end

.named_route_tablesObject

Public

Returns a Hash of route tables name or id to Aws::EC2::Types::RouteTable



105
106
107
108
# File 'lib/ec2/EC2.rb', line 105

def named_route_tables
  @named_route_tables ||= Hash[route_tables.map { |rt| [rt.name || rt.route_table_id, rt] }]
    .reject { |k, v| !k or !v }
end

.named_subnetsObject

Public

Returns a Hash of subnet name or id to Aws::EC2::Types::Subnet



58
59
60
61
# File 'lib/ec2/EC2.rb', line 58

def named_subnets
  @named_subnets ||= Hash[subnets.map { |subnet| [subnet.name || subnet.subnet_id, subnet] }]
    .reject { |k, v| !k or !v }
end

.named_vpcsObject

Public

Returns a Hash of VPC name or id to Aws::EC2::Types::Vpc



80
81
82
83
# File 'lib/ec2/EC2.rb', line 80

def named_vpcs
  @named_vpcs ||= Hash[vpcs.map { |vpc| [vpc.name || vpc.vpc_id, vpc] }]
    .reject { |k, v| !k or !v }
end

.network_aclsObject

Public: Lazily load the network acls



174
175
176
# File 'lib/ec2/EC2.rb', line 174

def network_acls
  @network_acls ||= init_network_acls
end

.network_interfacesObject

Public: Lazily load network interfaces



256
257
258
# File 'lib/ec2/EC2.rb', line 256

def network_interfaces
  @network_interfaces ||= init_network_interfaces
end

.placement_groupsObject

Public: Lazily load placement groups



349
350
351
# File 'lib/ec2/EC2.rb', line 349

def placement_groups
  @placement_groups ||= init_placement_groups
end

.public_addressesObject

Public

Returns a Hash of public ip to Aws::EC2::Types::Address



212
213
214
# File 'lib/ec2/EC2.rb', line 212

def public_addresses
  @public_addresses ||= Hash[addresses.map { |addr| [addr.public_ip, addr] }]
end

.refresh_network_acls!Object

Public: Refresh the list of Network ACLs



179
180
181
# File 'lib/ec2/EC2.rb', line 179

def refresh_network_acls!
  @network_acls = init_network_acls
end

.refresh_route_tables!Object

Public refreshes the list of route tables



141
142
143
# File 'lib/ec2/EC2.rb', line 141

def refresh_route_tables!
  @route_tables = init_route_tables
end

.refresh_vpcs!Object

Public refreshes the list of vpcs



93
94
95
# File 'lib/ec2/EC2.rb', line 93

def refresh_vpcs!
  @vpcs = init_vpcs
end

.route_tablesObject

Public: Lazily load route tables



136
137
138
# File 'lib/ec2/EC2.rb', line 136

def route_tables
  @route_tables ||= init_route_tables
end

.subnet_network_aclsObject

Public

Returns a Hash of subnet id to Aws::EC2::Types::NetworkAcl associated with the subnet



148
149
150
151
152
153
# File 'lib/ec2/EC2.rb', line 148

def subnet_network_acls
  @subnet_network_acls =
  Hash[network_acls.flat_map do |acl|
    acl.subnet_ids.map { |subnet_id| [subnet_id, acl] }
  end]
end

.subnet_route_tablesObject

Public

Returns a Hash of subnet id to Aws::EC2::Types::RouteTable



113
114
115
116
117
# File 'lib/ec2/EC2.rb', line 113

def subnet_route_tables
  @subnet_route_tables ||= Hash[route_tables.flat_map do |rt|
    rt.subnet_ids.map { |subnet_id| [subnet_id, rt] }
  end]
end

.subnetsObject

Public: Lazily load the subnets



73
74
75
# File 'lib/ec2/EC2.rb', line 73

def subnets
  @subnets ||= init_subnets
end

.supported_platformsObject



390
391
392
393
394
# File 'lib/ec2/EC2.rb', line 390

def supported_platforms
  @supported_platforms ||= @@client.({
    attribute_names: ["supported-platforms"]
  })..first.attribute_values.map(&:attribute_value)
end

.supports_ec2_classicObject



386
387
388
# File 'lib/ec2/EC2.rb', line 386

def supports_ec2_classic
  @supports_ec2_classic ||= supported_platforms.include?("EC2")
end

.supports_vpcObject



382
383
384
# File 'lib/ec2/EC2.rb', line 382

def supports_vpc
  @supports_vpc ||= supported_platforms.include?("VPC")
end

.vpc_addressesObject

Public

Returns a Hash of vpc id to array of Aws::EC2::Types::Address that has a network interface in the vpc



219
220
221
222
223
224
# File 'lib/ec2/EC2.rb', line 219

def vpc_addresses
  @vpc_addresses ||= Hash[id_vpcs.map do |vpc_id, _|
    interface_ids = vpc_network_interfaces[vpc_id].map { |interface| interface.network_interface_id }
    [vpc_id, addresses.select { |addr| interface_ids.include? addr.network_interface_id }]
  end]
end

.vpc_endpointsObject

Public: Lazily load the vpc endpoints

Returns a Hash of vpc id to array of Aws::EC2::Types::VpcEndpoint



198
199
200
201
202
# File 'lib/ec2/EC2.rb', line 198

def vpc_endpoints
  @vpc_endpoints ||= Hash[id_vpcs.map do |vpc_id, _|
    [vpc_id, endpoints.select { |e| e.vpc_id == vpc_id } ]
  end]
end

.vpc_network_aclsObject

Public

Returns a Hash of vpc id to array of Aws::EC2::Types::NetworkAcl



158
159
160
161
162
# File 'lib/ec2/EC2.rb', line 158

def vpc_network_acls
  @vpc_network_acls = Hash[id_vpcs.map do |vpc_id, _|
    [vpc_id, network_acls.select { |acl| acl.vpc_id == vpc_id }]
  end]
end

.vpc_network_interfacesObject

Public

Returns a Hash of vpc id to array of Aws::EC2::Types::NetworkInterface



249
250
251
252
253
# File 'lib/ec2/EC2.rb', line 249

def vpc_network_interfaces
  @vpc_network_interfaces ||= Hash[id_vpcs.map do |vpc_id, _|
    [vpc_id, network_interfaces.select { |net| net.vpc_id == vpc_id}]
  end]
end

.vpc_route_tablesObject

Public

Returns a Hash of vpc id to array of Aws::EC2::Types::RouteTable



122
123
124
125
126
# File 'lib/ec2/EC2.rb', line 122

def vpc_route_tables
  @vpc_route_tables ||= Hash[id_vpcs.map do |vpc_id, _|
    [vpc_id, route_tables.select { |rt| rt.vpc_id == vpc_id }]
  end]
end

.vpc_subnetsObject

Public

Returns a Hash of VPC id to array of Aws::EC2::Types::Subnet for the VPC



66
67
68
69
70
# File 'lib/ec2/EC2.rb', line 66

def vpc_subnets
  @vpc_subnets ||= Hash[id_vpcs.map do |vpc_id, _|
    [vpc_id, subnets.select { |subnet| subnet.vpc_id == vpc_id }]
  end]
end

.vpcsObject

Public: Lazily load the vpcs



98
99
100
# File 'lib/ec2/EC2.rb', line 98

def vpcs
  @vpcs ||= init_vpcs
end