Skip to content

Instantly share code, notes, and snippets.

@akhilerm
Last active August 8, 2019 09:52
Show Gist options
  • Save akhilerm/eb3a9fe81dc83e176fff8e6f0291824f to your computer and use it in GitHub Desktop.
Save akhilerm/eb3a9fe81dc83e176fff8e6f0291824f to your computer and use it in GitHub Desktop.
UUID generation for disks in NDM
// gets the uuid of the provided disk
func getUid(device *udev.UdevDevice) string {
uid := device.GetPropertyValue(udev.UDEV_WWN) +
device.GetPropertyValue(udev.UDEV_MODEL) +
device.GetPropertyValue(udev.UDEV_SERIAL) +
device.GetPropertyValue(udev.UDEV_VENDOR)
idtype := device.GetPropertyValue(udev.UDEV_TYPE)
model := device.GetPropertyValue(udev.UDEV_MODEL)
// in case of virtual of ephemeral we go with the gpt label (partition label in general),
// if it is also not available check for filesystem label. Or should we?
localDiskModels := make([]string, 0)
localDiskModels = append(localDiskModels, "EphemeralDisk")
localDiskModels = append(localDiskModels, "Virtual_disk")
if len(idtype) == 0 || util.Contains(localDiskModels, model) {
gptLabel := device.GetPropertyValue(udev.UDEV_PART_TABLE)
fsLabel := device.GetPropertyValue(udev.UDEV_FS_UUID)
if gptLabel == "" {
if fsLabel == "" {
// we have no way to uniquely identify the disk.
} else {
uid = fsLabel
}
} else {
uid = gptLabel
}
}
// take an md5 hash of the uid and return
return util.Hash(uid)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment