2424
2525@fix_docs
2626class ASADevice (BaseDevice ):
27-
28- def __init__ (self , host , username , password , secret = '' , port = 22 , ** kwargs ):
29- super (ASADevice , self ).__init__ (host , username , password ,
30- vendor = 'cisco' ,
31- device_type = 'cisco_asa_ssh' )
27+ def __init__ (self , host , username , password , secret = "" , port = 22 , ** kwargs ):
28+ super (ASADevice , self ).__init__ (host , username , password , vendor = "cisco" , device_type = "cisco_asa_ssh" )
3229
3330 self .native = None
3431 self .host = host
3532 self .username = username
3633 self .password = password
3734 self .secret = secret
3835 self .port = int (port )
39- self .global_delay_factor = kwargs .get (' global_delay_factor' , 1 )
40- self .delay_factor = kwargs .get (' delay_factor' , 1 )
36+ self .global_delay_factor = kwargs .get (" global_delay_factor" , 1 )
37+ self .delay_factor = kwargs .get (" delay_factor" , 1 )
4138 self ._connected = False
4239 self .open ()
4340
@@ -50,7 +47,7 @@ def _enter_config(self):
5047 self ._enable ()
5148 self .native .config_mode ()
5249
53- def _file_copy_instance (self , src , dest = None , file_system = ' flash:' ):
50+ def _file_copy_instance (self , src , dest = None , file_system = " flash:" ):
5451 if dest is None :
5552 dest = os .path .basename (src )
5653
@@ -66,9 +63,9 @@ def _get_file_system(self):
6663 Raises:
6764 FileSystemNotFound: When the module is unable to determine the default file system.
6865 """
69- raw_data = self .show (' dir' )
66+ raw_data = self .show (" dir" )
7067 try :
71- file_system = re .match (r' \s*.*?(\S+:)' , raw_data ).group (1 )
68+ file_system = re .match (r" \s*.*?(\S+:)" , raw_data ).group (1 )
7269 return file_system
7370 except AttributeError :
7471 # TODO: Get proper hostname
@@ -82,51 +79,46 @@ def _image_booted(self, image_name, **vendor_specifics):
8279 return False
8380
8481 def _interfaces_detailed_list (self ):
85- ip_int = self .show ('show interface' )
86- ip_int_data = get_structured_data ('cisco_asa_show_interface.template' ,
87- ip_int )
82+ ip_int = self .show ("show interface" )
83+ ip_int_data = get_structured_data ("cisco_asa_show_interface.template" , ip_int )
8884
8985 return ip_int_data
9086
9187 def _is_catalyst (self ):
92- return self .facts [' model' ].startswith (' WS-' )
88+ return self .facts [" model" ].startswith (" WS-" )
9389
9490 def _raw_version_data (self ):
95- show_version_out = self .show (' show version' )
91+ show_version_out = self .show (" show version" )
9692 try :
97- version_data = \
98- get_structured_data ('cisco_asa_show_version.template' ,
99- show_version_out )[0 ]
93+ version_data = get_structured_data ("cisco_asa_show_version.template" , show_version_out )[0 ]
10094 return version_data
10195 except IndexError :
10296 return {}
10397
104- def _send_command (self , command , expect = False , expect_string = '' ):
98+ def _send_command (self , command , expect = False , expect_string = "" ):
10599 if expect :
106100 if expect_string :
107- response = self .native .send_command_expect (command ,
108- expect_string = expect_string )
101+ response = self .native .send_command_expect (command , expect_string = expect_string )
109102 else :
110103 response = self .native .send_command_expect (command )
111104 else :
112105 response = self .native .send_command_timing (command )
113106
114- if '% ' in response or ' Error:' in response :
107+ if "% " in response or " Error:" in response :
115108 raise CommandError (command , response )
116109
117110 return response
118111
119112 def _show_vlan (self ):
120- show_vlan_out = self .show ('show vlan' )
121- show_vlan_data = get_structured_data ('cisco_ios_show_vlan.template' ,
122- show_vlan_out )
113+ show_vlan_out = self .show ("show vlan" )
114+ show_vlan_data = get_structured_data ("cisco_ios_show_vlan.template" , show_vlan_out )
123115
124116 return show_vlan_data
125117
126118 def _uptime_components (self , uptime_full_string ):
127- match_days = re .search (r' (\d+) days?' , uptime_full_string )
128- match_hours = re .search (r' (\d+) hours?' , uptime_full_string )
129- match_minutes = re .search (r' (\d+) minutes?' , uptime_full_string )
119+ match_days = re .search (r" (\d+) days?" , uptime_full_string )
120+ match_hours = re .search (r" (\d+) hours?" , uptime_full_string )
121+ match_minutes = re .search (r" (\d+) minutes?" , uptime_full_string )
130122
131123 days = int (match_days .group (1 )) if match_days else 0
132124 hours = int (match_hours .group (1 )) if match_hours else 0
@@ -145,7 +137,7 @@ def _uptime_to_seconds(self, uptime_full_string):
145137
146138 def _uptime_to_string (self , uptime_full_string ):
147139 days , hours , minutes = self ._uptime_components (uptime_full_string )
148- return ' %02d:%02d:%02d:00' % (days , hours , minutes )
140+ return " %02d:%02d:%02d:00" % (days , hours , minutes )
149141
150142 def _wait_for_device_reboot (self , timeout = 3600 ):
151143 start = time .time ()
@@ -160,7 +152,7 @@ def _wait_for_device_reboot(self, timeout=3600):
160152 raise RebootTimeoutError (hostname = self .host , wait_time = timeout )
161153
162154 def backup_running_config (self , filename ):
163- with open (filename , 'w' ) as f :
155+ with open (filename , "w" ) as f :
164156 f .write (self .running_config )
165157
166158 def checkpoint (self , checkpoint_file ):
@@ -184,8 +176,7 @@ def config_list(self, commands):
184176 try :
185177 self ._send_command (command )
186178 except CommandError as e :
187- raise CommandListError (
188- entered_commands , command , e .cli_error_msg )
179+ raise CommandListError (entered_commands , command , e .cli_error_msg )
189180 self .native .exit_config_mode ()
190181
191182 @property
@@ -214,8 +205,7 @@ def file_copy(self, src, dest=None, file_system=None):
214205
215206 if not self .file_copy_remote_exists (src , dest , file_system ):
216207 raise FileTransferError (
217- message = "Attempted file copy, "
218- "but could not validate file existed after transfer"
208+ message = "Attempted file copy, but could not validate file existed after transfer"
219209 )
220210
221211 # TODO: Make this an internal method since exposing file_copy should be sufficient
@@ -230,9 +220,9 @@ def file_copy_remote_exists(self, src, dest=None, file_system=None):
230220 return False
231221
232222 def get_boot_options (self ):
233- show_boot_out = self .show (' show boot | i BOOT variable' )
223+ show_boot_out = self .show (" show boot | i BOOT variable" )
234224 # Improve regex to get only the first boot $var in the sequence!
235- boot_path_regex = r' Current BOOT variable = (\S+):\/(\S+)'
225+ boot_path_regex = r" Current BOOT variable = (\S+):\/(\S+)"
236226
237227 match = re .search (boot_path_regex , show_boot_out )
238228 if match :
@@ -263,56 +253,59 @@ def open(self):
263253 self ._connected = False
264254
265255 if not self ._connected :
266- self .native = ConnectHandler (device_type = 'cisco_asa' ,
267- ip = self .host ,
268- username = self .username ,
269- password = self .password ,
270- port = self .port ,
271- global_delay_factor = self .global_delay_factor ,
272- secret = self .secret ,
273- verbose = False )
256+ self .native = ConnectHandler (
257+ device_type = "cisco_asa" ,
258+ ip = self .host ,
259+ username = self .username ,
260+ password = self .password ,
261+ port = self .port ,
262+ global_delay_factor = self .global_delay_factor ,
263+ secret = self .secret ,
264+ verbose = False ,
265+ )
274266 self ._connected = True
275267
276268 def reboot (self , timer = 0 , confirm = False ):
277269 if confirm :
270+
278271 def handler (signum , frame ):
279- raise RebootSignal (' Interrupting after reload' )
272+ raise RebootSignal (" Interrupting after reload" )
280273
281274 signal .signal (signal .SIGALRM , handler )
282275 signal .alarm (10 )
283276
284277 try :
285278 if timer > 0 :
286- first_response = self .show (' reload in %d' % timer )
279+ first_response = self .show (" reload in %d" % timer )
287280 else :
288- first_response = self .show (' reload' )
281+ first_response = self .show (" reload" )
289282
290- if ' System configuration' in first_response :
291- self .native .send_command_timing ('no' )
283+ if " System configuration" in first_response :
284+ self .native .send_command_timing ("no" )
292285
293- self .native .send_command_timing (' \n ' )
286+ self .native .send_command_timing (" \n " )
294287 except RebootSignal :
295288 signal .alarm (0 )
296289
297290 signal .alarm (0 )
298291 else :
299- print (' Need to confirm reboot with confirm=True' )
292+ print (" Need to confirm reboot with confirm=True" )
300293
301294 def rollback (self , rollback_to ):
302295 raise NotImplementedError
303296
304297 @property
305298 def running_config (self ):
306- return self .show (' show running-config' , expect = True )
299+ return self .show (" show running-config" , expect = True )
307300
308- def save (self , filename = ' startup-config' ):
309- command = ' copy running-config %s' % filename
301+ def save (self , filename = " startup-config" ):
302+ command = " copy running-config %s" % filename
310303 # Changed to send_command_timing to not require a direct prompt return.
311304 self .native .send_command_timing (command )
312305 # If the user has enabled 'file prompt quiet' which dose not require any confirmation or feedback.
313306 # This will send return without requiring an OK.
314- # Send a return to pass the [OK]? message - Incease delay_factor for looking for response.
315- self .native .send_command_timing (' \n ' , delay_factor = 2 )
307+ # Send a return to pass the [OK]? message - Increase delay_factor for looking for response.
308+ self .native .send_command_timing (" \n " , delay_factor = 2 )
316309 # Confirm that we have a valid prompt again before returning.
317310 self .native .find_prompt ()
318311 return True
@@ -327,7 +320,9 @@ def set_boot_options(self, image_name, **vendor_specifics):
327320 if re .search (image_name , file_system_files ) is None :
328321 raise NTCFileNotFoundError (
329322 # TODO: Update to use hostname
330- hostname = self .host , file = image_name , dir = file_system
323+ hostname = self .host ,
324+ file = image_name ,
325+ dir = file_system ,
331326 )
332327
333328 current_images = current_boot .splitlines ()
@@ -342,10 +337,9 @@ def set_boot_options(self, image_name, **vendor_specifics):
342337 message = "Setting boot command did not yield expected results" ,
343338 )
344339
345- def show (self , command , expect = False , expect_string = '' ):
340+ def show (self , command , expect = False , expect_string = "" ):
346341 self ._enable ()
347- return self ._send_command (command , expect = expect ,
348- expect_string = expect_string )
342+ return self ._send_command (command , expect = expect , expect_string = expect_string )
349343
350344 def show_list (self , commands ):
351345 self ._enable ()
@@ -357,14 +351,13 @@ def show_list(self, commands):
357351 try :
358352 responses .append (self ._send_command (command ))
359353 except CommandError as e :
360- raise CommandListError (entered_commands , command ,
361- e .cli_error_msg )
354+ raise CommandListError (entered_commands , command , e .cli_error_msg )
362355
363356 return responses
364357
365358 @property
366359 def startup_config (self ):
367- return self .show (' show startup-config' )
360+ return self .show (" show startup-config" )
368361
369362
370363class RebootSignal (NTCError ):
0 commit comments