(self, parsed_args, parsed_globals)
| 149 | ) |
| 150 | |
| 151 | def _run_main(self, parsed_args, parsed_globals): |
| 152 | self._validate_parsed_args(parsed_args) |
| 153 | |
| 154 | # Describe instance to validate instance exist |
| 155 | ec2_client = self._session.create_client( |
| 156 | 'ec2', |
| 157 | region_name=parsed_globals.region, |
| 158 | verify=parsed_globals.verify_ssl, |
| 159 | endpoint_url=parsed_globals.endpoint_url, |
| 160 | ) |
| 161 | instance_metadata = ec2_client.describe_instances( |
| 162 | InstanceIds=[parsed_args.instance_id] |
| 163 | )['Reservations'][0]['Instances'][0] |
| 164 | |
| 165 | private_ip_address = instance_metadata.get('PrivateIpAddress') |
| 166 | public_ip_address = instance_metadata.get('PublicIpAddress') |
| 167 | ipv6_address = instance_metadata.get('Ipv6Address') |
| 168 | |
| 169 | use_open_tunnel = False |
| 170 | ip_address_to_connect = None |
| 171 | if parsed_args.instance_ip: |
| 172 | use_open_tunnel = parsed_args.connection_type == 'eice' |
| 173 | ip_address_to_connect = parsed_args.instance_ip |
| 174 | elif parsed_args.connection_type == 'eice' or parsed_args.eice_options: |
| 175 | use_open_tunnel = True |
| 176 | ip_address_to_connect = private_ip_address or ipv6_address |
| 177 | elif parsed_args.connection_type == 'direct': |
| 178 | use_open_tunnel = False |
| 179 | ip_address_to_connect = ( |
| 180 | public_ip_address or ipv6_address or private_ip_address |
| 181 | ) |
| 182 | elif parsed_args.connection_type == 'auto': |
| 183 | # In case of auto we use IPv4 address first and then IPv6 because right now most instance have these, but |
| 184 | # in future we might want to switch this logic to where we select IPv6 first and then fallback to IPv4. |
| 185 | if public_ip_address: |
| 186 | use_open_tunnel = False |
| 187 | ip_address_to_connect = public_ip_address |
| 188 | elif private_ip_address: |
| 189 | use_open_tunnel = True |
| 190 | ip_address_to_connect = private_ip_address |
| 191 | elif ipv6_address: |
| 192 | use_open_tunnel = False |
| 193 | ip_address_to_connect = ipv6_address |
| 194 | |
| 195 | if ip_address_to_connect is None: |
| 196 | raise ParamValidationError( |
| 197 | 'Unable to find any IP address on the instance to connect to.' |
| 198 | ) |
| 199 | |
| 200 | instance_connect_endpoint_id = self._get_eice_option( |
| 201 | parsed_args.eice_options, 'endpointId' |
| 202 | ) |
| 203 | instance_connect_endpoint_dns_name = self._get_eice_option( |
| 204 | parsed_args.eice_options, 'dnsName' |
| 205 | ) |
| 206 | if use_open_tunnel and not instance_connect_endpoint_dns_name: |
| 207 | eice_fetcher = InstanceConnectEndpointRequestFetcher() |
| 208 | eice_info = eice_fetcher.get_available_instance_connect_endpoint( |
nothing calls this directly
no test coverage detected