Module: Awspec::Helper::Finder::Ec2
- Included in:
- Awspec::Helper::Finder
- Defined in:
- lib/awspec/helper/finder/ec2.rb
Instance Method Summary collapse
- #find_ec2(id) ⇒ Object
- #find_ec2_attribute(id, attribute) ⇒ Object
- #find_ec2_status(id) ⇒ Object
- #find_nat_gateway(gateway_id) ⇒ Object
- #find_network_interface(interface_id) ⇒ Object
- #find_vpn_connection(vpn_connection_id) ⇒ Object
- #select_ec2_by_vpc_id(vpc_id) ⇒ Object
- #select_eip_by_instance_id(id) ⇒ Object
- #select_eip_by_public_ip(id) ⇒ Object
- #select_internet_gateway_by_vpc_id(vpc_id) ⇒ Object
- #select_nat_gateway_by_vpc_id(vpc_id) ⇒ Object
- #select_network_interface_by_instance_id(id) ⇒ Object
- #select_network_interface_by_vpc_id(vpc_id) ⇒ Object
Instance Method Details
#find_ec2(id) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/awspec/helper/finder/ec2.rb', line 4 def find_ec2(id) # instance_id or tag:Name begin res = ec2_client.describe_instances({ instance_ids: [id] }) rescue # Aws::EC2::Errors::InvalidInstanceIDMalformed # Aws::EC2::Errors::InvalidInstanceIDNotFound res = ec2_client.describe_instances({ filters: [{ name: 'tag:Name', values: [id] }] }) end # rubocop:enable Style/GuardClause if res.reservations.count == 1 res.reservations.first.instances.single_resource(id) elsif res.reservations.count > 1 raise Awspec::DuplicatedResourceTypeError, "Duplicate instances matching id or tag #{id}" end end |
#find_ec2_attribute(id, attribute) ⇒ Object
25 26 27 28 29 |
# File 'lib/awspec/helper/finder/ec2.rb', line 25 def find_ec2_attribute(id, attribute) res = ec2_client.describe_instance_attribute({ instance_id: id, attribute: attribute }) end |
#find_ec2_status(id) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/awspec/helper/finder/ec2.rb', line 31 def find_ec2_status(id) res = ec2_client.describe_instance_status({ instance_ids: [id] }) res.instance_statuses.first if res.instance_statuses.count == 1 end |
#find_nat_gateway(gateway_id) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/awspec/helper/finder/ec2.rb', line 78 def find_nat_gateway(gateway_id) res = ec2_client.describe_nat_gateways({ filter: [{ name: 'nat-gateway-id', values: [gateway_id] }] }) res.nat_gateways.single_resource(gateway_id) end |
#find_network_interface(interface_id) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/awspec/helper/finder/ec2.rb', line 85 def find_network_interface(interface_id) res = ec2_client.describe_network_interfaces({ filters: [ { name: 'network-interface-id', values: [interface_id] } ] }) resource = res.network_interfaces.single_resource(interface_id) return resource if resource res = ec2_client.describe_network_interfaces({ filters: [{ name: 'tag:Name', values: [interface_id] }] }) res.network_interfaces.single_resource(interface_id) end |
#find_vpn_connection(vpn_connection_id) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/awspec/helper/finder/ec2.rb', line 56 def find_vpn_connection(vpn_connection_id) res = ec2_client.describe_vpn_connections({ filters: [ { name: 'vpn-connection-id', values: [vpn_connection_id] } ] }) resource = res.vpn_connections.single_resource(vpn_connection_id) return resource if resource res = ec2_client.describe_vpn_connections({ filters: [ { name: 'tag:Name', values: [vpn_connection_id] } ] }) res.vpn_connections.single_resource(vpn_connection_id) end |
#select_ec2_by_vpc_id(vpc_id) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/awspec/helper/finder/ec2.rb', line 102 def select_ec2_by_vpc_id(vpc_id) res = ec2_client.describe_instances({ filters: [{ name: 'vpc-id', values: [vpc_id] }] }) instances = [] res.reservations.each do |reservation| reservation.instances.each do |instance| instances.push(instance) end end instances end |
#select_eip_by_instance_id(id) ⇒ Object
115 116 117 118 119 120 |
# File 'lib/awspec/helper/finder/ec2.rb', line 115 def select_eip_by_instance_id(id) res = ec2_client.describe_addresses({ filters: [{ name: 'instance-id', values: [id] }] }) res.addresses end |
#select_eip_by_public_ip(id) ⇒ Object
122 123 124 125 126 127 |
# File 'lib/awspec/helper/finder/ec2.rb', line 122 def select_eip_by_public_ip(id) res = ec2_client.describe_addresses({ filters: [{ name: 'public-ip', values: [id] }] }) res.addresses end |
#select_internet_gateway_by_vpc_id(vpc_id) ⇒ Object
143 144 145 146 147 148 |
# File 'lib/awspec/helper/finder/ec2.rb', line 143 def select_internet_gateway_by_vpc_id(vpc_id) res = ec2_client.describe_internet_gateways({ filters: [{ name: 'attachment.vpc-id', values: [vpc_id] }] }) res.internet_gateways end |
#select_nat_gateway_by_vpc_id(vpc_id) ⇒ Object
136 137 138 139 140 141 |
# File 'lib/awspec/helper/finder/ec2.rb', line 136 def select_nat_gateway_by_vpc_id(vpc_id) res = ec2_client.describe_nat_gateways({ filter: [{ name: 'vpc-id', values: [vpc_id] }] }) res.nat_gateways end |
#select_network_interface_by_instance_id(id) ⇒ Object
129 130 131 132 133 134 |
# File 'lib/awspec/helper/finder/ec2.rb', line 129 def select_network_interface_by_instance_id(id) res = ec2_client.describe_network_interfaces({ filters: [{ name: 'attachment.instance-id', values: [id] }] }) res.network_interfaces end |
#select_network_interface_by_vpc_id(vpc_id) ⇒ Object
150 151 152 153 154 155 |
# File 'lib/awspec/helper/finder/ec2.rb', line 150 def select_network_interface_by_vpc_id(vpc_id) res = ec2_client.describe_network_interfaces({ filters: [{ name: 'vpc-id', values: [vpc_id] }] }) res.network_interfaces end |