1
- import hashlib
2
1
import binascii
2
+ import hashlib
3
+
3
4
from routeros_api import api_communicator
4
- from routeros_api import communication_exception_parsers
5
5
from routeros_api import api_socket
6
6
from routeros_api import api_structure
7
7
from routeros_api import base_api
8
+ from routeros_api import communication_exception_parsers
8
9
from routeros_api import exceptions
9
10
from routeros_api import resource
10
11
11
12
12
- def connect (host , username = 'admin' , password = '' , port = None , plaintext_login = False , use_ssl = False , ssl_verify = True , ssl_verify_hostname = True , ssl_context = None ):
13
- return RouterOsApiPool (host , username , password , port , plaintext_login , use_ssl , ssl_verify , ssl_verify_hostname , ssl_context ).get_api ()
13
+ def connect (host , username = 'admin' , password = '' , port = None , plaintext_login = False , use_ssl = False , ssl_verify = True ,
14
+ ssl_verify_hostname = True , ssl_context = None ):
15
+ return RouterOsApiPool (
16
+ host , username , password , port , plaintext_login , use_ssl , ssl_verify , ssl_verify_hostname , ssl_context ,
17
+ ).get_api ()
14
18
15
19
16
20
class RouterOsApiPool (object ):
17
21
socket_timeout = 15.0
18
22
19
- def __init__ (self , host , username = 'admin' , password = '' , port = None , plaintext_login = False , use_ssl = False , ssl_verify = True , ssl_verify_hostname = True , ssl_context = None ):
23
+ def __init__ (self , host , username = 'admin' , password = '' , port = None , plaintext_login = False , use_ssl = False ,
24
+ ssl_verify = True , ssl_verify_hostname = True , ssl_context = None ):
20
25
self .host = host
21
26
self .username = username
22
27
self .password = password
@@ -41,8 +46,9 @@ def __init__(self, host, username='admin', password='', port=None, plaintext_log
41
46
42
47
def get_api (self ):
43
48
if not self .connected :
44
- self .socket = api_socket .get_socket (self .host , self .port ,
45
- timeout = self .socket_timeout , use_ssl = self .use_ssl , ssl_verify = self .ssl_verify , ssl_verify_hostname = self .ssl_verify_hostname , ssl_context = self .ssl_context )
49
+ self .socket = api_socket .get_socket (
50
+ self .host , self .port , timeout = self .socket_timeout , use_ssl = self .use_ssl , ssl_verify = self .ssl_verify ,
51
+ ssl_verify_hostname = self .ssl_verify_hostname , ssl_context = self .ssl_context )
46
52
base = base_api .Connection (self .socket )
47
53
communicator = api_communicator .ApiCommunicator (base )
48
54
self .api = RouterOsApi (communicator )
@@ -83,7 +89,7 @@ def login(self, login, password, plaintext_login):
83
89
login = login .encode ()
84
90
if isinstance (password , str ):
85
91
password = password .encode ()
86
- response = self .get_binary_resource ('/' ).call ('login' ,{ 'name' : login , 'password' : password })
92
+ response = self .get_binary_resource ('/' ).call ('login' , { 'name' : login , 'password' : password })
87
93
else :
88
94
response = self .get_binary_resource ('/' ).call ('login' )
89
95
if 'ret' in response .done_message :
0 commit comments