summaryrefslogtreecommitdiff
path: root/sbhs_server/tables/management/commands/initialize_machines.py
diff options
context:
space:
mode:
authorttt2017-05-13 00:29:47 +0530
committerttt2017-05-13 00:29:47 +0530
commit4336f5f06f61de30ae3fa54650fce63a9d5ef5be (patch)
tree23b4ee9b8e8f24bf732acf2f7ad22ed50cdd5670 /sbhs_server/tables/management/commands/initialize_machines.py
downloadSBHS-2018-Rpi-4336f5f06f61de30ae3fa54650fce63a9d5ef5be.tar.gz
SBHS-2018-Rpi-4336f5f06f61de30ae3fa54650fce63a9d5ef5be.tar.bz2
SBHS-2018-Rpi-4336f5f06f61de30ae3fa54650fce63a9d5ef5be.zip
added all server files
Diffstat (limited to 'sbhs_server/tables/management/commands/initialize_machines.py')
-rw-r--r--sbhs_server/tables/management/commands/initialize_machines.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/sbhs_server/tables/management/commands/initialize_machines.py b/sbhs_server/tables/management/commands/initialize_machines.py
new file mode 100644
index 0000000..1987a27
--- /dev/null
+++ b/sbhs_server/tables/management/commands/initialize_machines.py
@@ -0,0 +1,45 @@
+from django.core.management.base import BaseCommand, CommandError
+from sbhs_server import settings
+from sbhs_server.tables.models import Board
+from sbhs_server import helpers
+
+class Command(BaseCommand):
+ args = ''
+ help = 'Initializes the SBHS board data in the database'
+
+ def handle(self, *args, **options):
+ previous_onlines = Board.objects.only("mid").filter(online=True)
+ previous_onlines = [p.mid for p in previous_onlines]
+ for o in settings.online_mids:
+ try:
+ Board.objects.get_or_create(mid=o)
+ except:
+ pass
+
+ new_offlines = []
+ for p in previous_onlines:
+ if p not in settings.online_mids:
+ new_offlines.append(p)
+
+ message = "SBHS Administrator,\n\n"
+ message += "Following issue requires immidiate attention.\n\n"
+ message += "SBHS could not be connected\n"
+ for n in new_offlines:
+ message += ("MID: %d\n" % n)
+ message += "\nYou can check the SBHS status on http://vlabs.iitb.ac.in/sbhs/admin/."
+ message += " Possible correction actions are:\n"
+ message += "1. Run this command without brackets -> ( cd $SBHS_SERVER_ROOT; ./cron_job.sh )\n"
+ message += "2. If same machine comes offline multiple times, replacement of the machine is advised.\n\n\n"
+ message += "Regards,\nSBHS Vlabs Server Code"
+
+ print "New offline board mids", new_offlines
+ subject = "SBHS Vlabs: Notice - SBHS not connected"
+
+ if len(new_offlines) > 0:
+ for admin in settings.SBHS_ADMINS:
+ helpers.mailer.email(admin[2], subject, message)
+
+ Board.objects.filter(mid__in=settings.online_mids).update(online=True)
+ Board.objects.exclude(mid__in=settings.online_mids).update(online=False)
+
+ self.stdout.write('Boards loaded')