VMware Cloud Community
TimDScott
Enthusiast
Enthusiast

Getting a machines VCAC:Reservation

I have the following code in an action (it takes a vCAC:VCACHost and a vCAC:VirtualMachine as inputs):

var id = vCACMachine.getProperty("HostReservationID");

System.debug("Reservation Id: " + id);

var idprop = new Properties( {

"HostReservationID" : id

});

if (!id || id == "") throw "Error getting Reservation ID of VM.";

var entity = vCACEntityManager.readModelEntity(vCACHost.id, "ManagementModelEntities.svc", "HostReservations", idprop, null);

System.debug("Got Entity: " + entity);

var reservation = entity.getInventoryObject();

if (!reservation) throw "Reservation with ID '" + id + "' not found";

return reservation;

I'm getting an error "Cannot create vCACReservation object : java.lang.NullPointerException" on the var reservation = entity.getInventoryObject(); line. The reservation id and the entity are being logged in the debug:

2020-02-27 11:42:20.754] [D] Reservation Id: f5f95f3e-53d9-43a7-bff9-837ec54acbc6

[2020-02-27 11:42:20.793] [D] Got Entity: DynamicWrapper (Instance) : [VCACEntity]-[class com.vmware.o11n.plugin.dynamicops.model.Entity] -- VALUE : org.odata4j.core.OEntities$OEntityAtomImpl@683d9163[title=,categoryTerm=DynamicOps.ManagementModel.HostReservation,entitySet=EdmEntitySet[HostReservations,org.odata4j.edm.EdmEntityType$Builder$1@2db42c7c],entityType=EdmEntityType[DynamicOps.ManagementModel.HostReservation,alias=null],entityKey=(guid'f5f95f3e-53d9-43a7-bff9-837ec54acbc6'),properties=[OProperty[HostReservationID,EdmSimpleType[Edm.Guid],f5f95f3e-53d9-43a7-bff9-837ec54acbc6]..................................

Any ideas why the VCACReservation object can't be created?

(v7.5)

0 Kudos
9 Replies
stevedrummond
Hot Shot
Hot Shot

Without any context is there a reason you're using the legacy vCAC components rather than vCACCAFE (which now proxies a lot of IaaS work)?

Considering the IaaS components are "legacy" it's possible changes were made but the linkage between Entity and plug-in object got broken.

As you have the reservation ID you can easily get the reservation object by using vCACCAFEEntitiesFinder.getReservation(vcacCafeHost, reservationId)

0 Kudos
TimDScott
Enthusiast
Enthusiast

I'm using the "Import vCenter Virtual Machine" workflow, this requires a vCAC host, so thought I would use this to do everything else too?

0 Kudos
stevedrummond
Hot Shot
Hot Shot

Right.

In that case since you already have the HostReservationID you can just do Server.findForType('vCAC:Reservation', hostReservationId) which will give you the vcac:Reservation object required for the hostReservation​ input.

0 Kudos
TimDScott
Enthusiast
Enthusiast

Thanks stevedrummond​ , unfortunately this doesn't seem to be working for me, getting this error:

'Unable to find for type, reason : Cannot create vCACReservation object : java.lang.NullPointerException'

This is the code from my action (takes the vCAC:VirtualMachine as an input, vCAC:Reservation as output):

var id = vCACMachine.getProperty("HostReservationID");

return Server.findForType('vCAC:Reservation', id)

0 Kudos
stevedrummond
Hot Shot
Hot Shot

So it seems something else is wrong, which is likely the cause of your initial Entity.getInventoryObject() error as well.

Considering you are trying to import a new machine are you sure there is a working reservation for this machine? Your log output above said the id is f5f95f3e-53d9-43a7-bff9-837ec54acbc6. I would have thought you would need to specify what reservation you want it to go on, not get it's "existing" since you're importing it.

Can you see this in the plug-in inventory of vRA? Or via the API? If you quickly jump into postgres and do

SELECT id, name, enabled FROM rsrv_reservation WHERE id = 'f5f95f3e-53d9-43a7-bff9-837ec54acbc6';

does it find it? If not, double check in the IaaS SQL database to make sure something screwy hasn't happened

SELECT HostReservationID, HostReservationName from iaasdb.dbo.HostReservation;

We don't import machines as we're predominately public cloud so I don't have much experience with machines that aren't already managed by vRA.

0 Kudos
TimDScott
Enthusiast
Enthusiast

OK, so what you are saying is that a machines reservation Id is unique to the machine, i.e. not a pointer to an actual reservation that's available for assignment to a new machine.

I guess I would need to try and determine the name of the reservation associated to the original machine, then lookup the vcac:reservation object by name somehow?

Thanks again for your continued help Steve :smileygrin:

0 Kudos
stevedrummond
Hot Shot
Hot Shot

I guess I would need to try and determine the name of the reservation associated to the original machine

What exactly are you trying to do? You never mentioned. Reading that, I assume the machine was previously managed, then became unmanaged (by choice or backup/restore, etc.), and you want to import it again?

OK, so what you are saying is that a machines reservation Id is unique to the machine, i.e. not a pointer to an actual reservation that's available for assignment to a new machine.

No, the reservation is the Infrastructure Reservation, which contains many machines. As you are importing a machine you need to identify beforehand which reservation it needs to be on, as vRA cannot do this itself (you may have many reservations pointing at the same compute/storage/network endpoints). If the machine was previously managed you should be able to get it by looking at the VirtualMachineHistory or VirtualMachinePropertiesHistory tables in IaaS, or from the resourcedata of the DELETED resource on the cat_resource table in postgres.

That seems like a lot of work though and if this is going to be repeated you should probably have some other manual or automated logic of determining the reservation. It may be easier to resolve the reservation by using Reservation Policies and working backward through Policy -> Reservation -> Filter by Business Group

0 Kudos
TimDScott
Enthusiast
Enthusiast

What exactly are you trying to do? You never mentioned. Reading that, I assume the machine was previously managed, then became unmanaged (by choice or backup/restore, etc.), and you want to import it again?

Yes, the scenario is that the machine is managed, then becomes unmanaged after a restore operation (as the restore tool deletes the original machine and re-creates it from the backup with a new instance UUID)

I'm trying to develop a workflow that:

  • Retrieves and stores the properties of the target machine that are needed by the "Import vCenter Virtual Machine" (in Library\vRealize Automation\Infrastructure Administration\Extensilbility\Discovery) workflow
  • Runs the restore operation
  • Detects the newly restored machine (grabbing the VC:VirtualMachine)
  • Runs the import workflow using the new machine along with the stored properties of the old one, therefore re-instating the machine as managed with everything set to what it was on the original machine

I have everything I need apart from the vCAC:Reservation.

0 Kudos
stevedrummond
Hot Shot
Hot Shot

OK, that makes way more sense.

So are you getting the error when attempting to get the reservation for an existing managed machine (to meet the criteria of your first dot point)?

If so, note its reservation ID and look in the database as I mentioned before. As the machine is ​currently managed it should have a working existing reservation ID; however, I have seen stranger things from vRA. Do other machines on the same reservation work?

0 Kudos