Ensure the specified endpoints exists for service

    name
        The Service name

    publicurl
        The public url of service endpoint (for V2 API)

    internalurl
        The internal url of service endpoint (for V2 API)

    adminurl
        The admin url of the service endpoint (for V2 API)

    region
        The region of the endpoint

    url
        The endpoint URL (for V3 API)

    interface
        The interface type, which describes the visibility
        of the endpoint. (for V3 API)

def endpoint_present(name,
                     publicurl=None,
                     internalurl=None,
                     adminurl=None,
                     region=None,
                     profile=None,
                     url=None,
                     interface=None, **connection_args):
    '''
    Ensure the specified endpoints exists for service

    name
        The Service name

    publicurl
        The public url of service endpoint (for V2 API)

    internalurl
        The internal url of service endpoint (for V2 API)

    adminurl
        The admin url of the service endpoint (for V2 API)

    region
        The region of the endpoint

    url
        The endpoint URL (for V3 API)

    interface
        The interface type, which describes the visibility
        of the endpoint. (for V3 API)

    '''
    ret = {'name': name,
           'changes': {},
           'result': True,
           'comment': ''}

    _api_version(profile=profile, **connection_args)

    endpoint = __salt__['keystone.endpoint_get'](name, region,
                                                 profile=profile,
                                                 interface=interface,
                                                 **connection_args)

    def _changes(desc):
        return ret.get('comment', '') + desc + '\n'

    def _create_endpoint():
        if _OS_IDENTITY_API_VERSION > 2:
            ret['changes'] = __salt__['keystone.endpoint_create'](
                name,
                region=region,
                url=url,
                interface=interface,
                profile=profile,
                **connection_args)
        else:
            ret['changes'] = __salt__['keystone.endpoint_create'](
                name,
                region=region,
                publicurl=publicurl,
                adminurl=adminurl,
                internalurl=internalurl,
                profile=profile,
                **connection_args)

    if endpoint and 'Error' not in endpoint and endpoint.get('region') == region:

        if _OS_IDENTITY_API_VERSION > 2:

            change_url = False
            change_interface = False

            if endpoint.get('url', None) != url:
                ret['comment'] = _changes('URL changes from "{0}" to "{1}"'.format(endpoint.get('url', None), url))
                change_url = True

            if endpoint.get('interface', None) != interface:
                ret['comment'] = _changes('Interface changes from "{0}" to "{1}"'.format(endpoint.get('interface', None), interface))
                change_interface = True

            if __opts__.get('test') and (change_url or change_interface):
                ret['result'] = None
                ret['changes']['Endpoint'] = 'Will be updated'
                ret['comment'] += 'Endpoint for service "{0}" will be updated'.format(name)
                return ret

            if change_url:
                ret['changes']['url'] = url

            if change_interface:
                ret['changes']['interface'] = interface

        else:
            change_publicurl = False
            change_adminurl = False
            change_internalurl = False

            if endpoint.get('publicurl', None) != publicurl:
                change_publicurl = True

                ret['comment'] = _changes('Public URL changes from "{0}" to "{1}"'.format(
                    endpoint.get('publicurl', None), publicurl)
                )

            if endpoint.get('adminurl', None) != adminurl:
                change_adminurl = True
                ret['comment'] = _changes('Admin URL changes from "{0}" to "{1}"'.format(
                    endpoint.get('adminurl', None), adminurl)
                )

            if endpoint.get('internalurl', None) != internalurl:
                change_internalurl = True
                ret['comment'] = _changes(
                    'Internal URL changes from "{0}" to "{1}"'.format(
                        endpoint.get('internalurl', None),
                        internalurl
                    )
                )

            if __opts__.get('test') and (change_publicurl or change_adminurl or change_internalurl):
                ret['result'] = None
                ret['comment'] += 'Endpoint for service "{0}" will be updated'.format(name)
                ret['changes']['Endpoint'] = 'Will be updated'
                return ret

            if change_publicurl:
                ret['changes']['publicurl'] = publicurl

            if change_adminurl:
                ret['changes']['adminurl'] = adminurl

            if change_internalurl:
                ret['changes']['internalurl'] = internalurl

        if ret['comment']:  # changed
            __salt__['keystone.endpoint_delete'](name, region, profile=profile, interface=interface, **connection_args)
            _create_endpoint()
            ret['comment'] += 'Endpoint for service "{0}" has been updated'.format(name)

    else:
        # Add new endpoint
        if __opts__.get('test'):
            ret['result'] = None
            ret['changes']['Endpoint'] = 'Will be created'
            ret['comment'] = 'Endpoint for service "{0}" will be added'.format(name)
            return ret
        _create_endpoint()
        ret['comment'] = 'Endpoint for service "{0}" has been added'.format(name)

    if ret['comment'] == '':  # => no changes
        ret['comment'] = 'Endpoint for service "{0}" already exists'.format(name)
    return ret