<commit_before>from django.http import HttpResponse
from django.shortcuts import get_object_or_404

from cloudmeta.apps.metadata.models import KEYTYPE_CHOICES, Node

def _get_node(request):
    remote_addr = request.META['HTTP_X_REAL_IP'] or request.META['REMOTE_ADDR']
    try:
        node = Node.objects.get(name=remote_addr)
    except Node.DoesNotExist:
        # Possible ipv4->ipv6 conversion?
        node = get_object_or_404(Node, name=remote_addr.lstrip('::ffff:'))
    return node

def index(request):
    return HttpResponse("meta-data service: {meta[REMOTE_ADDR]}".format(meta=request.META))

def hostname(request):
    node = _get_node(request)
    return HttpResponse(node.hostname)<commit_msg>Refelect the source IP that we care about<commit_after>from django.http import HttpResponse
from django.shortcuts import get_object_or_404

from cloudmeta.apps.metadata.models import KEYTYPE_CHOICES, Node

def _get_node(request):
    remote_addr = request.META['HTTP_X_REAL_IP'] or request.META['REMOTE_ADDR']
    try:
        node = Node.objects.get(name=remote_addr)
    except Node.DoesNotExist:
        # Possible ipv4->ipv6 conversion?
        node = get_object_or_404(Node, name=remote_addr.lstrip('::ffff:'))
    return node

def index(request):
    return HttpResponse("meta-data service: {}".format(
        request.META['HTTP_X_REAL_IP'] or request.META['REMOTE_ADDR']))

def hostname(request):
    node = _get_node(request)
    return HttpResponse(node.hostname)
{'fraction_non_alphanumeric': 0.10661268556005399, 'fraction_numerical': 0.010796221322537112, 'mean_word_length': 4.703846153846154, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4100436', 'n_tokens_mistral': 498, 'n_tokens_neox': 479, 'n_words': 97}