module Cumulus::EC2
Constants
- InstanceAttributes
Easily load instance attribute data individually and lazy
- VolumeGroup
Public Class Methods
Public: Lazily load the addresses
# File lib/ec2/EC2.rb, line 227 def addresses @addresses ||= init_addresses end
Public: Lazily load the dhcp options
# File lib/ec2/EC2.rb, line 191 def dhcp_options @dhcp_options ||= init_dhcp_options end
Public
Returns an array of the group names used by all ebs volumes
# File lib/ec2/EC2.rb, line 283 def ebs_groups @ebs_groups ||= ebs_volumes.map(&:group).reject(&:nil?).uniq end
Public: Lazily loads EBS volumes, rejecting all root-mounted volumes
# 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
Public: Lazily load the endpoints
# File lib/ec2/EC2.rb, line 205 def endpoints @endpoints ||= init_endpoints end
Public
Returns a Hash of ebs volume group name to EbsGroupConfig
# 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
Public
Returns a Hash of ebs volume group name to Aws::EC2::Types::Volume
# 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
Public
Returns a Hash of dhcp options id to Aws::EC2::Types::DhcpOptions
# 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
Public
Returns a Hash of ebs volume id to volume
# File lib/ec2/EC2.rb, line 290 def id_ebs_volumes @id_ebs_volumes ||= Hash[ebs_volumes.map { |vol| [vol.volume_id, vol] }] end
Public
Returns a Hash of instance id to attributes, lazily loading each attribute
# 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
Public
Returns a Hash of instance id to Aws::EC2::Types::Instance
# File lib/ec2/EC2.rb, line 307 def id_instances @id_instances ||= Hash[instances.map { |i| [i.instance_id, i] }] end
Public
Returns a Hash of interface id to Aws::EC2::Types::NetworkInterface
# 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
Public
Returns a Hash of route table id Aws::EC2::Types::RouteTable
# 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
Public
Returns a Hash of subnet id to Aws::EC2::Types::Subnet
# File lib/ec2/EC2.rb, line 51 def id_subnets @id_subnets ||= Hash[subnets.map { |subnet| [subnet.subnet_id, subnet] }] end
Public
Returns a Hash of VPC
id to Aws::EC2::Types::Vpc
# File lib/ec2/EC2.rb, line 88 def id_vpcs @vpc_ids ||= Hash[vpcs.map { |vpc| [vpc.vpc_id, vpc] }] end
Public: Load instance attributes
Returns the instance attribute as whatever type that attribute is
# 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
Public: Lazily loads instances
# File lib/ec2/EC2.rb, line 337 def instances @instances ||= init_instances.reject(&:terminated?) end
Public
Returns a Hash of instance name or id to Aws::EC2::Types::Instance
# File lib/ec2/EC2.rb, line 314 def named_instances @named_instances ||= Hash[instances.map { |i| [i.name || i.instance_id, i] }] end
Public
Returns a Hash of network acl name or id to Aws::EC2::Types::NetworkAcl
# 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
Public
Returns a Hash of interface name to Aws::EC2::Types::NetworkInterface
# 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
Public
Returns a Hash of placement group name to Aws::EC2::Types::PlacementGroup
# File lib/ec2/EC2.rb, line 344 def named_placement_groups @named_placement_groups ||= Hash[placement_groups.map { |pg| [pg.group_name, pg] }] end
Public
Returns a Hash of route tables name or id to Aws::EC2::Types::RouteTable
# 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
Public
Returns a Hash of subnet name or id to Aws::EC2::Types::Subnet
# 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
Public
Returns a Hash of VPC
name or id to Aws::EC2::Types::Vpc
# 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
Public: Lazily load the network acls
# File lib/ec2/EC2.rb, line 174 def network_acls @network_acls ||= init_network_acls end
Public: Lazily load network interfaces
# File lib/ec2/EC2.rb, line 256 def network_interfaces @network_interfaces ||= init_network_interfaces end
Public: Lazily load placement groups
# File lib/ec2/EC2.rb, line 349 def placement_groups @placement_groups ||= init_placement_groups end
Public
Returns a Hash of public ip to Aws::EC2::Types::Address
# File lib/ec2/EC2.rb, line 212 def public_addresses @public_addresses ||= Hash[addresses.map { |addr| [addr.public_ip, addr] }] end
Public: Refresh the list of Network ACLs
# File lib/ec2/EC2.rb, line 179 def refresh_network_acls! @network_acls = init_network_acls end
Public refreshes the list of route tables
# File lib/ec2/EC2.rb, line 141 def refresh_route_tables! @route_tables = init_route_tables end
Public refreshes the list of vpcs
# File lib/ec2/EC2.rb, line 93 def refresh_vpcs! @vpcs = init_vpcs end
Public: Lazily load route tables
# File lib/ec2/EC2.rb, line 136 def route_tables @route_tables ||= init_route_tables end
Public
Returns a Hash of subnet id to Aws::EC2::Types::NetworkAcl associated with the subnet
# 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
Public
Returns a Hash of subnet id to Aws::EC2::Types::RouteTable
# 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
Public: Lazily load the subnets
# File lib/ec2/EC2.rb, line 73 def subnets @subnets ||= init_subnets end
# File lib/ec2/EC2.rb, line 390 def supported_platforms @supported_platforms ||= @@client.describe_account_attributes({ attribute_names: ["supported-platforms"] }).account_attributes.first.attribute_values.map(&:attribute_value) end
# File lib/ec2/EC2.rb, line 386 def supports_ec2_classic @supports_ec2_classic ||= supported_platforms.include?("EC2") end
# File lib/ec2/EC2.rb, line 382 def supports_vpc @supports_vpc ||= supported_platforms.include?("VPC") end
Public
Returns a Hash of vpc id to array of Aws::EC2::Types::Address that has a network interface in the vpc
# 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
Public: Lazily load the vpc endpoints
Returns a Hash of vpc id to array of Aws::EC2::Types::VpcEndpoint
# 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
Public
Returns a Hash of vpc id to array of Aws::EC2::Types::NetworkAcl
# 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
Public
Returns a Hash of vpc id to array of Aws::EC2::Types::NetworkInterface
# 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
Public
Returns a Hash of vpc id to array of Aws::EC2::Types::RouteTable
# 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
Public: Lazily load the vpcs
# File lib/ec2/EC2.rb, line 98 def vpcs @vpcs ||= init_vpcs end
Private Class Methods
Internal: Load allocated addresses
Returns the address as Aws::EC2::Types::Address
# File lib/ec2/EC2.rb, line 456 def init_addresses @@client.describe_addresses.addresses end
Internal: Load DHCP Options
Returns the dhcp options as Aws::EC2::Types::DhcpOptions
# File lib/ec2/EC2.rb, line 429 def init_dhcp_options @@client.describe_dhcp_options.dhcp_options end
Internal: Load EBS Volumes
Returns the volumes as Aws::EC2::Types::Volume
# File lib/ec2/EC2.rb, line 470 def init_ebs_volumes @@client.describe_volumes.volumes end
Internal: Load VPC
Endpoints
Returns the vpc endpoints as Aws::EC2::Types::VpcEndpoint
# File lib/ec2/EC2.rb, line 436 def init_endpoints endpoints = [] next_token = nil all_records_retrieved = false until all_records_retrieved response = @@client.describe_vpc_endpoints({ next_token: next_token }) next_token = response.next_token all_records_retrieved = next_token.nil? || next_token.empty? endpoints << response.vpc_endpoints end endpoints.flatten end
Internal: Load instances
Returns the instances as Aws::EC2::Types::Instance
# File lib/ec2/EC2.rb, line 477 def init_instances instances = [] next_token = nil all_records_retrieved = false until all_records_retrieved response = @@client.describe_instances({ next_token: next_token }) next_token = response.next_token all_records_retrieved = next_token.nil? || next_token.empty? instances << response.reservations.map { |r| r.instances } end instances.flatten end
Internal: Load network acls
Returns the network acls as Aws::EC2::Types::NetworkAcl
# File lib/ec2/EC2.rb, line 422 def init_network_acls @@client.describe_network_acls.network_acls end
Internal: Load network interfaces
Returns the network interface as Aws::EC2::Types::NetworkInterface
# File lib/ec2/EC2.rb, line 463 def init_network_interfaces @@client.describe_network_interfaces.network_interfaces end
Internal: Load placement groups
Returns the placement groups as Aws::EC2::Types::PlacementGroup
# File lib/ec2/EC2.rb, line 497 def init_placement_groups @@client.describe_placement_groups.placement_groups end
Internal: Load route tables
Returns the route tables as Aws::EC2::Types::RouteTable
# File lib/ec2/EC2.rb, line 415 def init_route_tables @@client.describe_route_tables.route_tables end
Internal: Load all subnets
Returns an array of Aws::EC2::Types::Subnet
# File lib/ec2/EC2.rb, line 401 def init_subnets @@client.describe_subnets.subnets end
Internal: Load VPCs
Returns the VPCs as Aws::EC2::Types::Vpc
# File lib/ec2/EC2.rb, line 408 def init_vpcs @@client.describe_vpcs.vpcs end