in src/mount_efs/__init__.py [0:0]
def match_device(config, device, options):
"""Return the EFS id, the remote path, and the az to mount"""
try:
remote, path = device.split(":", 1)
except ValueError:
remote = device
path = "/"
if FS_ID_RE.match(remote):
return remote, path, None
try:
primary, secondaries, _ = socket.gethostbyname_ex(remote)
hostnames = list(filter(lambda e: e is not None, [primary] + secondaries))
except socket.gaierror:
create_default_cloudwatchlog_agent_if_not_exist(config, options)
fatal_error(
'Failed to resolve "%s" - check that the specified DNS name is a CNAME record resolving to a valid EFS DNS '
"name" % remote,
'Failed to resolve "%s"' % remote,
)
if not hostnames:
create_default_cloudwatchlog_agent_if_not_exist(config, options)
fatal_error(
'The specified domain name "%s" did not resolve to an EFS mount target'
% remote
)
for hostname in hostnames:
efs_fqdn_match = EFS_FQDN_RE.match(hostname)
if efs_fqdn_match:
az = efs_fqdn_match.group("az")
fs_id = efs_fqdn_match.group("fs_id")
if az and "az" in options and az != options["az"]:
fatal_error(
'The hostname "%s" resolved by the specified domain name "%s" does not match the az provided in the '
"mount options, expected = %s, given = %s"
% (hostname, remote, options["az"], az)
)
expected_dns_name, _ = get_dns_name_and_fallback_mount_target_ip_address(
config, fs_id, add_field_in_options(options, "az", az)
)
# check that the DNS name of the mount target matches exactly the DNS name the CNAME resolves to
if hostname == expected_dns_name:
return fs_id, path, az
else:
create_default_cloudwatchlog_agent_if_not_exist(config, options)
fatal_error(
'The specified CNAME "%s" did not resolve to a valid DNS name for an EFS mount target. '
"Please refer to the EFS documentation for mounting with DNS names for examples: %s"
% (
remote,
"https://docs.aws.amazon.com/efs/latest/ug/mounting-fs-mount-cmd-dns-name.html",
)
)