VRA Cloud / On-Prem — How to Export managed machine using Python in CSV,HTML and Json

In this blog we will go through how we can utilise Python and export the managed machine for vSphere endpoint.

Prerequisites :

  • Python 3.x should be installed on machine or Laptop where we want to run below code.
  • Connectivity from machine to vRealize Automation Cloud or On-Prem.
  • Once Python 3.x is installed we need to install 2 modules by using below commands
    pip3 install requests
    pip3 install prettytable

If you are using windows then you can follow the this article or we can use any Code editor like Visual Studio also to run this.

  • If want to run against On-Prem vRA 8.X then we need below details .
    FQDN of vRealize Automation
  • for vRA Cloud CSP token which has access to Cloud Assembly and Service Broker.
  • If we want to pull details from vRA Cloud then we need Cloud API url details from Specific Region
    Below are the Region and their correspond URL.
          api.mgmt.cloud.vmware.com    -- U.S.A
          in.api.mgmt.cloud.vmware.com -- India
          uk.api.mgmt.cloud.vmware.com -- Untied Kingdom 
          au.api.mgmt.cloud.vmware.com -- Australia
          sg.api.mgmt.cloud.vmware.com -- Singapore
          br.api.mgmt.cloud.vmware.com -- Brazil
          de.api.mgmt.cloud.vmware.com -- Germany
          ca.api.mgmt.cloud.vmware.com -- Canada
          jp.api.mgmt.cloud.vmware.com -- Japan


Download the attach file ,unzip it and open the file with Python IDLE.

Once opened Press F5 or from Menu choose Run

For VRA Cloud Run the below command,In my example i am providung U.S region url.
How to generate the CSP token
To authenticate vRA Cloud:

authtoken = vRACloud_Login(token='CSP token', cloudurl='api.mgmt.cloud.vmware.com')

To Authenticate vRA On-Prem:

authtoken = vRAOnPrem_Login(vrafqdn='vra.vmwarecode.com', username='configadmin', password='VMware1!')


vRA Cloud: To see the List of Managed Machines :

get_Managed_vSphere_VMs(url='api.mgmt.cloud.vmware.com', token=authtoken)

vRA Cloud: To Generate the CSV file :

get_Managed_vSphere_VMs(url='api.mgmt.cloud.vmware.com', token=authtoken, ExportToCSV=True)

vRA Cloud: To Generate the HTML File:

get_Managed_vSphere_VMs(url='api.mgmt.cloud.vmware.com', token=authtoken, ExportToHTML=True)

vRA Cloud: To Generate Json data File:

get_Managed_vSphere_VMs(url='api.mgmt.cloud.vmware.com', token=authtoken, ExpertToJson=True)

vRA Cloud: To generate All Files for vRA Cloud:

get_Managed_vSphere_VMs(url='api.mgmt.cloud.vmware.com', token=authtoken1, ExportToCSV=True, ExportToHTML=True, ExpertToJson=True)

vRA On-Prem: Commands:

get_Managed_vSphere_VMs(url='vra.vmwarecode.com', token=authtoken)
get_Managed_vSphere_VMs(url='vra.vmwarecode.com', token=authtoken, ExportToCSV=True)
get_Managed_vSphere_VMs(url='vra.vmwarecode.com', token=authtoken, ExportToHTML=True)
get_Managed_vSphere_VMs(url='vra.vmwarecode.com', token=authtoken, ExpertToJson=True)
get_Managed_vSphere_VMs(url='vra.vmwarecode.com', token=authtoken1, ExportToCSV=True, ExportToHTML=True, ExpertToJson=True)

Sample screenshot of how report looks like:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: