diff options
author | CruiseDevice | 2018-10-31 19:33:15 +0530 |
---|---|---|
committer | CruiseDevice | 2018-10-31 19:33:15 +0530 |
commit | 0bb3e3efd22a5a0f48c88720f6142bc3f49bc349 (patch) | |
tree | 72392968460ca64ffe5082e57ff670d594ddf15e /sbhs/management/commands | |
parent | be12eb39711d62b72b7d6fd125a5da47ae603a98 (diff) | |
download | sbhs_server-0bb3e3efd22a5a0f48c88720f6142bc3f49bc349.tar.gz sbhs_server-0bb3e3efd22a5a0f48c88720f6142bc3f49bc349.tar.bz2 sbhs_server-0bb3e3efd22a5a0f48c88720f6142bc3f49bc349.zip |
Change RASP_PI_IPS to SBHS_API_IPS in settings.py
- Change RASP_PI_IPS to SBHS_API_IPS in settings.py
- Host machine now has to be added in SBHS_API_IPS to be detected.
- Add login_required decorator over experiment view function.
Diffstat (limited to 'sbhs/management/commands')
-rw-r--r-- | sbhs/management/commands/update_boards.py | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/sbhs/management/commands/update_boards.py b/sbhs/management/commands/update_boards.py index 238646c..849f020 100644 --- a/sbhs/management/commands/update_boards.py +++ b/sbhs/management/commands/update_boards.py @@ -9,6 +9,7 @@ from django.core.management.base import BaseCommand, CommandError from django.contrib.auth.models import User, Group, Permission # local imports +from django.conf import settings from sbhs.models import Board from sbhs.views import map_sbhs_to_rpi @@ -16,23 +17,26 @@ from sbhs.views import map_sbhs_to_rpi class Command(BaseCommand): help = 'Ping all boards and update status of boards' - def add_arguments(self, parser): - # Positional arguments - parser.add_argument('host_ip', type=str) - def handle(self, *args, **options): app_label = 'sbhs' - try: - board_check, dead_servers = map_sbhs_to_rpi(options["host_ip"]) - board = Board() - all_mac_ids = [] - for machines in board_check: - all_mac_ids.extend(machines["mac_ids"]) - board.switch_off_inactive_boards(all_mac_ids) - self.stdout.write('Updated Board Status') - if dead_servers: - self.stdout.write('Servers {0} are not responding.'\ - .format(", ".join(dead_servers)) - ) - except Exception as e: - self.stdout.write('Failed updating Board because {0}'.format(e))
\ No newline at end of file + if settings.SBHS_API_IPS: + try: + board_check, dead_servers = map_sbhs_to_rpi() + board = Board() + all_mac_ids = [] + for machines in board_check: + all_mac_ids.extend(machines["mac_ids"]) + board.switch_off_inactive_boards(all_mac_ids) + self.stdout.write('Updated Board Status') + if dead_servers: + self.stdout.write('Servers {0} are not responding.'\ + .format(", ".join(dead_servers)) + ) + except Exception as e: + self.stdout.write('Failed updating Board because {0}'\ + .format(e) + ) + else: + self.stdout.write('No API IP added in settings.py. ' + " Please try with adding IPs in the SBHS_API_IPS variable " + ) |