提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
kvm利用thinkter实现可视化
提示:这里可以添加本文要记录的大概内容:
例如:云计算技术
提示:以下是本篇文章正文内容,下面案例可供参考
一、云计算是什么?
二、使用步骤
1.引入库
代码如下(示例):
import libvirt
from tkinter.filedialog import askopenfilename
import tkinter.messagebox as messagebox
from tkinter import *
import tkinter as tk
import tkinter.simpledialog
from functools import partial
import paramiko
import psutil
import os
import sys
from paramiko import SSHException
from tkinter import filedialog
import time
from xml.etree import ElementTree
import sys
2.可视化
代码如下(示例):
def close_connection(): # 关闭连接,暂时不考虑
try:
conn.close()
except:
print("--关闭连接失败--")
return 1
print('--成功关闭连接--')
def cpu_change_rate():
host_list = ({'ip': '192.168.200.13', 'port': 22, 'username': 'mpiuser', 'password': '123456'},
{'ip': '192.168.200.14', 'port': 22, 'username': 'mpiuser', 'password': '123456'},)
ssh = paramiko.SSHClient()
# 设置为接受不在known_hosts 列表的主机可以进行ssh连接
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for host in host_list:
ssh.connect(hostname=host['ip'], port=host['port'], username=host['username'], password=host['password'])
print(host['ip'])
stdin, stdout, stderr = ssh.exec_command('cat /proc/stat | grep "cpu "')
str_out = stdout.read().decode()
str_err = stderr.read().decode()
if str_err != "":
print(str_err)
continue
else:
cpu_time_list = re.findall('\d+', str_out)
cpu_idle1 = cpu_time_list[3]
total_cpu_time1 = 0
for t in cpu_time_list:
total_cpu_time1 = total_cpu_time1 + int(t)
time.sleep(2)
stdin, stdout, stderr = ssh.exec_command('cat /proc/stat | grep "cpu "')
str_out = stdout.read().decode()
str_err = stderr.read().decode()
if str_err != "":
print(str_err)
continue
else:
cpu_time_list = re.findall('\d+', str_out)
cpu_idle2 = cpu_time_list[3]
total_cpu_time2 = 0
for t in cpu_time_list:
total_cpu_time2 = total_cpu_time2 + int(t)
cpu_usage = round(1 - (float(cpu_idle2) - float(cpu_idle1)) / (total_cpu_time2 - total_cpu_time1), 2)
print('当前CPU使用率为:' + str(cpu_usage))
ssh.close()
`
def list_connection(): # 主机信息
print("---------node1主机信息---------")
nodeinfo = conn.getInfo() # 获取虚拟化主机信息
print('模型: ' + str(nodeinfo[0])) # cpu模型
print('内存大小: ' + str(nodeinfo[1]) + 'MB') # 内存
print('CPU数量: ' + str(nodeinfo[2])) # cpu数量
print('虚拟类型: ' + conn.getType()) # 虚拟化类型
uri = conn.getURI() # 目前链接的uri
print('连接URI: : ' + uri)
mem = conn.getFreeMemory()
print("空闲内存: " + str(mem) + " bytes.")
print("-------------------------")
#text = "--------主机信息--------\n"+"模型:{}\n"+"内存大小:{}MB\n"+ "CPU数量:{}个\n"+ "虚拟类型:{}\n"+ "连接URI:{}\n"+ "内存空间:{}bytes\n".format(str(nodeinfo[0]), str(nodeinfo[1]), str(nodeinfo[2]), conn.getType(), uri, str(mem))
text = ("--------node1主机信息--------\n"
"模型:{}\n"
"内存大小:{}MB\n"
"CPU数量:{}个\n"
"虚拟类型:{}\n"
"连接URI:{}\n"
"内存空间:{}bytes\n"
.format(str(nodeinfo[0]), str(nodeinfo[1]), str(nodeinfo[2]), conn.getType(), uri, str(mem)))
txt.insert(END, text)
txt.tag_add("center", 1.0, "end")
print("---------node2主机信息---------")
nodeinfo = conn1.getInfo() # 获取虚拟化主机信息
print('模型: ' + str(nodeinfo[0])) # cpu模型
print('内存大小: ' + str(nodeinfo[1]) + 'MB') # 内存
print('CPU数量: ' + str(nodeinfo[2])) # cpu数量
print('虚拟类型: ' + conn1.getType()) # 虚拟化类型
uri = conn1.getURI() # 目前链接的uri
print('连接URI: : ' + uri)
mem = conn1.getFreeMemory()
print("空闲内存: " + str(mem) + " bytes.")
print("-------------------------")
# text = "--------主机信息--------\n"+"模型:{}\n"+"内存大小:{}MB\n"+ "CPU数量:{}个\n"+ "虚拟类型:{}\n"+ "连接URI:{}\n"+ "内存空间:{}bytes\n".format(str(nodeinfo[0]), str(nodeinfo[1]), str(nodeinfo[2]), conn.getType(), uri, str(mem))
text = ("--------node2主机信息--------\n"
"模型:{}\n"
"内存大小:{}MB\n"
"CPU数量:{}个\n"
"虚拟类型:{}\n"
"连接URI:{}\n"
"内存空间:{}bytes\n"
.format(str(nodeinfo[0]), str(nodeinfo[1]), str(nodeinfo[2]), conn.getType(), uri, str(mem)))
txt.insert(END,text)
txt.tag_add("center", 1.0, "end")
# lableInit.config(text="--------主机信息--------\n"
# "模型:{}\n"
# "内存大小:{}MB\n"
# "CPU数量:{}个\n"
# "虚拟类型:{}\n"
# "连接URI:{}\n"
# "内存空间:{}bytes\n"
# .format(str(nodeinfo[0]), str(nodeinfo[1]), str(nodeinfo[2]), conn.getType(), uri, str(mem)))
def show_machine(): # 显示虚拟机状态
# 开启的域
begin_text=""
end_txt=""
vms_dict = {}
domain_list = conn.listDomainsID() ## 返回一个列表,元素为当前所有运行中的域的ID。
#domain_list1=conn1.listDomainsID()
for vm in domain_list:
vms_dict[str(vm)] = conn.lookupByID(vm).name() # 通过名字寻找虚拟机
print("""
处于开启状态的虚拟机
----------------
ID Name
----------------""")
if vms_dict:
for id_part, name_part in vms_dict.items():
print("{} {}".format(id_part, name_part))
begin_text=begin_text+" "+name_part
text=("开启状态:{}".format(id_part, name_part))
# text = ("开启状态:{}" "关机状态:{}".format(vms_dict, vmd_list))
# txt.insert(END, text)
# lableInit.config(text="开启状态:".format(vms_dict))
else:
print("None")
print("----------------")
# 关闭的域
global vmd_list
vmd_list = []
undomain_list=conn.listDefinedDomains()
#undomain_list1=conn1.listDefinedDomains()
# undomain_list=undomain_list+undomain_list1
for i in undomain_list:
vmd_list.append(i)
print("""
处于关闭状态的虚拟机
----------------
Name
----------------""")
if vmd_list:
for name_part in vmd_list:
print("{}".format(name_part))
end_txt+=name_part
text=( "关机状态:{}".format(vms_dict, vmd_list))
else:
print("None")
print("----------------")
vms_dict = {}
# domain_list = conn.listDomainsID() ## 返回一个列表,元素为当前所有运行中的域的ID。
domain_list = conn1.listDomainsID()
for vm in domain_list:
vms_dict[str(vm)] = conn1.lookupByID(vm).name() # 通过名字寻找虚拟机
print("""
处于开启状态的虚拟机
----------------
ID Name
----------------""")
if vms_dict:
for id_part, name_part in vms_dict.items():
print("{} {}".format(id_part, name_part))
begin_text = begin_text + " " + name_part
text = ("开启状态:{}".format(id_part, name_part))
# text = ("开启状态:{}" "关机状态:{}".format(vms_dict, vmd_list))
# txt.insert(END, text)
# lableInit.config(text="开启状态:".format(vms_dict))
else:
print("None")
print("----------------")
# 关闭的域
vmd_list = []
undomain_list = conn1.listDefinedDomains()
#undomain_list1 = conn1.listDefinedDomains()
# undomain_list = undomain_list + undomain_list1
for i in undomain_list:
vmd_list.append(i)
print("""
处于关闭状态的虚拟机
----------------
Name
----------------""")
if vmd_list:
for name_part in vmd_list:
print("{}".format(name_part))
end_txt += name_part
text = ("关机状态:{}".format(vms_dict, vmd_list))
else:
print("None")
print("----------------")
if(begin_text!=""):
begin_text="处于开机状态虚拟机:\n"+begin_text+"\n"
txt.insert(END, begin_text)
txt.tag_add("center", 1.0, "end")
if (end_txt != ""):
end_txt="处于关机状态虚拟机:\n"+end_txt+"\n"
txt.insert(END, end_txt)
txt.tag_add("center", 1.0, "end")
#lableInit.config(text="虚拟机信息已在终端显示")
# --------对虚拟机域进行操作---------
# 显示虚拟机的详细状态
def show_machine2():
vms1 = conn.listAllDomains()
vms2 =conn1.listAllDomains()
vms1=vms1+vms2
print(vms1)
for dom in vms1:
instance_name = dom.name()
# 获取虚拟机的 UUID
UUID = dom.UUIDString()
INFO = dom.info()
# info 参数: 状态, 最大内存 已用内存 CPU数量 响应时间
print("名称:{}\n"
"虚拟机UUID:{}MB\n"
"虚拟机基本信息:{}\n"
# "虚拟机内存信息:{}\n"
.format(str(instance_name), str(UUID), str(INFO)))
text = ("--------虚拟机详细信息--------\n"
"名称:{}\n"
"虚拟机UUID:{}MB\n"
"虚拟机基本信息:{}\n"
# "虚拟机内存信息:{}\n"
.format(str(instance_name), str(UUID), str(INFO)))
txt.insert(END, text)
txt.tag_add("center", 1.0, "end")
#
# lableInit.config(text="--------虚拟机详细信息--------\n"
# "名称:{}\n"
# "虚拟机UUID:{}MB\n"
# "虚拟机基本信息:{}\n"
# # "虚拟机内存信息:{}\n"
# .format(str(instance_name), str(UUID), str(INFO)))
# 创建虚拟机
def define():
top1 = tk.Toplevel()
top1.title('虚拟机安装向导')
tk.Label(top1, text='请输入虚拟机名称:').grid(row=1, column=0, padx=1, pady=1)
v1 = tk.Entry(top1, width=10)
v1.grid(row=1, column=1, padx=1, pady=1)
tk.Label(top1, text='请输入虚拟机CPU数量(个):').grid(row=2, column=0, padx=1, pady=1)
v2 = tk.Entry(top1, width=10)
v2.grid(row=2, column=1, padx=1, pady=1)
tk.Label(top1, text='请输入虚拟机内存大小(MB):').grid(row=3, column=0, padx=1, pady=1)
v3 = tk.Entry(top1, width=10)
v3.grid(row=3, column=1, padx=1, pady=1)
tk.Label(top1, text='请输入镜像文件大小(G):').grid(row=4, column=0, padx=1, pady=1)
v4 = tk.Entry(top1, width=10)
v4.grid(row=4, column=1, padx=1, pady=1)
# v1_value = str(v1.get())
# v2_value = str(v2.get())
# v3_value = str(v3.get())
# v4_value = str(v4.get())
# print(v4_value+'******')
# diskname = v1_value # 眼输入的虚拟机名称
# shape = v4_value # 镜像文件的大小
# ram = v3_value
# cpus = v2_value
def cmd(diskname, shape, ram, cpus):
os.system('cd /var/lib/libvirt/images;'
f'sudo qemu-img create -f qcow2 {diskname} {shape} ;'
f'sudo virt-install --connect qemu:///system --virt-type kvm --name {diskname} --ram {ram} --vcpus {cpus} --network network=br0 --disk path=/var/lib/libvirt/images/{diskname},size={shape},format=qcow2 --cdrom /home/mpiuser/.cache/vmware/drag_and_drop/mLmnTR/CentOS-7-x86_64-DVD-2009.iso --noautoconsole'
)
text=("虚拟机 {} 创建成功".format(diskname))
txt.insert(END, text)
A=tk.Button(top1,text='确定创建',command=lambda:cmd(str(v1.get()),str(v2.get()),str(v3.get()),str(v4.get())))
A.grid(row=5, column=0, padx=1, pady=1)
top1.mainloop()
def undefine():
dom = conn.lookupByName(entryName.get())
dom.undefine()
print("虚拟机 {} 已取消定义".format(entryName.get()))
text=("虚拟机 {} 已取消定义".format(entryName.get()))
txt.insert(END, text)
txt.tag_add("center", 1.0, "end")
def suspand():
dom = conn.lookupByName(entryName.get())
dom.suspend()
print("虚拟机 {} 暂停成功".format(entryName.get()))
text=("虚拟机 {} 已暂停".format(entryName.get()))
txt.insert(END, text)
txt.tag_add("center", 1.0, "end")
def resume():
dom = conn.lookupByName(entryName.get())
dom.resume()
print("虚拟机 {} 运行成功".format(entryName.get()))
text=("虚拟机 {} 继续运行".format(entryName.get()))
txt.insert(END, text)
txt.tag_add("center", 1.0, "end")
def destroy():
dom = conn.lookupByName(entryName.get())
dom.destroy()
print("虚拟机 {} 销毁成功".format(entryName.get()))
text=("虚拟机 {} 已销毁".format(entryName.get()))
txt.insert(END, text)
txt.tag_add("center", 1.0, "end")
def start():
dom = conn.lookupByName(entryName.get())
dom.create()
print("虚拟机 {} 启动成功".format(entryName.get()))
text=("虚拟机 {} 已启动".format(entryName.get()))
txt.insert(END, text)
txt.tag_add("center", 1.0, "end")
def shutdown():
dom = conn.lookupByName(entryName.get())
dom.shutdown()
print("虚拟机 {} 关闭成功".format(entryName.get()))
text=("虚拟机 {} 已关闭".format(entryName.get()))
txt.insert(END, text)
def bytes2symbols(bytes_value):
'''单位符号'''
symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
'''每个单位对应的bytes数的字典,先定义为空'''
prefix = {}
'''要得到这样的{K:1024, M:1024*1024,G:1024**3},进行for循环'''
for i, s in enumerate(symbols):
# '''enumerate()为列举函数'''
# '''i:代表下标'''
# '''s:代表改下标对应的值'''
# '''取到符号元组的值,作为prfix字典的key,根据key给value进行赋值'''
prefix[s] = 1024 ** (i + 1)
# '''打印得到的对应字典'''
# print(prefix)
symbols_value = 0
symbol = ''
# '''循环prefix字典,得到转换值'''
for key, value in prefix.items():
if bytes_value >= value:
symbols_value = bytes_value / value
symbol = key
# 如果不满足最小的KB,则以B显示
elif bytes_value < 1024:
return '%0.2fB' % bytes_value
# '''返回转换值(str)'''
return '%0.2f%sB' % (symbols_value, symbol)
#y运行中的虚拟机的状态
def state():
max_cpu=0.0
if len(conn.listDomainsID()+conn1.listDomainsID()) <= 0:
print('\033[0;37;41m%s\033[0m' % '没有正在运行的虚拟机,程序退出.'+'\n')
text=('\033[0;37;41m%s\033[0m' % '没有正在运行的虚拟机,程序退出.'+'\n')
txt.insert(END,text)
os.system('command')
time.sleep(1)
sys.exit()
try:
for id in reversed(conn.listDomainsID()):
print('\n')
domain = conn.lookupByID(id)
print ('实例名:' + domain.name()+'\n')
text =('实例名:' + domain.name()+'\n')
txt.insert(END, text)
print('状态:' + '\033[0;37;42m%s\033[0m' % '开机' if domain.info()[0] == 1 else '\033[0;37;41m%s\033[0m' % '关机',)
# text = ('状态:' + '开机'+'\n' if domain.info()[0] == 1 else '关机'+'\n')
# txt.insert(END, text)
print('最大内存:' + (str)(domain.info()[1] / 1024) + 'Mb',)
print('CPU数量:' + (str)(domain.info()[3]),)
print('CPU时间:' + (str)(domain.info()[4]))
# 开始计算虚拟机内存
domain.setMemoryStatsPeriod(10)
meminfo = domain.memoryStats()
free_mem = float(meminfo['unused'])
total_mem = float(meminfo['available'])
util_mem = ((total_mem - free_mem) / total_mem) * 100
print('内存已使用:' + str(util_mem) + '%')
text=('内存已使用:' + str(util_mem) + '%'+'\n')
txt.insert(END,text)
# 开始计算磁盘I/O
tree = ElementTree.fromstring(domain.XMLDesc())
devices = tree.findall('devices/disk/target')
for d in devices:
device = d.get('dev')
try:
devstats = domain.blockStats(device)
read_bytes = bytes2symbols((device, devstats)[1][0])
write_bytes = bytes2symbols((device, devstats)[1][2])
print ('磁盘设备:' + (device, devstats)[0],read_bytes , write_bytes)
print('读:%10s' % read_bytes),
print('读取请求:' + (str)((device, devstats)[1][1]) + '次',)
print('写:%10s' % read_bytes),
print('写入请求:' + (str)((device, devstats)[1][3]) + '次')
except libvirt.libvirtError:
pass
# 开始计算cpu使用率
t1 = time.time()
c1 = int(domain.info()[4])
time.sleep(0.05)
t2 = time.time()
c2 = int(domain.info()[4])
c_nums = int(domain.info()[3])
usage = (c2 - c1) * 100 / ((t2 - t1) * c_nums * 1e9)
print("CPU 已使用:" + (str)(usage)+ '%')
text=("CPU 已使用:" + (str)(usage)+ '%'+'\n')
txt.insert(END, text)
if(usage>max_cpu):
max_cpu=usage
except:
pass
try:
for id in reversed(conn1.listDomainsID()):
print('\n')
domain = conn1.lookupByID(id)
print('实例名:' + domain.name() + '\n')
text = ('实例名:' + domain.name() + '\n')
txt.insert(END, text)
print(
'状态:' + '\033[0;37;42m%s\033[0m' % '开机' if domain.info()[0] == 1 else '\033[0;37;41m%s\033[0m' % '关机', )
# text = ('状态:' + '开机'+'\n' if domain.info()[0] == 1 else '关机'+'\n')
# txt.insert(END, text)
print('最大内存:' + (str)(domain.info()[1] / 1024) + 'Mb', )
print('CPU数量:' + (str)(domain.info()[3]), )
print('CPU时间:' + (str)(domain.info()[4]))
# 开始计算虚拟机内存
domain.setMemoryStatsPeriod(10)
meminfo = domain.memoryStats()
free_mem = float(meminfo['unused'])
total_mem = float(meminfo['available'])
util_mem = ((total_mem - free_mem) / total_mem) * 100
print('内存已使用:' + str(util_mem) + '%')
text = ('内存已使用:' + str(util_mem) + '%' + '\n')
txt.insert(END, text)
# 开始计算磁盘I/O
tree = ElementTree.fromstring(domain.XMLDesc())
devices = tree.findall('devices/disk/target')
for d in devices:
device = d.get('dev')
try:
devstats = domain.blockStats(device)
read_bytes = bytes2symbols((device, devstats)[1][0])
write_bytes = bytes2symbols((device, devstats)[1][2])
print('磁盘设备:' + (device, devstats)[0], read_bytes, write_bytes)
print('读:%10s' % read_bytes),
print('读取请求:' + (str)((device, devstats)[1][1]) + '次', )
print('写:%10s' % read_bytes),
print('写入请求:' + (str)((device, devstats)[1][3]) + '次')
except libvirt.libvirtError:
pass
# 开始计算cpu使用率
t1 = time.time()
c1 = int(domain.info()[4])
time.sleep(0.05)
t2 = time.time()
c2 = int(domain.info()[4])
c_nums = int(domain.info()[3])
usage = (c2 - c1) * 100 / ((t2 - t1) * c_nums * 1e9)
print("CPU 已使用:" + (str)(usage) + '%')
text = ("CPU 已使用:" + (str)(usage) + '%' + '\n')
txt.insert(END, text)
if (usage > max_cpu):
max_cpu = usage
except:
pass
text = ("CPU 最大使用率:" + (str)(max_cpu) + '%' + '\n')
txt.insert(END, text)
#显示快排结果
def show_result():
file3 = askopenfilename(initialdir='/home/mpiuser/mpich/mpich-3.3.1/examples/result')
# listt = file3
# window = tk.Tk()
# window.withdraw() # hides the window
# file = tk.simpledialog.askstring("选择文件", "/home/mpiuser/mpich/mpich-3.3.1/examples")
# os.system(
# 'cd /home/mpiuser/mpich/mpich-3.3.1/examples;'
# 'cat result.txt'
#运行MPI程序
def action():
print(' ')
# os.system(
# 'cd /home/mpiuser/mpich/mpich-3.3.1/examples;'
# '/home/mpiuser/mpich/bin/mpirun -n 6 -f /home/mpiuser/mpich/servers ./test'
# )
ssh_cli = paramiko.SSHClient() # 创建SSHClient实例
ssh_cli.load_system_host_keys() # 加载系统默认ssh_keys
ssh_cli.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_cli.connect(hostname='192.168.246.13', username='mpiuser', password='123456')
try:
stdin, stdout, stderr = ssh_cli.exec_command(
'mpirun -n {} -f /home/mpiuser/mpich/servers /home/mpiuser/mpich/mpich-3.3.1/examples/test'.format(6), get_pty=True)
for line in iter(stdout.readline, ""):
text=("{}".format(line))
text.strip(" ")
txt.insert(END, text)
txt.tag_add("center", 1.0, "end")
# print(line) # 改成输出到前端的代码
print('finished.')
state()
except SSHException as err:
print(str(err))
ssh_cli.close() # 关闭连接
# ------------菜单控制-------------
def test():
name = str(entryName.get())
print(name)
def node_test_f():
ssh_cli = paramiko.SSHClient() # 创建SSHClient实例
ssh_cli.load_system_host_keys() # 加载系统默认ssh_keys
ssh_cli.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_cli.connect(hostname='192.168.246.13', username='mpiuser', password='123456')
try:
judge = 0
stdin, stdout, stderr = ssh_cli.exec_command('ping node1 -c 2', get_pty=True)
for line in iter(stdout.readline, ""):
if (line[0] == '6'):
judge = 1
if (judge == 1):
txt.insert(END, "节点node1正常!\n")
txt.tag_add("center", 1.0, "end")
else:
txt.insert(END, "节点node1发生异常!\n")
txt.tag_add("center", 1.0, "end")
stdin, stdout, stderr = ssh_cli.exec_command('ping slave0 -c 2', get_pty=True)
for line in iter(stdout.readline, ""):
if (line[0] == '6'):
judge = 1
if (judge == 1):
txt.insert(END, "节点slave0正常!\n")
txt.tag_add("center", 1.0, "end")
else:
txt.insert(END, "节点slave0发生异常!\n")
txt.tag_add("center", 1.0, "end")
judge = 0
stdin, stdout, stderr = ssh_cli.exec_command('ping slave1 -c 2', get_pty=True)
for line in iter(stdout.readline, ""):
if (line[0] == '6'):
judge = 1
if (judge == 1):
txt.insert(END, "节点slave1正常!\n")
txt.tag_add("center", 1.0, "end")
else:
txt.insert(END, "节点slave1发生异常!\n")
txt.tag_add("center", 1.0, "end")
judge=0
stdin, stdout, stderr = ssh_cli.exec_command('ping slave2 -c 2',get_pty=True)
for line in iter(stdout.readline, ""):
if(line[0]=='6'):
judge=1
if(judge==1):
txt.insert(END, "节点slave2正常!\n")
txt.tag_add("center", 1.0, "end")
else:
txt.insert(END, "节点slave2发生异常!\n")
txt.tag_add("center", 1.0, "end")
judge=0
stdin, stdout, stderr = ssh_cli.exec_command('ping slave3 -c 2', get_pty=True)
for line in iter(stdout.readline, ""):
if (line[0] == '6'):
judge = 1
if (judge == 1):
txt.insert(END, "节点slave3正常!\n")
txt.tag_add("center", 1.0, "end")
else:
txt.insert(END, "节点slave3发生异常!\n")
txt.tag_add("center", 1.0, "end")
judge = 0
except SSHException as err:
print(str(err))
ssh_cli.close()
# --------------------------------
conn = libvirt.open("qemu:///system") # 通过这一步,实现与虚拟机的链接,conn本质上就是一个虚拟机
conn1= libvirt.open('qemu+ssh://mpiuser@node2:22/system')
top:tk=tk.Tk(screenName="192.168.246.19:0.0") # 通过Xmanager连接生成
#添加背景
# image_file=tk.PhotoImage(file=r"/home/mpiuser/图片/cug.gif")
# w = tk.Label(top,image=image_file)
# w.grid()
top.geometry('1000x1000')
top.title("虚拟机管理平台")
# top.geometry('602x')#窗体大小
lableTitle = tk.Label(top, bg='#00BFFF', fg="#EEE8AA", font='Helvetica -24 bold', text="虚 拟 机 管 理 平 台",
width=69, relief=RAISED)
lableTitle.grid(row=0, column=0, columnspan=2, ipady=10)
labelHello = tk.Label(top, fg='#c71585', font='Helvetica -18 bold', text="请输入虚拟机的名称:")
labelHello.grid(row=1, column=0, padx=2, pady=6, sticky='E')
entryName = tk.Entry(top, width=24)
entryName.grid(row=1, column=1, padx=2, sticky='W')
# -------操作------
showHost = tk.Button(top, bg='#00BFFF', fg='white', width=18, height=2, font='Helvetica -15 bold', text="显示主机信息",
command=list_connection)
showHost.grid(row=2, column=0, padx=4, pady=4, sticky='E')
showVM = tk.Button(top, bg='#00BFFF', fg='white', width=18, height=2, font='Helvetica -15 bold', text="显示虚拟机开关状态",
command=show_machine)
showVM.grid(row=2, column=1, padx=4, pady=4, sticky='W')
tempVM = tk.Button(top, bg='#00BFFF', fg='white', width=18, height=2, font='Helvetica -15 bold', text="显示虚拟机状态",
command=show_machine2)
tempVM.grid(row=3, column=0, padx=4, pady=4, sticky='E')
destroyVM = tk.Button(top, bg='#00BFFF', fg='white', width=18, height=2, font='Helvetica -15 bold', text="销毁虚拟机",
command=destroy)
destroyVM.grid(row=3, column=1, padx=4, pady=4, sticky='W')
action_mpi = tk.Button(top, bg='#00BFFF', fg='white', width=18, height=2, font='Helvetica -15 bold', text="运行MPI程序",
command=action)
action_mpi.place(relx=0.65,rely=0.135,relwidth=0.20,relheight=0.045)
suspandVM = tk.Button(top, bg='#00BFFF', fg='white', width=18, height=2, font='Helvetica -15 bold', text="暂停虚拟机",
command=suspand)
suspandVM.grid(row=4, column=0, padx=4, pady=4, sticky='E')
resumeVM = tk.Button(top, bg='#00BFFF', fg='white', width=18, height=2, font='Helvetica -15 bold', text="运行虚拟机",
command=resume)
resumeVM.grid(row=4, column=1, padx=4, pady=4, sticky='W')
result = tk.Button(top, bg='#00BFFF', fg='white', width=18, height=2, font='Helvetica -15 bold', text="显示运行文件",
command=show_result)
result.place(relx=0.65,rely=0.2,relwidth=0.20,relheight=0.045)
startVM = tk.Button(top, bg='#00BFFF', fg='white', width=18, height=2, font='Helvetica -15 bold', text="开启虚拟机",
command=start)
startVM.grid(row=5, column=0, padx=4, pady=4, sticky='E')
shutdownVM = tk.Button(top, bg='#00BFFF', fg='white', width=18, height=2, font='Helvetica -15 bold', text="关闭虚拟机",
command=shutdown)
shutdownVM.grid(row=5, column=1, padx=4, pady=4, sticky='W')
node_test = tk.Button(top, bg='#00BFFF', fg='white', width=18, height=2, font='Helvetica -15 bold', text="节点测试",
command=node_test_f)
node_test.place(relx=0.65,rely=0.265,relwidth=0.20,relheight=0.045)
defineVM = tk.Button(top, bg='#00BFFF', fg='white', width=18, height=2, font='Helvetica -15 bold', text="创建虚拟机"
, command=define)
defineVM.grid(row=6, column=0, padx=4, pady=4, sticky='E')
undefineVM = tk.Button(top, bg='#00BFFF', fg='white', width=18, height=2, font='Helvetica -15 bold', text="删除虚拟机"
"(取消定义)",
command=undefine)
undefineVM.grid(row=6, column=1, padx=4, pady=4, sticky='W')
CPU_SHOW= tk.Button(top, bg='#00BFFF', fg='white', width=18, height=2, font='Helvetica -15 bold', text="CPU详情",
command=state)
CPU_SHOW.place(relx=0.65,rely=0.32,relwidth=0.20,relheight=0.045)
#
# lableInitTitle = tk.Label(top, bg='white', font='Helvetica -13 bold', text="=====系 统 反 馈 信 息=====", width=125,
# fg="blue")
# lableInitTitle.grid(row=7, column=0, columnspan=2, ipady=10)
#
# lableInit = tk.Label(top, bg='white', font='Helvetica -13 bold', text="NULL", width=160, height=15, fg="black")
# lableInit.grid(row=8, column=0, rowspan=5, columnspan=2, ipady=10)
# quitVM = tk.Button(top,text="退出管理系统",command=close_connection())
# quitVM.pack()
top.title('可视化显示')
txt = Text(top)
#fontExample = tkFont.Font(family=, size=16, weight="bold", slant="italic")
txt.tag_configure("center",justify='center')
txt.configure(font=("Arial",12, "italic"))
# 在窗体垂直自上而下位置70%处起,布局相对窗体高度40%高的文本框
txt.place(rely=0.4,relwidth=1, relheight=0.6)
top.mainloop()
``
该处使用的url网络请求的数据。
---
# 总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。