Linux环境中安装libvirt-python模块

linux环境中:python3 安装libvirt-python模块

下载libvirt-python安装包:https://pypi.org/project/libvirt-python/6.8.0/#files

上传解压安装包:

安装kvm环境:yum install -y libvirt-devel

安装模块

查看

使用:

 

python获取本机ip

import socket
web_server = socket.gethostname(socket.gethostname())
print(web_server)

 

cmd连接10.0.0.60

 

python执行远程linux中脚本文件

import subprocess
result = {}
ret = ""
libvirt_api_path = os.path.join(os.path.join(os.path.join(settings.BASE_DIR, "drm"), "api"), "commvault") + os.sep + "libvirtApi.py"
interface_existed = os.path.exists(libvirt_api_path)
if not interface_existed:
    result["data"] = "libvirtApi接口文件不存在。"
else:
    try:
        ret = subprocess.getstatusoutput(libvirt_api_path)
        exec_status, recover_job_id = ret
    except Exception as e:
        result["data"] = "执行libvirtApi接口出现异常{0}。".format(e)
    else:
        if exec_status == 0:
            result["data"] = "调用libvirtApi接口成功。"

 

 sftp本地上传文件到linux上

import paramiko
ip = '10.0.0.60'
username = 'root'
password = '******'
myfilepath = r'C:\Users\admin\Downloads\Test1.qcow2'
path = '/home/Test1.qcow2'
try:
  ssh = paramiko.Transport((ip, 22))
  ssh.connect(username=username, password=password)
  sftp = paramiko.SFTPClient.from_transport(ssh)except Exception as e:
  print('服务器连接失败。')
else:
  try:
    sftp.put(myfilepath, path)
  except Exception as e:
    print('上传失败。')
  else:
    print('上传成功。')

 

scp传文件

 

帆软报表注册

 

posted @ 2020-09-26 22:22  TianShu  Views(2001)  Comments(0Edit  收藏  举报