Skip to content

Commit 175baf8

Browse files
committed
Switch to arg or GUI driven tasks. Removed menu.
Closes issues #29, #26, #23, #14, #5, and #4. Closes PR #32 Squashed commit of the following: commit b4df6d7 Author: Todd Butters <todd@ctera.com> Date: Sun Oct 17 00:22:59 2021 -0400 Pass 99% of pylint and flake8 checks. Add configs. commit ab16230 Author: Todd Butters <todd@ctera.com> Date: Wed Oct 13 10:29:23 2021 -0400 Import cterasdk config for setting SSL trust. commit 8a399ed Author: Todd Butters <todd@ctera.com> Date: Fri Oct 8 10:48:53 2021 -0400 Fixed pylint issues and made requested changes. And other general cleanup or minor refactors of functions. commit 3094163 Author: Todd Butters <todd@ctera.com> Date: Wed Oct 6 01:04:54 2021 -0400 Handle invalid certs. Refactor login module. Resolve #29. ctools.py -- add optional ignore_cert flag to portal parser login.py -- refactored. Added exception handler, device_sso check, disable ssl warnings if ignore_cert flag is passed run_cmd.py -- phrasing unlock.py -- removed exit that caused an apparent crash in GUI README.md -- updated LICENSE.md -- added commit 953e08e Author: Todd Butters <todd@ctera.com> Date: Fri Oct 1 17:30:12 2021 -0400 Fixed another GUI error in enable_telnet task. commit 4c780c7 Author: Todd Butters <todd@ctera.com> Date: Fri Oct 1 17:18:13 2021 -0400 Fix error in GUI run_cmd task. Bump minor version. commit 1986f4d Author: Todd Butters <todd@ctera.com> Date: Fri Oct 1 16:58:00 2021 -0400 Run_cmd per device, tenant, or global. run_cmd.py -- Add granularity to target one or more filers. ctools.py -- Add new run_cmd args. Add logout and exit log msg. filer.py -- Remove input() calls as they're no longer used. By default, it will now run the command on all Filers of the current tenant. Added optional -all flag to allow running against all Filers globally as it worked before or --device flag if provided it will only run on that filer. commit b30db2e Author: Todd Butters <todd@ctera.com> Date: Tue Sep 28 10:44:56 2021 -0400 Add task to reset a local Filer user's password. Requires Filer is connected to portal like all our tasks currently. Also increased the size of the GUI so no scrolling is required and tweaked our program description. commit 3831bcc Author: Todd Butters <todd@ctera.com> Date: Fri Sep 24 16:15:11 2021 -0400 Added About and Help menu. commit 27c0705 Author: Todd Butters <todd@ctera.com> Date: Thu Sep 23 23:51:49 2021 -0400 Added screenshot to README from new images folder. commit 4ad2c51 Author: Todd Butters <todd@ctera.com> Date: Thu Sep 23 17:45:27 2021 -0400 Updated setup instructions. commit a0796cd Author: Todd Butters <todd@ctera.com> Date: Thu Sep 23 16:49:23 2021 -0400 Added AD domain join status to Filer status report. Created a function, get_ad_status() that stores the result of status.fileservices.cifs.joinStatus and parses the result. If it's -1, it's on a workgroup. If 0, return Ok. Else, return Failed. commit 6804fb2 Author: Todd Butters <todd@ctera.com> Date: Thu Sep 23 02:04:57 2021 -0400 Get Filer status per tenant or globally. Updated docstring in ctools.py, added optional --all flag which will run the previoiusly default function of getting all connected filers to a portal globally which is slow for large deployments. Commented out the function to browse the admin portal. By doing the above, we will now default to browsing the tenant based on the current session and only browse to Administration if the --all flag is set which sets all_tenants to True in filer.py. In filer.py, I added tenant name column and checking if the output file already exists, if it does, we skip writing the header and just append to the file. I also added try statements to some values that were throwing exceptions on a 6.0.247 filer. commit efd4c6e Author: Todd Butters <todd@ctera.com> Date: Wed Sep 22 17:20:15 2021 -0400 Check if admin has allowSSO to manage devices. For #26, this adds a check and logs a warning if the admin signing in does not have 'Allow Single Sign on to Devices' checked for the Read Write Admin role in the Administration tenant. commit 8871f1b Author: Todd Butters <todd@ctera.com> Date: Mon Sep 20 07:09:01 2021 -0400 Added enable_telnet support in Gooey GUI. Renamed unlock function to enable_telnet. Changed logic from interactive to parameter based since Gooey cannot finish if a function calls input(). commit 794d4dc Author: toddatctera <todd@ctera.com> Date: Mon May 24 23:54:38 2021 -0400 Updated requirements, Windows setup, and easy CLI. Added setup steps for Windows using PowerShell. Updated requirements to include Gooey for the GUI. Added easy CLI mode based on below comment chriskiehl/Gooey#449 (comment) commit 8bb39f3 Author: toddatctera <todd@ctera.com> Date: Wed May 12 17:58:24 2021 -0400 Added parent parsers and verbose toggle. Added portal_parent_parser since each task so far requires logging into the portal. This allows us to re-use the parent parser in a all sub-parsers which are the tasks. Stolen from here: https://stackoverflow.com/questions/33645859/how-to-add-common-arguments-to-argparse-subcommands Also got the -v/--verbose flag working in CLI (--ignore-gooey) mode in GUI mode. In not specified or left unchecked, uses INFO level. TODO: - Add enable_telnet to tasks again - Cleanup and document everything well - Test, test, test - Think about code review and merging. commit bfccba4 Author: toddatctera <todd@ctera.com> Date: Fri May 7 16:12:49 2021 -0400 Functional GUI using Gooey and argparse. Tasks now show up in the side bar and don't have to be selected twice. Logs look good. Can also be run from the CLI with the flag `--ignore-gooey` and it works! Example: python ctools.py --ignore-gooey run_cmd 'dbg level debug' portal.example.com admin p@ssw0rd TODO: - Add docstrings for Gooey code - Add the remaining tasks like enable ssh commit c24314e Author: toddatctera <todd@ctera.com> Date: Fri May 7 03:29:08 2021 -0400 Added run_cmd to Gooey Technically this works but I have to select the task twice because of how I previously was calling functions with the FUNCTION_MAP. So still a WIP but still an improvement for #23 commit bf0c568 Author: toddatctera <todd@ctera.com> Date: Fri May 7 01:42:28 2021 -0400 Added subparser and get_status filename with Gooey. Added a subparser to lay groundwork for each task having its own page with required arguments like filename for get_status. commit ed5d258 Author: Todd Butters <todd@ctera.com> Date: Thu Apr 22 17:50:28 2021 -0400 Initial Gooey POC WIP for #23. Only works with get status function and only after hardcoding the output filename. commit 7696bd7 Author: Todd Butters <47750691+toddatctera@users.noreply.github.com> Date: Thu Apr 22 00:19:09 2021 -0400 Added disable_ssh and Portal creds as arguments.
1 parent d5c3f56 commit 175baf8

