in cookbooks/aws-parallelcluster-environment/files/default/ec2_udev_rules/manageVolume.py [0:0]
def adapt_device_name(dev):
# Translate the device name as provided by the OS to the one used by EC2
# FIXME This approach could be broken in some OS variants, see # pylint: disable=fixme
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html#identify-nvme-ebs-device
#
# A nosec comment is appended to the following line in order to disable the B605 check.
# The only current use of this script in the repo sets the `dev` arg to the value of a device name
# obtained via the OS.
# Validation to sanitize the input argument and make it safe to use the function affected by B605
validate_device_name(dev)
if "/nvme" in dev:
return (
"/dev/"
+ os.popen("sudo /usr/local/sbin/parallelcluster-ebsnvme-id -u -b " + dev) # nosec B605 nosemgrep
.read()
.strip()
)
elif "/hd" in dev:
return dev.replace("hd", "sd")
elif "/xvd" in dev:
return dev.replace("xvd", "sd")
else:
return dev