1
1
import ctypes
2
2
import libspecinfra
3
- from libspecinfra .structures import BackendWrapperS
3
+ from libspecinfra .structures import BackendWrapperS , BackendWrapperS , SSHBuilderS
4
4
5
5
6
6
class Direct (object ):
@@ -16,12 +16,40 @@ def __exit__(self, exc_type, exc_value, traceback):
16
16
17
17
class SSH (object ):
18
18
19
- def __init__ (self , host ):
19
+ def __init__ (self , host , user = None , password = None , key_file = None , port = None ):
20
20
lib = libspecinfra .load ()
21
- lib .backend_ssh_new .argtypes = (ctypes .c_char_p ,)
22
- lib .backend_ssh_new .restype = ctypes .POINTER (BackendWrapperS )
23
- lib .backend_ssh_free .argtypes = (ctypes .POINTER (BackendWrapperS ),)
24
- self .obj = lib .backend_ssh_new (host .encode ('utf-8' ))
21
+ ssh_builder_p = ctypes .POINTER (SSHBuilderS )
22
+ lib .backend_ssh_builder_new .argtypes = (ctypes .c_char_p ,)
23
+ lib .backend_ssh_builder_new .restype = ssh_builder_p
24
+ ssh_builder = lib .backend_ssh_builder_new (host .encode ('utf-8' ))
25
+
26
+ if user is not None :
27
+ user = user .encode ('utf-8' )
28
+ lib .backend_ssh_builder_user .argtypes = (ssh_builder_p , ctypes .c_char_p ,)
29
+ lib .backend_ssh_builder_user .restype = ssh_builder_p
30
+ ssh_builder = lib .backend_ssh_builder_user (ssh_builder , user )
31
+
32
+ if password is not None :
33
+ password = password .encode ('utf-8' )
34
+ lib .backend_ssh_builder_password .argtypes = (ssh_builder_p , ctypes .c_char_p ,)
35
+ lib .backend_ssh_builder_password .restype = ssh_builder_p
36
+ ssh_builder = lib .backend_ssh_builder_password (ssh_builder , password )
37
+
38
+ if key_file is not None :
39
+ key_file = key_file .encode ('utf-8' )
40
+ lib .backend_ssh_builder_key_file .argtypes = (ssh_builder_p , ctypes .c_char_p ,)
41
+ lib .backend_ssh_builder_key_file .restype = ssh_builder_p
42
+ ssh_builder = lib .backend_ssh_builder_key_file (ssh_builder , key_file )
43
+
44
+ if port is not None :
45
+ lib .backend_ssh_builder_port .argtypes = (ssh_builder_p , ctypes .c_uint32 ,)
46
+ lib .backend_ssh_builder_port .restype = ssh_builder_p
47
+ ssh_builder = lib .backend_ssh_builder_port (ssh_builder , port )
48
+
49
+ lib .backend_ssh_builder_finalize .argtypes = (ssh_builder_p ,)
50
+ lib .backend_ssh_builder_finalize .restype = ctypes .POINTER (BackendWrapperS )
51
+ self .obj = lib .backend_ssh_builder_finalize (ssh_builder )
25
52
26
53
def __exit__ (self , exc_type , exc_value , traceback ):
54
+ libspecinfra .load ().backend_ssh_builder_free .argtypes = (ctypes .POINTER (SSHBuilderS ),)
27
55
self .lib .backend_ssh_free (self .obj )
0 commit comments