0

VMWare Sdk プログラミングは初めてです。仮想マシン (VM) の展開日を取得する必要があります。

他の必要な詳細を取得するために、以下のコードを作成しました。

package com.vmware.vim25.mo.samples;

import java.net.URL;

import com.vmware.vim25.*;
import com.vmware.vim25.mo.*; 


public class HelloVM {


     public static void main(String[] args) throws Exception
     {
     long start = System.currentTimeMillis();
     int i;
     ServiceInstance si = new ServiceInstance(new URL("https://bgl-clvs-vc.bgl.com/sdk"), "sbibi", "sibi_123", true);
     long end = System.currentTimeMillis();
     System.out.println("time taken:" + (end-start));
     Folder rootFolder = si.getRootFolder();
     String name = rootFolder.getName();
     System.out.println("root:" + name);
     ManagedEntity[] mes = new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine");


     System.out.println("No oF vm:" + mes.length);
     if(mes==null || mes.length ==0)
     {
         return;
     }
     for(i=0;i<mes.length; i++){

         VirtualMachine vm = (VirtualMachine) mes[i];

         VirtualMachineConfigInfo vminfo = vm.getConfig();
         VirtualMachineCapability vmc = vm.getCapability();
         vm.getResourcePool();
         System.out.println("VM Name " + vm.getName());
         System.out.println("GuestOS: " + vminfo.getGuestFullName());
         System.out.println("Multiple snapshot supported: " + vmc.isMultipleSnapshotsSupported());
         System.out.println("Summary: " + vminfo.getDatastoreUrl()); 
     }


     si.getServerConnection().logout();

     } 


}

VM の作成日を取得する方法を教えてもらえますか?

4

2 に答える 2

0
private DateTime GetVMCreatedDate(VirtualMachine vm)
    {
        var date = DateTime. Now;
        var userName = new EventFilterSpecByUsername ();
        userName . SystemUser = false;
        var filter = new EventFilterSpec ();
        filter . UserName = userName;
        filter . EventTypeId = ( new String [] { "VmCreatedEvent" , "VmBeingDeployedEvent" ,"VmRegisteredEvent" , "VmClonedEvent" });
        var collector = vm .GetEntityOnlyEventsCollectorView(filter);
        foreach (Event e in collector . ReadNextEvents(1 ))
        {
            Console .WriteLine(e . GetType(). ToString() + " :" + e. CreatedTime);
            date = e. CreatedTime;
        }

        Console .WriteLine( "---------------------------------------------------" );
        return date;
    }
于 2014-12-31T05:36:40.317 に答える