def update(request): """provide a simple interface to allow Torrent Suite to be updated""" if request.method == "POST": updateLocked = run_update() data = json.dumps({"lockBlocked": updateLocked}) return http.HttpResponse(data, content_type="application/json") elif request.method == "GET": about, meta_version = findUpdates() config = GlobalConfig.objects.filter()[0] config_dict = model_to_dict(config) eula_content, isValid, errorMsg = get_EULA_text() try: # Disable Update Server button for some reason # Checking root partition for > 1GB free allow_update = (files.getSpaceKB("/") > 1048576 and files.getSpaceKB("/var") > 1048576) if not allow_update: GlobalConfig.objects.update( ts_update_status="Insufficient disk space") else: if config.ts_update_status in "Insufficient disk space": GlobalConfig.objects.update(ts_update_status="No updates") except Exception: allow_update = True return render_to_response( "admin/update.html", { "about": about, "meta": meta_version, "show_available": config.ts_update_status not in ["No updates", "Finished installing"], "eula_content": eula_content, "eula_error": errorMsg, "global_config_json": json.dumps(config_dict), "maintenance_mode": maintenance_action("check")["maintenance_mode"], "allow_update": allow_update, }, RequestContext(request, {}), )
def update(request): """provide a simple interface to allow Torrent Suite to be updated""" if request.method=="POST": updateLocked = run_update() data = json.dumps({"lockBlocked" : updateLocked }) return http.HttpResponse(data, content_type="application/json") elif request.method=="GET": about, meta_version = findUpdates() # don't use cached method here, update page needs current info config = GlobalConfig.objects.filter()[0] config_dict = model_to_dict(config) try: # Disable Update Server button for some reason # Checking root partition for > 1GB free allow_update = True if files.getSpaceKB("/") > 1048576 else False if not allow_update: GlobalConfig.objects.update(ts_update_status="Insufficient disk space") else: if config.ts_update_status in "Insufficient disk space": GlobalConfig.objects.update(ts_update_status="No updates") except: allow_update = True return render_to_response( "admin/update.html", {"about": about, "meta": meta_version, "show_available": config.ts_update_status not in ['No updates', 'Finished installing'], "global_config_json": json.dumps(config_dict), "allow_update": allow_update}, RequestContext(request, {}), )
def update(request): """provide a simple interface to allow Torrent Suite to be updated""" if request.method == "POST": updateLocked = run_update() data = json.dumps({"lockBlocked": updateLocked}) return http.HttpResponse(data, content_type="application/json") elif request.method == "GET": about, meta_version = findUpdates() config = GlobalConfig.get() from iondb.rundb.api import GlobalConfigResource resource = GlobalConfigResource() bundle = Bundle(config) serialized_config = resource.serialize(None, resource.full_dehydrate(bundle), "application/json") try: # Disable Update Server button for some reason # Checking root partition for > 1GB free allow_update = True if files.getSpaceKB("/") > 1048576 else False if not allow_update: GlobalConfig.objects.update( ts_update_status="Insufficient disk space") else: if GlobalConfig.objects.get( ).ts_update_status in "Insufficient disk space": GlobalConfig.objects.update(ts_update_status="No updates") except: allow_update = True return render_to_response( "admin/update.html", { "about": about, "meta": meta_version, "show_available": config.ts_update_status not in ['No updates', 'Finished installing'], "global_config_json": serialized_config, "allow_update": allow_update }, RequestContext(request, {}), )
def update(request): """provide a simple interface to allow Torrent Suite to be updated""" if request.method == "POST": updateLocked = run_update() data = json.dumps({"lockBlocked": updateLocked}) return http.HttpResponse(data, content_type="application/json") elif request.method == "GET": about, meta_version = findUpdates() config = GlobalConfig.objects.filter()[0] config_dict = model_to_dict(config) try: # Disable Update Server button for some reason # Checking root partition for > 1GB free allow_update = True if files.getSpaceKB("/") > 1048576 else False if not allow_update: GlobalConfig.objects.update( ts_update_status="Insufficient disk space") else: if config.ts_update_status in "Insufficient disk space": GlobalConfig.objects.update(ts_update_status="No updates") except: allow_update = True return render_to_response( "admin/update.html", { "about": about, "meta": meta_version, "show_available": config.ts_update_status not in ['No updates', 'Finished installing'], "legacy_OS": findOSversion().get('RELEASE') == '10.04', "global_config_json": json.dumps(config_dict), "maintenance_mode": maintenance_action("check")['maintenance_mode'], "allow_update": allow_update }, RequestContext(request, {}), )
def update(request): """provide a simple interface to allow Torrent Suite to be updated""" if request.method=="POST": updateLocked = run_update() data = json.dumps({"lockBlocked" : updateLocked }) return http.HttpResponse(data, content_type="application/json") elif request.method=="GET": about, meta_version = findUpdates() config = GlobalConfig.get() from iondb.rundb.api import GlobalConfigResource resource = GlobalConfigResource() bundle = Bundle(config) serialized_config = resource.serialize(None, resource.full_dehydrate(bundle), "application/json") try: # Disable Update Server button for some reason # Checking root partition for > 1GB free allow_update = True if files.getSpaceKB("/") > 1048576 else False if not allow_update: GlobalConfig.objects.update(ts_update_status="Insufficient disk space") else: if GlobalConfig.objects.get().ts_update_status in "Insufficient disk space": GlobalConfig.objects.update(ts_update_status="No updates") except: allow_update = True return render_to_response( "admin/update.html", {"about": about, "meta": meta_version, "show_available": config.ts_update_status not in ['No updates', 'Finished installing'], "global_config_json": serialized_config, "allow_update": allow_update}, RequestContext(request, {}), )
def check_disk_space(): """ For every FileServer object, get percentage of used disk space. Checks root partition for sufficient space. """ from iondb.rundb import models from iondb.utils import files import socket import traceback from django.core import mail def notify_diskfull(msg): '''sends an email with message''' #TODO make a utility function to send email try: recipient = models.User.objects.get(username='******').email logger.warning("dm_contact is %s." % recipient) except: logger.warning("Could not retrieve dm_contact. No email sent.") return False # Check for blank email # TODO: check for valid email address if recipient is None or recipient == "": logger.warning("No dm_contact email configured. No email sent.") return False #Needed to send email settings.EMAIL_HOST = 'localhost' settings.EMAIL_PORT = 25 settings.EMAIL_USE_TLS = False try: site_name = models.GlobalConfig.get().site_name except: site_name = "Torrent Server" hname = socket.getfqdn() subject_line = 'Torrent Server Data Management Disk Alert' reply_to = '*****@*****.**' message = 'From: %s (%s)\n' % (site_name, hname) message += '\n' message += msg message += "\n" # Send the email try: recipient = recipient.replace(',',' ').replace(';',' ').split() logger.debug(recipient) mail.send_mail(subject_line, message, reply_to, recipient) except: logger.warning(traceback.format_exc()) return False else: logger.info("Notification email sent for user acknowledgement") return True try: fileservers = models.FileServer.objects.all() except: logger.error(traceback.print_exc()) return for fs in fileservers: update_diskusage(fs) # TS-6669: Generate a Message Banner when disk usage gets critical crit_tag = "%s_disk_usage_critical" % (fs.name) warn_tag = "%s_disk_usage_warning" % (fs.name) golink = "<a href='%s' > Visit Services Tab </a>" % ('/configure/services/') if fs.percentfull > 99: msg = "* * * CRITICAL! %s: Partition is getting very full - %0.2f%% * * *" % (fs.filesPrefix,fs.percentfull) logger.debug(msg+" %s" % golink) message = models.Message.objects.filter(tags__contains=crit_tag) if not message: models.Message.error(msg+" %s" % golink,tags=crit_tag) notify_diskfull(msg) elif fs.percentfull > 95: msg = "%s: Partition is getting full - %0.2f%%" % (fs.filesPrefix,fs.percentfull) logger.debug(msg+" %s" % golink) message = models.Message.objects.filter(tags__contains=warn_tag) if not message: models.Message.error(msg+" %s" % golink,tags=warn_tag) notify_diskfull(msg) else: # Remove any message objects models.Message.objects.filter(tags__contains=crit_tag).delete() models.Message.objects.filter(tags__contains=warn_tag).delete() #======================================================================== # Check root partition #======================================================================== root_threshold = 1048576 # 1 GB in KB warn_tag = "root_partition_space_warning" try: root_free_space = files.getSpaceKB('/') if root_free_space < root_threshold: msg = "Root Partition is getting full - less than 1GB available" logger.warn(msg) message = models.Message.objects.filter(tags__contains=warn_tag) if not message: models.Message.warn(msg, tags=warn_tag) else: models.Message.objects.filter(tags__contains=warn_tag).delete() #logger.debug("Root partition is spacious enough with %0.2f" % (root_free_space)) except: logger.error(traceback.format_exc())