File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -884,3 +884,23 @@ class IdentityTranslator(AddressTranslator):
884884 """
885885 def translate (self , addr ):
886886 return addr
887+
888+
889+ class EC2MultiRegionTranslator (AddressTranslator ):
890+ """
891+ Resolves private ips of the hosts in the same datacenter as the client, and public ips of hosts in other datacenters.
892+ """
893+ def translate (self , addr ):
894+ """
895+ Reverse DNS the public broadcast_address, then lookup that hostname to get the AWS-resolved IP, which
896+ will point to the private IP address within the same datacenter.
897+ """
898+ # get family of this address so we translate to the same
899+ family = socket .getaddrinfo (addr , 0 , socket .AF_UNSPEC , socket .SOCK_STREAM )[0 ][0 ]
900+ host = socket .getfqdn (addr )
901+ for a in socket .getaddrinfo (host , 0 , family , socket .SOCK_STREAM ):
902+ try :
903+ return a [4 ][0 ]
904+ except Exception :
905+ pass
906+ return addr
You can’t perform that action at this time.
0 commit comments