-
Notifications
You must be signed in to change notification settings - Fork 924
/
Copy pathvminfo_quick.py
executable file
·70 lines (58 loc) · 2.25 KB
/
vminfo_quick.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
"""
Written by Michael Rice
Github: https://github.com/michaelrice
Website: https://michaelrice.github.io/
Blog: http://www.errr-online.com/
This code has been released under the terms of the Apache 2 licenses
http://www.apache.org/licenses/LICENSE-2.0.html
Script to quickly get all the VMs with a set of common properties.
"""
import atexit
try:
# Python 3.8 : time.clock was deprecated and removed.
from time import perf_counter as clock
except ImportError:
from time import clock
from pyVmomi import vim
from tools import cli, service_instance, pchelper
START = clock()
def endit():
"""
times how long it took for this script to run.
:return:
"""
end = clock()
total = end - START
print("Completion time: {0} seconds.".format(total))
# List of properties.
# See: http://goo.gl/fjTEpW
# for all properties.
vm_properties = ["name", "config.uuid", "config.hardware.numCPU",
"config.hardware.memoryMB", "guest.guestState",
"config.guestFullName", "config.guestId",
"config.version"]
parser = cli.Parser()
args = parser.get_args()
si = service_instance.connect(args)
atexit.register(endit)
root_folder = si.content.rootFolder
view = pchelper.get_container_view(si, obj_type=[vim.VirtualMachine])
vm_data = pchelper.collect_properties(si,
view_ref=view,
obj_type=vim.VirtualMachine,
path_set=vm_properties,
include_mors=True)
for vm in vm_data:
print("-" * 70)
print("Name: {0}".format(vm["name"]))
print("BIOS UUID: {0}".format(vm["config.uuid"]))
print("CPUs: {0}".format(vm["config.hardware.numCPU"]))
print("MemoryMB: {0}".format(
vm["config.hardware.memoryMB"]))
print("Guest PowerState: {0}".format(vm["guest.guestState"]))
print("Guest Full Name: {0}".format(vm["config.guestFullName"]))
print("Guest Container Type: {0}".format(vm["config.guestId"]))
print("Container Version: {0}".format(vm["config.version"]))
print("")
print("Found {0} VirtualMachines.".format(len(vm_data)))