VMware Cloud Community
kallischlauch
Enthusiast
Enthusiast
Jump to solution

vRealize Cloud Client in scripting?

Hey all,

i can pull information I'm interested in using the interactive cloud client. Example: I want a custom property of a machine I deployed.  Log in and manually type one command after another. But how can I use this in a script?

manual procedure as example

Find deployment: vra deployment list

+--------------------------------------+-----------------------+--------+--------------------------------------+-----------------------------------+

| name                                 | resourceTypeRef.label | status | id                                   | owners[*].ref                     |

+--------------------------------------+-----------------------+--------+--------------------------------------+-----------------------------------+

| DEMO-L4-2Nodes-79867318              | Deployment            | ACTIVE | 08480bcb-e3ee-4a63-98b4-3668ed623caf | "myemail@address                " |



Find the component machines: vra deployment component list --id DEMO-L4-2Nodes-79867318

CloudClient>vra deployment component list --id DEMO-L4-2Nodes-79867318

+----------------+---------------------------------------+--------+--------------------------------------+---------------------------------+

| name           | catalogResource.resourceTypeRef.label | status | catalogResource.id                   | owner                           |

+----------------+---------------------------------------+--------+--------------------------------------+---------------------------------+

| AAAA-RDSHWB463 | Virtual Machine                       | On     | 019625c4-bdca-4ca8-88bc-4c74ed4c6438 | myemail@address                 |

| AAAA-RDSHWB464 | Virtual Machine                       | On     | f9374c50-8cde-474b-8f3f-850afae10361 | myemail@address                 |

+----------------+---------------------------------------+--------+--------------------------------------+---------------------------------+


Then query the component machine: vra machines detail --id SXRSHWB464 to find custom properties.

I can find ALL info using cloud client, but how can I do this in a single script?

if I run it in commandshell as such:

cloudclient.bat vra deployment list

cloudclient.bat vra deployment component list --id xxx


then

a) every single time I invoke it the command logs in to vra, iaas and vco ?! so thats 5 times in a short script. not only bad but causes huge delays

b) how do you parse the output? its a really nice table view, but how do i reasonably easy get the data from "vra deployment list", find my item and shove it into the next command?


cloud client not the right tool for it, stick to (direct) Rest API?


Thanks for any help

Kalli

Tags (1)
1 Solution

Accepted Solutions
kallischlauch
Enthusiast
Enthusiast
Jump to solution

I was able to figure out half my question :smileylaugh:

to parse the output you can set --format JSON in the call (see below)

i can then parse this with powershell (see below)

However the main problem is still that cloudclient logs in every time. How can I avoid that. It also messes up the output causing me to have to export the data from cloudclient to file and read it again with power shell

I'll mark this one as answered and create a new question for the log in problem

example script to deploy a catalogitem using PowerVRA and then read the value of a custom property

GitHub - jakkulabs/PowervRA: vRealize Automation PowerShell Toolkit

### Author Kalli - please modify to your own needs!!

### it shows how cloudclient commands can be integraded into powershell script

### also it utilises PowerVRA to deploy the Blueprint (needs to be installed)

### requirement is that cloudclient (I'm using 4.1) is configured to be able to automatically authenticate (cloudclient.properties file configured)

### modify those:

$bluePrintName="<Full Name of the Catalog Item you want to deploy>"

$propertyName="<the name of the property you want to read>"

$vRAServerName="<vRA server FQDN (or LB)>"

$env:Path=$env:Path + ";<full path to /bin directory of cloud client>"

###connect to VRA

Connect-vRAServer -Server $vRAServerName

$CatalogItemId = (Get-vRAConsumerCatalogItem -Name $bluePrintName).Id

#assign the deployment a variable. it returns an array of all deployed items (machines, networks etc)

$Request=Request-vRAConsumerCatalogItem -Id $CatalogItemId -Wait -Verbose -Confirm:$false

#find _any_ virtual machine in this deployment and get the name (modify so it finds a specific one if needed)

foreach($deployeditem in $Request){if ($deployeditem.ResourceType -eq "Infrastructure.Virtual"){$machinename = $deployeditem.Name}}

#invoke Cloud Client and export the machines properties in json format

#because of the fact that cloud client logs in everytime this is logged in stdout.

#this is why we have to export the data, then re-import later 😞

$exportPath=$env:temp+$machineName+"_detail.txt"

cloudclient.bat vra machines detail --id $machineName --format JSON --export $exportPath

#gather the content into variable (like I said ... awkward)

$machineDetail=(Get-Content -path $exportPath) | convertfrom-json

#find and display the value of

$PropertyValue=$machineDetail.properties | ?{$_.name -eq $propertyName} | Select-Object -expandProperty value

Write-Host("The VIP of the LB is: "+$PropertyValue)

View solution in original post

1 Reply
kallischlauch
Enthusiast
Enthusiast
Jump to solution

I was able to figure out half my question :smileylaugh:

to parse the output you can set --format JSON in the call (see below)

i can then parse this with powershell (see below)

However the main problem is still that cloudclient logs in every time. How can I avoid that. It also messes up the output causing me to have to export the data from cloudclient to file and read it again with power shell

I'll mark this one as answered and create a new question for the log in problem

example script to deploy a catalogitem using PowerVRA and then read the value of a custom property

GitHub - jakkulabs/PowervRA: vRealize Automation PowerShell Toolkit

### Author Kalli - please modify to your own needs!!

### it shows how cloudclient commands can be integraded into powershell script

### also it utilises PowerVRA to deploy the Blueprint (needs to be installed)

### requirement is that cloudclient (I'm using 4.1) is configured to be able to automatically authenticate (cloudclient.properties file configured)

### modify those:

$bluePrintName="<Full Name of the Catalog Item you want to deploy>"

$propertyName="<the name of the property you want to read>"

$vRAServerName="<vRA server FQDN (or LB)>"

$env:Path=$env:Path + ";<full path to /bin directory of cloud client>"

###connect to VRA

Connect-vRAServer -Server $vRAServerName

$CatalogItemId = (Get-vRAConsumerCatalogItem -Name $bluePrintName).Id

#assign the deployment a variable. it returns an array of all deployed items (machines, networks etc)

$Request=Request-vRAConsumerCatalogItem -Id $CatalogItemId -Wait -Verbose -Confirm:$false

#find _any_ virtual machine in this deployment and get the name (modify so it finds a specific one if needed)

foreach($deployeditem in $Request){if ($deployeditem.ResourceType -eq "Infrastructure.Virtual"){$machinename = $deployeditem.Name}}

#invoke Cloud Client and export the machines properties in json format

#because of the fact that cloud client logs in everytime this is logged in stdout.

#this is why we have to export the data, then re-import later 😞

$exportPath=$env:temp+$machineName+"_detail.txt"

cloudclient.bat vra machines detail --id $machineName --format JSON --export $exportPath

#gather the content into variable (like I said ... awkward)

$machineDetail=(Get-Content -path $exportPath) | convertfrom-json

#find and display the value of

$PropertyValue=$machineDetail.properties | ?{$_.name -eq $propertyName} | Select-Object -expandProperty value

Write-Host("The VIP of the LB is: "+$PropertyValue)