-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyvmomi_vm_inventory.py
More file actions
56 lines (40 loc) · 1.43 KB
/
pyvmomi_vm_inventory.py
File metadata and controls
56 lines (40 loc) · 1.43 KB
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
from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim
import ssl
context = ssl._create_unverified_context()
si = SmartConnect(
host="192.168.10.69",
user="administrator@vsphere.local",
pwd="VMware123!",
sslContext=context
)
content = si.RetrieveContent()
container = content.viewManager.CreateContainerView(
content.rootFolder,
[vim.VirtualMachine], # type of object to search
True
)
for vm in container.view:
print(vm.name, vm.runtime.powerState)
# from pyVim.connect import SmartConnect, Disconnect
# # SmartConnect = login wrapper for SOAP API
# # Disconnect = gracefully close session
# from pyVmomi import vim
# # vim object model = all vSphere managed objects (VM, host, datastore…)
# import ssl
# # imported to create a context that ignores SSL certs
# context = ssl._create_unverified_context()
# # prevents SSL errors from vCenter's self-signed certificate
# si = SmartConnect(…)
# # connect to vCenter SOAP endpoint
# # return a ServiceInstance
# content = si.RetrieveContent()
# # get vCenter’s entire inventory
# container = content.viewManager.CreateContainerView(
# content.rootFolder, # where to start the search
# [vim.VirtualMachine], # what object type to find
# True # recursive search
# )
# for vm in container.view:
# print(vm.name, vm.runtime.powerState)
# # loop through VM objects and print properties