17 files changed

+1331
-343
lines changed

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length=140

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
*.csv
22
*.log
33
*.swp
4+
*-log.txt
5+
ctools.spec
6+
pyvenv.cfg
47
__pycache__
5-
8+
build/
9+
dist/
10+
Lib/
11+
Scripts/

.pylintrc

Lines changed: 583 additions & 0 deletions
Large diffs are not rendered by default.

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2021, CTERA Networks
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

README.md

Lines changed: 236 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,254 @@
11
# ctools
22

3-
## Purpose
3+
## Description
44

5-
A tool to check the status of all CTERA filers and more coming soon.
5+
A toolbox of tasks to check and manage CTERA Edge Filers via CLI or GUI.
66

77
## Development Requirements
88

9-
- [Python 3.5+](https://www.python.org/)
10-
- [git](https://git-scm.com/)
11-
- [pip](https://pip.pypa.io/en/stable/user_guide/)
129
- [CTERA Environment](https://www.ctera.com/)
10+
- [CTERA SDK for Python](https://github.com/ctera/ctera-python-sdk)
11+
- [Python](https://www.python.org/downloads/)
12+
- [git](https://git-scm.com/)
13+
- [Gooey](https://github.com/chriskiehl/Gooey)
1314

1415
## Setup
1516

17+
### Linux
18+
19+
General instructions. Actual commands will vary by distro and version.
20+
```
21+
git clone https://github.com/ctera/ctools.git
22+
python -m pip install -r ctools/requirements.txt
23+
```
24+
25+
### Windows
26+
27+
For a machine without Python and git already installed, you can use these steps to simplify setup.
28+
Here we use [Chocolatey](https://chocolatey.org/) as a commmand line package manager for Windows.
29+
Run PowerShell as an Administrator to setup. Close and re-open PowerShell
30+
after to refresh the environment and enable tab completion of commands.
31+
1632
```
33+
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
34+
choco install python --yes
35+
choco install git --yes
36+
# Close and re-open your shell
1737
git clone https://github.com/ctera/ctools.git
18-
python3 -m pip install -r ctools/requirements.txt
38+
python -m pip install --upgrade pip
39+
python -m pip install -r .\ctools\requirements.txt
40+
cd ctools
1941
```
2042

2143
## Run
2244

2345
```
24-
python3 ctools.py
25-
```
26-
27-
## Example
28-
29-
```
30-
[user@localhost ctools]$ ./ctools.py
31-
2021-01-22 12:27:51,898 INFO [ctools.py:10] [<module>] - Starting ctools
32-
33-
#################
34-
ctools menu
35-
v 1.5.1
36-
#################
37-
38-
Available tasks:
39-
40-
0. Quit
41-
1. Record status details of all connected Edge Filers.
42-
2. Enable telnet on one or more connected Edge Filers.
43-
3. Run a specified command on all connected Edge Filers.
44-
45-
Enter a task number to run: 3
46-
2021-01-22 12:27:53,246 INFO [run_cmd.py:12] [run_cmd] - Starting run_cmd task
47-
Portal (IP, Hostname or FQDN): portal.example.com
48-
Admin Username: admin
49-
Admin Password: password
50-
2021-01-22 12:27:55,279 INFO [login.py:18] [login] - Logging into portal.example.com
51-
2021-01-22 12:27:55,347 INFO [login.py:19] [login] - User logged in. {'host': 'portal.example.com', 'user': 'admin'}
52-
2021-01-22 12:27:55,360 INFO [login.py:21] [login] - Successfully logged in to portal.example.com
53-
Enter command to run: dbg level backup
54-
You enetered: dbg level backup
55-
### Start command on: todd-vGateway
56-
2021-01-22 12:28:00,655 INFO [cli.py:16] [run_command] - Executing CLI command. {'cli_command': 'dbg level backup'}
57-
2021-01-22 12:28:00,782 INFO [cli.py:20] [run_command] - CLI command executed. {'cli_command': 'dbg level backup'}
58-
Response:
59-
Setting debug level to 0x00000800
60-
### End command on: todd-vGateway
61-
### Start command on: vGateway-5439
62-
2021-01-22 12:28:00,782 INFO [cli.py:16] [run_command] - Executing CLI command. {'cli_command': 'dbg level backup'}
63-
2021-01-22 12:28:00,911 INFO [cli.py:20] [run_command] - CLI command executed. {'cli_command': 'dbg level backup'}
64-
Response:
65-
Setting debug level to 0x00000800
66-
### End command on: vGateway-5439
67-
2021-01-22 12:28:00,911 INFO [run_cmd.py:26] [run_cmd] - Finished run_cmd task
68-
Finished task. Returning to menu.
69-
70-
#################
71-
ctools menu
72-
v 1.5.1
73-
#################
74-
75-
Available tasks:
76-
77-
0. Quit
78-
1. Record status details of all connected Edge Filers.
79-
2. Enable telnet on one or more connected Edge Filers.
80-
3. Run a specified command on all connected Edge Filers.
81-
82-
Enter a task number to run: 0
83-
[user@localhost] ctools]$
46+
# To launch the GUI, invoke ctools.py
47+
python ctools.py
48+
# To use on CLI, pass valid arguments to ctools.py
49+
python ctools.py -h
50+
```
51+
52+
## Instructions
53+
54+
### Task Usage
55+
56+
The first required argument is the task to run.
57+
Each task has its own positional arguments, usually login info then any arguments required to complete the task.
58+
59+
**Use a Portal Global Administrator account to login.**
60+
There is currently no support for tenant admins or direct logins to Filers. All requests are sent through the Portal to connected Filers.
61+
62+
Specify the task and run to see that task's required and optional arguments.
63+
Any task can be run with `-h` or `--help` to see usage instructions.
64+
Any task can be run with the optional flag `-v` or `--verbose` to enable debug logging.
65+
66+
```
67+
Manage CTERA Edge Filers
68+
69+
positional arguments:
70+
{get_status,run_cmd,enable_telnet,enable_ssh,disable_ssh,suspend_sync,unsuspend_sync}
71+
Task choices.
72+
get_status Record current status of all connected Filers. Use --all to browse all Tenants
73+
run_cmd Run a comand on each connected Filer.
74+
enable_telnet Enable SSH on a Filer.
75+
enable_ssh Enable SSH on a Filer.
76+
disable_ssh Disable SSH on a Filer.
77+
suspend_sync Suspend sync on a given Filer
78+
unsuspend_sync Unsuspend sync on a given Filer
79+
```
80+
81+
#### get_status
82+
83+
Record current status of connected Filers to a specified CSV output file.
84+
Provide a portal URL, e.g. portal.ctera.me, to scan all connected Filers to that tenant and write various bits of
85+
information to a specified CSV file.
86+
If an IP address is provided, the Default Tenant Portal will be used.
87+
Or you can use/check the `-a, --all` flag to scan all connected Filers across all Tenant Portals.
88+
If the output filename already exists, the results will be appended to the existing file.
89+
90+
```
91+
positional arguments:
92+
address Portal IP, hostname, or FQDN
93+
username Username for portal administrator
94+
password Password. Enter ? to prompt in CLI
95+
filename output filename
96+
97+
optional arguments:
98+
-h, --help show this help message and exit
99+
-v, --verbose Add verbose logging
100+
-a, --all All Filers, All Tenants
101+
```
102+
#### run_cmd
103+
104+
Run a "hidden CLI command", i.e. execute a RESTful API request to each connected Filer.
105+
106+
```
107+
usage: ctools.py run_cmd [-h] [-v] [-i] [-a] [-d DEVICE] address username password command
108+
109+
positional arguments:
110+
address Portal IP, hostname, or FQDN
111+
username Username for portal administrator
112+
password Password. Enter ? to prompt in CLI
113+
command Run a comand on one or more connected Filers.
114+
115+
optional arguments:
116+
-h, --help show this help message and exit
117+
-v, --verbose Add verbose logging
118+
-i, --ignore_cert Ignore cert warnings
119+
-a, --all Run a command globally, on all Filers, on all Tenants.
120+
-d DEVICE, --device DEVICE
121+
Device name to run command against. Overrides --all flag.
122+
```
123+
#### enable_telnet
124+
125+
Enable the telnet service on a given Filer. If no unlock code is provided, return the required MAC address
126+
and firmware version to get an unlock code from CTERA Support.
127+
128+
```
129+
usage: ctools.py enable_telnet [-h] [-v] [-i] [-c CODE] address username password device_name tenant_name
130+
131+
positional arguments:
132+
address Portal IP, hostname, or FQDN
133+
username Username for portal administrator
134+
password Password. Enter ? to prompt in CLI
135+
device_name Device Name
136+
tenant_name Tenant Name
137+
138+
optional arguments:
139+
-h, --help show this help message and exit
140+
-v, --verbose Add verbose logging
141+
-i, --ignore_cert Ignore cert warnings
142+
-c CODE, --code CODE Required code to enable telnet
143+
```
144+
145+
#### enable_ssh
146+
147+
Enable the ssh service on a given Filer and add the public key to the authorized_keys of the Filer.
148+
If no public key is provided, a new keypair will generated and saved to the Downloads folder.
149+
150+
```
151+
usage: ctools.py enable_ssh [-h] [-v] [-i] [-p PUBKEY] address username password device_name tenant_name
152+
153+
positional arguments:
154+
address Portal IP, hostname, or FQDN
155+
username Username for portal administrator
156+
password Password. Enter ? to prompt in CLI
157+
device_name Device Name
158+
tenant_name Tenant Name
159+
160+
optional arguments:
161+
-h, --help show this help message and exit
162+
-v, --verbose Add verbose logging
163+
-i, --ignore_cert Ignore cert warnings
164+
-p PUBKEY, --pubkey PUBKEY
165+
Provide an SSH Public Key
166+
```
167+
168+
#### suspend_sync / unsuspend_sync
169+
Suspend or Unususpend Cloud Drive syncing on a Filer.
170+
171+
```
172+
usage: ctools.py suspend_sync [-h] [-v] [-i] address username password device_name tenant_name
173+
174+
positional arguments:
175+
address Portal IP, hostname, or FQDN
176+
username Username for portal administrator
177+
password Password. Enter ? to prompt in CLI
178+
device_name Device Name
179+
tenant_name Tenant Name
180+
181+
optional arguments:
182+
-h, --help show this help message and exit
183+
-v, --verbose Add verbose logging
184+
-i, --ignore_cert Ignore cert warnings
185+
```
186+
187+
#### reset_password
188+
Reset a local user account password on a Filer.
189+
```
190+
usage: ctools.py reset_password [-h] [-v] [-i] address username password device_name tenant_name user_name filer_password
191+
192+
positional arguments:
193+
address Portal IP, hostname, or FQDN
194+
username Username for portal administrator
195+
password Password. Enter ? to prompt in CLI
196+
device_name Device Name
197+
tenant_name Tenant Name
198+
user_name User Name
199+
filer_password New Filer Password. Enter ? to prompt in CLI
200+
201+
optional arguments:
202+
-h, --help show this help message and exit
203+
-v, --verbose Add verbose logging
204+
-i, --ignore_cert Ignore cert warnings
205+
```
206+
207+
## Examples
208+
209+
### GUI
210+
To launch the GUI, simply invoke python and specify our main module, ctools.py, without specifying any flags.
211+
212+
```
213+
PS C:\Users\ctera\git\ctools> python ctools.py
214+
```
215+
![ctools GUI screenshot](./images/screenshot-ctools-gui.png)
216+
217+
### CLI
218+
219+
Run ctools.py with any flags to run it from a CLI.
220+
221+
```
222+
(ctools) PS C:\Users\ctera\git\ctools> python ctools.py run_cmd portal.ctera.me admin ? 'show /config/logging/log2File' --all --ignore_cert
223+
2021-10-06 02:09:08,677 [INFO] Starting ctools
224+
Password:
225+
2021-10-06 02:09:11,683 [INFO] Logging into portal.ctera.me
226+
2021-10-06 02:09:12,014 [INFO] User logged in. {'host': 'portal.ctera.me', 'user': 'admin'}
227+
2021-10-06 02:09:12,202 [WARNING] Allow Single Sign On to Devices is not enabled.
228+
Some tasks may fail or output may be incomplete
229+
2021-10-06 02:09:12,203 [INFO] Starting run_cmd task
230+
2021-10-06 02:09:12,272 [INFO] Getting all Filers since tenant is Administration
231+
2021-10-06 02:09:12,986 [INFO] Running command on: vgw-1b6c
232+
2021-10-06 02:09:12,988 [INFO] Executing CLI command. {'cli_command': 'show /config/logging/log2File'}
233+
2021-10-06 02:09:13,047 [INFO] CLI command executed. {'cli_command': 'show /config/logging/log2File'}
234+
2021-10-06 02:09:13,048 [INFO] No such attribute log2File
235+
2021-10-06 02:09:13,049 [INFO] Finished command on: vgw-1b6c
236+
2021-10-06 02:09:13,049 [INFO] Running command on: svtvgw
237+
2021-10-06 02:09:13,050 [INFO] Executing CLI command. {'cli_command': 'show /config/logging/log2File'}
238+
2021-10-06 02:09:13,113 [INFO] CLI command executed. {'cli_command': 'show /config/logging/log2File'}
239+
2021-10-06 02:09:13,114 [INFO] {
240+
type: log2FileSetting
241+
maxFileSizeMB: "100"
242+
maxfiles: "70"
243+
}
244+
2021-10-06 02:09:13,116 [INFO] Finished command on: svtvgw
245+
2021-10-06 02:09:13,116 [INFO] Running command on: team-vGateway1
246+
2021-10-06 02:09:13,117 [INFO] Executing CLI command. {'cli_command': 'show /config/logging/log2File'}
247+
2021-10-06 02:09:13,178 [INFO] CLI command executed. {'cli_command': 'show /config/logging/log2File'}
248+
2021-10-06 02:09:13,179 [INFO] No such attribute log2File
249+
2021-10-06 02:09:13,180 [INFO] Finished command on: team-vGateway1
250+
2021-10-06 02:09:13,181 [INFO] Finished run_cmd task on all Tenants.
251+
2021-10-06 02:09:13,243 [INFO] User logged out. {'host': 'portal.ctera.me', 'user': 'admin'}
252+
2021-10-06 02:09:13,244 [INFO] Exiting ctools
253+
84254
```

0 commit comments

Comments
 (0)