kvsphanikrishna
Contributor
Contributor

Issue with VRA 7 Rest API to revert a snapshot

Hi All,

Did anyone try managing snapshots like create, revert and delete a snapshot using VRA 7 rest API's.

Below is the JSON request paylod, any idea what should the provider-SnapshotReference value should be when i am reverting a snapshot.

{

  "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

  }

}

i am using a VRA 7 Java sdk for implementing this API call, and this is the error that i get everytime

[Rest Error]: {Status code: 400}, {Error code: 10101} , {Error Source: null},

{Error Msg: Invalid argument.}, {System Msg: Expected EntityReferenceDatum, not java.lang.String for Field: provider-SnapshotReference}

The snapshot already exists for my VM, this is the response for getCatalogResource call,

SNAPSHOT_LIST : MultipleLiteral[[ComplexLiteral[componentTypeId=com.vmware.csp.component.iaas.proxy.provider, componentId=null, classId=dynamicops.api.model.SnapshotViewModel, typeFilter=null, values=LiteralMap[values={SNAPSHOT_DESC=test123, SNAPSHOT_IS_CURRENT=true, SNAPSHOT_IS_MEMORY=true, SNAPSHOT_CREATION_DATE=Tue May 02 15:48:55 AEST 2017}]]]]

Can you please help me in fixing this issue ?

4 Replies
Jonesie946
Contributor
Contributor

Were you able to get this working?

I have the same issue. I have been digging around with the various HTTP-REST calls for vRA 7.2 and I can't find anything related to the snapshot that vRA will accept.

Thanks - David

0 Kudos
nsb24
VMware Employee
VMware Employee

You should be using generate a request template API to get request template.

e.g. use this to create snapshot you will do the following:

Get resource actions (retrieve resource action guid)

GET https://{{va-fqdn}}/catalog-service/api/consumer/resources/{{resource-guid}}/actions

Get request template for resource and its respective action

GET https://{{va-fqdn}}/catalog-service/api/consumer/resources/{{resource-guid}}/actions/{{resource-action-guid}}/requests/template

Submit the request

POST https://{{va-fqdn}}/catalog-service/api/consumer/resources/{{resource-guid}}/actions/{{resource-action-guid}}/requests

{

  "type": "com.vmware.vcac.catalog.domain.request.CatalogResourceRequest",

  "resourceId": "{{resource-guid}}",

  "actionId": "{{resource-action-guid}}",

  "description": null,

  "data": {

    "provider-SnapshotInputDescription": null,

    "provider-SnapshotInputMemoryIncluded": null,

    "provider-SnapshotInputName": ""

  }

}

Here is a sample for above steps:

vra-api-samples-for-postman/Catalog at master · vmwaresamples/vra-api-samples-for-postman · GitHub

You can use similar steps to get the payload for revert to a snapshot, most likely it should look like below but again use request template to get your request data.

{

  "type": "com.vmware.vcac.catalog.domain.request.CatalogResourceRequest",

  "resourceId": "{{resource-guid}}",

  "actionId": "{{resource-action-guid}}",

  "description": null,

  "data": {

    "SnapshotReference": {

      "componentId": "{{component-guid}}",

      "classId": "Infrastructure.Compute.Machine.Snapshot",

      "id": "4130",

      "label": "{{snapshot-label}}"

    }

  }

}

0 Kudos
Sany_1973
Enthusiast
Enthusiast

How can we find out the provider-SnapshotReference  from the catalogResource VM ?

Thanks

0 Kudos
Sany_1973
Enthusiast
Enthusiast

Following code will revert the current snapshot

//vm  vcaccafe:catalogresource

var operationName = "Revert To Snapshot";

System.log("Found resource. Fetching operation '" + operationName + "'...");

var operation = vCACCAFEEntitiesFinder.findCatalogResourceActions(vm,operationName)[0];

if (!operation) {

    System.log("Operation not found for '" + resource.name + "', returning null.");

 

}else{

  var requestTemplate = vCACCAFERequestsHelper.getRequestForResourceAction(operation)

var jsonData = vCACCAFERequestsHelper.getResourceActionRequestData(requestTemplate);

var json = JSON.parse(jsonData);

//System.log("form input: "+JSON.stringify(json));

vCACCAFERequestsHelper.setResourceActionRequestData(requestTemplate, JSON.stringify(json));

var snapRequest = System.getModule("com.vmware.library.vcaccafe.request").requestResourceActionWithRequestTemplate(operation, requestTemplate);

}