def set_connection(self, connection_type=constants.ConnectionType.SSH, username=None, password=None): ''' Sometimes for special target we need to change its connection type dynamically, for example, we make default connection type as SSH for ESX, but for some special operation like set_nsx_manager, we need to use EXPECT connection to register hosts, in thus scenario, we need to temporary change its connection type, after use it we should restore its default connection type by calling restore_connection method. @type connection_type: ssh | expect @param connection_type: connection type you wan to change dynamically, currently only 'expect' and 'ssh' types are suppported ''' if username is None: username = self.username if password is None: password = self.password if connection_type == constants.ConnectionType.EXPECT: self._connection = expect_connection.ExpectConnection( ip=self.ip, username=username, password=password) elif connection_type == constants.ConnectionType.SSH: self._connection = ssh_connection.SSHConnection(ip=self.ip, username=username, password=password) else: raise ValueError("Currently only 'ssh' and 'expect' " "connection_types are supported, but you " "passed %r" % connection_type)
def os_version(self): if self._os_version: return self._os_version connection = ssh_connection.SSHConnection(ip=self.ip, username=self.username, password=self.password) connection.create_connection() raw_data = connection.request('lsb_release -a').response_data connection.close() lsb_info = utilities.procinfo_to_dict(raw_data) os_key = '%s' % lsb_info['Distributor ID'] self._os_version = self.os_map.get(os_key, None) if not self._os_version: raise ValueError('%r is not supported' % os_key) return self._os_version
def os_version(self): if self._os_version: return self._os_version connection = ssh_connection.SSHConnection(ip=self.ip, username=self.username, password=self.password) connection.create_connection() raw_data = connection.request('lsb_release -a').response_data connection.close() lsb_info = utilities.procinfo_to_dict(raw_data) if lsb_info['Distributor ID'] is None: raise ValueError("Distributor ID on Linux platform is %r" % lsb_info['Distributor ID']) os_key = '%s' % lsb_info['Distributor ID'] self._os_version = self.os_map.get(os_key) if not self._os_version: raise ValueError("Linux platform %r is currently not supported" % os_key) return self._os_version
def get_connection(self): return ssh_connection.SSHConnection( self.ip, self.username, self.password)
def get_connection(self): return ssh_connection.SSHConnection( ip=self.ip, username=self.username, password=self.password)
def get_connection(self): # the connection object can be ssh or pexpect # depending on the product's cli implementation return ssh_connection.SSHConnection( self.ip, self.username, self.password)