VMware {code} Community
terrygeorge
Contributor
Contributor

ManagedObjectNotFoundFault

I am trying to reconfiure a VM  using converter API.

This is code snippet

      ConverterComputerSpecManagedVmLocation sourceVM= new  ConverterComputerSpecManagedVmLocation();
         ConverterVimConnectionSpecLoginVimCredentials vimCredentials =
                                  new ConverterVimConnectionSpecLoginVimCredentials();
         vimCredentials.setPassword(_vcPassword);
         vimCredentials.setUsername(_vcUsername);
         ConverterVimConnectionSpec vimConnectionSpec = new  ConverterVimConnectionSpec();
         vimConnectionSpec.setHostname(_vcServerName);
         vimConnectionSpec.setCredentials(vimCredentials);
         System.out.println("_vcServerName"+vimConnectionSpec.getHostname());
         vimConnectionSpec.setVerifyPeer(false);
         vimConnectionSpec.setSslThumbprint(null);
         sourceVM.setVimConnect(vimConnectionSpec);
         com.vmware.converter.ManagedObjectReference vmMoRef= new  com.vmware.converter.ManagedObjectReference();
         vmMoRef.setType ("VirtualMachine");
        vmMoRef.set_value  (_vcVMToCreate);
        sourceVM.setVm(vmMoRef);
         //sourceVM.setUuid(getVMUUID());
        ConverterComputerSpec  liveSourceSpec = new ConverterComputerSpec();
             liveSourceSpec.setLocation(sourceVM);
        return liveSourceSpec;

This is the  error I get.

AxisFault
faultCode: ServerFaultCode
faultSubcode:
faultString: The  request refers to an object that no longer exists or has never
existed.
faultActor:
faultNode:
faultDetail:
         {urn:converter}ManagedObjectNotFoundFault:<vim25:obj  type="ManagedEntity
">P2V1</vim25:obj>

_vcVMToCreate  is passed a value P2V1

The VM exists but API cant find it.

Reply
0 Kudos
1 Reply
peevs
VMware Employee
VMware Employee

It's not correct to put VM name as value of the VM managed object reference ( i suppose P2V1 is your source VM name ).

The managed object ref. for VM which resides on a VC have to look like:

ManagedObjectReference vmMor = new ManagedObjectReference();

vmMor.setType("VirtualMachine");

vmMor.set_value("vm-554"); // vm-554 is the VM ID, vm IDs has format vm-XXX, where XXX is some integer

To get the exact ID of you VM you have to use VC API... here is example code which do this:

Here it is example code (note: you have to get serviceInstance to the is VC first, ref VC dev forum for details)

/**
    * This function takes in virtual machine name check it's
    * existence and return back it's VirtualMachine instance.
    *
    * @param vmName
    * @return VirtualMachine Instance
    * @throws Exception
    */
   public VirtualMachine getVm(String vmName)
   throws Exception {
      InventoryNavigator nav =
         new InventoryNavigator(this.getServiceInstance().getRootFolder());
      VirtualMachine vm =
         (VirtualMachine) nav.searchManagedEntity("VirtualMachine", vmName);
      if(vm == null) {
         throw new Exception("Null pointer returned while trying to "
               + "retrieve virtual machines");
      }
      return vm;
   }

Reply
0 Kudos