import hashlib


def dvportgroup_name(uuid, sg_set):
    """
    Returns a dvportgroup name for the particular security group set
    in the context of the switch of the given uuid
    """
    # There is an upper limit on managed object names in vCenter
    dvs_id = ''.join(uuid.split(' '))[:8]
    name = sg_set + "-" + dvs_id
    if len(name) > 80:
        # so we use a hash of the security group set
        hex = hashlib.sha224()
        hex.update(sg_set)
        name = hex.hexdigest() + "-" + dvs_id

    return name