|
1 | | -#! /usr/bin/env python3 |
2 | | - |
3 | | -""" |
4 | | -ONTAP REST API Python Client Library Sample Scripts |
5 | | -This script was developed by NetApp to help demonstrate NetApp |
6 | | -technologies. This script is not officially supported as a |
7 | | -standard NetApp product. |
8 | | -
|
9 | | -Purpose: Script to use CLI commands using ONTAP REST API Python Client Library. |
10 | | -
|
11 | | -usage: python3 system_node_power_update.py [-h] -c CLUSTER -vs SVM_NAME [-u API_USER] |
12 | | - [-p API_PASS] |
13 | | -
|
14 | | -Copyright (c) 2020 NetApp, Inc. All Rights Reserved. |
15 | | -Licensed under the BSD 3-Clause "New" or "Revised" License (the "License"); |
16 | | -you may not use this file except in compliance with the License. |
17 | | -You may obtain a copy of the License at |
18 | | -https://opensource.org/licenses/BSD-3-Clause |
19 | | -
|
20 | | -""" |
21 | | - |
22 | | -import json |
23 | | -import time |
24 | | -from netapp_ontap.resources import CLI |
25 | | -from utils import Argument, parse_args, setup_logging, setup_connection |
26 | | - |
27 | | - |
28 | | -def system_node_power_on() -> None: |
29 | | - """ system node power on module""" |
30 | | - node_name = input("\n Enter the node name: ") |
31 | | - response = CLI().execute( |
32 | | - "system node power on", |
33 | | - body={ |
34 | | - "node": node_name}, |
35 | | - privilege_level="diagnostic") |
36 | | - time.sleep(15) |
37 | | - response = CLI().execute( |
38 | | - "system node power show", status="on") |
39 | | - print(json.dumps(response.http_response.json(), indent=4)) |
40 | | - |
41 | | - |
42 | | -def system_node_power_off() -> None: |
43 | | - """ System node power off module """ |
44 | | - node = input("\n Enter the node name: ") |
45 | | - response = CLI().execute( |
46 | | - "system node power off", body={ |
47 | | - "node": node}, privilege_level="diagnostic") |
48 | | - time.sleep(5) |
49 | | - response = CLI().execute( |
50 | | - "system node power show", status="off") |
51 | | - print(json.dumps(response.http_response.json(), indent=4)) |
52 | | - |
53 | | - |
54 | | -def check_system_power() -> None: |
55 | | - """Module to retrieve user input for system node power""" |
56 | | - print("\n===============================================================") |
57 | | - print("This Module covers System node power CLI command usage in PCL") |
58 | | - print("===============================================================") |
59 | | - print("\n 1. CLI Command >> system node power on") |
60 | | - print("\n 2. CLI Command >> system node power off") |
61 | | - option = input("\n\nEnter the option: ") |
62 | | - if option == '1': |
63 | | - system_node_power_on() |
64 | | - if option == '2': |
65 | | - system_node_power_off() |
66 | | - |
67 | | - |
68 | | -def main() -> None: |
69 | | - """Main function""" |
70 | | - arguments = [ |
71 | | - Argument("-c", "--cluster", "API server IP:port details")] |
72 | | - args = parse_args( |
73 | | - "This script will update system power status ON/OFF", arguments) |
74 | | - setup_logging() |
75 | | - setup_connection(args.cluster, args.api_user, args.api_pass) |
76 | | - check_system_power() |
77 | | - |
78 | | - |
79 | | -if __name__ == "__main__": |
80 | | - main() |
| 1 | +#! /usr/bin/env python3 |
| 2 | + |
| 3 | +""" |
| 4 | +ONTAP REST API Python Client Library Sample Scripts |
| 5 | +This script was developed by NetApp to help demonstrate NetApp |
| 6 | +technologies. This script is not officially supported as a |
| 7 | +standard NetApp product. |
| 8 | +
|
| 9 | +Purpose: Script to use CLI commands using ONTAP REST API Python Client Library. |
| 10 | +
|
| 11 | +usage: python3 system_node_power_update_cli.py [-h] -c CLUSTER -vs SVM_NAME [-u API_USER] |
| 12 | + [-p API_PASS] |
| 13 | +
|
| 14 | +Copyright (c) 2020 NetApp, Inc. All Rights Reserved. |
| 15 | +Licensed under the BSD 3-Clause "New" or "Revised" License (the "License"); |
| 16 | +you may not use this file except in compliance with the License. |
| 17 | +You may obtain a copy of the License at |
| 18 | +https://opensource.org/licenses/BSD-3-Clause |
| 19 | +
|
| 20 | +""" |
| 21 | + |
| 22 | +import json |
| 23 | +import time |
| 24 | +from netapp_ontap.resources import CLI |
| 25 | +from utils import Argument, parse_args, setup_logging, setup_connection |
| 26 | + |
| 27 | + |
| 28 | +def system_node_power_on() -> None: |
| 29 | + """ system node power on module""" |
| 30 | + node_name = input("\n Enter the node name: ") |
| 31 | + response = CLI().execute( |
| 32 | + "system node power on", |
| 33 | + body={ |
| 34 | + "node": node_name}, |
| 35 | + privilege_level="diagnostic") |
| 36 | + time.sleep(15) |
| 37 | + response = CLI().execute( |
| 38 | + "system node power show", status="on") |
| 39 | + print(json.dumps(response.http_response.json(), indent=4)) |
| 40 | + |
| 41 | + |
| 42 | +def system_node_power_off() -> None: |
| 43 | + """ System node power off module """ |
| 44 | + node = input("\n Enter the node name: ") |
| 45 | + response = CLI().execute( |
| 46 | + "system node power off", body={ |
| 47 | + "node": node}, privilege_level="diagnostic") |
| 48 | + time.sleep(5) |
| 49 | + response = CLI().execute( |
| 50 | + "system node power show", status="off") |
| 51 | + print(json.dumps(response.http_response.json(), indent=4)) |
| 52 | + |
| 53 | + |
| 54 | +def check_system_power() -> None: |
| 55 | + """Module to retrieve user input for system node power""" |
| 56 | + print("\n===============================================================") |
| 57 | + print("This Module covers System node power CLI command usage in PCL") |
| 58 | + print("===============================================================") |
| 59 | + print("\n 1. CLI Command >> system node power on") |
| 60 | + print("\n 2. CLI Command >> system node power off") |
| 61 | + option = input("\n\nEnter the option: ") |
| 62 | + if option == '1': |
| 63 | + system_node_power_on() |
| 64 | + if option == '2': |
| 65 | + system_node_power_off() |
| 66 | + |
| 67 | + |
| 68 | +def main() -> None: |
| 69 | + """Main function""" |
| 70 | + arguments = [ |
| 71 | + Argument("-c", "--cluster", "API server IP:port details")] |
| 72 | + args = parse_args( |
| 73 | + "This script will update system power status ON/OFF", arguments) |
| 74 | + setup_logging() |
| 75 | + setup_connection(args.cluster, args.api_user, args.api_pass) |
| 76 | + check_system_power() |
| 77 | + |
| 78 | + |
| 79 | +if __name__ == "__main__": |
| 80 | + main() |
0 commit comments