Ray Milkey | a2b52b4 | 2019-02-07 09:25:27 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
Ray Milkey | b2e6be8 | 2019-03-06 14:58:42 -0800 | [diff] [blame^] | 3 | import subprocess |
| 4 | import sys |
| 5 | import json |
| 6 | import os |
Ray Milkey | a2b52b4 | 2019-02-07 09:25:27 -0800 | [diff] [blame] | 7 | |
| 8 | REQUIRED_APPS = ["org.onosproject.drivers"] |
| 9 | |
| 10 | |
| 11 | def _main(): |
| 12 | # Get the ONOS node address |
Ray Milkey | a2b52b4 | 2019-02-07 09:25:27 -0800 | [diff] [blame] | 13 | if len(sys.argv) > 1: |
| 14 | onos_node = sys.argv[1] |
| 15 | else: |
| 16 | onos_node = os.environ["OCI"] |
| 17 | |
| 18 | # Get a JSON representation of the apps that are currently running |
| 19 | current_apps_json = subprocess.check_output(["onos", onos_node, "onos:apps", "-a", "-s", "-j"]) |
| 20 | |
| 21 | # Determine which apps need to be deactivated |
| 22 | apps_to_deactivate = [] |
| 23 | config = json.loads(current_apps_json) |
| 24 | |
| 25 | for app_description in config: |
Ray Milkey | b2e6be8 | 2019-03-06 14:58:42 -0800 | [diff] [blame^] | 26 | app_name = app_description["name"] |
| 27 | if app_name not in REQUIRED_APPS: |
| 28 | apps_to_deactivate.append(app_name) |
Ray Milkey | a2b52b4 | 2019-02-07 09:25:27 -0800 | [diff] [blame] | 29 | |
| 30 | # Deactivate all apps |
| 31 | if len(apps_to_deactivate) > 0: |
| 32 | deactivate_command = ["onos", onos_node, "onos:app", "deactivate"] |
| 33 | for app_to_deactivate in apps_to_deactivate: |
Ray Milkey | b2e6be8 | 2019-03-06 14:58:42 -0800 | [diff] [blame^] | 34 | |
| 35 | deactivate_command.append(app_to_deactivate) |
Ray Milkey | a2b52b4 | 2019-02-07 09:25:27 -0800 | [diff] [blame] | 36 | subprocess.check_output(deactivate_command) |
| 37 | |
Ray Milkey | a2b52b4 | 2019-02-07 09:25:27 -0800 | [diff] [blame] | 38 | |
| 39 | if __name__ == "__main__": |
| 40 | _main() |