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 ->Tweet about this on Twitter26Share on Facebook0Share on LinkedIn10Share on Google+0Email this to someone

8 thoughts on “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
    }
    }

Leave a Reply

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

*