Executing Day 2 Actions with the vRA 7 REST API

In this guide I will show you how to use the vRA 7 REST API to perform day 2 actions on a VM. This is common for users or developers that want to programmatically control the VM’s provisioned from vRealize Automation.

Pre-Reqs

  • Already provisioned vRA 7 Blueprint with Destroy Deployment entitled See my guide here to use the API
  • A linux system with a command line that you can run curl from to connect to the vRealize Appliance API
  • An account with access to vRA 7 that can provision a vRA 7 blueprint with the Shutdown Machine Entitlment
  • A quiet place where you will not be interrupted see my guide here

Lets get started, first we will need to set some environment variables to save us time. Let’s export the vRA appliance host name.

export VRA=vra-01a.corp.local

Create variable for the HTTP Accept header, which tells the server what format you want the response to be in.

export ACCEPT="application/json"

Here we will authenticate by requesting a bearer token via a POST against /identity/api/tokens API, and we will store the bearer token in a variable so we can use it on future API invocations. This example passes a devusers credentials with inline JSON, but you could also create variables or store this JSON in a file and use the file instead.

curl --insecure -H "Accept: application/json" -H 'Content-Type: application/json' --data '{"username":"tony@corp.local","password":"VMware1!","tenant":"vsphere.local"}' https://$VRA/identity/api/tokens

Now let’s grab the bearer token from the response above. Highlight all the text between the quotes as shown and copy it to the clip board

Now we will export the token to a variable like below

export AUTH="Bearer MTQ0OTYwMjc2MDI4NToyODlmZWM2MjZlNzNkMDAwZmRmYjp0ZW5hbnQ6dnNwaGVyZS5sb2NhbHVzZXJuYW1lOnRvbnlAY29ycC5sb2NhbGV4cGlyYXRpb246MTQ0OTYzMTU2MDAwMDo4MzE3NThmNjhjZTNjNzg5MDNiMWM3ODdlODBmMDQ3NGYzNmYwMzBkYWFjNGM4Y2I3YTk5YmY1ODBmN2E4N2IyNzM4MTRhM2M3NmQzNzM3ZTUzMmZjZDI4OGEwZTI0OTA4NTZjMDg3YTQ2NzRjMjczZTIyOTQyZGJlOWQwNDU2NQ=="

Now lets test connectivity by listing the entitled catalog items with curl –insecure -H “Accept: $ACCEPT” -H “Authorization: $AUTH” https://$VRA/catalog-service/api/consumer/entitledCatalogItems | python -m json.tool

Notice I add a pipe on the end of the command. This makes the JSON output more readable.  | python -m json.tool

Ok, now that we have connectivity let’s get the list of available resources (Hint, this is the data from the items view tab in the vRA Portal)

curl --insecure -H "Accept: $ACCEPT" -H "Authorization: $AUTH" https://$VRA/catalog-service/api/consumer/resources | python -m json.tool

In the output we will need the Request ID of the deployment

Copy and paste the ID to note pad, we will need to use this later in this guide

Now let’s get the list of actions that are available for that resource ID with the following

Notice I highlighted where you need to enter that resource ID that we copied in the step above.

curl --insecure -H "Accept: $ACCEPT" -H "Authorization: $AUTH" https://$VRA/catalog-service/api/consumer/requests/b4382744-c6d6-4326-920c-5995e8e04747/resourceViews | python -m json.tool

Now we need to get the Resource ID of the virtual Machine in this deployment

Scroll up until you find the following and copy it to the clipboard, we will need it in the next step

Now we need to list the available actions for this resource

Now let’s get the ID for the shutdown machine action

Copy this to the clipboard, we will need it in the next step

Now we need to get the json payload for the shutdown action

curl --insecure -H "Accept: $ACCEPT" -H "Authorization: $AUTH" https://$VRA/catalog-service/api/consumer/resources/1a0cd3ad-03c0-40aa-a00a-3876e35b6d03/actions/00ef75d5-1a61-4ead-a5e6-f01b43ece1d0/requests/template | python -m json.tool > /tmp/shutdowncentos7.json

You can view the payload with the following command

cat /tmp/shutdowncentos7.json

Now let’s send the request with the following command

curl --insecure -H "Accept: $ACCEPT" -H "Authorization: $AUTH" https://$VRA/catalog-service/api/consumer/resources/1a0cd3ad-03c0-40aa-a00a-3876e35b6d03/actions/00ef75d5-1a61-4ead-a5e6-f01b43ece1d0/requests --data @/tmp/shutdowncentos7.json --verbose -H "Content-Type: application/json" | python -m json.tool

Verify on the items view tab that the requested action was successful.

Remember sharing is caring!

