VMware Cloud Community
SteskaljGE
Enthusiast
Enthusiast
Jump to solution

add Custom Properties to On-Boarding Deployment through the rest api

Has anyone been able to do this:

Add Custom Properties to On-Boarding Deployment through the rest api?

In the documentation for the relocate api there is an example for tags on the resource, but no custom properties.

This is the api in reference to: /relocation/onboarding/task/create-deployment
Here is the example from the swagger:


Example Value
Model
{
"planLink": "string",
"deploymentLink": "string",
"name": "string",
"description": "string",
"resources": [
{
"link": "string",
"name": "string",
"tagLinks": [
"string"
]
}
],
"createBlueprint": true
}

Labels (3)
0 Kudos
1 Solution

Accepted Solutions
StefanSchnell
Enthusiast
Enthusiast
Jump to solution

Hello @SteskaljGE,

I had the same requirement recently. I did not set the custom property to the deployment, but to the VM that was used for onboarding. You can do that very easily with a  PATCH  REST call from the Infrastructure as a Service API  /iaas/api/machines/{id}.  There you can pass the custom properties in the body. First I use  GET  /iaas/api/machine  to detect the ID of the VM by its name, to use this in the PATCH call.

Check in your Actions if the folder com.vmware.library.vra.infrastructure.machine exists. If so, there should be the Action createMachineCustomProperties, with which you can also set custom properties.

Best regards
Stefan


More interesting information at blog.stschnell.de

View solution in original post

0 Kudos
3 Replies
StefanSchnell
Enthusiast
Enthusiast
Jump to solution

Hello @SteskaljGE,

I had the same requirement recently. I did not set the custom property to the deployment, but to the VM that was used for onboarding. You can do that very easily with a  PATCH  REST call from the Infrastructure as a Service API  /iaas/api/machines/{id}.  There you can pass the custom properties in the body. First I use  GET  /iaas/api/machine  to detect the ID of the VM by its name, to use this in the PATCH call.

Check in your Actions if the folder com.vmware.library.vra.infrastructure.machine exists. If so, there should be the Action createMachineCustomProperties, with which you can also set custom properties.

Best regards
Stefan


More interesting information at blog.stschnell.de

0 Kudos
emacintosh
Hot Shot
Hot Shot
Jump to solution

Here is the powershell function we use.  The base is simply the url for your vra instance and the token is an access token you've already obtained elsewhere.  The resourceId is the one for the vm in vRA.

 

It takes a hashtable of properties that you want to update.  I believe the other properties are left alone, but probably worth testing.

 

function update-customProperties {
    param (
        [Parameter(Mandatory)]
        [string] $base,

        [Parameter(Mandatory)]
        [string] $token,

        [Parameter(Mandatory)]
        [string] $resourceId,

        [Parameter(Mandatory)]
        [hashtable] $properties
    )

    $uri = "$base/iaas/api/machines/$resourceId"

    $headers = @{
        "Authorization" = "Bearer $token"
    }

    $body = @{
        customProperties = $properties
    }

    try {
        $response = Invoke-RestMethod -Uri $uri -Method Patch -Headers $headers -body ($body | ConvertTo-Json)
        write-output $response
    }
    catch {
        throw $_
    }
}

 

0 Kudos
eoinbyrne
Expert
Expert
Jump to solution

Hi

Yes, I have done this for vRA 7 VMs in vRA 8 onboarding plans. We needed to preserve the most important custom properties for the integrations to work in 8 as they do in 7. The Onboarding UI provides for manual property updates on each resource in the plan but for hundreds of VMs this is a large data entry task & probably error prone. 

I wrote a workflow to wrangle the 2 REST APIs as follows

Read the resources in a vRA 8 Onboarding plan and then for each, contact vRA 7 CatalogService to get the custom properties. Transfer the important properties to the plan resource and then use the PATCH call to update it

eoinbyrne_0-1684490648906.png

 

It works quite well and saves a lot of mucking about

-HTH