Beispiel #1
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})
Beispiel #2
0
                              timeout=timeout, reboot=True)
             else:
                 shutdown_win(device.name, user, msg=options.message,
                              timeout=timeout*60, reboot=True)
         except Exception as e:
             logging.error("Exception %s" % e)
             hf.save(device, 3, 1)
         else:
             hf.save(device, 3, 0, options.message)
 elif options.wol :
     if (device.wakeup == False) :
         logging.error("This device don't allow the wake up.")
     else:
         print("Booting with mac address : %s" % device.MAC)
         try:
             wake_on_lan(device.MAC)
         except Exception as e:
             logging.error("Exception %s" % e)
             hf.save(device, 1, 1)
         else:
             hf.save(device, 1, 0)
 elif options.history :
     record = History.objects.filter(device=device).latest('timestamp')
     print("%s %s @ %s -> %s " %
           (ACTION_TYPES_CHOICES[record.action][1], record.device.name,
            str(record.timestamp)[:19], RESULTS_CODE[record.result][1]))
 else:
     try:
         isUp = ping(device.name)
     except Exception as e:
         logging.error("Exception %s" % e)