本文整理汇总了Python中Server.Server.set_hostname方法的典型用法代码示例。如果您正苦于以下问题:Python Server.set_hostname方法的具体用法?Python Server.set_hostname怎么用?Python Server.set_hostname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server.Server
的用法示例。
在下文中一共展示了Server.set_hostname方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Ssh
# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import set_hostname [as 别名]
class Ssh(QtCore.QObject):
"""
Class created by PyUML
# PyUML: Do not remove this line! # XMI_ID:_sfuNQBCnEd-9mr2Tj73dvA
# PyUML: Associations of this class:
# PyUML: Association (being 'src') to class ServersPool (being 'dst') in package /base/
# PyUML: Association (being 'dst') to class Server (being 'src') in package /base/
# PyUML: Association (being 'dst') to class Auth (being 'src') in package /base/
# PyUML: Association (being 'src') to class Monitor (being 'dst') in package /base/
"""
server = None # created by PyUML
def __init__(self, host, port, type, id = 0):
super(Ssh, self).__init__()
self.auth = None # created by PyUML
self.server = Server(host, port, type, id)
self.client = paramiko.SSHClient()
self.client.load_system_host_keys()
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.isConnected = False
self.monitoring = Monitor(self)
def __del__(self):
self.close()
def set_auth(self, login, password = 'rsa'):
self.auth = Auth(login, password)
def connect_thread(self):
try:
if self.auth.is_rsa():
self.client.connect(self.server.host, self.server.port, self.auth.login, key_filename=self.auth.get_rsa_files(), timeout=25)
else:
self.client.connect(self.server.host, self.server.port, self.auth.login, self.auth.password, timeout=25)
self.isConnected = self.client.get_transport().is_active()
if(self.isConnected):
self.client.get_transport().set_keepalive(300)
hostname, os = self.sendCommand('hostname && uname').split()
self.server.set_hostname(hostname)
self.server.set_os(os.lower())
# Emits signal that server is connected
self.emit(QtCore.SIGNAL('connected'), self)
return True
except:
# Emits signal that server is connected
self.emit_notconnected()
#self.emit(QtCore.SIGNAL('notConnected'), self)
print 'Unable to connect to %s:%s with login %s, pass %s' % (self.server.host, self.server.port, self.auth.login, self.auth.password)
QtCore.QCoreApplication.processEvents();
try:
self.client.close()
except:
pass
return False
def connect(self):
try:
self.close()
finally:
# Connect to the servers (thread-safe)
# Random avoid to fail a connection on windows when all connections
# are initialized
global connectDelay
t = Timer(connectDelay, self.connect_thread)
t.start()
connectDelay += .1
def close(self):
self.client.close()
if self.isConnected:
# Emits signal that server is connected
self.emit_notconnected()
self.isConnected = False
#self.emit(QtCore.SIGNAL('notConnected'), self)
def sendCommand(self, command):
if self.isConnected:
if not self.client.get_transport().is_active():
self.isConnected = False
# Emits signal that server is connected
self.emit_notconnected()
#self.emit(QtCore.SIGNAL('notConnected'), self)
stdin, stdout, stderr = self.client.exec_command(command)
response = stdout.read()
if response == False:
#.........这里部分代码省略.........