StefanxNil
Contributor
Contributor

Register unmanaged machine using vRealize API

Jump to solution

Hello,

I am trying to register a VM by using the following API:

/iaas-proxy-provider/api/machines/register

with the following payload:

{

    "owner": "user@example.local",

    "virtualMachineId": "ff1b4d87-1209-4096-8920-2ac8dcff3f3d",

    "requestingUser": "user@example.local",

    "componentId": "VirtualMachine",

    "machineProperties": [],

    "compositeBlueprintId": "CentOS7",

    "deploymentName": "Deployment_MACHINE-1",

    "hostReservationId": "17d5fde6-6d13-48d6-a62d-271e5323b79a",

    "templateId": "de26e2f2-b4b1-43f6-a96a-cb4c5ae753b0",

    "hostStorageReservationId": "819ee0b5-b1dc-4b77-bba3-2a691333a090"

}

My question is: how to get the values for templateId and hostStorageReservationId. I was able to determine correct values expected by API by performing Bulk Import functionality of vRealize and examining the logs on IaaS server:

RegisterVmFromQueueActivity.ProcessElement:

Register VM: ff1b4d87-1209-4096-8920-2ac8dcff3f3d,

blueprint: de26e2f2-b4b1-43f6-a96a-cb4c5ae753b0,

reservation: Reservation-DEV-1 (17d5fde6-6d13-48d6-a62d-271e5323b79a),

storage: Pure-A (819ee0b5-b1dc-4b77-bba3-2a691333a090),

owner: user@example.local,

element: 4

The value for blueprint matches the templateId in API call and storage matches hostStorageReservationId. If I performed the API call, the import process started correctly.

It appears that IaaS server is able to extract these 2 values from its SQL internal database.

My question is: Is there a way to get these values by using vRealize API or any vRO plugin? I am unable to find any relevant API or class that would provide these values.

0 Kudos
1 Solution

Accepted Solutions
siglert
Enthusiast
Enthusiast

You can always look in orchestrator to get what you need if you can not find it with the API.

View solution in original post

5 Replies
eoinbyrne
Expert
Expert

You can get the Reservations from here (so you can locate the ID of the entry you need)

pastedImage_0.png

And do the same for Blueprints from here

pastedImage_1.png

0 Kudos
StefanxNil
Contributor
Contributor

The storage information I get if I query reservations with:

reservation-service/api/reservations

is:

{

    "key": "storagePath",

    "value": {

        "type": "entityRef",

        "classId": "Storage",

        "id": "9136c769-7a3a-4870-952d-191437cfb25b",

        "componentId": null,

        "label": "Pure-A"

    }

}

If I used the id above, I got the error:

An error occurs when registering a machine Invalid Storage Reservation ID 9136c769-7a3a-4870-952d-191437cfb25b

As for blueprint the data I get is:

{

    "@type": "CompositeBlueprintInfo",

    "createdDate": "2018-08-30T13:46:54.221Z",

    "lastUpdated": "2020-03-30T02:05:44.249Z",

    "version": 86,

    "name": "CentOS 7",

    "description": "",

    "publishStatus": "PUBLISHED",

    "publishStatusName": "Published",

    "customFormStatus": "NA",

    "customFormStatusName": "{customform.status.NA}",

    "id": "CentOS7"

}

API expects templateId to be UUID and blueprint Id is specified with compositeBlueprintId which works perfectly fine.
I believe that in case of Bulk import via CSV, IaaS server is resolving these values into IDs in its own database which have different IDs as the one provided by corresponding vRA API endpoints.
I am currently digging through IaaS Proxy Provider Service API and will post results if find anything.
0 Kudos
siglert
Enthusiast
Enthusiast

You can always look in orchestrator to get what you need if you can not find it with the API.

View solution in original post

eoinbyrne
Expert
Expert

The ID of the Reservation is the one to use there. You've used the ID of the Storage/Datastore which I'd expect to fail (and it has Smiley Happy). vRA has always had a "split-brain" as some of the APIs are hosted on the .Net applications on the Windows node(s) and the others are on the Appliance (CAFE APIs). In most cases where objects are shared between the two, the IDs are the same (e.g., BusinessGroup in CAFE API vs ProvisioningGroup in IaaS side)

You should be safe enough to use the Reservation ID from the CAFE Reservation API as it will be the same in the IaaS one (& the register call probably checks the ID against the CAFE Reservation API anyway)

0 Kudos
StefanxNil
Contributor
Contributor

I think there was misunderstanding here. I was looking for templateId and hostStorageReservationId (not hostReservationId). Anyway, I could not find some REST API (which I would prefer), so as per siglert suggestion, I look into vRO a bit more and found the solution. Posting it here in case someone find it useful:

// host = vCAC:VCACHost

var hostToStorage = System.getModule("com.vmware.library.vcac").getHostToStorageByNameAndReservation(host, "Pure-A","Reservation-DEV-1");

var hostToStorageProperties = hostToStorage.getProperties();

System.log("hostStorageReservationId:" + hostToStorageProperties.get("HostReservationToStorageID"));

// vm = vCAC:VirtualMachine

var vmBlueprint = System.getModule("com.vmware.library.vcac").getSystemBlueprintByVirtualMachine(host, vm);

var blueprintProperties = vmBlueprint.getProperties()

System.log("templateId:" + blueprintProperties.get("VirtualMachineTemplateID"));

As you said, IDs are same most of the time (for reservation itself), but for hostStorageReservationId it is definitely not. As for templateId I am not sure why I have to pass it to API since IaaS server could always pull it from vCAC:VirtualMachine.

Best regards

0 Kudos