<s> """<STR_LIT>""" <EOL> import os <EOL> import pexpect <EOL> import gflags <EOL> import logging <EOL> import base_device <EOL> import pexpect_connection <EOL> import push_exceptions as exceptions <EOL> FLAGS = gflags . FLAGS <EOL> gflags . DEFINE_float ( '<STR_LIT>' , None , <EOL> '<STR_LIT>' ) <EOL> gflags . DEFINE_float ( '<STR_LIT>' , None , <EOL> '<STR_LIT>' ) <EOL> gflags . DEFINE_float ( '<STR_LIT>' , None , <EOL> '<STR_LIT>' ) <EOL> gflags . DEFINE_float ( '<STR_LIT>' , None , <EOL> '<STR_LIT>' ) <EOL> gflags . DEFINE_float ( '<STR_LIT>' , None , <EOL> '<STR_LIT>' ) <EOL> INVALID_OUT1 = "<STR_LIT>" <EOL> INVALID_OUT2 = '<STR_LIT>' <EOL> class ArubaDevice ( base_device . BaseDevice ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . vendor_name = '<STR_LIT>' <EOL> super ( ArubaDevice , self ) . __init__ ( ** kwargs ) <EOL> self . _success = r'<STR_LIT>' <EOL> def _Connect ( self , username , password = None , ssh_keys = None , <EOL> enable_password = None , ssl_cert_set = None ) : <EOL> _ = enable_password , ssl_cert_set <EOL> self . _connection = pexpect_connection . ParamikoSshConnection ( <EOL> self . loopback_ipv4 , username , password , self . _success , <EOL> timeout = self . timeout_connect , find_prompt = True , ssh_keys = ssh_keys ) <EOL> try : <EOL> self . _connection . Connect ( ) <EOL> self . _DisablePager ( ) <EOL> self . connected = True <EOL> except pexpect_connection . ConnectionError as e : <EOL> self . connected = False <EOL> raise exceptions . ConnectError ( e ) <EOL> except pexpect_connection . TimeoutError as e : <EOL> self . connected = False <EOL> raise exceptions . ConnectError ( '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> ( self . host , self . loopback_ipv4 , str ( e ) ) ) <EOL> def _Cmd ( self , command , mode = None ) : <EOL> def SendAndWait ( command ) : <EOL> """<STR_LIT>""" <EOL> self . _connection . child . send ( command + '<STR_LIT:\r>' ) <EOL> self . _connection . child . expect ( '<STR_LIT:\r\n>' , timeout = self . timeout_response ) <EOL> self . _connection . child . expect ( self . _connection . re_prompt , <EOL> timeout = self . timeout_response , <EOL> searchwindowsize = <NUM_LIT> ) <EOL> return self . _connection . child . before . replace ( '<STR_LIT:\r\n>' , os . linesep ) <EOL> _ = mode <EOL> command = command . replace ( '<STR_LIT:?>' , '<STR_LIT>' ) <EOL> result = '<STR_LIT>' <EOL> try : <EOL> result = SendAndWait ( command ) <EOL> except pexpect . TIMEOUT as e : <EOL> self . connected = False <EOL> raise exceptions . CmdError ( '<STR_LIT>' % ( e . __class__ , str ( e ) ) ) <EOL> except pexpect . EOF : <EOL> try : <EOL> self . connected = False <EOL> self . _connection . Connect ( ) <EOL> self . _DisablePager ( ) <EOL> self . connected = True <EOL> result = SendAndWait ( command ) <EOL> except pexpect . EOF : <EOL> raise exceptions . CmdError ( '<STR_LIT>' ) <EOL> except pexpect_connection . ConnectionError as e : <EOL> raise exceptions . CmdError ( '<STR_LIT>' % e ) <EOL> except pexpect_connection . TimeoutError as e : <EOL> raise exceptions . CmdError ( '<STR_LIT>' % e ) <EOL> if result and result [ - <NUM_LIT:1> ] == '<STR_LIT:\r>' : <EOL> result = result [ : - <NUM_LIT:1> ] + '<STR_LIT:\n>' <EOL> if result . endswith ( INVALID_OUT1 ) or result . startswith ( INVALID_OUT2 ) : <EOL> raise exceptions . CmdError ( '<STR_LIT>' % result ) <EOL> return result <EOL> def _Disconnect ( self ) : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> try : <EOL> self . _connection . child . send ( '<STR_LIT>' ) <EOL> self . _connection . child . expect ( self . _success , <EOL> timeout = self . timeout_act_user ) <EOL> self . _connection . child . send ( '<STR_LIT>' ) <EOL> self . _connection . child . expect ( self . _connection . exit_list , <EOL> timeout = self . timeout_act_user ) <EOL> self . connected = False <EOL> except ( pexpect . EOF , pexpect . TIMEOUT ) as e : <EOL> self . connected = False <EOL> raise exceptions . DisconnectError ( '<STR_LIT>' % ( e . __class__ , str ( e ) ) ) <EOL> def _DisablePager ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . _connection . child . send ( '<STR_LIT>' ) <EOL> self . _connection . child . expect ( self . _connection . re_prompt , <EOL> timeout = self . timeout_connect , <EOL> searchwindowsize = <NUM_LIT> ) <EOL> except ( pexpect . EOF , pexpect . TIMEOUT ) as e : <EOL> self . connected = False <EOL> raise exceptions . ConnectError ( '<STR_LIT>' % ( e . __class__ , str ( e ) ) ) <EOL> logging . debug ( '<STR_LIT>' ) </s>
