Hello everyone, how are you today?
I am trying to collect some jobs ID to perform a shutdown and power on for several VMs using the REST API at vRA 6.0.2, but the curl command to collect those not working. It gave the result "No JSON object could be decoded".
I am running the follow steps to connect at vRA appliance and try to collect those informations:
1) export VRA=server.name.fqdn
2) export ACCEPT="application/json"
3) curl --insecure -H "Accept: application/json" -H 'Content-Type: application/json' --data '{"username":"xxxx","password":"yyyy","tenant":"ttt"}' https://$VRA/identity/api/tokens
4) export AUTH="Bearer MTUyMjY3NDQwNjY2ODo4Y2EyYTU3NjA3OWJjOGU3MTM2OTp0ZW5hbnQ6cmpvdXNlcm5hbWU6ZGNhdXRlbGxhQGxldmVsM2RjLm5ldDplNmEwNThjMzZjYWQ1NTMyMWFlYzVjNDdiZDFmMWQ0YmQ1NDk0NThiMGVkODFiNWVlN2RlYzk4OWE2MmI1NDg0MDNjZjg4MGQyMGQyYjQ4MzI4MzdlY2Y0ZmZiNzViMjIwOWE1MDZjZmU3OTljOGE5ZDMwYTNhMTJhODA1MzRiYw=="
5) curl --insecure -H "Accept: $ACCEPT" -H "Authorization: $AUTH" https://$VRA/catalog-service/api/consumer/entitledCatalogItems | python -m json.tool
6) curl --insecure -H "Accept: $ACCEPT" -H "Authorization: $AUTH" https://$VRA/catalog-service/api/consumer/resources | python -m json.tool
This gave the information about one VM at end, like bellow:
},
"dateCreated": "2018-01-20T01:28:33.866Z",
"description": "Provisioned by VMware vCAC",
"forms": {
"catalogResourceInfoHidden": true,
"details": {
"extensionId": "csp.places.iaas.item.details",
"extensionPointId": null,
"type": "extension"
}
},
"hasCosts": true,
"hasLease": true,
"iconId": "c24b42b4-538d-4991-9341-a9eab8989ec2",
"id": "8f5386ea-2fa0-4073-bef9-04204f2df38e",
"lastUpdated": "2018-01-20T12:20:53.558Z",
"lease": {
"start": "2018-01-20T01:07:22.000Z"
},
"leaseForDisplay": null,
"name": "VM-RJO-028",
"operations": null,
"organization": {
"subtenantLabel": "ttttttttttttttttt",
"subtenantRef": "b6f188fd-aaec-490c-8457-4b7f400ff88e",
"tenantLabel": "tttttttttttttttt",
"tenantRef": "tttt"
},
"owners": [
{
"ref": "ddddddddddddd",
"tenantName": "tttt",
"type": "USER",
"value": "xxxxxxxxxx"
}
],
"providerBinding": {
"bindingId": "dbf7a44e-b5db-4112-9566-8d5351ebafff",
"providerRef": {
"id": "6c0d6ec9-7ef0-42ea-8993-fab7f5cddee7",
"label": "iaas-service"
}
},
"requestId": "b870c84f-d840-48c6-b471-4a580288d658",
"resourceData": {
"entries": []
},
"resourceTypeRef": {
"id": "Infrastructure.Virtual",
"label": "Virtual Machine"
},
"status": "ACTIVE",
"totalCost": null
}
],
"links": [],
"metadata": {
"number": 1,
"offset": 0,
"size": 20,
"totalElements": 12,
"totalPages": 1
}
}
If i try to use the requestID of this VM, by the follow command, i received the follow error:
curl --insecure -H "Accept: $ACCEPT" -H "Authorization: $AUTH" https://$VRA/catalog-service/api/consumer/requests/b870c84f-d840-48c6-b471-4a580288d658/resourceView... | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 93 100 93 0 0 49 0 0:00:01 0:00:01 --:--:-- 49
No JSON object could be decoded
And i can not collect all informations. By other way, i opened the DEV options at Chrome web browser and collect the job string when i perform the Power Off (for example), and collect the follow information:
curl --insecure -H "Accept: $ACCEPT" -H "Authorization: $AUTH" https://vra.level3dc.net/catalog-service/api/consumer/requests/7ac73abf-9b63-44bf-a76b-c35eeb7890b0
{"@type":"ResourceActionRequest","id":"7ac73abf-9b63-44bf-a76b-c35eeb7890b0","iconId":"machinePowerOff.png","version":5,"requestNumber":32247,"state":"SUCCESSFUL","description":null,"reasons":null,"requestedFor":"cloud-rjo@level3dc.net","requestedBy":"cloud-rjo@level3dc.net","organization":{"tenantRef":"rjo","tenantLabel":"Datacenter-RJO","subtenantRef":"b6f188fd-aaec-490c-8457-4b7f400ff88e","subtenantLabel":"CLOUD_OPERATIONS_RJO"},"requestorEntitlementId":"6816129e-d107-40ed-bf1b-f913ab00d321","preApprovalId":null,"postApprovalId":null,"dateCreated":"2018-04-02T13:40:13.145Z","lastUpdated":"2018-04-02T13:40:21.291Z","dateSubmitted":"2018-04-02T13:40:13.145Z","dateApproved":null,"dateCompleted":"2018-04-02T13:40:21.289Z","quote":{"leaseRate":{"type":"moneyTimeRate","cost":{"type":"money","currencyCode":"USD","amount":0.0},"basis":{"type":"timeSpan","unit":"DAYS","amount":1}}},"requestCompletion":{"requestCompletionState":"SUCCESSFUL","completionDetails":"The request was successfully completed"},"requestData":{"entries":[]},"retriesRemaining":3,"requestedItemName":"Power Off - VM-RJO-027","requestedItemDescription":"{com.vmware.csp.component.iaas.proxy.provider@resource.action.name.desc.machine.PowerOff}","stateName":"Successful","phase":"SUCCESSFUL","waitingStatus":"NOT_WAITING","approvalStatus":"POST_APPROVED","executionStatus":"STOPPED","resourceRef":{"id":"855eca83-7019-4a8d-8828-57b90b1aa193","label":"VM-RJO-027"},"resourceActionRef":{"id":"f27f7a47-6f10-4f4a-9808-6d6639344972","label":"Power Off"}}
Could someone help me to perform a REST API script to just perform a power off and/or power on? I tried like intruduce, but in this version of vRA i believe that form of connection changed in comparation of new on (vRA 7.x).
Thanks in advanced