Exemplo n.º 1
0
def ping_all(request):
    '''
    Ping all devices
    '''

    devices = Device.objects.all().order_by('name')
    for dev in devices :
        hf = Karma()
        try:
          isUp=ping(dev.name)
        except Exception as e :
            hf.save(dev, 0, 1)
        else:
            hf.save(dev, 0, not isUp)
    return redirect(index)
Exemplo n.º 2
0
def device_ping(request, device_id):
    '''
    Ping and display a device
    '''

    error_message = None
    dev = get_object_or_404(Device, pk=device_id)
    hf = Karma()
    try:
      isUp=ping(dev.name)
    except Exception as e :
        error_message = e.__unicode__()
        hf.save(dev, 0, 1)
    else:
        hf.save(dev, 0, not isUp)
    return redirect(device, device_id)
Exemplo n.º 3
0
def device_shutdown(request, device_id):
    '''
    Shutdown a device
    '''
    error_message = None
    dev = get_object_or_404(Device, pk=device_id)
    if dev.shutdown == False :
        error_message = "This device don't allow the shutdown."
    else:
        hf = Karma()
        if 'reboot' in request.POST and request.POST['reboot'] == 'on'  :
            action = 3
            reboot = True
        else:
            action = 2
            reboot = False
        try:
            if request.POST['timeout'] :
                timeout = int(request.POST['timeout'])
            else :
                timeout = 5
            if request.POST['password'] :
                password = request.POST['password']
            else :
                password = ''

            if dev.platform == "linux" :
                shutdown_nix(dev.name, request.POST['user'], password,
                             msg=request.POST['message'], reboot=reboot, timeout=timeout)
            else:
                shutdown_win(dev.name, request.POST['user'], password,
                             msg=request.POST['message'], reboot=reboot, timeout=timeout*60)
        except Exception as e:
            error_message = e.__unicode__()
            hf.save(dev, action, 1)
        finally:
            hf.save(dev, action, 0, request.POST['message'])
            t = Timer(180.0, device_ping, (request, device_id))
            t.start()
    last = History.objects.filter(device=device_id).latest()
    return render_to_response('bodhi/refresh.html',
                                {'device': dev,
                                'latest' : last,
                                'error_message' : error_message})
Exemplo n.º 4
0
def device_wol(request, device_id):
    '''
    Wake up a device
    '''
    error_message = None
    dev = get_object_or_404(Device, pk=device_id)
    if dev.wakeup == False :
        error_message = "This device don't allow wakeups."
    else:
        hf = Karma()
        try:
            wake_on_lan(dev.MAC)
        except Exception as e:
            error_message = e.__unicode__()
            hf.save(dev, 1, 1)
        finally:
            hf.save(dev, 1, 0)
            t = Timer(180.0, device_ping, (request, device_id))
            t.start()
    last = History.objects.filter(device=device_id).latest()
    return render_to_response('bodhi/refresh.html',
                                {'device': dev,
                                'latest' : last,
                                'error_message' : error_message})
Exemplo n.º 5
0
else :
    user = getpass.getuser()

######################################################################
## Logging & History
######################################################################

if options.verbose :
    log_level=logging.DEBUG
else:
    log_level=logging.WARNING
logging.basicConfig(format='%(levelname)s-%(asctime)s-%(message)s',
            level=log_level,
            datefmt='%H:%M:%S')

hf = Karma(user=user)

######################################################################
## Main
######################################################################

logging.info("Searching devices %s*..." % args[0])
devices = Device.objects.filter(name__istartswith=string.upper(args[0]))

if len(devices) == 0 :
    logging.error("Device not found.")
    exit(1)

for device in devices :
    logging.info("... found devices %s." % device)
    if options.shutdown :