本文整理汇总了Python中pxssh.pxssh函数的典型用法代码示例。如果您正苦于以下问题:Python pxssh函数的具体用法?Python pxssh怎么用?Python pxssh使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pxssh函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, user='sa', host='jj.ax.lt', pswd='', remote=False):
#Instance variables
#self.startupScript = '/Users/jack/.mcserver/start.sh'
self.startupScript = '/home/sa/bukkit/minecraft.sh'
self.bukkitDir = os.path.split(self.startupScript)[0]
self.remote=remote
self.user=user
self.host=host
self.pswd=pswd
if remote:
self.remoteStatusPX = pxssh.pxssh()
self.remoteStatusPX.login(host, user, pswd)
#Check the server status. If it is already running, resume it
if self.status():
print 'Resuming already running server.'
if self.remote:
self.mcServer = pxssh.pxssh()
self.mcServer.login(self.host, self.user, self.pswd)
self.mcServer.sendline('screen -rd mc')
else:
self.mcServer = pexpect.spawn('screen -rd mc')
else:
print 'Server not running. Start with myServer.start()'
示例2: __init__
def __init__(self, user=None, password=None, host=None, logfile=None, environment=None, verbose=False,
virtualenv=None, working_dir=None):
"""
:param user: the remote user account
:type user: str
:param password: the password for the remote user account
:type password: str
:param host: the remote machine
:type host: str
:param logfile: optional logfile
:type logfile: str
:param environment: Optional key to Project.prefix and Project.postfix dictionaries
:type environment: str
:param verbose: extra logging
:type verbose: bool
:param virtualenv: directory that contains a virtual environment to activate upon connection
:type virtualenv: str
"""
super(RemoteShell, self).__init__(is_remote=True, verbose=verbose)
if not user:
user = Project.user
if not host:
host = Project.address
Project.user = user
Project.password = password
Project.address = host
self.ssh = pxssh(timeout=1200)
try:
if password:
self.ssh.login(host, user, password)
else:
self.ssh.login(host, user)
except ExceptionPxssh:
if not password:
password = Project.password
if not password:
password = getpass('password for {user}@{host}: '.format(user=user, host=host))
self.ssh.close()
self.ssh = pxssh(timeout=1200)
self.ssh.login(host, user, password)
self.accept_defaults = False
self.logfile = logfile
self.prefix = []
self.postfix = []
if environment:
self.prefix.extend(Project.prefix[environment] or [])
self.postfix.extend(Project.postfix[environment] or [])
if working_dir:
self.prefix.insert(0, "cd {dir} ; ".format(dir=working_dir))
if virtualenv:
self.prefix.insert(0, "source {path}/bin/activate ; ".format(path=virtualenv))
示例3: __init__
def __init__(self, username, password, hostname="127.0.0.1"):
self.username = username
self.password = password
self.hostname = hostname
self.process = pxssh.pxssh()
self.process.login(hostname, username, password)
示例4: node_reboot
def node_reboot(tokenid, hostname, username, password, ip_address=''):
if ip_address == '':
nicinfo = node_nic_info(tokenid, hostname)
ip_address = nicinfo.get_ip_address(nicinfo.M_PLANE)
if (ip_address == -1):
print '#### node_reboot get_nic Error'
return -1
try:
s2 = pxssh.pxssh()
s2.login(ip_address, username, password)
s2.sendline('sudo reboot')
s2.expect('.*password for .*', timeout=2*600)
s2.sendline(password)
s2.prompt()
s2.logout()
return 0
except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)
print "use bmc reboot."
ret = bmc_reboot(tokenid, hostname)
return ret
示例5: executeCommand
def executeCommand(command,master = True):
ollin = pxssh.pxssh()
if not ollin.login('ollin.fisica.unam.mx','root'):
print "ssh session failed longin"
print str(ollin)
else:
print "ssh session login successful"
if master == False:
for i in range(1,3):
ollin.sendline('ssh [email protected]'+str(i))
ollin.sendline(command)
ollin.prompt()
print ollin.before
else:
ollin.sendline(command)
for i in range(1,3):
ollin.sendline('ssh [email protected]'+str(i))
ollin.sendline(command)
ollin.prompt()
print ollin.before
ollin.logout()
示例6: verify_control
def verify_control(self, targetnode_ip):
result = True
handle = pxssh.pxssh()
ip = targetnode_ip
login = "root"
passwd = 'c0ntrail123'
prompt = "#"
try:
ret = handle.login (ip,login,passwd,original_prompt=prompt, login_timeout=1000,auto_prompt_reset=False)
except:
pass
cmd = "contrail-status"
output = send_cmd(handle,cmd,prompt,120)
pattern = ["supervisor-control: active",
"contrail-control active",
"contrail-control-nodemgr active",
"contrail-dns active",
"contrail-named active"]
for line in pattern:
if line not in output:
print 'verify %s has Failed' %line
result = result and False
print "result of verify_control %s"%result
assert result
return result
示例7: __init__
def __init__(self,_host,_user,_psw,_port=None) :
self.host = _host
self.user = _user
self.psw = _psw
self.port = _port
self.ssh = pxssh.pxssh()
self.login = False
示例8: connect
def connect(host, user, password, release):
global Found
global Fails
# debugging shows thread name and hex location
# print current_thread()
# attempt login with pxssh
try:
s = pxssh.pxssh()
s.login(host, user, password)
print '[+] Password Found: ' + password
Found = True
# error check
except Exception, e:
# if read_nonblocking si thrown
if 'read_nonblocking' in str(e):
# debugging print 'in fail 1'
Fails += 1
time.sleep(5)
connect(host, user, password, False)
# if synchronize with original prompt is thrown
elif 'synchronize with original prompt' in str(e):
# debugging print 'in fail 2'
time.sleep(1)
connect(host, user, password, False)
示例9: main
def main():
s = pxssh.pxssh()
hostname = raw_input('host-ip (without last number): ')
username = raw_input('username: ')
password = getpass.getpass('password: ')
cl = address(username,hostname,password)
for i in range(256):
print i,":"
try:
s.login (cl.us,cl.ip,cl.pwd)
except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)
cl.next_ip
pass
print "Login Success"
s.sendline ('uptime') # run a command
s.prompt() # match the prompt
print s.before # print everything before the prompt.
s.sendline ('ls -l')
s.prompt()
print s.before
s.sendline ('df')
s.prompt()
print s.before
s.logout()
示例10: run
def run(self):
self.setName(self.server_name_) # set the name of thread
try:
s = pxssh.pxssh(options={
"StrictHostKeyChecking": "no",
"UserKnownHostsFile": "/dev/null"})
#s = pxssh.pxssh()
#s.SSH_OPTS += " -o StrictHostKeyChecking=no UserKnownHostsFile=/dev/null"
s.login (self.server_name_,self.user_, self.passwd_, original_prompt='[$#>]')
s.sendline ('hostname;uptime')
#s.prompt()
#ret = s.before
print(s.before)
s.logout()
ret = 0
print('ret: 0')
except pxssh.ExceptionPxssh as e:
#except:
ret = 1
print("pxssh failed on login: ")
#print(e)
print('ret: 1')
self.result_= ret
return self.result_
示例11: sendStartupRequest
def sendStartupRequest(self, entry):
#''' ===== still have prombles I need to debug ===== '''
print("Send request to {addr}".format(addr=entry.strAddr()))
script_dir = "/mnt/images/nfs/new_roystonea_script/roystonea_script/"
script_file = self.convnameType2Script(entry.level)
script_ab_file = script_dir + script_file
log_ab_file = script_dir + "log/{host}-{port}-printout.txt".format(host=entry.host, port=entry.port)
ssh_cmd = "nohup python {script_absolute_filepath} {host} {port} console_off > {log_ab} &".format(
script_absolute_filepath=script_ab_file, host=entry.host, port=entry.port, log_ab=log_ab_file
)
print(ssh_cmd)
account = "ot32em"
passwd = ""
remote = pxssh.pxssh()
t = remote.login(entry.host, account, passwd)
print("Login done")
remote.sendline(ssh_cmd)
remote.prompt()
remote.logout()
print("Update the PM Relation to {host}:{port}.".format(host=entry.host, port=entry.port))
entry.dump_pretty()
req = Message.CmdUpdatePMRelationReq(pm_relation=entry)
res = Client.send_message(entry.addr, req)
示例12: execute_command
def execute_command(username, password, hostname, command, password=1):
try:
s = pxssh.pxssh()
s.login (hostname, username, password)
print "Repl Leader: "
s.sendline ('riak-repl status | grep "leader: \'"')
s.expect(["password for " + username + ":"])
s.sendline (password)
s.prompt()
print s.before
print "Riak Ping: "
s.sendline ('riak ping')
s.prompt()
print s.before
print "Disk Space: "
s.sendline ('du --max-depth=1 -h /var/lib/riak/')
s.prompt()
print s.before
s.logout()
except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)
示例13: ssh
def ssh(self):
"""Handle SSH login to a host"""
#log.debug('We made it into the SSH function')
#log.debug('instantiating the pxssh object')
self.ses = pxssh.pxssh()
#print 'we just created a pxssh object'
"""
log.debug('The credentials to be used are:')
log_msg = 'host:', self.host
log.debug(log_msg)
log_msg = 'Username:', self.username
log.debug(log_msg)
log_msg = 'Password:', self.passwd
log.debug(log_msg)
"""
try:
log_msg = 'Trying to login to host: ' + self.host + ' as user: ' + self.username\
+ ' with password: ' + self.passwd
log.info(log_msg)
#print 'This is after the log message'
print "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
self.ses.login(self.host, self.username, self.passwd)
print "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
print self.ses.before
except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)
示例14: set_switch_mirroring
def set_switch_mirroring(switch_IP,mirrored_port,monitoring_port):
time_lasting_start=time.time()
print '\r\nPlease wait a minute,it is connecting to the switch...'
#login to the switch of being set to mirror
myssh = pxssh.pxssh()
myssh.login1(server=switch_IP,username=username,password=pwd)
if ('10.0.3' in switch_IP):
myssh.sendline('configure')
time.sleep(0.1)
print 'Ports mirrored:'
for c in mirrored_port:
if c!= int(monitoring_port):
print 'ge-1/1/'+str(c),
myssh.sendline('set interface ethernet-switching-options analyzer 1 input egress ge-1/1/'+str(c))
time.sleep(0.1)
myssh.sendline('set interface ethernet-switching-options analyzer 1 input ingress ge-1/1/'+str(c))
time.sleep(0.1)
print '\r\nport monitoring:\r\n'+'ge-/1/1/'+monitoring_port
myssh.sendline('set interface ethernet-switching-options analyzer 1 output ge-1/1/'+monitoring_port)
time.sleep(0.1)
#commit , exit configure,exit login
myssh.sendline('commit')
time.sleep(0.2)
myssh.sendline('exit')
time.sleep(0.1)
myssh.sendline('exit')
time.sleep(0.1)
else:
myssh.sendline('enable')
time.sleep(0.1)
myssh.sendline('configure terminal')
time.sleep(0.1)
print 'Ports mirrored:'
for c in mirrored_port:
if c!= int(monitoring_port):
print 'ethernet-'+str(c),
myssh.sendline('monitor session 1 source ethernet '+str(c)+' both')
time.sleep(0.1)
print '\r\nport monitoring:\r\n'+'ethernet-'+monitoring_port
myssh.sendline('monitor session 1 destination ethernet '+monitoring_port)
time.sleep(0.1)
#commit , exit configure,exit login
myssh.sendline('exit')
time.sleep(0.1)
myssh.sendline('write')
time.sleep(0.1)
myssh.sendline('exit')
time.sleep(0.1)
time_lasting_end=time.time()
print '\r\nIt takes '+str(time_lasting_end-time_lasting_start)+' seconds to set the switch to mirror.\r\n'
return 1
示例15: delete_switch_mirroring
def delete_switch_mirroring(switch_IP):
print 'Deleting mirroring configure ... '
myssh1 = pxssh.pxssh()
myssh1.login1(server=switch_IP,username=username,password=pwd)
if ('10.0.3' in switch_IP):
time.sleep(0.1)
myssh1.sendline('configure')
time.sleep(0.1)
myssh1.sendline('delete interface ethernet-switching-options analyzer 1')
time.sleep(0.1)
# simulate input space to check more
myssh1.sendline(' ')
time.sleep(0.1)
myssh1.sendline('commit')
time.sleep(0.1)
myssh1.sendline('exit')
time.sleep(0.1)
myssh1.sendline('exit')
time.sleep(0.1)
else:
myssh1.sendline('enable')
time.sleep(0.1)
myssh1.sendline('configure terminal')
time.sleep(0.1)
myssh1.sendline('no monitor session 1')
time.sleep(0.1)
myssh1.sendline('exit')
time.sleep(0.1)
myssh1.sendline('write')
time.sleep(0.1)
myssh1.sendline('exit')
time.sleep(0.1)
return 1