16 Replies to “Executing Day 2 Actions with the vRA 7 REST API”

  1. Hi Ryan,
    Great Post!!

    Did you ever tried to trigger a reconfigure before?
    I have an use-case where I want to resize VM file system and resize the existing disk or add another disk.
    I’ve tried using the day2 triggering you’ve offered and changing only the disk size in the JSON template but no luck.
    I can see the request in the vRA but the data I’ve changed in the JSON body is not part of this request.

    Same is happening when trying to add CPU via reconfigure, but in the CPU I can see the new value in the request but nothing is changing in the machine itself.

    Important to mentioned that a reconfigure is triggered in the vCenter in both cases but nothing is changing in the machines.

    vRA manual reconfigure is working well.

    Any ideas?
    Erez.

    • Hi Erez,

      I am working with engineering on this issue now, trying to recreate in my lab, will post here or create a new post when I have a solution.

      • Buenos días,en breve recibirás un email con cruceros que puedan ser de tu interés.Que tengas un buen día.VN:F [11pa22_.171]9le.se wait…VN:F [1.9.22_1171](from 0 votes)

  2. Your payload for a second disk should look like the following, note a few things though:
    1. “Cafe.Shim.VirtualMachine.Reconfigure.Requestor”: “grant”, is not present in the template when you get it from the API, you will need to add it manually. The value doesn’t matter, they presence of the key does however.
    2. The externalId of your second disk will need to be null.
    3. You will need to change the “storage” key at the end of the json to the total value of storage assigned to the item.

    {
    “type”: “com.vmware.vcac.catalog.domain.request.CatalogResourceRequest”,
    “resourceId”: “981f0832-6477-4e1f-a2c8-04942ac53881”,
    “actionId”: “cc33f02a-8963-4e01-a29d-24cb11fce3a3”,
    “description”: null,
    “data”: {
    “Cafe.Shim.VirtualMachine.Reconfigure.Requestor”: “grant”,
    “allowForceShutdown”: “false”,
    “cpu”: 1,
    “customProperties”: [
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “_number_of_instances”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “1”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “Cafe.Shim.VirtualMachine.TotalStorageSize”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “1”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “trace_id”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “gCbqCFVs”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “VirtualMachine.Admin.AgentID”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “dda11a42-889c-e839-fc57-63475791e3d7”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “VirtualMachine.Admin.Hostname”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “Cluster-01a”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “VirtualMachine.Admin.TotalDiskUsage”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “1024”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “VirtualMachine.Admin.UUID”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “501a2d25-b310-c8d5-b439-e66f79379908”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “VirtualMachine.Cafe.Blueprint.Component.Cluster.Index”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “0”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “VirtualMachine.Cafe.Blueprint.Component.Id”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “vSphere_Machine_1”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “VirtualMachine.Cafe.Blueprint.Component.TypeId”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “Infrastructure.CatalogItem.Machine.Virtual.vSphere”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “VirtualMachine.Cafe.Blueprint.Id”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “CentOS”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “VirtualMachine.Cafe.Blueprint.Name”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “CentOS”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “VirtualMachine.CPU.Count”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “1”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “VirtualMachine.Memory.Size”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “4096”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “VirtualMachine.Storage.Name”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “vmfs-01a”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “VMware.VirtualCenter.OperatingSystem”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “rhel6_64Guest”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “Vrm.ProxyAgent.Uri”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “https://mgr-01a.lab.local/VMPS2Proxy”
    }
    }
    ],
    “description”: null,
    “disks”: [
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.Compute.Machine.MachineDisk”,
    “typeFilter”: null,
    “data”: {
    “customProperties”: [
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “IsClone”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “false”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “Name”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “Hard disk 1”
    }
    }
    ],
    “driveLetter”: null,
    “externalId”: “6000C291-9d06-f0ce-ac17-6378d19fac17”,
    “label”: null,
    “reservationPolicy”: null,
    “reservationPolicyMode”: null,
    “size”: 1,
    “storagePath”: “vmfs-01a”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.Compute.Machine.MachineDisk”,
    “typeFilter”: null,
    “data”: {
    “customProperties”: [
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “IsClone”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “false”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “Name”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “Hard disk 2”
    }
    }
    ],
    “driveLetter”: null,
    “externalId”: null,
    “label”: null,
    “reservationPolicy”: null,
    “reservationPolicyMode”: null,
    “size”: 1,
    “storagePath”: “vmfs-01a”
    }
    }
    ],
    “executionSelector”: “1”,
    “memory”: 4096,
    “name”: “Validation0013”,
    “nics”: [
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.Compute.Machine.Nic”,
    “typeFilter”: null,
    “data”: {
    “customProperties”: [
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “Gateway”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “192.168.50.254”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “PrimaryDns”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “172.16.103.78”
    }
    },
    {
    “componentTypeId”: “com.vmware.csp.component.iaas.proxy.provider”,
    “componentId”: null,
    “classId”: “Infrastructure.CustomProperty”,
    “typeFilter”: null,
    “data”: {
    “id”: “SubnetMask”,
    “is_encrypted”: false,
    “is_hidden”: false,
    “prompt_user”: false,
    “value”: “255.255.255.0”
    }
    }
    ],
    “macAddress”: “00:50:56:9a:a3:8e”,
    “name”: “Virtual Machines”,
    “staticNetworkAddress”: “00:50:56:9a:a3:8e”
    }
    }
    ],
    “powerActionSelector”: “0”,
    “storage”: 2
    }
    }

    • Thanks!

      Just resolved it with VMware support.
      The way Grant Orchard mentioned is the right way, except of the last part of the total storage amount, as it not necessary from what I’ve tried.

      Worth to mentioned that reconfigure for editing CPU or memory should have the “Cafe.Shim.VirtualMachine.Reconfigure.Requestor” attribute in the root level of the JSON template and not in the data level.

      Great day,
      Erez.

    • This is what I aprptciaee about Google, some people treat them like they are out to take you for a ride where as Google actually helps people. Thanks google

    • I have heard that Ruby Blue is a very good book. I can't wait to read this series and find out more about her. I love that quote too:X "The universe if full of magical things, patiently waiting for our wits to grow sharper." – Eden Phillpotts (1862-1960) She's one of my favorite authors.

  3. Did anyone try Reverting a snapshot from Rest API – as part of Day 2 Operations…..
    I got this json payload, but not sure what to pass in the provider-snapshot reference tag.
    I am using a java sdk to submit the requests, but i get an error where it expects some Entity Reference type input which i am not able to extract from the VM properties.

    {
    “type”: “com.vmware.vcac.catalog.domain.request.CatalogResourceRequest”,
    “resourceId”: “60c53ce6-f97d-4808-8742-b93f87c8a177”,
    “actionId”: “4b8c52ed-8d67-4c27-9c74-677e54790ce0”,
    “description”: null,
    “data”: {
    “provider-SnapshotReference”: null
    }
    }

  4. Hi there,I read your blog named “Executing Day 2 Actions with the vRA 7 REST API | | VMtoCloud.com” like every week.Your story-telling style is awesome, keep doing what you’re doing! And you can look our website about proxy server list.

  5. Hi Ryan. We have been using the vRA 7.5 API for a few months now, and all of it is working great.

    In your demo, after you run the Day2 RA Shutdown, you use the UI to check that RA did run. And we can see this too.

    But what we would like to do, is check the running and completion status of an invoked Day2 RA through the vRA API.

    Looking through the vRA API doc/pdf, I do not see any descriptions as to how this might be done.

    They do show how, from the POST output, how to check that the RA was successfully, or not, invoked, by looking the http return code.

    But I do not see anything about testing the RA’s running state, if it completed, via the API, like you can for BP’s provision request.

    Or am I missing something ?
    -bh

  6. Hi Ryan, did you hear back from Engineering ?

    Anyway, we figured out a solution for getting back Day2 RA status info.
    The Answer is in your blog post’s 2nd to last screen showing of the http output from running the Day2 RA via the curl.
    On the line labeled “Location:”, at the end of that URL is a vRA request Id.
    You can use that vRA Id like you would use a provisioning Id to check deployment requests.
    This is the kind of info you can get back:

    “requestedItemName”:”Change RAM – “,”requestId”:”2b3e9f95-683a-4608-ac7d-b7f561b9d982″,”requestedBy”:””,”State”:”IN_PROGRESS”,”waitingStatus”:”WAITING_FOR_PROVIDER”,”Phase”:”IN_PROGRESS”,”Status”:”STARTED”
    And afterwards …
    “State”:”SUCCESSFUL”,”requestedBy”:”””requestedItemName”:”Change RAM – “,”requestId”:”2b3e9f95-683a-4608-ac7d-b7f561b9d982″
    Or if it fails
    “status”:”Failure”,”State”:”Failure”
    -bh

    • Hi Bill, Your answer will be helpful for me. Want to know How will you get this vra request id to check the status of the action.

  7. Hi,

    I go through the every article provided and I found it is very helpful,However I am still finding how to provision VMs from catalog through API call. Is there any guide ? If it is there then please guide me.
    I am waiting for your positive reply.

    Thanks

  8. last step gave me below error
    < X-Frame-Options: SAMEORIGIN
    <
    { [data not shown]
    100 359 100 111 100 248 285 636 –:–:– –:–:– –:–:– 635
    * Connection #0 to host vra01.test.crop.local left intact
    {
    "errors": [
    {
    "code": 50505,
    "message": "System exception.",
    "moreInfoUrl": null,
    "source": null,
    "systemMessage": null
    }

  9. we have 1000 request id are there and how to get resource id for 1000. how to write automation scripts for getting resource id in REST 7

Leave a Reply to Bill Hickey Cancel reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.