PyVMomiを介して VM から空き領域を取得するには、最初に VM 用のVMware ツールがシステムにインストールされているかどうかを確認する必要があります。インストールされているかどうかを確認するには、概要ページ (MOB 経由) から VM のゲスト情報を確認します。
toolsStatus - VirtualMachineToolsStatus - "toolsNotInstalled" : これは、VMware ツールをそれぞれの VM にインストールする必要があることを意味します。次のリンクを参照してインストールできます: a) https://my.vmware.com/web/vmware/details?productId =491&downloadGroup=VMTOOLS1000または、b) https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1018377
toolsStatus - VirtualMachineToolsStatus - "toolsOk" : これは、VM に既に VMware ツールがインストールされており、vim.vm.GuestInfo.DiskInfoからdiskPath、capacity、およびfreeSpaceプロパティの値を取得できることを意味します。(上記のように VMware Tools を手動でインストールする場合は、次のようになります)
上記の環境が設定されると、次のコードを使用して VM からそれぞれの情報を取得できます。
service_instance = None
vcenter_host = "HOSTNAME"
vcenter_port = NUMERIC_PORT
vcenter_username = "USERNAME"
vcenter_password = "PASSWORD"
vmName = "VM_NAME";
try:
#For trying to connect to VM
service_instance = connect.SmartConnect(host=vcenter_host, user=vcenter_username, pwd=vcenter_password, port=vcenter_port, sslContext=context)
atexit.register(connect.Disconnect, service_instance)
content = service_instance.RetrieveContent()
container = content.rootFolder # starting point to look into
viewType = [vim.VirtualMachine] # object types to look for
recursive = True # whether we should look into it recursively
containerView = content.viewManager.CreateContainerView(
container, viewType, recursive)
#getting all the VM's from the connection
children = containerView.view
#going 1 by 1 to every VM
for child in children:
vm = child.summary.config.name
#check for the VM
if(vm == vmName):
vmSummary = child.summary
#get the diskInfo of the selected VM
info = vmSummary.vm.guest.disk
#check for the freeSpace property of each disk
for each in info:
#To get the freeSPace in GB's
diskFreeSpace = each.freeSpace/1024/1024/1024
問題が解決することを願っています。