Package TestON :: Package drivers :: Package common :: Package cli :: Package remotetestbed :: Module remotevmdriver
[hide private]
[frames] | no frames]

Source Code for Module TestON.drivers.common.cli.remotetestbed.remotevmdriver

  1  #!/usr/bin/env python 
  2  """ 
  3  Created on 12-Feb-2013 
  4   
  5  author:: Anil Kumar ( anilkumar.s@paxterrasolutions.com ) 
  6   
  7   
  8      TestON is free software: you can redistribute it and/or modify 
  9      it under the terms of the GNU General Public License as published by 
 10      the Free Software Foundation, either version 2 of the License, or 
 11      ( at your option ) any later version. 
 12   
 13      TestON is distributed in the hope that it will be useful, 
 14      but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16      GNU General Public License for more details. 
 17   
 18      You should have received a copy of the GNU General Public License 
 19      along with TestON.  If not, see <http://www.gnu.org/licenses/>. 
 20   
 21   
 22  RemoteVMDriver is the basic driver which will handle the Mininet functions 
 23  """ 
 24  import pexpect 
 25   
 26  from drivers.common.cli.remotetestbeddriver import RemoteTestBedDriver 
 27   
 28   
29 -class RemoteVMDriver( RemoteTestBedDriver ):
30 31 """ 32 RemoteVMDriver is the basic driver which will handle the Mininet functions 33 """
34 - def __init__( self ):
35 super( RemoteTestBedDriver, self ).__init__()
36
37 - def connect( self, **connectargs ):
38 for key in connectargs: 39 vars( self )[ key ] = connectargs[ key ] 40 41 self.name = self.options[ 'name' ] 42 43 self.handle = super( 44 RemoteVMDriver, 45 self ).connect( 46 user_name=self.user_name, 47 ip_address=self.ip_address, 48 port=self.port, 49 pwd=self.pwd ) 50 if self.handle: 51 main.log.info( self.name + " connected successfully " ) 52 return self.handle 53 return main.TRUE
54
55 - def SSH( self, **connectargs ):
56 for key in connectargs: 57 vars( self )[ key ] = connectargs[ key ] 58 59 """ 60 Connection will establish to the remote host using ssh. 61 It will take user_name ,ip_address and password as arguments<br> 62 and will return the handle. 63 """ 64 for key in connectargs: 65 vars( self )[ key ] = connectargs[ key ] 66 67 ssh_newkey = 'Are you sure you want to continue connecting' 68 refused = "ssh: connect to host " + \ 69 self.ip_address + " port 22: Connection refused" 70 if self.port: 71 self.handle.sendline( 72 'ssh -p ' + 73 self.port + 74 ' ' + 75 self.user_name + 76 '@' + 77 self.ip_address ) 78 else: 79 self.handle.sendline( 80 'ssh ' + 81 self.user_name + 82 '@' + 83 self.ip_address ) 84 self.handle.sendline( "\r" ) 85 86 i = self.handle.expect( [ ssh_newkey, 87 'password:', 88 pexpect.EOF, 89 pexpect.TIMEOUT, 90 refused ], 91 120 ) 92 93 if i == 0: 94 main.log.info( "ssh key confirmation received, send yes" ) 95 self.handle.sendline( 'yes' ) 96 i = self.handle.expect( [ ssh_newkey, 'password:', pexpect.EOF ] ) 97 if i == 1: 98 main.log.info( "ssh connection asked for password, gave password" ) 99 self.handle.sendline( self.pwd ) 100 self.handle.expect( '>|#|$' ) 101 102 elif i == 2: 103 main.log.error( "Connection timeout" ) 104 return main.FALSE 105 elif i == 3: # timeout 106 main.log.error( 107 "No route to the Host " + 108 self.user_name + 109 "@" + 110 self.ip_address ) 111 return main.FALSE 112 elif i == 4: 113 main.log.error( 114 "ssh: connect to host " + 115 self.ip_address + 116 " port 22: Connection refused" ) 117 return main.FALSE 118 119 self.handle.sendline( "\r" ) 120 return main.TRUE
121