bottle 接口实例

import paramiko  
from bottle import *
  
@route('/api/auto_publish/publish/env/:env/app/:app/ip/:ip',methods=['GET', 'POST'])
def publish(env, app, ip):
    hostname = ip  
    port = 22
    username = 'root'
    key_file = '/root/.ssh/id_rsa'
    key = paramiko.RSAKey.from_private_key_file(key_file)  
    s = paramiko.SSHClient()  
    s.load_system_host_keys()  
    s.connect(hostname,port,username,pkey=key)  
    if(app=='zjzc-hy-core-01'):
        stdin,stdout,stderr = s.exec_command('/bin/bash /root/auto_run/publish81.sh')  
        channel = stdout.channel
        status = channel.recv_exit_status()
        if status==100:
            return '['+'ftp get error'+']'
        else:
            return '['+'public success'+']'
    s.close() 
run(host='0.0.0.0', port=9999)

你可能感兴趣的:(bottle 接口实例)