def dict_to_capabilities(caps_dict):
    """Convert a dictionary into a string with the capabilities syntax."""
    if isinstance(caps_dict, str):
        return caps_dict

    # NOTE(dtantsur): sort capabilities so that their order does not change
    # between updates.
    items = sorted(caps_dict.items(), key=lambda tpl: tpl[0])
    return ','.join(["%s:%s" % (key, value)
                     for key, value in items
                     if value is not None])