def get_mgmt_interface(device, mgmt_ip=None):
    """ Get the name of the management interface.

    if the mgmt_ip is provided, will use that for the lookup. If not, will
    call the get_mgmt_ip API to get the IP.

    Args:
        mgmt_ip: (str) IP address of the management interface (optional)

    Returns:
        String with interface name
    """
    mgmt_ip = mgmt_ip or device.api.get_mgmt_ip()
    out = device.parse('show ip interface brief')
    result = out.q.contains_key_value(key='ip_address', value=mgmt_ip).get_values('interface')
    if result:
        return result[0]