Export vRO Packages to Actions & Configuration Elements (*.js files) + Create your own Git Repository

Hello everyone!!!

Have you ever heard about Fling “VMware vRealize Build Tools“, sometimes we also use different names such as #COE development tools, #vRO integration with VSCode, IaC for vRealize Suite or any other name that comes into mind.

Yes! That’s is indeed really nice the possibility to integrate your vRO 7x or vRO 8x with maven, javascript, Artifact server such as jfrog, github or DevOps Azure.

You may see quick video what is all about below:

BUT…

If you have ever heard about it and tried to implement!! OMG!!! Really OMG!!! That’s is really a pain!

Couple of use cases works fine for it, maybe you have a team of developers in house or has a fixed environment to work with it! Yes, that may be worth to expend couple of days on the setup and couple of months on training your personal!

@vdgMichael and myself @JoseCavalheri, we are consultants for a company specialized in VMware products and as you can imagine, we are vRealize Automation and Orchestrator guys 🙂

In this type of approach is almost impossible to have a setup like above, hence we came up with a different approach, something that would take less effort and more benefits to us both!

Hence the question came : Why we don’t export our Actions and Configuration Elements to a central repository? In this case our requirements were quite simple and we came up with a list below

  • Don’t turn on your own vRO server everytime you need something similar
  • Share within ourselves and our internal team all the actions created by us
  • Don’t reinvent the wheel! If you have ever created a “Add CPU” or a “Add RAM”, just reuse/re-adapt
  • Quality! Quality! Quality! >> Yes!! If you build it once nicely, that will guarantee you that!
  • vRA 8x transitions came along too! More and more customers want it! Hence, always changing from VCACCafe and similar actions will be pretty handy to have it out of the shelve!
  • Any many others… anyway… you got the point!

So that was the challenge and we accepted! We came up with the following easy solution:

1- Every vRO Package we have, we export the actions and configuration elements;

2- Easy way to add to a GitHub repository

3- All Actions Parameters must be clear with input,types and description when possible(* Auto exported);

4- All Configuration Elements with input,types and description when possible(* Auto exported);

5- We can clearly see in VSCode with correct javascript format, so it will be easy to copy/paste to the next project

Attention: Here is some good difference between this solution and Fling. We are using for consultation, reuse and improvements, but there is ” NO LINK” to any vRO. We are just talking about *.js code and git repository.

Hereby you can see the result from our solution (script based export).

We have defined the structure we wanted, let’s say a repository for vRA7x and one for vRA8x + Actions, Configuration Elements, CloudTemplates,etc…

OUR CORE MESSAGE is SHARE TO COMMUNITY !

Hence here it is … The code is written in PowerShell and it works in both Windows and MAC.

There is no needed to read the code, basically it ask for:

1 – Where is your vRO Package folder (after unzipped it )

2 – Where do you want to save it

3 – Windows or Mac

4 – Few seconds, just go and check folder location. 🙂

<#
    Version 2.0
    Created by:
        - Jose Cavalheri
    Contributed by:
        - Michael Van de gaer

    Description:
    - Skip Workflows and Resource Elements 
    - Get all content from exported vRO package Elements folder
    - Run through each folder and read categories (Modules)
    - Run through each folder and read data (Action name, parameters and content)
    - Create a new file *.js with the correct syntax for javascript
    - Create new folders as Actions or Configuration Elements
    - Export Configuration Elements as Commented Parameters + add inputs& descriptions
    - Export to c:\uploadVRO folder    

#>
## Inputs: 
#Element Folder Path after package unziped
$ElementsFolder = $(Write-Host "Where is your unzipped vRO Package stored? (provide full path - e.g.: C:\vRA4U\com.vro.some.module\elements)-- " -NoNewLine -ForegroundColor yellow; Read-Host)

# Path to save all new Modules and Actions
$savePath = $(Write-Host "Where would you like to save all Modules and Actions? (provide full path) -- " -NoNewLine -ForegroundColor yellow; Read-Host)

#Ask if Script is being executed on a Mac (for forwards slash vs backslash in folders)
$defaultOSType = 'windows'  
if (!($osType = $(Write-Host "What is your OS Version? [windows|mac] - default: windows -- " -NoNewLine -ForegroundColor yellow; Read-Host))){$osType = $defaultOSType}
$osType = $osType.ToLower()

#Set Slash / BackSlash
$slash = "\"
if ($osType -eq 'mac'){$slash = "/"}

# Enter the folder path
cd $ElementsFolder 

