コード例 #1
0
ファイル: api_donpedro.py プロジェクト: damjanek/ralph
 def obj_create(self, bundle, request=None, **kwargs):
     ip = remote_addr(request)
     logger.debug('Got json data: %s' % bundle.data.get('data'))
     try:
         return save_device_data(bundle.data.get('data'), ip)
     except Exception:
         logger.error(traceback.format_exc())
         raise
コード例 #2
0
ファイル: views.py プロジェクト: ReJeCtAll/ralph
def dhcp_synch(request):
    if not api.is_authenticated(request):
        return HttpResponseForbidden('API key required.')
    address = remote_addr(request)
    server = get_object_or_404(DHCPServer, ip=address)
    server.last_synchronized = datetime.datetime.now()
    server.save()
    return HttpResponse('OK', content_type='text/plain')
コード例 #3
0
def dhcp_synch(request):
    if not api.is_authenticated(request):
        return HttpResponseForbidden('API key required.')
    address = remote_addr(request)
    server = get_object_or_404(DHCPServer, ip=address)
    server.last_synchronized = datetime.datetime.now()
    server.save()
    return HttpResponse('OK', content_type='text/plain')
コード例 #4
0
 def obj_create(self, bundle, **kwargs):
     ip = remote_addr(bundle.request)
     logger.debug('Got json data: %s' % bundle.data.get('data'))
     try:
         return save_device_data(bundle.data.get('data'), ip)
     except Exception:
         logger.error(traceback.format_exc())
         raise
コード例 #5
0
def dhcp_config_head(request):
    server_address = request.GET.get('server')
    if not server_address:
        server_address = remote_addr(request)
    dhcp_server = get_object_or_404(DHCPServer, ip=server_address)
    return HttpResponse(
        generate_dhcp_config_head(
            dhcp_server=dhcp_server,
        ),
        content_type='text/plain',
    )
コード例 #6
0
def dhcp_config_head(request):
    if not api.is_authenticated(request):
        return HttpResponseForbidden('API key required.')
    server_address = request.GET.get('server')
    if not server_address:
        server_address = remote_addr(request)
    dhcp_server = get_object_or_404(DHCPServer, ip=server_address)
    return HttpResponse(
        generate_dhcp_config_head(dhcp_server=dhcp_server, ),
        content_type='text/plain',
    )
コード例 #7
0
ファイル: views.py プロジェクト: Makdaam/ralph
def get_current_deployment(request):
    ip = remote_addr(request)
    deployment = None
    try:
        deployment = Deployment.objects.get(ip=ip,
            status=DeploymentStatus.in_deployment.id)
    except Deployment.DoesNotExist:
        if request.user.is_superuser and request.GET.get('ip'):
            ip = request.GET.get('ip')
            deployment = Deployment.objects.get(ip=ip,
                status=DeploymentStatus.in_deployment.id)
    return deployment
コード例 #8
0
ファイル: views.py プロジェクト: damjanek/ralph
def dhcp_config(request):
    if not api.is_authenticated(request):
        return HttpResponseForbidden('API key required.')
    if request.GET.get('dc'):
        dc = DataCenter.objects.get(name__iexact=request.GET['dc'])
    else:
        dc = None
    address = remote_addr(request)
    return HttpResponse(
        generate_dhcp_config(dc=dc, server_address=address),
        content_type="text/plain",
    )
コード例 #9
0
def get_current_deployment(request):
    ip = remote_addr(request)
    deployment = None
    try:
        deployment = Deployment.objects.get(
            ip=ip, status=DeploymentStatus.in_deployment.id)
    except Deployment.DoesNotExist:
        if request.user.is_superuser and request.GET.get('ip'):
            ip = request.GET.get('ip')
            deployment = Deployment.objects.get(
                ip=ip, status=DeploymentStatus.in_deployment.id)
    return deployment
