39
39
40
40
logger = get_logger (__name__ )
41
41
42
+ def ipsec_exists ():
43
+ """
44
+ Verifies if ipsec is existing in the os
45
+ :return: a boolean: True if ipsec exists, false otherwise
46
+ """
47
+ (_ , err ) = Popen (["sudo" , "ipsec" , "--version" ], stdout = PIPE , stderr = PIPE ).communicate ()
48
+ if "not found" in err :
49
+ return False
50
+
51
+ return True
52
+
42
53
43
54
def __ikev2_save_credentials__ (username , password ):
44
55
"""
@@ -143,7 +154,7 @@ def ikev2_is_running():
143
154
"""
144
155
145
156
args = ['sudo' , 'ipsec' , 'status' ]
146
- ipsec_stop_command = Popen (args , stdout = PIPE , universal_newlines = True )
157
+ ipsec_stop_command = Popen (args , stdout = PIPE , stderr = PIPE , universal_newlines = True )
147
158
(out , _ ) = ipsec_stop_command .communicate ()
148
159
149
160
if 'ESTABLISHED' in out :
@@ -158,7 +169,7 @@ def __ikev2_ipsec_reload__():
158
169
restarts ipsec (used to load saved settings)
159
170
"""
160
171
args = ['sudo' , 'ipsec' , 'reload' ]
161
- (out , _ ) = Popen (args , stdout = PIPE ).communicate ()
172
+ (out , _ ) = Popen (args , stdout = PIPE , universal_newlines = True ).communicate ()
162
173
163
174
if 'not running' in out :
164
175
Popen (['sudo' , 'ipsec' , 'start' ]).communicate ()
0 commit comments