# -*- coding: utf-8 -*-
import time
import tarfile
import paramiko
import commands
import os
class master():
"""
Compress file and use SSH to push the .tar file to remote,
then uncompress and setup.
"""
def __init__(self, object_file_path, compress_file_name, ip, port, username, password):
self.object_file_path = object_file_path
self.compress_file_name = compress_file_name
self.ip = ip
self.port = port
self.username = username
self.password = password
# Initiate SSH connection
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(self.ip, self.port, self.username, self.password, timeout=10)
self.ssh_handler = ssh
except Exception, e:
print e
print'ssh error'
def set_file_property(self, tar_file_name, remote_object_file_path, collector_file_name):
# set file property
try:
self.tar_file_name = tar_file_name
self.remote_object_file_path = remote_object_file_path
self.tar_file_full_path = self.remote_object_file_path + self.tar_file_name
self.collector_file_name = collector_file_name
except Exception, e:
print e
print'set property error'
def execute_command(self, cmd, sync=True):
try:
if sync:
i, o , e = self.ssh_handler.exec_command(cmd)
res = e.readlines()
python代码:本地压缩文件,然后连接远端linux,上传文件,解压,安装
最新推荐文章于 2022-04-25 21:28:22 发布