コード例 #10
0
ファイル: views.py プロジェクト: ReJeCtAll/ralph
def dhcp_config_head(request):
    if not api.is_authenticated(request):
        return HttpResponseForbidden('API key required.')
    server_address = request.GET.get('server')
    if not server_address:
        server_address = remote_addr(request)
    dhcp_server = get_object_or_404(DHCPServer, ip=server_address)
    return HttpResponse(
        generate_dhcp_config_head(
            dhcp_server=dhcp_server,
        ),
        content_type='text/plain',
    )
コード例 #11
0
ファイル: views.py プロジェクト: ReJeCtAll/ralph
def get_current_deployment(request):
    ip = remote_addr(request)
    deployment = None
    try:
        deployment = Deployment.objects.get(ip=ip, status=DeploymentStatus.in_progress)
    except Deployment.DoesNotExist:
        ip = request.GET.get("ip")
        if ip:
            try:
                deployment = Deployment.objects.get(ip=ip, status=DeploymentStatus.in_progress)
            except Deployment.DoesNotExist:
                pass
    return deployment
コード例 #12
0
 def obj_create(self, bundle, **kwargs):
     if DISCOVERY_DISABLED:
         raise DiscoveryDisabledError(
             'Discovery is deprecated since Ralph 2.0. '
             'Update your DonPedro installation to the version 2.0 or '
             'higher.',
         )
     ip = remote_addr(bundle.request)
     logger.debug('Got json data: %s' % bundle.data.get('data'))
     try:
         return save_device_data(bundle.data.get('data'), ip)
     except Exception:
         logger.error(traceback.format_exc())
         raise
コード例 #13
0
ファイル: views.py プロジェクト: rainsome-org1/ralph
def get_current_deployment(request):
    ip = remote_addr(request)
    deployment = None
    try:
        deployment = Deployment.objects.get(
            ip=ip, status=DeploymentStatus.in_progress)
    except Deployment.DoesNotExist:
        ip = request.GET.get('ip')
        if ip:
            try:
                deployment = Deployment.objects.get(
                    ip=ip, status=DeploymentStatus.in_progress)
            except Deployment.DoesNotExist:
                pass
    return deployment
コード例 #14
0
ファイル: api.py プロジェクト: pydubreucq/ralph
 def obj_create(self, bundle, **kwargs):
     remote_ip = remote_addr(bundle.request)
     logger.debug("Received JSON data (remote IP: %s): %s" % (remote_ip, bundle.data.get("data")))
     data = bundle.data.get("data", {})
     plugin_name = data.get("plugin")
     if not plugin_name:
         msg = "Improper data received (remote IP: %s)" % remote_ip
         logger.exception(msg)
         raise ValueError(msg)
     try:
         bundle.obj = store_device_data({plugin_name: data})
     except Exception:
         logger.exception("An exception occurred (remote IP: %s): %s" % (remote_ip, traceback.format_exc()))
         raise
     return bundle
コード例 #15
0
ファイル: api.py プロジェクト: rainsome-org1/ralph
 def obj_create(self, bundle, **kwargs):
     remote_ip = remote_addr(bundle.request)
     logger.debug('Received JSON data (remote IP: %s): %s' % (
         remote_ip,
         bundle.data.get('data'),
     ))
     try:
         bundle.obj = store_device_data({
             'donpedro': bundle.data.get('data'),
         })
     except Exception:
         logger.exception('An exception occurred (remote IP: %s): %s' % (
             remote_ip,
             traceback.format_exc(),
         ))
         raise
     return bundle
コード例 #16
0
def dhcp_config(request):
    if not api.is_authenticated(request):
        return HttpResponseForbidden('API key required.')
    if request.GET.get('dc'):
        dc = DataCenter.objects.get(name__iexact=request.GET['dc'])
    else:
        dc = None
    with_networks = bool(request.GET.get('with_networks', False))
    address = remote_addr(request)
    return HttpResponse(
        generate_dhcp_config(
            dc=dc,
            server_address=address,
            with_networks=with_networks,
        ),
        content_type="text/plain",
    )
