22Authors:
3344"""
5-
5+ import re
66from unicon .eal .dialogs import Dialog
77from unicon .bases .routers .connection_provider import BaseStackRpConnectionProvider
88
99from unicon .plugins .generic .statements import connection_statement_list , custom_auth_statements
1010
11-
1211class StackwiseVirtualConnectionProvider (BaseStackRpConnectionProvider ):
1312 """ Implements Stack Connection Provider,
1413 This class overrides the base class with the
@@ -49,9 +48,11 @@ def designate_handles(self):
4948 con .log .debug ('{} in state: {}' .format (subcon .alias , subcon .state_machine .current_state ))
5049
5150 if subcon1 .state_machine .current_state == 'enable' :
51+ target_con = subcon1
5252 target_alias = subcon1_alias
5353 other_alias = subcon2_alias
5454 elif subcon2 .state_machine .current_state == 'enable' :
55+ target_con = subcon2
5556 target_alias = subcon2_alias
5657 other_alias = subcon1_alias
5758
@@ -60,7 +61,6 @@ def designate_handles(self):
6061 con ._handles_designated = True
6162
6263 device = con .device
63-
6464 try :
6565 # To check if the device is in SVL state
6666 output = device .parse ("show switch" )
@@ -72,7 +72,23 @@ def designate_handles(self):
7272 # There are case when in non-SVL the device connection
7373 # becomes active for both connection and there isn't a standby state
7474 # it would have either active and member state or just active state
75- super ().designate_handles ()
75+
76+ # Verify the active and standby
77+ target_con .spawn .sendline (target_con .spawn .settings .SHOW_REDUNDANCY_CMD )
78+ output = target_con .spawn .expect (
79+ target_con .state_machine .get_state ('enable' ).pattern ,
80+ timeout = con .settings .EXEC_TIMEOUT ).match_output
81+
82+ state = re .findall (target_con .spawn .settings .REDUNDANCY_STATE_PATTERN , output , flags = re .M )
83+ target_con .log .debug (f'{ target_con .spawn } state: { state } ' )
84+ if any ('active' in s .lower () for s in state ):
85+ con ._set_active_alias (target_alias )
86+ con ._set_standby_alias (other_alias )
87+ elif any ('standby' in s .lower () for s in state ):
88+ con ._set_standby_alias (target_alias )
89+ con ._set_active_alias (other_alias )
90+ else :
91+ raise ConnectionError ('unable to designate handles' )
7692
7793 except Exception :
7894 con .log .exception ("Failed to designate handle for SVL stack" )
0 commit comments