def generate_analysis_target_id(analysis_target, name):
# this function generates 'machine-id's for analysis target's that
# might not be hosts.
#
# 'machine_id' is what Insights uses to uniquely identify
# the thing-to-be-analysed. Primarily it determines when two uploads
# are for the 'same thing', and so the latest upload should update the
# later one Up till now that has only been hosts (machines), and so a
# random uuid (uuid4) machine-id was generated for the host as its machine-id,
# and written to a file on the host, and reused for all insights
# uploads for that host.
#
# For docker images and containers, it will be difficult to impossible
# to save their machine id's anywhere. Also, while containers change
# over time just like hosts, images don't change over time, though they
# can be rebuilt. So for images we want the 'machine-id' for an 'image'
# to follow the rebuilt image, not change every time the image is rebuilt.
# Typically when an image is rebuilt, the rebuilt image will have the same
# name as its predicessor, but a different version (tag).
#
# So for images and containers, instead of random uuids, we use namespace uuids
# (uuid5's). This generates a new uuid based on a combination of another
# uuid, and a name (a character string). This will always generate the
# same uuid for the same given base uuid and name. This saves us from
# having to save the image's uuid anywhere, and lets us control the created uuid
# by controlling the name used to generate it. Keep the name and base uuid) the
# same, we get the same uuid.
#
# For the base uuid we use the uuid of the host we are running on.
# For containers this is the obvious choice, for images it is less obviously
# what base uuid is correct. For now we will just go with the host's uuid also.
#
# For the name, we leave that outside this function, but in general it should
# be the name of the container or the name of the image, and if you want to
# replace the results on the insights server, you have to use the same name
if analysis_target == "host":
return generate_machine_id()
elif (analysis_target == "docker_image" or
analysis_target == "docker_container" or
analysis_target == "compressed_file" or
analysis_target == "mountpoint"):
return generate_container_id(name)
else:
raise ValueError("Unknown analysis target: %s" % analysis_target)
评论列表
文章目录