コード例 #17
0
ファイル: middleware.py プロジェクト: Zydnar/kitdjango
 def process_request(self, request):
     _now_dt = now()
     _now_ts = int(time())
     delta = _now_ts - CURRENTLY_ONLINE_INTERVAL
     users_online = cache.get('users_online', {})
     guests_online = cache.get('guests_online', {})
     users_touched = False
     guests_touched = False
     if request.user.is_authenticated():
         users_online[request.user.id] = _now_ts
         users_touched = True
         user_id = request.user.id
     else:
         guest_sid = request.COOKIES.get(settings.SESSION_COOKIE_NAME)
         if guest_sid:
             guests_online[guest_sid] = _now_ts
             guests_touched = True
         user_id = None
     for uid in users_online.keys():
         try:
             is_stale_key = users_online[uid] < delta
         except TypeError:
             is_stale_key = True
         if is_stale_key:
             users_touched = True
             del users_online[uid]
     if users_touched:
         cache.set('users_online', users_online, 60 * 60 * 24)
     for gid in guests_online.keys():
         try:
             is_stale_key = guests_online[gid] < delta
         except TypeError:
             is_stale_key = True
         if is_stale_key:
             guests_touched = True
             del guests_online[gid]
     if guests_touched:
         cache.set('guests_online', guests_online, 60 * 60 * 24)
     address = remote_addr(request)
     agent = request.META.get('HTTP_USER_AGENT')
     request.activity = update_activity.delay(
         user_id,
         address,
         agent,
         _now_dt,
     )
コード例 #18
0
ファイル: middleware.py プロジェクト: ambv/kitdjango
 def process_request(self, request):
     _now_dt = now()
     _now_ts = int(time())
     delta = _now_ts - CURRENTLY_ONLINE_INTERVAL
     users_online = cache.get('users_online', {})
     guests_online = cache.get('guests_online', {})
     users_touched = False
     guests_touched = False
     if request.user.is_authenticated():
         users_online[request.user.id] = _now_ts
         users_touched = True
         user_id = request.user.id
     else:
         guest_sid = request.COOKIES.get(settings.SESSION_COOKIE_NAME)
         if guest_sid:
             guests_online[guest_sid] = _now_ts
             guests_touched = True
         user_id = None
     for uid in users_online.keys():
         try:
             is_stale_key = users_online[uid] < delta
         except TypeError:
             is_stale_key = True
         if is_stale_key:
             users_touched = True
             del users_online[uid]
     if users_touched:
         cache.set('users_online', users_online, 60 * 60 * 24)
     for gid in guests_online.keys():
         try:
             is_stale_key = guests_online[gid] < delta
         except TypeError:
             is_stale_key = True
         if is_stale_key:
             guests_touched = True
             del guests_online[gid]
     if guests_touched:
         cache.set('guests_online', guests_online, 60 * 60 * 24)
     address = remote_addr(request)
     agent = request.META.get('HTTP_USER_AGENT')
     request.activity = update_activity.delay(
         user_id, address, agent, _now_dt,
     )
コード例 #19
0
 def obj_create(self, bundle, **kwargs):
     remote_ip = remote_addr(bundle.request)
     logger.debug('Received JSON data (remote IP: %s): %s' % (
         remote_ip,
         bundle.data.get('data'),
     ))
     data = bundle.data.get('data', {})
     plugin_name = data.get('plugin')
     if not plugin_name:
         msg = "Improper data received (remote IP: %s)" % remote_ip
         logger.exception(msg)
         raise ValueError(msg)
     try:
         bundle.obj = store_device_data({
             plugin_name: data,
         })
     except Exception:
         logger.exception('An exception occurred (remote IP: %s): %s' % (
             remote_ip,
             traceback.format_exc(),
         ))
         raise
     return bundle
コード例 #20
0
def dhcp_synch(request):
    address = remote_addr(request)
    server = get_object_or_404(DHCPServer, ip=address)
    server.last_synchronized = datetime.datetime.now()
    server.save()
    return HttpResponse('OK', content_type='text/plain')