VMware Cloud Community
renauddzielicki
Enthusiast
Enthusiast
Jump to solution

Looking for a way to convert VM id to iaasVM ID Object

Hello,

All is in the title,

To VCvirtualmachine object input i'm looking for a way to extract the iaas ID of a VM, tried some REST but didnt found yet anything useful

0 Kudos
1 Solution

Accepted Solutions
xian_
Expert
Expert
Jump to solution

id.content is an array, being a search result

Check its length and use id.content[0].id if the result contains only one element.

View solution in original post

13 Replies
renauddzielicki
Enthusiast
Enthusiast
Jump to solution

externalId": "5031a44b-5142-2193-619c-055bdb153fa9",
"name": "TEST",
"description": "TEST ",
"id": "a3cdcd16-5a30-4883-ac7a-93fa48b31b09",

0 Kudos
renauddzielicki
Enthusiast
Enthusiast
Jump to solution

i want to avoid to fetch by API all items of a deployment to get the VM

0 Kudos
renauddzielicki
Enthusiast
Enthusiast
Jump to solution

API is  https://<vra fqdn>iaas/api/machines/a3cdcd16-5a30-4883-ac7a-93fa48b31b09

0 Kudos
xian_
Expert
Expert
Jump to solution

Try /iaas/api/machines?$filter=externalId%20eq%205031a44b-5142-2193-619c-055bdb153fa9

0 Kudos
renauddzielicki
Enthusiast
Enthusiast
Jump to solution

Yes filter would work but it would assume that i've already the ID which is not the case because i just have in input the vcVM virtulmachine and as far as i know there's no generic API to fetch all those ID

0 Kudos
xian_
Expert
Expert
Jump to solution

externalId is the VM's instanceId:

vm.instanceId
=> 5035a142-da26-a422-083e-547337c4b961

/iaas/api/machines?$filter=externalId+eq+%275035a142-da26-a422-083e-547337c4b961%27

should give you the same VM

0 Kudos
renauddzielicki
Enthusiast
Enthusiast
Jump to solution

Sounds great but There is something i shoud miss:

 

Get iaas/api/machines?$filter=externalId+eq+%5031a44b-5142-2193-619c-055bdb153fa9%27

 

{
"message": "undetermined string (externalId eq P31a44b-5142-2193-619c-055bdb153fa9') and (type eq 'VM_GUEST')",
"statusCode": 400,
"errorCode": 0,

 

Get iaas/api/machines/a3cdcd16-5a30-4883-ac7a-93fa48b31b09

"externalId": "5031a44b-5142-2193-619c-055bdb153fa9",
"name": "VMPrefix.000934",
"description": "TEST",
"id": "a3cdcd16-5a30-4883-ac7a-93fa48b31b09",

 

 

0 Kudos
xian_
Expert
Expert
Jump to solution

%27 is '

you should have at both before and after the actual ID

renauddzielicki
Enthusiast
Enthusiast
Jump to solution

Thanks didnt spot that ( looks like i'm little bit tired 😉

 

iaas/api/machines?$filter=externalId+eq+%275031a44b-5142-2193-619c-055bdb153fa9%27

{
"content": [],
"totalElements": 0,
"numberOfElements": 0
}

do i need to specify a field?

0 Kudos
renauddzielicki
Enthusiast
Enthusiast
Jump to solution

By filtering by VM.name it seems ok to fetch the ID i'll test it!

0 Kudos
renauddzielicki
Enthusiast
Enthusiast
Jump to solution

var vmname = VM.name;

 

--> Go to a worklow that generate a REST API

 

var url_input = url_input + '?$filter=name+eq+' + "'" + vmname + "'";

 

Now left to parse 😉

0 Kudos
renauddzielicki
Enthusiast
Enthusiast
Jump to solution

With VM name it works but at least i'm stuck by parsing the answer of the rest api:

 

tried this but my var parsed is empty, could you help me to parse the ID field?

 

Here s my scriptable task:

var id = JSON.parse(result.contentAsString );
var parsed = id.content.id;
System.log("result " + parsed);

 

 

 

0 Kudos
xian_
Expert
Expert
Jump to solution

id.content is an array, being a search result

Check its length and use id.content[0].id if the result contains only one element.