5

私は最近、インスタンスを AWS に移行する前に、pyvmomi を使用して vmware サーバーの詳細なインベントリを取得し始めました。

vCenter Web インターフェイスまたは vsphere クライアントで、インスタンスを調べてそのディスクを確認すると、ディスク サイズ (プロビジョニング済み) と使用中 (使用済みストレージ) の量がわかります。

サンプルの github リポジトリ ( https://github.com/vmware/pyvmomi-community-samples ) から、インスタンスに関する情報を取得する方法をすぐに学ぶことができたので、ディスク サイズを取得するのは簡単です (SO には、ドライブを取得する簡単な方法 - PyVMomi を使用して VMWare VM ディスクのサイズを取得する方法)、しかし、Web/クライアントが表示できる実際に使用されているストレージを取得する方法がわかりません。

では、特定のインスタンス ディスクの使用済み領域を取得するにはどうすればよいでしょうか?

4

2 に答える 2

3

PyVMomiを介して VM から空き領域を取得するには、最初に VM 用のVMware ツールがシステムにインストールされているかどうかを確認する必要があります。インストールされているかどうかを確認するには、概要ページ (MOB 経由) から VM のゲスト情報を確認します。

  1. 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

  2. toolsStatus - VirtualMachineToolsStatus - "toolsOk" : これは、VM に既に VMware ツールがインストールされており、vim.vm.GuestInfo.DiskInfoからdiskPathcapacity、および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

問題が解決することを願っています。

于 2016-08-10T08:39:39.857 に答える