import requests


def get_ipam_roles(url, headers):
    """
    Get dictionary of existing IPAM roles
    """
    api_url = f"{url}/api/ipam/roles/"
    response = requests.request("GET", api_url, headers=headers)
    all_roles = response.json()["results"]
    roles = []
    for role in all_roles:
        role_info = dict()
        role_info["name"] = role["name"]
        role_info["state"] = "present"
        role_info["weight"] = role["weight"]
        roles.append(role_info)

    return roles