paramiko引用

导入paramiko

import paramiko

获取远程ip

class Excel(object):
    def __init__(self, local_path, sheet_name):
        '''
        :param local_path: 文件本地路径
        :param sheet_name: 工作册名称
        '''
        self.local_path = local_path
        self.sheet_name = sheet_name


    def read_excel(self):
        excel = xlrd.open_workbook(self.local_path)
        table = excel.sheet_by_name(self.sheet_name)
        L = []
        for rowNum in range(0, table.nrows): # 行
            # 数据筛选
            list = {'地址': None, '用户名': None, 'kylin密码': None, 'root密码': None}
            for colNum in range(table.ncols): # 列
                if colNum == 0:
                    list['地址'] = table.cell_value(rowNum, colNum)
                elif colNum ==1:
                    list['用户名'] = table.cell_value(rowNum, colNum)
                elif colNum == 2:
                    list['kylin密码'] = table.cell_value(rowNum, colNum)
                elif colNum == 3:
                    list['root密码'] = table.cell_value(rowNum, colNum)
            L.append(list)
        return L

连接物理机

class Check():
    def __init__(self, Server_ip, Server_port, username, password, local_path, remotepath):
        '''
        :param Server_ip: 服务器ip
        :param Server_port: 服务器端口
        :param username: 用户名
        :param password: 密码
        :param local_path: 上传文件的本地路径
        :param remotepath: 目标路径
        :param DB_ip: 数据库ip
        :param DB_user: 用户名
        :param DB_password: 密码
        :param DB_db: 库
        '''
        self.Server_ip = Server_ip
        self.Server_port = Server_port
        self.username = username
        self.password = password
        self.local_path = local_path
        self.remotepath = remotepath
        self.DB_ip = DB_ip
        self.DB_user = DB_user
        self.DB_password = DB_password
        self.DB_db = DB_db
        self.transport = paramiko.Transport((self.Server_ip, self.Server_port))
        self.transport.connect(username=self.username, password=self.password)
        self.sftp = paramiko.SFTPClient.from_transport(self.transport)
        self.ssh = paramiko.SSHClient()
        self.ssh._transport = self.transport
        self.conn = mysql.connector.connect(host=ip, user=username, password=password, database='system')


    def do_toll_check(self):
        stdin, stdout, stderr = self.ssh.exec_command("df -Th")
        print(str(stdout.channel.recv(1024), encoding='utf-8'))
        return str(stderr)



    def conf_check(self, ssh):
        print("开始检查程序")
        stdin, stdout, stderr = ssh.exec_command("df -Th")
        print(str(stdout.channel.recv(1024), encoding='utf-8'))
        return str(stderr)


    def update_file(self):
        self.sftp.get(self.local_path, self.remotepath)


    def do_DB_check(self):
        try:
            cur = self.conn.cursor()
            sql1 = 'SELECT * FROM system.mc_allroadinfo_version'
            print("检查最短路径费率版本表:{}:".format(sql1))
            cur.execute(sql1)
            self.print_sql_result(cur.fetchall())
        except ProgrammingError as e:
            print('检查最短路径费率版本表失败')


    def print_sql_result(listall):
        for sql_result in listall:
            print(sql_result)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值