VMware {code} Community
hnehnes
Contributor
Contributor

Problems with Java SDK/VMCreate-example

Hi,

I've a problem with the vCenter-SDK: I tried to run the VMCreate-example and it does not work correctly for me. I get the following error:

java.lang.Exception: Specified Datastore is not Found

Any hints?

Best Regards,

Hendrik

Tags (3)
0 Kudos
2 Replies
hartsocks
VMware Employee
VMware Employee

ManagedObjectReference dcmor =
                getMOREFsInContainerByType(serviceContent.getRootFolder(),
                        "Datacenter").get(dataCenterName);

The error is usually thrown from a code block like this... and very simply nothing with the type "Datacenter" was found with the name specified. It could be that your name has a space in it or a special character the command line doesn't like. Try putting quotes or escaping the special characters.

// Shawn Hartsock
0 Kudos
hnehnes
Contributor
Contributor

Hi,

well this is not the problem, I actually get a datacenter-object, this works. My ConfigTarget looks pretty empty:

configTarget    ConfigTarget  (id=27)   
    autoVmotion    null   
    cdRom    null   
    datastore    null   
    distributedVirtualPortgroup    null   
    distributedVirtualSwitch    null   
    dynamicProperty    null   
    dynamicType    null   
    floppy    null   
    ideDisk    null   
    legacyNetworkInfo    null   
    maxMemMBOptimalPerf    98293   
    network    ArrayList<E>  (id=48)   
        elementData    Object[10]  (id=50)   
        modCount    0   
        size    0   
    numCpuCores    8   
    numCpus    8   
    numNumaNodes    2   
    parallel    null   
    pciPassthrough    null   
    resourcePool    null   
    scsiDisk    null   
    scsiPassthrough    ArrayList<E>  (id=52)   
    serial    ArrayList<E>  (id=12733)   
    smcPresent    Boolean  (id=12734)   
    sound    null   
    usb    null

The problem is, I don't get neither a network nor a datastore. Here is the code:

ConfigTarget configTarget = getConfigTargetForHost(computeResMor, hostMor);
      List<VirtualDevice> defaultDevices = getDefaultDevices(computeResMor, hostMor);
      VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec();
      String networkName = null;
      if (configTarget.getNetwork() != null) {
         for (int i = 0; i < configTarget.getNetwork().size(); i++) {
            VirtualMachineNetworkInfo netInfo = configTarget.getNetwork().get(i);
            NetworkSummary netSummary = netInfo.getNetwork();
            if (netSummary.isAccessible()) {
               networkName = netSummary.getName();
               System.out.println(networkName);
               break;
            }
         }
      }
      ManagedObjectReference datastoreRef = null;
      if (datastoreName != null) {
         boolean flag = false;
         for (int i = 0; i < configTarget.getDatastore().size(); i++) {
            VirtualMachineDatastoreInfo vdsInfo = configTarget.getDatastore().get(i);
            DatastoreSummary dsSummary = vdsInfo.getDatastore();
            if (dsSummary.getName().equals(datastoreName)) {
               flag = true;
               if (dsSummary.isAccessible()) {
                  datastoreName = dsSummary.getName();
                  datastoreRef = dsSummary.getDatastore();
                  System.out.println(datastoreName);
                  System.out.println(datastoreRef);
               } else {
                  throw new Exception("Specified Datastore is not accessible");
               }
               break;
            }
         }
         if (!flag) {
            throw new Exception("Specified Datastore is not Found");
         }

Thanks and Regards,

Hendrik

0 Kudos