@@ -7,14 +7,14 @@ SSH library [paramiko](https://github.com/paramiko/paramiko/).
7
7
## Installation
8
8
Run:
9
9
```
10
- pip3 install --user sshcontroller-oroques
10
+ pip3 install --user sshcontroller
11
11
```
12
12
13
- Note that the package has been exclusively tested on Python 3+.
13
+ Note that the package has been exclusively tested on Python 3.6 +.
14
14
15
15
## Usage
16
16
17
- The code snippets can also be found at [ demo.py] ( ./examples/demo.py ) .
17
+ All code snippets can also be found at [ demo.py] ( ./examples/demo.py ) .
18
18
19
19
#### 1. Create a new SSH controller from a SSH key
20
20
``` python
@@ -26,7 +26,7 @@ KEY_PWD = "password"
26
26
ssh_controller = sshcontroller.SSHController(
27
27
host = HOST_IP ,
28
28
user = " olivier" ,
29
- key_path = " ~/.ssh/id_rsa" , # if omitted, look in agent and in ~/.ssh
29
+ key_path = " ~/.ssh/id_rsa" , # if omitted, look for keys in SSH agent and in ~/.ssh/
30
30
key_password = KEY_PWD , # optional
31
31
key_type = " rsa" , # rsa (default), dsa, ecdsa or ed25519
32
32
port = 22 , # 22 is the default
@@ -43,11 +43,11 @@ ssh_controller.connect()
43
43
return_code, output = ssh_controller.run(
44
44
command = " echo 'Hello world!' > /tmp/hello.txt" ,
45
45
display = True , # display output, false by default
46
- combine_stderr = False , # combine stderr and stdout, false by default
47
46
capture_output = True , # return output, false by default
47
+ combine_stderr = False , # combine stderr and stdout, false by default
48
48
timeout = 10 , # command timeout in seconds, 600s by default
49
49
)
50
- logging.info (f " return code: { return_code} , output: { output} " )
50
+ print (f " return code: { return_code} , output: { output} " )
51
51
```
52
52
53
53
#### 4. Transfer data with SFTP
@@ -56,10 +56,10 @@ All functions from paramiko's `SFTPClient` are available through the
56
56
[ paramiko's documentation] ( http://docs.paramiko.org/en/stable/api/sftp.html#paramiko.sftp_client.SFTPClient )
57
57
for a complete list.
58
58
59
- In addition, the package adds new methods:
59
+ In addition, the package implements additional methods:
60
60
* ` exists(path) ` : check that a file or a directory exists on the remote host
61
61
* ` list_dirs(path) ` : return the list of directories present in ` path `
62
- * ` list_dirs (path)` : return the list of files present in ` path `
62
+ * ` list_files (path)` : return the list of files present in ` path `
63
63
64
64
``` python
65
65
print (f " hello.txt exists: { ssh_controller.exists(' /tmp/hello.txt' )} " )
@@ -77,29 +77,29 @@ with open("/tmp/bonjour.txt", 'r') as bonjour:
77
77
ssh_controller.disconnect()
78
78
```
79
79
80
- #### 6. Use SSH password instead
80
+ #### 6. Use a SSH password instead of a key
81
81
``` python
82
82
import sshcontroller
83
83
84
84
HOST_IP = " 93.184.216.34" # an IPv4 or IPv6 address
85
- SSH_PWD = " "
85
+ SSH_PWD = " password "
86
86
87
87
ssh_controller = sshcontroller.SSHController(
88
88
host = HOST_IP ,
89
- user = " root " ,
89
+ user = " olivier " ,
90
90
ssh_password = SSH_PWD
91
91
)
92
92
ssh_controller.connect()
93
93
```
94
94
95
95
#### 7. Run a command until an event is set
96
- If the argument ` stop_event ` is set when calling ` run() ` , the controller waits
97
- for the given event to be triggered before stopping. This is especially useful
98
- when using threads.
96
+ If the argument ` stop_event ` is set when calling ` run() ` , the controller
97
+ ignores ` timeout ` and stops only when the given event is triggered instead.
98
+ This is especially useful when using threads.
99
99
100
100
The example below starts two threads with an event attached to each one:
101
101
one is pinging localhost, the other sleeps for 10s. When the sleeping threads
102
- has finished, we trigger the events to also stop the pinging thread.
102
+ has finished, the events are triggered to also stop the pinging thread.
103
103
104
104
``` python
105
105
import logging
@@ -108,6 +108,8 @@ import sshcontroller
108
108
import threading
109
109
import time
110
110
111
+ # ... set up ssh_controller here ...
112
+
111
113
output = queue.Queue() # a queue to store the ping command output
112
114
stop_event_sleep = threading.Event()
113
115
stop_event_ping = threading.Event()
0 commit comments