multiSSH3 5.95__py3-none-any.whl → 6.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- multiSSH3.py +327 -165
- multissh3-6.1.dist-info/METADATA +698 -0
- multissh3-6.1.dist-info/RECORD +6 -0
- multissh3-5.95.dist-info/METADATA +0 -379
- multissh3-5.95.dist-info/RECORD +0 -6
- {multissh3-5.95.dist-info → multissh3-6.1.dist-info}/WHEEL +0 -0
- {multissh3-5.95.dist-info → multissh3-6.1.dist-info}/entry_points.txt +0 -0
- {multissh3-5.95.dist-info → multissh3-6.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,698 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: multiSSH3
|
|
3
|
+
Version: 6.1
|
|
4
|
+
Summary: Run commands on multiple hosts via SSH
|
|
5
|
+
Home-page: https://github.com/yufei-pan/multiSSH3
|
|
6
|
+
Author: Yufei Pan
|
|
7
|
+
Author-email: pan@zopyr.us
|
|
8
|
+
License: GPLv3+
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
|
11
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
12
|
+
Classifier: Operating System :: MacOS
|
|
13
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
14
|
+
Requires-Python: >=3.6
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
Requires-Dist: argparse
|
|
17
|
+
Requires-Dist: ipaddress
|
|
18
|
+
Dynamic: author
|
|
19
|
+
Dynamic: author-email
|
|
20
|
+
Dynamic: classifier
|
|
21
|
+
Dynamic: description
|
|
22
|
+
Dynamic: description-content-type
|
|
23
|
+
Dynamic: home-page
|
|
24
|
+
Dynamic: license
|
|
25
|
+
Dynamic: requires-dist
|
|
26
|
+
Dynamic: requires-python
|
|
27
|
+
Dynamic: summary
|
|
28
|
+
|
|
29
|
+
# multiSSH3
|
|
30
|
+
|
|
31
|
+
## Introduction
|
|
32
|
+
A script that is able to issue commands to multiple hosts while monitoring their progress.
|
|
33
|
+
Can be used in bash scripts for automation actions.
|
|
34
|
+
Also able to be imported and / or use with Flexec SSH Backend to perform cluster automation actions.
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
Install via
|
|
38
|
+
```bash
|
|
39
|
+
pip install multiSSH3
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
multiSSH3 will be in cli available as
|
|
43
|
+
```bash
|
|
44
|
+
mssh
|
|
45
|
+
mssh3
|
|
46
|
+
multissh
|
|
47
|
+
multissh3
|
|
48
|
+
multiSSH3
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Configuration
|
|
52
|
+
### Config File Chain
|
|
53
|
+
multissh treat config files as definable default values.
|
|
54
|
+
|
|
55
|
+
Configed values can be inspected by simply running
|
|
56
|
+
```bash
|
|
57
|
+
mssh -h
|
|
58
|
+
```
|
|
59
|
+
to print the help message with current default values.
|
|
60
|
+
|
|
61
|
+
Defaults are read from the following chain map stored as json files, top ones overwrite the bottom ones.:
|
|
62
|
+
| `CONFIG_FILE_CHAIN` |
|
|
63
|
+
| ------------- |
|
|
64
|
+
| `./multiSSH3.config.json` |
|
|
65
|
+
| `~/multiSSH3.config.json` |
|
|
66
|
+
| `~/.multiSSH3.config.json` |
|
|
67
|
+
| `~/.config/multiSSH3/multiSSH3.config.json`|
|
|
68
|
+
| `/etc/multiSSH3.d/multiSSH3.config.json`|
|
|
69
|
+
| `/etc/multiSSH3.config.json`|
|
|
70
|
+
|
|
71
|
+
### Generating / Storing Config File
|
|
72
|
+
To store / generate a config file with the current command line options, you can use
|
|
73
|
+
```bash
|
|
74
|
+
mssh --store_config_file [STORE_CONFIG_FILE_PATH]
|
|
75
|
+
```
|
|
76
|
+
> `--store_config_file [STORE_CONFIG_FILE]`<br/>
|
|
77
|
+
> is equivalent to <br/>
|
|
78
|
+
> `--generate_config_file --config_file [CONFIG_FILE]` <br/>
|
|
79
|
+
> and <br/>
|
|
80
|
+
> `--generate_config_file > [STORE_CONFIG_FILE_PATH]`.
|
|
81
|
+
>
|
|
82
|
+
>`--generate_config_file` will output to stdout if `--config_file` is not specified.
|
|
83
|
+
|
|
84
|
+
> Use `--store_config_file` without a path will store to `multiSSH3.config.json` in the current working directory.
|
|
85
|
+
|
|
86
|
+
You can modify the json file or use command line arguments to update values and store them as defaults.
|
|
87
|
+
```bash
|
|
88
|
+
mssh --timeout 180 --store_config_file
|
|
89
|
+
```
|
|
90
|
+
will store
|
|
91
|
+
```json
|
|
92
|
+
...
|
|
93
|
+
"DEFAULT_CLI_TIMEOUT": "180"
|
|
94
|
+
...
|
|
95
|
+
```
|
|
96
|
+
into `./multiSSH3.config.json`
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
> If you want to store password, it will be a plain text password in this config file. This will be better to supply it everytime as a CLI argument but you should really consider setting up public-key authentication.
|
|
100
|
+
|
|
101
|
+
>On some systems, scp / rsync will require you use public-key authentication to work.<br/>
|
|
102
|
+
|
|
103
|
+
### SSH ControlMaster Configuration
|
|
104
|
+
|
|
105
|
+
Note: you probably want to set presistent ssh connections to speed up each connection events.
|
|
106
|
+
|
|
107
|
+
You can add the following to your `~/.ssh/config` file to enable ControlMaster with a 1 hour persistence by running
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
mssh --add_control_master_config
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```config
|
|
114
|
+
Host *
|
|
115
|
+
ControlMaster auto
|
|
116
|
+
ControlPath /run/user/%i/ssh_sockets_%C
|
|
117
|
+
ControlPersist 3600
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Environment Variables for Hostname Aliases
|
|
121
|
+
|
|
122
|
+
multissh3 is able to read hostname grouping / aliases from environment variables.
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
By default mssh reads env variables and recursive resolves them if specified with a hostname that is not be able to be resolved from `/etc/hosts`. This functions as a pseudo dns service for hostname grouping.
|
|
126
|
+
|
|
127
|
+
> Use `[0-9]`, `[0-f]`, `[a-Z]` ranges in the hostname strings for range expansion.
|
|
128
|
+
|
|
129
|
+
> Use `,` to separate multiple hostnames / hostname groups.
|
|
130
|
+
|
|
131
|
+
### Hostname Resolution Logic
|
|
132
|
+
|
|
133
|
+
First, mssh will expand [a-b] ranges in the hostname strings.
|
|
134
|
+
|
|
135
|
+
- Check if an IPv4 range is given
|
|
136
|
+
- Expand using ipv4 range expansion logic.
|
|
137
|
+
- Return
|
|
138
|
+
- Check if range given is all numerical
|
|
139
|
+
- Expand using numerical expansion logic.
|
|
140
|
+
- Resolve hostnames
|
|
141
|
+
- Return
|
|
142
|
+
- Check if range given is all hex characters
|
|
143
|
+
- Expand using hex expansion logic.
|
|
144
|
+
- Resolve hostnames
|
|
145
|
+
- Return
|
|
146
|
+
- Else
|
|
147
|
+
- Expand using alphanumeric expansion logic.
|
|
148
|
+
- Resolve hostnames
|
|
149
|
+
- Return
|
|
150
|
+
|
|
151
|
+
When hostname need to be resolved, mssh will check in the following order:
|
|
152
|
+
- Return if it is an ipv4 address
|
|
153
|
+
- Return if hostname is in /etc/hosts
|
|
154
|
+
- If `-C, --no_env` is not specified and hostname is in current terminal environment variables
|
|
155
|
+
- Redo the whole range -> hostname resolution logic with the resolved env variable value.
|
|
156
|
+
- hostname is in map generated from env_file(s) specified by `--env_files ENV_FILES`
|
|
157
|
+
- Redo the whole range -> hostname resolution logic with the resolved env variable value.
|
|
158
|
+
- Lookup using `socket.gethostbyname()` to query dns server. ( Slow! )
|
|
159
|
+
|
|
160
|
+
> TLDR:
|
|
161
|
+
>
|
|
162
|
+
> ipv4 address expansion -> range expansion -> identify ipv4 -> resolve using environment variables ( if not no_env ) -> env map from env_files -> remote hostname resolution
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
### Default Env Files
|
|
166
|
+
|
|
167
|
+
> Because command environment variables take precedence over env files, you can specify `-C, --no_env` or set `"DEFAULT_NO_ENV": true` in config file to disable environment variable lookup.
|
|
168
|
+
|
|
169
|
+
> Use `-ef ENV_FILE, --env_file ENV_FILE` to specify a single env file to replace the default env file lookup chain. ( Only this file will be used. )
|
|
170
|
+
|
|
171
|
+
> Use `-efs ENV_FILES, --env_files ENV_FILES` to append files to the end of the default env file lookup chain. ( Files will be loaded first to last. )
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
| `DEFAULT_ENV_FILES` |
|
|
175
|
+
| ------------- |
|
|
176
|
+
| `/etc/profile.d/hosts.sh` |
|
|
177
|
+
| `~/.bashrc` |
|
|
178
|
+
| `~/.zshrc` |
|
|
179
|
+
| `~/host.env` |
|
|
180
|
+
| `~/hosts.env` |
|
|
181
|
+
| `.env` |
|
|
182
|
+
| `host.env` |
|
|
183
|
+
| `hosts.env` |
|
|
184
|
+
|
|
185
|
+
Later files take precedence over earlier files.
|
|
186
|
+
|
|
187
|
+
### Example Env Hostname File
|
|
188
|
+
|
|
189
|
+
An example hostname alias file will look like:
|
|
190
|
+
```bash
|
|
191
|
+
us_east='100.100.0.1-3,us_east_prod_[1-5]'
|
|
192
|
+
us_central=""
|
|
193
|
+
us_west="100.101.0.1-2,us_west_prod_[a-c]_[1-3]"
|
|
194
|
+
us="$us_east,$us_central,$us_west"
|
|
195
|
+
asia="100.90.0-1.1-9"
|
|
196
|
+
eu=''
|
|
197
|
+
rhel8="$asia,$us_east"
|
|
198
|
+
all="$us,$asia,$eu"
|
|
199
|
+
```
|
|
200
|
+
( You can use bash replacements for grouping. )
|
|
201
|
+
|
|
202
|
+
### Hostname Range Expansion
|
|
203
|
+
|
|
204
|
+
mssh is also able to recognize ip blocks / number blocks / hex blocks / character blocks directly.
|
|
205
|
+
|
|
206
|
+
For example:
|
|
207
|
+
```bash
|
|
208
|
+
mssh testrig[1-10] lsblk
|
|
209
|
+
mssh ww[a-c],10.100.0.* 'cat /etc/fstab' 'sed -i "/lustre/d' /etc/fstab' 'cat /etc/fstab'
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Misc Features
|
|
213
|
+
|
|
214
|
+
### Interactive Inputs
|
|
215
|
+
|
|
216
|
+
It also supports interactive inputs. ( and able to async boardcast to all supplied hosts )
|
|
217
|
+
```bash
|
|
218
|
+
mssh www bash
|
|
219
|
+
```
|
|
220
|
+
mssh cache all inputs and send them to all hosts when they are ready to receive inputs.
|
|
221
|
+
|
|
222
|
+
### Curses Window Size Control
|
|
223
|
+
|
|
224
|
+
By default, it will try to fit everything inside your window.
|
|
225
|
+
```bash
|
|
226
|
+
DEFAULT_CURSES_MINIMUM_CHAR_LEN = 40
|
|
227
|
+
DEFAULT_CURSES_MINIMUM_LINE_LEN = 1
|
|
228
|
+
```
|
|
229
|
+
While leaving minimum 40 characters / 1 line for each host display by default. You can modify this by using `-ww WINDOW_WIDTH, --window_width WINDOW_WIDTH` and `-wh WINDOW_HEIGHT, --window_height WINDOW_HEIGHT`.
|
|
230
|
+
|
|
231
|
+
> It is also possible to modify the window size within curses display by pressing keys:
|
|
232
|
+
> ```
|
|
233
|
+
> ? : Toggle Help Menu
|
|
234
|
+
> _ or + : Change window hight
|
|
235
|
+
> { or } : Change window width
|
|
236
|
+
> < or > : Change host index
|
|
237
|
+
> |(pipe) : Toggle single host
|
|
238
|
+
> Ctrl+D : Exit
|
|
239
|
+
> Ctrl+R : Force refresh
|
|
240
|
+
> ↑ or ↓ : Navigate history
|
|
241
|
+
> ← or → : Move cursor
|
|
242
|
+
> PgUp/Dn : Scroll history by 5
|
|
243
|
+
> Home/End: Jump cursor
|
|
244
|
+
> Esc : Clear line
|
|
245
|
+
> ```
|
|
246
|
+
> You can also toggle this help in curses by pressing `?` or `F1`.
|
|
247
|
+
|
|
248
|
+
### Command String Replacement
|
|
249
|
+
|
|
250
|
+
mssh will replace some magic strings in the command string with host specific values.
|
|
251
|
+
|
|
252
|
+
| Magic String | Description |
|
|
253
|
+
| ------------- | ------------------------------------ |
|
|
254
|
+
| `#HOST#` | Replaced with the expanded name /IP |
|
|
255
|
+
| `#HOSTNAME#` | Replaced with the expanded name / IP |
|
|
256
|
+
| `#USER#` | Replaced with the username |
|
|
257
|
+
| `#USERNAME#` | Replaced with the username |
|
|
258
|
+
| `#ID#` | Replaced with the ID of the host obj |
|
|
259
|
+
| `#I# ` | Replaced with the index of the host |
|
|
260
|
+
| `#PASSWD#` | Replaced with the password |
|
|
261
|
+
| `#PASSWORD#` | Replaced with the password |
|
|
262
|
+
| `#UUID#` | Replaced with the UUID of the host |
|
|
263
|
+
| `#RESOLVEDNAME#`| Replaced with the resolved name |
|
|
264
|
+
| `#IP#` | Replaced with the resolved IP |
|
|
265
|
+
|
|
266
|
+
> Note: `#HOST#` and `#HOSTNAME#` are the supplied hostname / ip before any resolution.
|
|
267
|
+
|
|
268
|
+
> Note: Resolved name is the IP / Hostname with user appended and ip prefix applied. This is what got used to connect to the host.
|
|
269
|
+
|
|
270
|
+
## Options
|
|
271
|
+
|
|
272
|
+
Here details the options for multiSSH3 6.01 @ 2025-11-06
|
|
273
|
+
|
|
274
|
+
### `-u USERNAME, --username USERNAME` | _`DEFAULT_USERNAME`_
|
|
275
|
+
- You can specify the username for all hosts using this option and / or specifying username@hostname per host in the host list.
|
|
276
|
+
|
|
277
|
+
### `-p PASSWORD, --password PASSWORD` | _`DEFAULT_PASSWORD`_
|
|
278
|
+
- You can specify the password for all hosts using this option. Although it is recommended to use SSH keys / store password in config file for authentication.
|
|
279
|
+
|
|
280
|
+
### `-k [KEY], --key [KEY], --identity [KEY]` | _`DEFAULT_IDENTITY_FILE`_
|
|
281
|
+
- You can specify the identity file or folder to use for public key authentication. If a folder is specified, it will search for a key file inside the folder.
|
|
282
|
+
- This option implies `--use_key`.
|
|
283
|
+
- If this option is not specified but `--use_key` is specified, it will search for identity files in `DEFAULT_IDENTITY_FILE`.
|
|
284
|
+
- If no value is specified, it will search `DEFAULT_SSH_KEY_SEARCH_PATH`.
|
|
285
|
+
|
|
286
|
+
### `-uk, --use_key` | _`DEFAULT_USE_KEY`_
|
|
287
|
+
- Attempt to use public key authentication to connect to the hosts.
|
|
288
|
+
- Will search for identity file in `DEFAULT_IDENTITY_FILE` if `--identity` is not specified.
|
|
289
|
+
|
|
290
|
+
### `-ea EXTRAARGS, --extraargs EXTRAARGS` | _`DEFAULT_EXTRA_ARGS`_
|
|
291
|
+
- Extra arguments to pass to the ssh / rsync / scp command. Put in one string for multiple arguments.
|
|
292
|
+
- Example:
|
|
293
|
+
```bash
|
|
294
|
+
mssh -ea="--delete" -f ./data/ allServers /tmp/data/
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### `-11, --oneonone` | _`DEFAULT_ONE_ON_ONE`_
|
|
298
|
+
- Run commands in one-on-one mode, where each command corresponds to each host, front to back.
|
|
299
|
+
- If command list length is not equal to expanded host list length, an error will be raised.
|
|
300
|
+
|
|
301
|
+
### `-f FILE, --file FILE` | None
|
|
302
|
+
- The file to be copied to the hosts. Use -f multiple times to copy multiple files.
|
|
303
|
+
- When file is specified, the command(s) will be treated as the destination path(s) on the remote hosts.
|
|
304
|
+
- By default, rsync will be tried first on linux, scp will be used on windows or if rsync have failed to on linux.
|
|
305
|
+
|
|
306
|
+
### `-s [FILE_SYNC], -fs [FILE_SYNC], --file_sync [FILE_SYNC]` | _`DEFAULT_FILE_SYNC`_
|
|
307
|
+
- Operate in file sync mode, sync path in `<COMMANDS>` from this machine to `<HOSTS>`.
|
|
308
|
+
- Treat `--file <FILE>` and `<COMMANDS>` both as source and source
|
|
309
|
+
- Destination path will be inferred from source path ( Absolute Path ).
|
|
310
|
+
- `-fs` can also be followed by a path, a syntaxic sugar for specifying the path after the option.
|
|
311
|
+
- Example:
|
|
312
|
+
```bash
|
|
313
|
+
mssh -fs -- allServers ./data/ # is equivalent to
|
|
314
|
+
mssh -fs ./data/ allServers # is equivalent to
|
|
315
|
+
mssh -fs -f ./data/ allServers # is equivalent to
|
|
316
|
+
# if the cwd is at /tmp,
|
|
317
|
+
mssh -f ./data/ allServers /tmp/data/
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### `-W, --scp` | _`DEFAULT_SCP`_
|
|
321
|
+
- Use scp for copying files by default instead of trying rsync.
|
|
322
|
+
- Can speed up operation if we know rsync will not be available on remote hosts.
|
|
323
|
+
|
|
324
|
+
### `-G, -gm, --gather_mode` | False
|
|
325
|
+
- Gather files from the hosts instead of sending files to the hosts.
|
|
326
|
+
- Will send remote files specified in `<FILE>` to local path specified in `<COMMANDS>`.
|
|
327
|
+
- Likely you will need to combine with the [Command String Replacement](#command-string-replacement) feature to let each host transfer to a different local path.
|
|
328
|
+
|
|
329
|
+
### `-t TIMEOUT, --timeout TIMEOUT` | _`DEFAULT_CLI_TIMEOUT`_
|
|
330
|
+
- Timeout for each command in seconds.
|
|
331
|
+
- When using 0, timeout is disabled.
|
|
332
|
+
- For CLI interface, will use `DEFAULT_CLI_TIMEOUT` as default.
|
|
333
|
+
- For module interface, will use `DEFAULT_TIMEOUT` as default.
|
|
334
|
+
|
|
335
|
+
### `-T, --use_script_timeout` | False
|
|
336
|
+
- In CLI, use `DEFAULT_TIMEOUT` as timeout value instead of `DEFAULT_CLI_TIMEOUT`.
|
|
337
|
+
- This is to emulate the module interface behavior as if using in a script.
|
|
338
|
+
|
|
339
|
+
### `-r REPEAT, --repeat REPEAT` | _`DEFAULT_REPEAT`_
|
|
340
|
+
- Repeat the commands for a number of times.
|
|
341
|
+
- Commands will be repeated in sequence for the specified number of times.
|
|
342
|
+
- Between repeats, it will wait for `--interval INTERVAL` seconds.
|
|
343
|
+
|
|
344
|
+
### `-i INTERVAL, --interval INTERVAL` | _`DEFAULT_INTERVAL`_
|
|
345
|
+
- Interval between command repeats in seconds.
|
|
346
|
+
- Only effective when `REPEAT` is greater than 1.
|
|
347
|
+
- Note: will wait for `INTERVAL` seconds before first run if `REPEAT` is greater than 1.
|
|
348
|
+
|
|
349
|
+
### `-M, --ipmi` | _`DEFAULT_IPMI`_
|
|
350
|
+
- Use ipmitool to run the command instead of ssh.
|
|
351
|
+
- Will strip `ipmitool` from the start of the command if it is present.
|
|
352
|
+
- Will replace the host's resolved IP address header with `DEFAULT_IPMI_INTERFACE_IP_PREFIX` in this mode
|
|
353
|
+
- Ex: `10.0.0.1` + `DEFAULT_IPMI_INTERFACE_IP_PREFIX='192.168'` -> `192.168.0.1`
|
|
354
|
+
- Will retry using original ip and run `ipmitool` over ssh if ipmi connection had failed. ( Will append ipmitool to the command if not present )
|
|
355
|
+
|
|
356
|
+
### `-mpre IPMI_INTERFACE_IP_PREFIX, --ipmi_interface_ip_prefix IPMI_INTERFACE_IP_PREFIX` | _`DEFAULT_IPMI_INTERFACE_IP_PREFIX`_
|
|
357
|
+
- The prefix of the IPMI interfaces. Will replace the resolved IP address with the given prefix when using ipmi mode.
|
|
358
|
+
- This will take precedence over `INTERFACE_IP_PREFIX` when in ipmi mode.
|
|
359
|
+
- Ex: `10.0.0.1` + `-mpre '192.168'` -> `192.168.0.1`
|
|
360
|
+
|
|
361
|
+
### `-pre INTERFACE_IP_PREFIX, --interface_ip_prefix INTERFACE_IP_PREFIX` | _`DEFAULT_INTERFACE_IP_PREFIX`_
|
|
362
|
+
- The prefix of the for the interfaces. Will replace the resolved IP address with the given prefix when connecting to the host.
|
|
363
|
+
- Will prioritize `IPMI_INTERFACE_IP_PREFIX` if it exists when in ipmi mode.
|
|
364
|
+
- Ex: `10.0.0.1` + `-pre '172.30'` -> `172.30.0.1`
|
|
365
|
+
|
|
366
|
+
...
|
|
367
|
+
|
|
368
|
+
## Usage
|
|
369
|
+
|
|
370
|
+
Use ```mssh --help``` for more info.
|
|
371
|
+
|
|
372
|
+
Below is a sample help message output from multiSSH3 6.01 @ 2025-11-06
|
|
373
|
+
|
|
374
|
+
```bash
|
|
375
|
+
$ mssh -h
|
|
376
|
+
usage: mssh [-h] [-u USERNAME] [-p PASSWORD] [-k [KEY]] [-uk] [-ea EXTRAARGS] [-11] [-f FILE] [-s [FILE_SYNC]] [-W] [-G] [-t TIMEOUT] [-T] [-r REPEAT] [-i INTERVAL] [-M] [-mpre IPMI_INTERFACE_IP_PREFIX]
|
|
377
|
+
[-pre INTERFACE_IP_PREFIX] [-iu IPMI_USERNAME] [-ip IPMI_PASSWORD] [-S] [-ww WINDOW_WIDTH] [-wh WINDOW_HEIGHT] [-B] [-R] [-Q] [-Z] [-C] [-ef ENV_FILE] [-efs ENV_FILES] [-m MAX_CONNECTIONS] [-j] [-w]
|
|
378
|
+
[-P] [-x | -a] [-uhe UNAVAILABLE_HOST_EXPIRY] [-X SKIP_HOSTS] [--generate_config_file] [--config_file [CONFIG_FILE]] [--store_config_file [STORE_CONFIG_FILE]] [--debug] [-ci] [-I] [-hf HISTORY_FILE]
|
|
379
|
+
[--script] [-e ENCODING] [-dt DIFF_DISPLAY_THRESHOLD] [--force_truecolor] [--add_control_master_config] [-V]
|
|
380
|
+
[hosts] [commands ...]
|
|
381
|
+
|
|
382
|
+
Run a command on multiple hosts, Use #HOST# or #HOSTNAME# to replace the host name in the command.
|
|
383
|
+
|
|
384
|
+
positional arguments:
|
|
385
|
+
hosts Hosts to run the command on, use "," to seperate hosts. (default: all)
|
|
386
|
+
commands the command to run on the hosts / the destination of the files #HOST# or #HOSTNAME# will be replaced with the host name.
|
|
387
|
+
|
|
388
|
+
options:
|
|
389
|
+
-h, --help show this help message and exit
|
|
390
|
+
-u USERNAME, --username USERNAME
|
|
391
|
+
The general username to use to connect to the hosts. Will get overwrote by individual username@host if specified. (default: None)
|
|
392
|
+
-p PASSWORD, --password PASSWORD
|
|
393
|
+
The password to use to connect to the hosts, (default: )
|
|
394
|
+
-k [KEY], --key [KEY], --identity [KEY]
|
|
395
|
+
The identity file to use to connect to the hosts. Implies --use_key. Specify a folder for program to search for a key. Use option without value to use ~/.ssh/ (default: None)
|
|
396
|
+
-uk, --use_key Attempt to use public key file to connect to the hosts. (default: False)
|
|
397
|
+
-ea EXTRAARGS, --extraargs EXTRAARGS
|
|
398
|
+
Extra arguments to pass to the ssh / rsync / scp command. Put in one string for multiple arguments.Use "=" ! Ex. -ea="--delete" (default: None)
|
|
399
|
+
-11, --oneonone Run one corresponding command on each host. (default: False)
|
|
400
|
+
-f FILE, --file FILE The file to be copied to the hosts. Use -f multiple times to copy multiple files
|
|
401
|
+
-s [FILE_SYNC], -fs [FILE_SYNC], --file_sync [FILE_SYNC]
|
|
402
|
+
Operate in file sync mode, sync path in <COMMANDS> from this machine to <HOSTS>. Treat --file <FILE> and <COMMANDS> both as source and source and destination will be the same in this mode. Infer destination from source path. (default: False)
|
|
403
|
+
-W, --scp Use scp for copying files instead of rsync. Need to use this on windows. (default: False)
|
|
404
|
+
-G, -gm, --gather_mode
|
|
405
|
+
Gather files from the hosts instead of sending files to the hosts. Will send remote files specified in <FILE> to local path specified in <COMMANDS> (default: False)
|
|
406
|
+
-t TIMEOUT, --timeout TIMEOUT
|
|
407
|
+
Timeout for each command in seconds. Set default value via DEFAULT_CLI_TIMEOUT in config file. Use 0 for disabling timeout. (default: 0)
|
|
408
|
+
-T, --use_script_timeout
|
|
409
|
+
Use shortened timeout suitable to use in a script. Set value via DEFAULT_TIMEOUT field in config file. (current: 50)
|
|
410
|
+
-r REPEAT, --repeat REPEAT
|
|
411
|
+
Repeat the command for a number of times (default: 1)
|
|
412
|
+
-i INTERVAL, --interval INTERVAL
|
|
413
|
+
Interval between repeats in seconds (default: 0)
|
|
414
|
+
-M, --ipmi Use ipmitool to run the command. (default: False)
|
|
415
|
+
-mpre IPMI_INTERFACE_IP_PREFIX, --ipmi_interface_ip_prefix IPMI_INTERFACE_IP_PREFIX
|
|
416
|
+
The prefix of the IPMI interfaces (default: )
|
|
417
|
+
-pre INTERFACE_IP_PREFIX, --interface_ip_prefix INTERFACE_IP_PREFIX
|
|
418
|
+
The prefix of the for the interfaces (default: None)
|
|
419
|
+
-iu IPMI_USERNAME, --ipmi_username IPMI_USERNAME
|
|
420
|
+
The username to use to connect to the hosts via ipmi. (default: ADMIN)
|
|
421
|
+
-ip IPMI_PASSWORD, --ipmi_password IPMI_PASSWORD
|
|
422
|
+
The password to use to connect to the hosts via ipmi. (default: )
|
|
423
|
+
-S, -q, -nw, --no_watch, --quiet
|
|
424
|
+
Quiet mode, no curses watch, only print the output. (default: False)
|
|
425
|
+
-ww WINDOW_WIDTH, --window_width WINDOW_WIDTH
|
|
426
|
+
The minimum character length of the curses window. (default: 40)
|
|
427
|
+
-wh WINDOW_HEIGHT, --window_height WINDOW_HEIGHT
|
|
428
|
+
The minimum line height of the curses window. (default: 1)
|
|
429
|
+
-B, -sw, --single_window
|
|
430
|
+
Use a single window for all hosts. (default: False)
|
|
431
|
+
-R, -eo, --error_only
|
|
432
|
+
Only print the error output. (default: False)
|
|
433
|
+
-Q, -no, --no_output Do not print the output. (default: False)
|
|
434
|
+
-Z, -rz, --return_zero
|
|
435
|
+
Return 0 even if there are errors. (default: False)
|
|
436
|
+
-C, --no_env Do not load the command line environment variables. (default: False)
|
|
437
|
+
-ef ENV_FILE, --env_file ENV_FILE
|
|
438
|
+
Replace the env file look up chain with this env_file. ( Still work with --no_env ) (default: None)
|
|
439
|
+
-efs ENV_FILES, --env_files ENV_FILES
|
|
440
|
+
The files to load the mssh file based environment variables from. Can specify multiple. Load first to last. ( Still work with --no_env ) (default: ['/etc/profile.d/hosts.sh', '~/.bashrc', '~/.zshrc', '~/host.env', '~/hosts.env', '.env', 'host.env', 'hosts.env'])
|
|
441
|
+
-m MAX_CONNECTIONS, --max_connections MAX_CONNECTIONS
|
|
442
|
+
Max number of connections to use (default: 4 * cpu_count)
|
|
443
|
+
-j, --json Output in json format. (default: False)
|
|
444
|
+
-w, --success_hosts Output the hosts that succeeded in summary as well. (default: False)
|
|
445
|
+
-P, -g, --greppable, --table
|
|
446
|
+
Output in greppable table. (default: False)
|
|
447
|
+
-x, -su, --skip_unreachable
|
|
448
|
+
Skip unreachable hosts. Note: Timedout Hosts are considered unreachable. Note: multiple command sequence will still auto skip unreachable hosts. (default: True)
|
|
449
|
+
-a, -nsu, --no_skip_unreachable
|
|
450
|
+
Do not skip unreachable hosts. Note: Timedout Hosts are considered unreachable. Note: multiple command sequence will still auto skip unreachable hosts. (default: False)
|
|
451
|
+
-uhe UNAVAILABLE_HOST_EXPIRY, --unavailable_host_expiry UNAVAILABLE_HOST_EXPIRY
|
|
452
|
+
Time in seconds to expire the unavailable hosts (default: 600)
|
|
453
|
+
-X SKIP_HOSTS, -sh SKIP_HOSTS, --skip_hosts SKIP_HOSTS
|
|
454
|
+
Skip the hosts in the list. (default: None)
|
|
455
|
+
--generate_config_file
|
|
456
|
+
Store / generate the default config file from command line argument and current config at --config_file / stdout
|
|
457
|
+
--config_file [CONFIG_FILE]
|
|
458
|
+
Additional config file to use, will pioritize over config chains. When using with store_config_file, will store the resulting config file at this location. Use without a path will use multiSSH3.config.json
|
|
459
|
+
--store_config_file [STORE_CONFIG_FILE]
|
|
460
|
+
Store the default config file from command line argument and current config. Same as --store_config_file --config_file=<path>
|
|
461
|
+
--debug Print debug information
|
|
462
|
+
-ci, --copy_id Copy the ssh id to the hosts
|
|
463
|
+
-I, -nh, --no_history
|
|
464
|
+
Do not record the command to history. Default: False
|
|
465
|
+
-hf HISTORY_FILE, --history_file HISTORY_FILE
|
|
466
|
+
The file to store the history. (default: ~/.mssh_history)
|
|
467
|
+
--script Run the command in script mode, short for -SCRIPT or --no_watch --skip_unreachable --no_env --no_history --greppable --error_only
|
|
468
|
+
-e ENCODING, --encoding ENCODING
|
|
469
|
+
The encoding to use for the output. (default: utf-8)
|
|
470
|
+
-dt DIFF_DISPLAY_THRESHOLD, --diff_display_threshold DIFF_DISPLAY_THRESHOLD
|
|
471
|
+
The threshold of lines to display the diff when files differ. {0-1} Set to 0 to always display the diff. Set to 1 to disable diff. (Only merge same) (default: 0.6)
|
|
472
|
+
--force_truecolor Force truecolor output even when not in a truecolor terminal. (default: False)
|
|
473
|
+
--add_control_master_config
|
|
474
|
+
Add ControlMaster configuration to ~/.ssh/config to speed up multiple connections to the same host.
|
|
475
|
+
-V, --version show program's version number and exit
|
|
476
|
+
```
|
|
477
|
+
Note: The default values can be modified / updated in the [Config file](#config).
|
|
478
|
+
|
|
479
|
+
## Importing as a Module
|
|
480
|
+
|
|
481
|
+
You can also import multiSSH3 as a module in your python scripts.
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
### Host Object
|
|
485
|
+
The `Host` object represents a host and its command execution state. The main execution function `run_command_on_hosts` returns a list of `Host` objects.
|
|
486
|
+
|
|
487
|
+
```python
|
|
488
|
+
class Host:
|
|
489
|
+
def __init__(self, name, command, files = None,ipmi = False,interface_ip_prefix = None,scp=False,extraargs=None,gatherMode=False,identity_file=None,shell=False,i = -1,uuid=uuid.uuid4(),ip = None):
|
|
490
|
+
self.name = name # the name of the host (hostname or IP address)
|
|
491
|
+
self.command = command # the command to run on the host
|
|
492
|
+
self.returncode = None # the return code of the command
|
|
493
|
+
self.output = [] # the output of the command for curses
|
|
494
|
+
self.stdout = [] # the stdout of the command
|
|
495
|
+
self.stderr = [] # the stderr of the command
|
|
496
|
+
self.lineNumToPrintSet = set() # line numbers to reprint
|
|
497
|
+
self.lastUpdateTime = time.monotonic() # the last time the output was updated
|
|
498
|
+
self.lastPrintedUpdateTime = 0 # the last time the output was printed
|
|
499
|
+
self.files = files # the files to be copied to the host
|
|
500
|
+
self.ipmi = ipmi # whether to use ipmi to connect to the host
|
|
501
|
+
self.shell = shell # whether to use shell to run the command
|
|
502
|
+
self.interface_ip_prefix = interface_ip_prefix # the prefix of the ip address of the interface to be used to connect to the host
|
|
503
|
+
self.scp = scp # whether to use scp to copy files to the host
|
|
504
|
+
self.gatherMode = gatherMode # whether the host is in gather mode
|
|
505
|
+
self.extraargs = extraargs # extra arguments to be passed to ssh
|
|
506
|
+
self.resolvedName = None # the resolved IP address of the host
|
|
507
|
+
# also store a globally unique integer i from 0
|
|
508
|
+
self.i = i if i != -1 else _get_i()
|
|
509
|
+
self.uuid = uuid
|
|
510
|
+
self.identity_file = identity_file
|
|
511
|
+
self.ip = ip if ip else getIP(name)
|
|
512
|
+
self.current_color_pair = [-1, -1, 1]
|
|
513
|
+
self.output_buffer = io.BytesIO()
|
|
514
|
+
self.stdout_buffer = io.BytesIO()
|
|
515
|
+
self.stderr_buffer = io.BytesIO()
|
|
516
|
+
self.thread = None
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### Example:
|
|
520
|
+
|
|
521
|
+
```python
|
|
522
|
+
import multiSSH3
|
|
523
|
+
ethReachableHosts = multiSSH3.run_command_on_hosts(nodesToCheck,['echo hi'],returnUnfinished = True) # returnUnfinished will return the host objects immediately without waiting for all hosts to finish.
|
|
524
|
+
ipmiReachableHosts = multiSSH3.run_command_on_hosts(nodesToCheck,['power status'], timeout = timeout, ipmi=True, password=password, skipUnreachable=False) # ipmi command
|
|
525
|
+
# You can use blocks like the following block to wait on a specific host list to finish ( That does respect timeout even if the host is hanging )
|
|
526
|
+
# Following block also implement an exponential backoff.
|
|
527
|
+
sleep_interval = 0.0001
|
|
528
|
+
while any([host.returncode is None for host in ethReachableHosts]):
|
|
529
|
+
time.sleep(sleep_interval) # avoid busy-waiting
|
|
530
|
+
if sleep_interval < 0.01:
|
|
531
|
+
sleep_interval *= 1.1
|
|
532
|
+
# You can also use join_threads to wait on all running threads ( including timedout hanging threads )
|
|
533
|
+
multiSSH3.join_threads()
|
|
534
|
+
...
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
### `run_command_on_hosts` Function
|
|
538
|
+
|
|
539
|
+
The run_command_on_hosts function includes almost all the options available in the CLI. ( some options modify the [global variables](#all-changable-config-options--global-variables-) and can be set before calling the function. )
|
|
540
|
+
|
|
541
|
+
```python
|
|
542
|
+
def run_command_on_hosts(hosts = DEFAULT_HOSTS,commands = None,oneonone = DEFAULT_ONE_ON_ONE, timeout = DEFAULT_TIMEOUT,password = DEFAULT_PASSWORD,no_watch = DEFAULT_NO_WATCH,json = DEFAULT_JSON_MODE,called = _DEFAULT_CALLED,max_connections=DEFAULT_MAX_CONNECTIONS,files = None,ipmi = DEFAULT_IPMI,interface_ip_prefix = DEFAULT_INTERFACE_IP_PREFIX,returnUnfinished = _DEFAULT_RETURN_UNFINISHED,scp=DEFAULT_SCP,gather_mode = False,username=DEFAULT_USERNAME,extraargs=DEFAULT_EXTRA_ARGS,skipUnreachable=DEFAULT_SKIP_UNREACHABLE,no_env=DEFAULT_NO_ENV,greppable=DEFAULT_GREPPABLE_MODE,willUpdateUnreachableHosts=_DEFAULT_UPDATE_UNREACHABLE_HOSTS,no_start=_DEFAULT_NO_START,skip_hosts = DEFAULT_SKIP_HOSTS, curses_min_char_len = DEFAULT_CURSES_MINIMUM_CHAR_LEN, curses_min_line_len = DEFAULT_CURSES_MINIMUM_LINE_LEN,single_window = DEFAULT_SINGLE_WINDOW,file_sync = False,error_only = DEFAULT_ERROR_ONLY,quiet = False,identity_file = DEFAULT_IDENTITY_FILE,copy_id = False, unavailable_host_expiry = DEFAULT_UNAVAILABLE_HOST_EXPIRY,no_history = True,history_file = DEFAULT_HISTORY_FILE,
|
|
543
|
+
):
|
|
544
|
+
"""
|
|
545
|
+
Run commands on multiple hosts via SSH or IPMI.
|
|
546
|
+
|
|
547
|
+
Parameters:
|
|
548
|
+
hosts (str or iterable): Hosts to run the command on. Can be a string (comma/space-separated) or iterable. Default: DEFAULT_HOSTS.
|
|
549
|
+
commands (list or None): List of commands to run on the hosts. If files are used, defines the destination. Default: None.
|
|
550
|
+
oneonone (bool): If True, run each command on the corresponding host (1:1 mapping). Default: DEFAULT_ONE_ON_ONE.
|
|
551
|
+
timeout (int): Timeout for each command in seconds. Default: DEFAULT_TIMEOUT.
|
|
552
|
+
password (str): Password for SSH/IPMI authentication. Default: DEFAULT_PASSWORD.
|
|
553
|
+
no_watch (bool): If True, do not use curses TUI; just print output. Default: DEFAULT_NO_WATCH.
|
|
554
|
+
json (bool): If True, output results in JSON format. Default: DEFAULT_JSON_MODE.
|
|
555
|
+
called (bool): If True, function is called programmatically (not CLI). Default: _DEFAULT_CALLED.
|
|
556
|
+
max_connections (int): Maximum concurrent SSH sessions. Default: 4 * os.cpu_count().
|
|
557
|
+
files (list or None): Files to copy to hosts. Default: None.
|
|
558
|
+
ipmi (bool): Use IPMI instead of SSH. Default: DEFAULT_IPMI.
|
|
559
|
+
interface_ip_prefix (str or None): Override IP prefix for host connection. Default: DEFAULT_INTERFACE_IP_PREFIX.
|
|
560
|
+
returnUnfinished (bool): If True, return hosts even if not finished. Default: _DEFAULT_RETURN_UNFINISHED.
|
|
561
|
+
scp (bool): Use scp for file transfer (instead of rsync). Default: DEFAULT_SCP.
|
|
562
|
+
gather_mode (bool): Gather files from hosts (pull mode). Default: False.
|
|
563
|
+
username (str or None): Username for SSH/IPMI. Default: DEFAULT_USERNAME.
|
|
564
|
+
extraargs (str or list or None): Extra args for SSH/SCP/rsync. Default: DEFAULT_EXTRA_ARGS.
|
|
565
|
+
skipUnreachable (bool): Skip hosts marked as unreachable. Default: DEFAULT_SKIP_UNREACHABLE.
|
|
566
|
+
no_env (bool): Do not load environment variables from shell. Default: DEFAULT_NO_ENV.
|
|
567
|
+
greppable (bool): Output in greppable table format. Default: DEFAULT_GREPPABLE_MODE.
|
|
568
|
+
willUpdateUnreachableHosts (bool): Update global unreachable hosts file. Default: _DEFAULT_UPDATE_UNREACHABLE_HOSTS.
|
|
569
|
+
no_start (bool): If True, return Host objects without running commands. Default: _DEFAULT_NO_START.
|
|
570
|
+
skip_hosts (str or None): Hosts to skip. Default: DEFAULT_SKIP_HOSTS.
|
|
571
|
+
curses_min_char_len (int): Minimum width per curses window. Default: DEFAULT_CURSES_MINIMUM_CHAR_LEN.
|
|
572
|
+
curses_min_line_len (int): Minimum height per curses window. Default: DEFAULT_CURSES_MINIMUM_LINE_LEN.
|
|
573
|
+
single_window (bool): Use a single curses window for all hosts. Default: DEFAULT_SINGLE_WINDOW.
|
|
574
|
+
file_sync (bool): Enable file sync mode (sync directories). Default: DEFAULT_FILE_SYNC.
|
|
575
|
+
error_only (bool): Only print error output. Default: DEFAULT_ERROR_ONLY.
|
|
576
|
+
quiet (bool): Suppress all output (overrides other output options). Default: False.
|
|
577
|
+
identity_file (str or None): SSH identity file. Default: DEFAULT_IDENTITY_FILE.
|
|
578
|
+
copy_id (bool): Use ssh-copy-id to copy public key to hosts. Default: False.
|
|
579
|
+
unavailable_host_expiry (int): Seconds to keep hosts marked as unavailable. Default: DEFAULT_UNAVAILABLE_HOST_EXPIRY.
|
|
580
|
+
no_history (bool): Do not record command history. Default: True.
|
|
581
|
+
history_file (str): File to store command history. Default: DEFAULT_HISTORY_FILE.
|
|
582
|
+
|
|
583
|
+
Returns:
|
|
584
|
+
list: List of Host objects representing each host/command run.
|
|
585
|
+
"""
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
## All Changable Config Options ( Global Variables )
|
|
589
|
+
|
|
590
|
+
Update these values in the config file to change the default behavior of multiSSH3.
|
|
591
|
+
|
|
592
|
+
> Values with leading `_` will not be included in the config file generated by mssh but are respected when set in the config file.
|
|
593
|
+
|
|
594
|
+
```python
|
|
595
|
+
AUTHOR = 'Yufei Pan'
|
|
596
|
+
AUTHOR_EMAIL = 'pan@zopyr.us'
|
|
597
|
+
DEFAULT_HOSTS = 'all'
|
|
598
|
+
DEFAULT_USERNAME = None
|
|
599
|
+
DEFAULT_PASSWORD = ''
|
|
600
|
+
DEFAULT_IDENTITY_FILE = None
|
|
601
|
+
DEFAULT_SSH_KEY_SEARCH_PATH = '~/.ssh/'
|
|
602
|
+
DEFAULT_USE_KEY = False
|
|
603
|
+
DEFAULT_EXTRA_ARGS = None
|
|
604
|
+
DEFAULT_ONE_ON_ONE = False
|
|
605
|
+
DEFAULT_SCP = False
|
|
606
|
+
DEFAULT_FILE_SYNC = False
|
|
607
|
+
DEFAULT_TIMEOUT = 50
|
|
608
|
+
DEFAULT_CLI_TIMEOUT = 0
|
|
609
|
+
DEFAULT_UNAVAILABLE_HOST_EXPIRY = 600
|
|
610
|
+
DEFAULT_REPEAT = 1
|
|
611
|
+
DEFAULT_INTERVAL = 0
|
|
612
|
+
DEFAULT_IPMI = False
|
|
613
|
+
DEFAULT_IPMI_INTERFACE_IP_PREFIX = ''
|
|
614
|
+
DEFAULT_INTERFACE_IP_PREFIX = None
|
|
615
|
+
DEFAULT_IPMI_USERNAME = 'ADMIN'
|
|
616
|
+
DEFAULT_IPMI_PASSWORD = ''
|
|
617
|
+
DEFAULT_NO_WATCH = False
|
|
618
|
+
DEFAULT_CURSES_MINIMUM_CHAR_LEN = 40
|
|
619
|
+
DEFAULT_CURSES_MINIMUM_LINE_LEN = 1
|
|
620
|
+
DEFAULT_SINGLE_WINDOW = False
|
|
621
|
+
DEFAULT_ERROR_ONLY = False
|
|
622
|
+
DEFAULT_NO_OUTPUT = False
|
|
623
|
+
DEFAULT_RETURN_ZERO = False
|
|
624
|
+
DEFAULT_NO_ENV = False
|
|
625
|
+
DEFAULT_ENV_FILE = ''
|
|
626
|
+
DEFAULT_ENV_FILES = ['/etc/profile.d/hosts.sh',
|
|
627
|
+
'~/.bashrc',
|
|
628
|
+
'~/.zshrc',
|
|
629
|
+
'~/host.env',
|
|
630
|
+
'~/hosts.env',
|
|
631
|
+
'.env',
|
|
632
|
+
'host.env',
|
|
633
|
+
'hosts.env',
|
|
634
|
+
]
|
|
635
|
+
DEFAULT_NO_HISTORY = False
|
|
636
|
+
DEFAULT_HISTORY_FILE = '~/.mssh_history'
|
|
637
|
+
DEFAULT_MAX_CONNECTIONS = 4 * os.cpu_count()
|
|
638
|
+
DEFAULT_JSON_MODE = False
|
|
639
|
+
DEFAULT_PRINT_SUCCESS_HOSTS = False
|
|
640
|
+
DEFAULT_GREPPABLE_MODE = False
|
|
641
|
+
DEFAULT_SKIP_UNREACHABLE = True
|
|
642
|
+
DEFAULT_SKIP_HOSTS = ''
|
|
643
|
+
DEFAULT_ENCODING = 'utf-8'
|
|
644
|
+
DEFAULT_DIFF_DISPLAY_THRESHOLD = 0.6
|
|
645
|
+
SSH_STRICT_HOST_KEY_CHECKING = False
|
|
646
|
+
FORCE_TRUECOLOR = False
|
|
647
|
+
ERROR_MESSAGES_TO_IGNORE = [
|
|
648
|
+
'Pseudo-terminal will not be allocated because stdin is not a terminal',
|
|
649
|
+
'Connection to .* closed',
|
|
650
|
+
'Warning: Permanently added',
|
|
651
|
+
'mux_client_request_session',
|
|
652
|
+
'disabling multiplexing',
|
|
653
|
+
'Killed by signal',
|
|
654
|
+
'Connection reset by peer',
|
|
655
|
+
]
|
|
656
|
+
__DEFAULT_COLOR_PALETTE = {
|
|
657
|
+
'cyan': (86, 173, 188),
|
|
658
|
+
'green': (114, 180, 43),
|
|
659
|
+
'magenta': (140, 107, 200),
|
|
660
|
+
'red': (196, 38, 94),
|
|
661
|
+
'white': (227, 227, 221),
|
|
662
|
+
'yellow': (179, 180, 43),
|
|
663
|
+
'blue': (106, 126, 200),
|
|
664
|
+
'bright_black': (102, 102, 102),
|
|
665
|
+
'bright_blue': (129, 154, 255),
|
|
666
|
+
'bright_cyan': (102, 217, 239),
|
|
667
|
+
'bright_green': (126, 226, 46),
|
|
668
|
+
'bright_magenta': (174, 129, 255),
|
|
669
|
+
'bright_red': (249, 38, 114),
|
|
670
|
+
'bright_white': (248, 248, 242),
|
|
671
|
+
'bright_yellow': (226, 226, 46),
|
|
672
|
+
}
|
|
673
|
+
COLOR_PALETTE = __DEFAULT_COLOR_PALETTE.copy()
|
|
674
|
+
_DEFAULT_CALLED = True
|
|
675
|
+
_DEFAULT_RETURN_UNFINISHED = False
|
|
676
|
+
_DEFAULT_UPDATE_UNREACHABLE_HOSTS = True
|
|
677
|
+
_DEFAULT_NO_START = False
|
|
678
|
+
_etc_hosts = {}
|
|
679
|
+
__ERROR_MESSAGES_TO_IGNORE_REGEX =None
|
|
680
|
+
__DEBUG_MODE = False
|
|
681
|
+
```
|
|
682
|
+
> Note: If color palette need to be changed, please change the `COLOR_PALETTE` values instead of the __DEFAULT_COLOR_PALETTE as if values are missing from __DEFAULT_COLOR_PALETTE, mssh may raise errors.
|
|
683
|
+
|
|
684
|
+
> When imported and calling as a module, `called` will be set to _DEFAULT_CALLED.<br/>
|
|
685
|
+
> When True, it sets several flags to make mssh behave better when called as a module.<br/>
|
|
686
|
+
> - if skipUnreachable is not set, it will skip unreachable hosts within one command call
|
|
687
|
+
> - Will clear global keyboard input cache
|
|
688
|
+
> - Will set global quiet mode to True
|
|
689
|
+
|
|
690
|
+
> `_DEFAULT_UPDATE_UNREACHABLE_HOSTS` is used to control whether to update the unreachable hosts file when mssh detects unreachable hosts.
|
|
691
|
+
|
|
692
|
+
> `_DEFAULT_NO_START` is somewhat analogous to "demo mode" where mssh will return Host objects without actually allocating and starting the execution threads. Although they still can be started using `start_run_on_hosts()` but you should really be looking for `returnUnfinished` instead for asynchronicity.
|
|
693
|
+
|
|
694
|
+
> `_etc_hosts` is a custom dict to use instead of reading /etc/hosts file for hostname resolution.
|
|
695
|
+
|
|
696
|
+
> `__ERROR_MESSAGES_TO_IGNORE_REGEX` is the compiled regex pattern for error messages to ignore. If custom defined, mssh will ignore `ERROR_MESSAGES_TO_IGNORE` and use supplied regex pattern instead.
|
|
697
|
+
|
|
698
|
+
> `__DEBUG_MODE` is used to control whether to print host thread execution debug information to its stderr.
|