VMware Cloud Community
subrat308
Contributor
Contributor

Rest API Call to get the Snapshot details of a VM in Vcac

Hello,

I want to get the snapshot details(Snapshot listing with Name) using Rest API, But when I tried the same, I am not getting the Snapshot information for that VM.(The other info like Lease Period etc I am getting in the JSON).

Has anyone implemented this successfully?

Thanks,

Subrat

Reply
0 Kudos
11 Replies
kumarankpl
Hot Shot
Hot Shot

As of now this information is not exposed as part of the API. You have access IAAS REST to get this data.

http://www.clearascloud.com/2013/01/vcloud-automation-centre-vcac-rest.html

Reply
0 Kudos
subrat308
Contributor
Contributor

Hello,

I dont know exactly what IAAS REST is? Can you describe more here, Do we have any sample code for the same.

Thanks,

Subrat

Reply
0 Kudos
SeanKohler
Expert
Expert


I would try to get it through VC:VirtualMachine in the Virtual Center plugin instead of IaaS.

It contains...

"Current snapshot and tree"

"The property is valid if snapshots have been created for this virtual machine."

Then there are methods and properties to work with it.

Edit: To achieve through REST... you would create a workflow in vRO that returns what you want and then use the REST API to vRO (VCO) which is better documented and more robust, IMHO. How to use the REST API to Start a Workflow

Reply
0 Kudos
Burke-
VMware Employee
VMware Employee

.. and in particular, have a look at the Snapshot Report workflow I provided in this thread: List all snapshots wth orchestator with

The code there can be modified to take the input of a single VM.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
Reply
0 Kudos
subrat308
Contributor
Contributor

Hi,

I am just trying below Powershell-REST way to get the catalog items/VMdetails and all.

$ApiToken = Invoke-RestMethod -Method Post -uri "https://XXX/identity/api/tokens" -Body $body -Headers @{"Accept"="application/json";"Content-Type"="application/json"}

$Token=$ApiToken.id

$CatalogList = Invoke-RestMethod -Method Get -uri "https://XXX/catalog-service/api/consumer/entitledCatalogItems" -Headers @{"Accept"="application/json";"Content-Type"="application/json";"Authorization"="Bearer $Token"}

return ConvertTo-Json $CatalogList -Compress

On the same way is there a possibility to get Snapshot Details as well for a VM?

Reply
0 Kudos
SeanKohler
Expert
Expert


Well you are not going to get it from entitledCatalogItems...  (and I am not sure the data is available where you are looking anyway)

If it was available, I think it would be on the Resource portion of the API. (type CatalogResource)  Or on some branch off of it...

It isn't a value held in catalogResource....

  <xs:complexType name="catalogResource">

    <xs:sequence>

      <xs:element name="id" type="xs:string" minOccurs="0"/>

      <xs:element name="iconId" type="xs:string" minOccurs="0"/>

      <xs:element name="resourceTypeRef" type="labelledReference" minOccurs="0"/>

      <xs:element name="name" type="xs:string" minOccurs="0"/>

      <xs:element name="description" type="xs:string" minOccurs="0"/>

      <xs:element name="status" type="resourceStatus" minOccurs="0"/>

      <xs:element name="catalogItem" type="labelledReference" minOccurs="0"/>

      <xs:element name="requestId" type="xs:string" minOccurs="0"/>

      <xs:element name="providerBinding" type="providerBinding" minOccurs="0"/>

      <xs:element name="owners" type="catalogPrincipal" minOccurs="0" maxOccurs="unbounded"/>

      <xs:element name="organization" type="catalogOrganizationReference" minOccurs="0"/>

      <xs:element name="dateCreated" type="xs:dateTime" minOccurs="0"/>

      <xs:element name="lastUpdated" type="xs:dateTime" minOccurs="0"/>

      <xs:element name="hasLease" type="xs:boolean"/>

      <xs:element name="lease" type="resourceLease" minOccurs="0"/>

      <xs:element name="leaseForDisplay" type="timeSpan" minOccurs="0"/>

      <xs:element name="hasCosts" type="xs:boolean"/>

      <xs:element name="costs" type="resourceCosts" minOccurs="0"/>

      <xs:element name="costToDate" type="monetaryValue" minOccurs="0"/>

      <xs:element name="totalCost" type="monetaryValue" minOccurs="0"/>

      <xs:element name="parentResourceRef" type="labelledReference" minOccurs="0"/>

      <xs:element name="childResources" type="catalogChildResource" minOccurs="0" maxOccurs="unbounded"/>

      <xs:element name="operations" type="consumerResourceOperation" nillable="true" minOccurs="0" maxOccurs="unbounded"/>

      <xs:element name="forms" type="resourceForms" minOccurs="0"/>

      <xs:element name="resourceData" type="literalMap" minOccurs="0"/>

    </xs:sequence>

  </xs:complexType>

Reply
0 Kudos
SeanKohler
Expert
Expert

I suspect you know this... but just in case, the REST API is mapped out in the service-catalog documentation off your appliance...

https://YourVcacHost/catalog-service/api/docs/index.html

Reply
0 Kudos
subrat308
Contributor
Contributor

My Bad, I typed the wrong URL.

$ApiToken = Invoke-RestMethod -Method Post -uri "https://XXX/identity/api/tokens" -Body $body -Headers @{"Accept"="application/json";"Content-Type"="application/json"}

$Token=$ApiToken.id

$VmDetails = Invoke-WebRequest -Method Get -uri "https://XXX/catalog-service/api/consumer/resources/$Id" -Headers @{"Accept"="application/json";"Content-Type"="application/json";"Authorization"="Bearer $Token"}

return $VmDetails.Content

When I called this, I got all other details except the snapshot details.

Check the attached JSON.

Reply
0 Kudos
SeanKohler
Expert
Expert


Hmmm...  one might think they should be the items in this complex type...

                "key": "SNAPSHOT_LIST",

                "value": {

                    "type": "multiple",

                    "elementTypeId": "COMPLEX",

                    "items": [

                       

                    ]

Sorry I can't help more.  You are hitting the edges of my understanding of the REST API, and I can't research further at the moment.  Maybe someone further along in their knowledge will answer.

Reply
0 Kudos
subrat308
Contributor
Contributor

"key": "SNAPSHOT_LIST",

                "value": {

                    "type": "multiple",

                    "elementTypeId": "COMPLEX",

                    "items": [

                       

                    ]

Here I could access the "items" here, but its coming as blank, when I accessed via code..

Reply
0 Kudos
subrat308
Contributor
Contributor

"key": "SNAPSHOT_LIST",

                "value": {

                    "type": "multiple",

                    "elementTypeId": "COMPLEX",

                    "items": [

                       

                    ]

Here I could access the "items" here, but its coming as blank, when I accessed via code..

Reply
0 Kudos