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