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 ...
随机推荐
- elasticsearch 通过HTTP RESTful API 操作数据
1.索引样例数据 下载样例数据集链接 下载后解压到ES的bin目录,然后加载到elasticsearch集群 curl -XPOST 127.0.0.1:9200/bank/account/_bulk ...
- Linux系统中用户组、文件权限浅解
用户组 在linux中的每个用户必须属于一个组,不能独立于组外.在Linux中每个文件有所有者.所在组.其它组的概念. [所有者] 一般为文件的创建者,谁创建了该文件,就天然的成为该文件的所有者,用& ...
- 【转】javascript代码混淆和压缩
隐藏 JavaScript 源代码?不,你只能混淆和压缩JavaScript源代码 http://www.yaohaixiao.com/tools/confuse-and-compressing-ja ...
- MySQL Connector 编程
MySQL Connector 是MySQL数据库客户端编程的接口, 它提供了通过网络访问数据库的接口, 这些功能在动态链接库(.dll, .so)或者静态对象库(.lib, .a)中实现. 使用时必 ...
- Mysql宽字节注入(转)
尽管现在呼吁所有的程序都使用unicode编码,所有的网站都使用utf-8编码,来一个统一的国际规范.但仍然有很多,包括国内及国外(特别是非英语国家)的一些cms,仍然使用着自己国家的一套编码,比如g ...
- (5)top k大的数目
一.问题 在一个很长的数组中,求出top k大小的数目 二.办法 用优先队列 时间复杂度O(nlog(k)),应该是最差的情况下是这个 三.Code package algorithm; import ...
- MVC下 Area和Web同名的Controller问题
错误如下图: 解决方案: 1:Area下的XXXAreaRegistration 添加:new string[] { "xxx.Areas.xxx.Controllers" } 2 ...
- Git学习之忽略特殊文件.gitignore的配置
1.Mac中使用Git上传项目代码时忽略.DS_Store文件 简单的说Mac每个目录都会有个文件叫.DS_Store,它是用于存储当前文件夹的一些Meta信息.所以每次查看Git目录的状态,如果没有 ...
- 玩转Google
前言: 网上浏览信息,用百度搜索的时候,第一页都是广告,真是槽心到极点,果断放弃百度,现在用谷歌是真舒服,用起一句话用好谷歌.用好搜索引擎.你可以打开世界的大门! 加入特殊字符搜索: | 同时搜索关键 ...
- struts2简单入门-参数传递的三种方式
三种方式的简单说明 属性传递 把参数定义为属性提供get/set方法. 使用情况 参数少,不需要共享. 演示代码 public class LoginAction extends ActionSupp ...