<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import , print_function <EOL> import logging <EOL> try : <EOL> import paramiko <EOL> HAS_PARAMIKO = True <EOL> except ImportError : <EOL> HAS_PARAMIKO = False <EOL> log = logging . getLogger ( __name__ ) <EOL> def __virtual__ ( ) : <EOL> if HAS_PARAMIKO : <EOL> return True <EOL> return False <EOL> def __connect ( hostname , timeout = <NUM_LIT:20> , username = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> if not username : <EOL> username = __opts__ [ '<STR_LIT>' ] . get ( '<STR_LIT:username>' , None ) <EOL> if not password : <EOL> password = __opts__ [ '<STR_LIT>' ] . get ( '<STR_LIT:password>' , None ) <EOL> client = paramiko . SSHClient ( ) <EOL> client . set_missing_host_key_policy ( paramiko . AutoAddPolicy ( ) ) <EOL> try : <EOL> client . connect ( hostname , username = username , password = password , timeout = timeout ) <EOL> except Exception as e : <EOL> log . error ( '<STR_LIT>' . format ( hostname , e ) ) <EOL> return False <EOL> return client <EOL> def __version ( client ) : <EOL> '''<STR_LIT>''' <EOL> versions = { <NUM_LIT:9> : '<STR_LIT>' , <EOL> <NUM_LIT:8> : '<STR_LIT>' , <EOL> <NUM_LIT:10> : '<STR_LIT>' , <EOL> <NUM_LIT:11> : '<STR_LIT>' , <EOL> <NUM_LIT:16> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' } <EOL> if isinstance ( client , paramiko . SSHClient ) : <EOL> ( stdin , stdout , stderr ) = client . exec_command ( '<STR_LIT>' ) <EOL> for i in stdout . readlines ( ) : <EOL> if i [ <NUM_LIT:2> : ] . startswith ( '<STR_LIT>' ) : <EOL> return versions . get ( int ( i [ <NUM_LIT:2> : ] . split ( '<STR_LIT:=>' ) [ <NUM_LIT:1> ] ) , None ) <EOL> return None <EOL> def pxe ( hostname , timeout = <NUM_LIT:20> , username = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> _cmds = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> client = __connect ( hostname , timeout , username , password ) <EOL> if isinstance ( client , paramiko . SSHClient ) : <EOL> for i , cmd in enumerate ( _cmds , <NUM_LIT:1> ) : <EOL> log . info ( '<STR_LIT>' . format ( i ) ) <EOL> ( stdin , stdout , stderr ) = client . exec_command ( cmd ) <EOL> if '<STR_LIT>' in stdout . readline ( ) : <EOL> log . info ( '<STR_LIT>' . format ( cmd ) ) <EOL> else : <EOL> log . error ( '<STR_LIT>' . format ( cmd ) ) <EOL> return False <EOL> return True <EOL> def reboot ( hostname , timeout = <NUM_LIT:20> , username = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> client = __connect ( hostname , timeout , username , password ) <EOL> if isinstance ( client , paramiko . SSHClient ) : <EOL> ( stdin , stdout , stderr ) = client . exec_command ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in stdout . readline ( ) : <EOL> log . info ( '<STR_LIT>' ) <EOL> else : <EOL> log . error ( '<STR_LIT>' ) <EOL> return False <EOL> else : <EOL> log . error ( '<STR_LIT>' ) <EOL> return False <EOL> return True <EOL> def poweroff ( hostname , timeout = <NUM_LIT:20> , username = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> client = __connect ( hostname , timeout , username , password ) <EOL> if isinstance ( client , paramiko . SSHClient ) : <EOL> ( stdin , stdout , stderr ) = client . exec_command ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in stdout . readline ( ) : <EOL> log . info ( '<STR_LIT>' ) <EOL> else : <EOL> log . error ( '<STR_LIT>' ) <EOL> return False <EOL> else : <EOL> log . error ( '<STR_LIT>' ) <EOL> return False <EOL> return True <EOL> def poweron ( hostname , timeout = <NUM_LIT:20> , username = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> client = __connect ( hostname , timeout , username , password ) <EOL> if isinstance ( client , paramiko . SSHClient ) : <EOL> ( stdin , stdout , stderr ) = client . exec_command ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in stdout . readline ( ) : <EOL> log . info ( '<STR_LIT>' ) <EOL> else : <EOL> log . error ( '<STR_LIT>' ) <EOL> return False <EOL> else : <EOL> log . error ( '<STR_LIT>' ) <EOL> return False <EOL> return True <EOL> def version ( hostname , timeout = <NUM_LIT:20> , username = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> return __version ( __connect ( hostname , timeout , username , password ) ) </s>
