Six Million Ways To…
  • About
Orchestrator , vRA

vRO: Using vRA REST API to get all vCAC VMs

by Axel March 8, 2019 No Comments

Hi there !!

It’s been a very long timmmmmeee since my last post.

As usual, just a post to help in saving time. Today we’ll deal with REST API and mainly how to get information registered vCAC VMs in a huge number of pages.

When we want to query your CAFE host and obtain the number of deployments, we very often a response that does not fit on a single page.

In vRA API REST guide, VMware tell us to make as many requests as we have pages to browse. Let me show you how I do this…

var restClient = vCACCafeHost.createRestClient(endpoint);
var deploymentResourceUrl = "/consumer/resources/types/Infrastructure.Virtual/";
var parentDeploymentInfos = new Properties();
var allDeployedVm = new Array();
var deployedVmCount = 0;

function preparingRestContext(url)
{
	jsonContent = getRestResponseInJsonFormat(url)
	var responseTotalPages = jsonContent.metadata.totalPages
	return responseTotalPages
}

function getRestResponseInJsonFormat(url)
{
	var response = restClient.get(url);
	var jsonContent = response.getBodyAsJson();
	return jsonContent
}

System.log("===================================================")
System.log("**** Collecting all resources of type \"Deployment\" ***")
System.log("===================================================")

var numberOfPagesToParse = preparingRestContext(deploymentResourceUrl)
System.log("Number of page to parse : " + numberOfPagesToParse + ".")

for(i=1;i<=numberOfPagesToParse;i++)
{
	requestUrl = "/consumer/resources/types/Infrastructure.Virtual/?page=" + i;
	var jsonContent = getRestResponseInJsonFormat(requestUrl)
	
	for each (var resource in jsonContent.content)
	{
		vmEnvironment = (resource.name).substring(4,5)
		var vmDeploymentProp = new Properties();
		vmDeploymentProp.put("Name",resource.name)
		vmDeploymentProp.put("ParentLabel",resource.parentResourceRef.label)
		vmDeploymentProp.put("Owner",resource.owners[0].ref)
		vmDeploymentProp.put("Environnement",vmEnvironment)
				
		allDeployedVm.push(vmDeploymentProp);
		deployedVmCount = deployedVmCount + 1;
	}
}

System.log("")
System.log("== Collecting resources information to identify deployment environment ==")
System.log("VM deployed number : " + deployedVmCount)

REST APIVRAVRO

  • Previous vRO : Workflow to Get Restarted VMs by HA4 years ago
  • Next VM : Quickly delete one or more VM4 years ago

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Menu

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Recent Posts

  • vRA : API : Submit a request
  • vRO: Setting constants for workflows
  • VM : Quickly delete one or more VM
  • vRO: Using vRA REST API to get all vCAC VMs
  • vRO : Workflow to Get Restarted VMs by HA

Archives

  • October 2019
  • March 2019
  • March 2018
  • September 2017

Categories

  • CLI (2)
  • ESXi (1)
  • Orchestrator (4)
  • Scripts (3)
    • Powercli (3)
  • vRA (2)
  • vSphere (1)

Tags

API (1) CLI (1) HA (1) Nutanix (1) PowerCLI (1) Reminder (1) REST (1) REST API (1) vCenter (3) VRA (2) VRO (3) vSphere (4)
2023 Six Million Ways To…. Donna Theme powered by WordPress