本文整理汇总了Python中pysphere.VIServer.get_performance_manager方法的典型用法代码示例。如果您正苦于以下问题:Python VIServer.get_performance_manager方法的具体用法?Python VIServer.get_performance_manager怎么用?Python VIServer.get_performance_manager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysphere.VIServer
的用法示例。
在下文中一共展示了VIServer.get_performance_manager方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_performance_manager [as 别名]
class ESXi_Server:
server_ip = ''
user_name = ''
password = ''
connect_flag = False
server = None
#vm_list = []
#def __init__(self):
#Use the given args to connect the esxi server you want
#@ip[string]: ESXi server's IP address
#@name[string]: the username used to login the ESXi server
#@pwd[string]: the password used to login the ESXi server
def connect_server(self, ip, name, pwd):
self.server_ip = ip
self.user_name = name
self.password = pwd
self.server = VIServer()
self.server.connect(self.server_ip, self.user_name, self.password)
self.connect_flag = self.server.is_connected()
if self.connect_flag:
return True
return False
#To get all the definition registered vms from the connected server
#@param[string]: can be set as ALL, POWER_ON, POWER_OFF, SUSPENDED
#According to the param, returns a list of VM Paths. You might also filter by datacenter,
#cluster, or resource pool by providing their name or MORs.
#if cluster is set, datacenter is ignored, and if resource pool is set
#both, datacenter and cluster are ignored.
def get_registered_vms(self, param, status=None, datacenter=None, cluster=None,
resource_pool=None):
if param not in ['ALL', 'POWER_ON', 'POWER_OFF', 'SUSPENDED']:
print "Get VMs error: param can only be set as ALL, POWER_ON, POWER_OFF, or SUSPENDED."
return None
if self.connect_flag == False:
print "Get VMs error: Server not connected."
return None
if param == 'ALL':
return self.server.get_registered_vms(datacenter, cluster, resource_pool)
elif param == 'POWER_ON':
return self.server.get_registered_vms(datacenter, cluster, resource_pool, status='poweredOn')
elif param == 'POWER_OFF':
return self.server.get_registered_vms(datacenter, cluster, resource_pool, status='poweredOff')
elif param == 'SUSPENDED':
return self.server.get_registered_vms(datacenter, cluster, resource_pool, status='suspended')
else:
return None
#Disconnect to the Server
def disconnect(self):
if self.connect_flag == True:
self.server = self.server.disconnect()
self.connect_flag == False
#To keep session alive
def keep_session_alive(self):
assert self.server.keep_session_alive()
#To get the server type
def get_server_type(self):
return self.server.get_server_type()
#To get performance manager
def get_performance_manager(self):
return self.server.get_performance_manager()
#To get the all the server's hosts
def get_all_hosts(self):
"""
Returns a dictionary of the existing hosts keys are their names
and values their ManagedObjectReference object.
"""
return self.server.get_hosts()
#To get all datastores
def get_all_datastores(self):
"""
Returns a dictionary of the existing datastores. Keys are
ManagedObjectReference and values datastore names.
"""
return self.server.get_datastores()
#To get all clusters
def get_all_clusters(self):
"""
Returns a dictionary of the existing clusters. Keys are their
ManagedObjectReference objects and values their names.
"""
return self.server.get_clusters()
#To get all datacenters
def get_all_datacenters(self):
"""
Returns a dictionary of the existing datacenters. keys are their
ManagedObjectReference objects and values their names.
"""
return self.server.get_datacenters()
#.........这里部分代码省略.........
示例2: socket
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_performance_manager [as 别名]
PASSWORD = "password"
prefix = "vsphere."
sock = socket()
try:
sock.connect( (CARBON_SERVER,CARBON_PORT) )
except:
print "Couldn't connect to %(server)s on port %(port)d, is carbon-agent.py running?" % { 'server':CARBON_SERVER, 'port':CARBON_PORT }
sys.exit(1)
try:
server.connect(HOST, USER, PASSWORD)
except:
print "Unable to connect to vsphere server"
sys.exit(1)
pm = server.get_performance_manager()
while True:
lines = []
for dc_mor, dc_name in server.get_datacenters().items():
now = int(time.time())
datastores = server.get_datastores(dc_mor)
for ds_mor, ds_name in datastores.items():
gphDSName = ds_name.replace('.', '_')
gphDSName = gphDSName.replace(' ', '_')
props = VIProperty(server, ds_mor)
lines.append(prefix + dc_name + ".datastores." + props.summary.type + "." + gphDSName + ".capacity " + str(props.summary.capacity) + " " + str(now))
lines.append(prefix + dc_name + ".datastores." + props.summary.type + "." + gphDSName + ".freespace " + str(props.summary.freeSpace) + " " +str(now))
if hasattr(props.summary, "uncommitted"):
lines.append(prefix + dc_name + ".datastores." + props.summary.type + "." + gphDSName + ".uncommitted " + str(props.summary.uncommitted) + " " + str(now))
message = '\n'.join(lines) + '\n'
示例3: getVMdata
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import get_performance_manager [as 别名]
def getVMdata(configFilePath, host, user, password, vmListFile):
if (host is None and user is None and password is None):
OPTION_CHAR = '='
options = {}
if os.path.exists(configFilePath):
content = open(configFilePath)
for line in content:
if OPTION_CHAR in line:
option, value = line.split(OPTION_CHAR, 1)
option = option.strip()
value = value.strip()
if value.startswith('"') and value.endswith('"'):
value = value[1:-1]
options[option] = value
HOST = options['HOST']
USER = options['USER']
PASSWORD = options['PASSWORD']
else:
print "Must supply valid ESX configuration file."
sys.exit(1)
else:
HOST = host
USER = user
PASSWORD = password
try:
server = VIServer()
server.connect(HOST, USER, PASSWORD)
if vmListFile is None:
vmlist = server.get_registered_vms()
else:
if os.path.exists(vmListFile):
fileptr = open(vmListFile)
content = fileptr.read()
vmlist = content.split(",")
metric = []
vmMetrics = {'disk.write': 131079, 'disk.read': 131078, 'disk.usage': 131073, 'cpu.usage': 1, 'mem.usage': 65537}
for vms in vmlist:
vms = vms.strip()
start = vms.find(']') + 2
end = vms.find('/', start)
vmName = vms[start:end]
pm = server.get_performance_manager()
vm = server.get_vm_by_path(vms)
mor = vm._mor
for key, value in vmMetrics.iteritems():
entitystats = pm.get_entity_statistic(mor, key)
for i in entitystats:
dict_result = dict((name, getattr(i, name)) for name in dir(i))
metric_name = vmName+'.'+dict_result['group']+'.'+dict_result['counter']
group = dict_result['group']
timeTuple = dict_result['time']
ts = time.mktime(timeTuple.timetuple())
maxValue = getMaxValue(group)
if dict_result['unit'] == 'percent':
mvalue = float(dict_result['value'])/100
else:
mvalue = dict_result['value']
metric.append({"metric_name": metric_name, "value": mvalue, "unit":dict_result['unit'], "server":vmName, "maxValue":maxValue,"time_stamp":ts})
return metric
except Exception as e:
print e
sys.exit(1)