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})
exit(1) for device in devices : logging.info("... found devices %s." % device) if options.shutdown : if (device.shutdown == False) : logging.error("This device don't allow the shutdown.") else: if not options.message : message = 'Remote shutdown by %s.' % user else : message = options.message print("Shutdown device : %s" % device.name) try : if (device.platform == 'linux') : shutdown_nix(device.name, user, msg=message, timeout=timeout) else: shutdown_win(device.name, user, msg=message, timeout=timeout*60) except Exception as e: logging.error("Exception %s" % e) hf.save(device, 2, 1) else: hf.save(device, 2, 0, message) elif options.reboot : if (device.shutdown == False) : logging.error("This device don't allow the shutdown.") else: print("Reboot device : %s" % device.name) try : if (device.platform == 'linux') :