VMware {code} Community
wizardnjau
Contributor
Contributor

How can I get vApp or VM 's host IP by rest API

Hi guys

I want to get vApp's host IP, I do not mean VM's IP, I mean the host which VM in.

I try several rest api but can not get this information.

I can see this information through web page, so I guess there must be a rest api which I can get this from.

regards

0 Kudos
10 Replies
Todor_Todorov
Hot Shot
Hot Shot

There're a couple of ways to achieve this using REST API. Basically this kind of information is only available to System administrators:

1) Using query service: you can use the query named 'adminVM':

GET <host>/api/query?type=adminVM

This returns a list of AdminVMRecord objects with a 'hostName' property in them. This 'hostName' property contains the IP address of the ESX host on which the VM resides:

<AdminVMRecord vmToolsVersion="6404" vdc="https://10.26.49.174/api/vdc/94964469-f3da-4f11-ae77-321f07421f83" vc="https://10.26.49.174/api/admin/extension/vimServer/e6136146-e097-42b6-a282-12d1967a92c5" status="POWERED_OFF" org="https://10.26.49.174/api/org/73ab2eb6-802b-46a6-8a3d-e55a0a99a957" numberOfCpus="1" networkName="AutomationNetwork" name="TemplateNic" moref="vm-1504" memoryMB="32" isVdcEnabled="true" isVAppTemplate="true" isPublished="false" isDeployed="false" isDeleted="false" hostName="10.23.116.201" hardwareVersion="7" guestOs="Other (32-bit)" datastoreName="datastore1" containerName="TemplateNic" container="https://10.26.49.174/api/vAppTemplate/vappTemplate-9e540670-44e9-45a0-950d-1dae5b9d198b" catalogName="CatalogvappTemplate-9e540670-44e9-45a0-950d-1dae5b9d198b" href="https://10.26.49.174/api/vApp/vm-05f2a7c5-016b-4043-81dc-d217b4a6583f" pvdcHighestSupportedHardwareVersion="8" containerStatus="RESOLVED"/>

2) Using the VCloudExtension element inside VM representation:

GET <host>/api/vApp/vm-<uuid>

This returns a <Vm> object with <VCloudExtension> element inside. It contains information about host, datastore and actual VM in vCenter. The drawback is that it returns the morefs (VC IDs) of these objects so you'll have to make another API call to resolve those IDs to IPs.

<VCloudExtension required="false">

<vmext:VmVimInfo>
<vmext:VmVimObjectRef>
<vmext:VimServerRef type="application/vnd.vmware.admin.vmwvirtualcenter+xml" name="ConfigWizard Configured vCenter" href="https://10.26.49.174/api/admin/extension/vimServer/e6136146-e097-42b6-a282-12d1967a92c5"/>
<vmext:MoRef>vm-1504</vmext:MoRef>
<vmext:VimObjectType>VIRTUAL_MACHINE</vmext:VimObjectType>
</vmext:VmVimObjectRef>
<vmext:DatastoreVimObjectRef>
<vmext:VimServerRef type="application/vnd.vmware.admin.vmwvirtualcenter+xml" name="ConfigWizard Configured vCenter" href="https://10.26.49.174/api/admin/extension/vimServer/e6136146-e097-42b6-a282-12d1967a92c5"/>
<vmext:MoRef>datastore-79</vmext:MoRef>
<vmext:VimObjectType>DATASTORE</vmext:VimObjectType>
</vmext:DatastoreVimObjectRef>
<vmext:HostVimObjectRef>
<vmext:VimServerRef type="application/vnd.vmware.admin.vmwvirtualcenter+xml" name="ConfigWizard Configured vCenter" href="https://10.26.49.174/api/admin/extension/vimServer/e6136146-e097-42b6-a282-12d1967a92c5"/>
<vmext:MoRef>host-78</vmext:MoRef>
<vmext:VimObjectType>HOST</vmext:VimObjectType>
</vmext:HostVimObjectRef>
<vmext:VirtualDisksMaxChainLength>2</vmext:VirtualDisksMaxChainLength>
</vmext:VmVimInfo>
</VCloudExtension>

Regards,

Todor Todorov

0 Kudos
haroonrasheed
Contributor
Contributor

Adding to the above question. Is there a way to assign a IP to a VM within a vApp using REST api. Since I am trying to automate few task including the assigning the VM IP within the vApps. If anyone could help me would be of great help..

Thanks in advance

Regards,

Haroon

0 Kudos
srmdocs
VMware Employee
VMware Employee

There's an example at Update the NetworkConnectionSection of a Virtual Machine that might help.

0 Kudos
RATrojan
Contributor
Contributor

Hello,

Does this solution requires vCloud Plugin to be installed?

Regards,

RA

0 Kudos
srmdocs
VMware Employee
VMware Employee

Not sure what plug-in you are referring to, but the procedure in Update the NetworkConnectionSection of a Virtual Machine does not require any plug-ins to be installed

0 Kudos
RATrojan
Contributor
Contributor

In the request and response of the API it mentioned vCloud, I highlighted below in red

Request:

PUT "https://vcloud.example.com/api/vApp/vm-4/networkConnectionSection/ Content-type: application/vnd.vmware.vcloud.networkConnectionSection+xml 

Response:

202 Accepted Content-Type: application/vnd.vmware.vcloud.task+xml ... <Task ... operation="Updating Virtual Application Linux FTP server (7)" ...> ...

vCloud Air vSphere Client Plug-in lets you view and manage your vCloud Air resources in the vSphere Web Client

I'm not sure if I have to install this plugin to run these APIs

0 Kudos
srmdocs
VMware Employee
VMware Employee

no plug-in is required

0 Kudos
RATrojan
Contributor
Contributor

Hi srmdocs,

Need some more help from you.

The link you provided is for vCloud Director, I don't have vCloud Director, We only have the vCenter and ESXi.

Is there a way I can assign IP without vCloud Director?

0 Kudos
srmdocs
VMware Employee
VMware Employee

you need to install the vCloud Director product to use the vCloud API

0 Kudos
RATrojan
Contributor
Contributor

Ok thanks, is there any other way to assign static IP address without installing vCloud Director?

0 Kudos