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
80 81 82 83 84 85 |
# File 'lib/awspec/helper/finder/ec2.rb', line 80 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
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/awspec/helper/finder/ec2.rb', line 87 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
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/awspec/helper/finder/ec2.rb', line 58 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
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/awspec/helper/finder/ec2.rb', line 104 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
117 118 119 120 121 122 |
# File 'lib/awspec/helper/finder/ec2.rb', line 117 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
124 125 126 127 128 129 |
# File 'lib/awspec/helper/finder/ec2.rb', line 124 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
145 146 147 148 149 150 |
# File 'lib/awspec/helper/finder/ec2.rb', line 145 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
138 139 140 141 142 143 |
# File 'lib/awspec/helper/finder/ec2.rb', line 138 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
131 132 133 134 135 136 |
# File 'lib/awspec/helper/finder/ec2.rb', line 131 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
152 153 154 155 156 157 |
# File 'lib/awspec/helper/finder/ec2.rb', line 152 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 |