$dir = dir $ElementsFolder | ?{$_.PSISContainer}
foreach ($d in $dir){
    # Enter subfolder path
    cd $d
    
    ## Do Tasks copying from Element folder and formatting to javascript with Parameters commented/scripts to .js

    #Get the categories file to determine vRO Module
        Select-Xml -Path .\categories -XPath 'categories'
        [xml]$xmlElm = Get-Content -Path .\categories
        #this getthe action name
        $catNameFolder = $xmlElm.categories.category.name.'#cdata-section'
        $catNameFolder = $catNameFolder.ToLower()
        write-host "Module name: " $catNameFolder

        [xml]$xmlElm = Get-Content -Path .\info
        $elementType = $xmlElm.properties.entry.'#text'
        
        if ($elementType -contains "ConfigurationElement") {

            #Create module folder

            if ($catNameFolder.Count -eq 1){
                $newPath = ($savePath + $slash+'ConfigurationElements'+$slash + $catNameFolder)
            } else {
                $newPath = ($savePath + $slash+'ConfigurationElements'+$slash + $catNameFolder[0] + $slash + $catNameFolder)
            }


            if ($osType -eq 'mac'){
                #mkdir -p $savePath$slash'ConfigurationElements'$slash$catNameFolder[0]$slash$catNameFolder
                mkdir -p $newPath
            } else {
                #mkdir $savePath$slash'ConfigurationElements'$slash$catNameFolder[0]$slash$catNameFolder
                mkdir $newPath
            }
            

            #Get the data file to determine vRO Action
            [xml]$xmlElm = Get-Content -Path .\data

            #Get Name of Config Element
            $configElementName = $xmlElm.'config-element'.'display-name'.'#cdata-section'
            $configElementName = $configElementName+".js"

            #Get Attributes / Parameters of Configuration Element
            $descriptions = @($xmlElm.'config-element'.atts.att.description.'#cdata-section')
            $attributes = @($xmlElm.'config-element'.atts.att)

            $myArray = @()

            $index = 0
            forEach ($att1 in $attributes){
                $object = New-Object -TypeName psobject
                $object | Add-Member -MemberType NoteProperty -Name "Name" -Value $att1.name 
                $object | Add-Member -MemberType NoteProperty -Name "Type" -Value $att1.type 
                $object | Add-Member -MemberType NoteProperty -Name "Description" -Value $descriptions[$index]

                $myArray += $Object
                $index = $index + 1
            }

            # creating file javascript
            New-Item -Name  $configElementName -ItemType File

            # adding parameters as description
            echo "/*" >> $configElementName
            echo "@Auto Export Created by VRA4U.COM:" >> $configElementName
            echo "Attributes:" >> $configElementName
            echo $myArray >> $configElementName
            echo "*/" >> $configElementName

            # Copy to final upload location
            #mv $configElementName $savePath$slash'ConfigurationElements'$slash$catNameFolder$slash$configElementName
            mv $configElementName $newPath

        } elseif ($elementType -contains "ScriptModule") {

            ## if module contains space or more than 1 categorie  = It's a  workflow Folder or Configuration Element type 
             #Create module folder
             if ($osType -eq 'mac'){
                mkdir -p $savePath$slash'Actions'$slash$catNameFolder
             } else {
                mkdir $savePath$slash'Actions'$slash$catNameFolder
             }
             

             #Get the data file to determine vRO Action
             Select-Xml -Path .\data -XPath 'dunes-script-module/script'
             [xml]$xmlElm = Get-Content -Path .\data

             #this get the action name
             $actionName = $xmlElm.'dunes-script-module'.name
             $actionName = $actionName+".js"

             # This returns all parameters
             $actionParams = $xmlElm.'dunes-script-module'.param

             #This return all script part
             $actionScript = $xmlElm.'dunes-script-module'.script.'#cdata-section'

             # creating file javascript
             New-Item -Name  $actionName -ItemType File

             # adding parameters as description
             echo "/*" >> $actionName
             echo "@Auto Export Created by VRA4U.COM:" >> $actionName
             echo "Input Parameters:" >> $actionName
             echo $actionParams >> $actionName
             echo "*/" >> $actionName
    
             # adding script content
             echo $actionScript >> $actionName

             # Copy to final upload location
             mv $actionName $savePath$slash'Actions'$slash$catNameFolder$slash$actionName

        }else{
            write-host "skipping Workflows & Resource Elements"
        
        }

    #Go back root level
    cd ..

}


Configuration Elements & Actions will be exported as commented code for @Parameters and @ScripsContent as a normal JavaScript code.

Don’t forget the flexibility of VSCode Search as well! If you want to search specific code, just type the search and it will show all actions available for you with examples/similar code within your repository.

At this moment,we didn’t include the script in a open repository, but it is a good start point!

Hope you enjoy it!

See you next at next blog post! Regards Jose Cavalheri.

One thought on “Export vRO Packages to Actions & Configuration Elements (*.js files) + Create your own Git Repository

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