python获取esxi的磁盘使用率信息
#!/usr/bin/python3
#coding:utf-8
#Author: ziming """
只用于模拟开发功能测试
"""
from pyVmomi import vim
from pyVim.connect import SmartConnect, Disconnect, SmartConnectNoSSL
import sys
import atexit
import argparse
from optparse import OptionParser
import json class Exsi(object): # 获取vcenter的相关参数
def __init__(self, host = 'x.x.x.x', port=443, user = 'zabbix', password='zabbix'):
self._host = host
self._port = port
self._user = user
self._password = password def get_obj(self,content, vimtype, name=None):
'''
列表返回,name 可以指定匹配的对象
'''
container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
obj = [ view for view in container.view]
return obj def get_conn(self):
# 连接vcenter
si = SmartConnectNoSSL(
host=self._host,
user=self._user,
pwd=self._password,
port=self._port)
# disconnect this thing
atexit.register(Disconnect, si)
content = si.RetrieveContent()
return content # 获取exsi的信息ip,磁盘使用情况等
def get_esxi_host(self):
esxi_host = {}
content = self.get_conn()
esxi_obj = self.get_obj(content, [vim.HostSystem])
for esxi in esxi_obj:
esxi_host[esxi.name] = {'datastore':{}} # for ds in esxi.datastore:
# esxi_host[esxi.name]['datastore'][ds.name] = {}
# esxi_host[esxi.name]['datastore'][ds.name]['总容量(G)'] = int((ds.summary.capacity)/1024/1024/1024)
# esxi_host[esxi.name]['datastore'][ds.name]['空闲容量(G)'] = int((ds.summary.freeSpace)/1024/1024/1024)
# esxi_host[esxi.name]['datastore'][ds.name]['类型'] = (ds.summary.type) total_capacity = 0
free_capacity = 0
for ds in esxi.datastore:
# esxi_host[esxi.name]['datastore'][ds.name] = {}
esxi_host[esxi.name] = {}
total_capacity += int((ds.summary.capacity)/1024/1024/1024)
free_capacity += int((ds.summary.freeSpace)/1024/1024/1024) esxi_host[esxi.name]['sotrage_used_percent'] = 100*(total_capacity - free_capacity)/total_capacity
# print(esxi_host)
return esxi_host # 获取exsi的host即ip列表
def get_esxi_iplist(self):
esxi_host = self.get_esxi_host()
data = list()
for exsi_ip in esxi_host:
data.append({"{#EXSI_IP}": exsi_ip}) return json.dumps({'data': data}, sort_keys=True, indent=7, separators=(",",":")) # 获取指定esxi的磁盘信息
def get_esxi_storageinfo(self, exsi_ip):
esxi_host = self.get_esxi_host() return esxi_host[exsi_ip]['sotrage_used_percent'] def main():
try: usage = "usage: %prog [options]\ngGet exsi Stat"
parser = OptionParser(usage) # 接收参数
parser.add_option("-l", "--list",
action="store_true", dest="is_list", default=False, help="if list all exsi ip") parser.add_option("--ip", "--ipaddr",
action="store", dest="ipaddr", type="string",
default="192.168.254.56", help="execute 'exsi info' to see more infomation") (options, args) = parser.parse_args()
if 1 >= len(sys.argv):
parser.print_help()
return #exsi_ins = Exsi(options.ipaddr)
exsi_ins = Exsi()
if options.is_list == True:
print(exsi_ins.get_esxi_iplist())
return # print(redis.ins.get_esxi_storageinfo(optins.ip, exsi_ip = ip))
print(exsi_ins.get_esxi_storageinfo(options.ipaddr)) except Exception as expt:
import traceback
tb = traceback.format_exc()
print(tb) if __name__ == '__main__':
main()
python获取esxi的磁盘使用率信息的更多相关文章
- Python获取CPU、内存使用率以及网络使用状态代码
Python获取CPU.内存使用率以及网络使用状态代码_python_脚本之家 http://www.jb51.net/article/134714.htm
- python结合pyvmomi 监控esxi的磁盘等信息
1.安装python3.6.6 # 安装依赖,一定要安装,否则后面可能无法安装一些python插件 yum -y install zlib-devel bzip2-devel openssl-deve ...
- 使用Python获取Linux系统的各种信息
哪个Python版本? 当我提及Python,所指的就是CPython 2(准确的是2.7).我会显式提醒那些相同的代码在CPython 3 (3.3)上是不工作的,以及提供一份解释不同之处的备选代码 ...
- python获取每颗cpu使用率
以下是关于python来获取服务器每颗CPU使用率的使用脚本. #!/usr/bin/env python # -*- coding: utf-8 -*- import re,time def _re ...
- 转:python获取linux系统及性能信息
原文:http://amitsaha.github.io/site/notes/articles/python_linux/article.html In this article, we will ...
- python 获取安装包apk, ipa 信息
# -*- coding:utf-8 -*- import re import os import zipfile from biplist import * from androguard.core ...
- win7下用python3.3获取cable modem的设备信息
毕业一年多了,一直做cable modem的测试,总是觉得在国内这一行的人才很少,想找个师傅真的很不容易. 苦闷了许久之后,终于决定,自己去写点东西,万一就找到同行了呢? 下面就是本小姐写的第一篇博客 ...
- [No0000112]ComputerInfo,C#获取计算机信息(cpu使用率,内存占用率,硬盘,网络信息)
github地址:https://github.com/charygao/SmsComputerMonitor 软件用于实时监控当前系统资源等情况,并调用接口,当资源被超额占用时,发送警报到个人手机: ...
- 使用python获取CPU和内存信息的思路与实现(linux系统)
linux里一切皆为文件,在linux/unix的根文件夹下,有个/proc文件夹,这个/proc 是一种内核和内核模块用来向进程(process)发送信息的机制(所以叫做"/proc&qu ...
随机推荐
- win7安装linux CentOS7双系统实践
开发需求要安装linux,百度了些资料,当然仅供参考,否则入坑. 步骤一 :制作Centos 7镜像文件,这步没什么坑 1.准备U盘8G以上 下载的话网上很多,这里提供一个下载路径: http:// ...
- 【1】【leetcode-33,81】 搜索旋转排序数组
(没思路) 33. 搜索旋转排序数组 假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] ). 搜索一个给 ...
- office 2016 破解教程
骤: 下载安装包——>安装(断网状态)——>下载破解工具——>破解完成 1. 下载 office2016,大家进入下面的链接进行 http://pan.baidu.com/s/1mi ...
- 第21月第4天 leetcode codinginterview c++
1.leetcode Implement strStr(). Returns the index of the first occurrence of needle in haystack, or - ...
- python网络编程初识
一,什么是计算机网络: 计算机网络是指将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路连接起来,在网络操作系统,网络管理软件及网络通信协议的管理和协调下,实现资源共享和 [1] 信 ...
- iic 之24C256存储器 及PCF8563
参考文章: http://www.21ic.com/jichuzhishi/mcu/memory/2013-02-28/159439.html 完整的例子: http://blog.csdn.net/ ...
- Linux 学大纲
- Django学习手册 - csrf
CSRF csrf原理 无csrf时存在隐患 Form提交 Ajax提交 默认为全局都csrf Form表单提交方式: <div> <form action="/login ...
- 小程序学习(冒泡,快速创建文件,以及tarbar)
1.关于小程序的事件冒泡机制 例如: <view catchtap="opp"> <text>当前内容</text> </view> ...
- POJ 1458 Common Subsequence 最长公共子序列
题目大意:求两个字符串的最长公共子序列 题目思路:dp[i][j] 表示第一个字符串前i位 和 第二个字符串前j位的最长公共子序列 #include<stdio.h> #include&l ...