VRO – XML work

Sooner or later you are going to have to work with XML in Ochestrator.  Orchestrator can be challenging with XML because it’s based upon E4X plugin not more current plugins.   You can find some specific details for now here.

I have been doing a lot of XML with NSX so let me explain with a real world example.  I have used the RestAPI to NSX to return the following XML:

<edge>
	<datacenterMoid>datacenter-21</datacenterMoid>
	<type>distributedRouter</type>
		<appliances>
			<appliance>
				<resourcePoolId>domain-c861</resourcePoolId>
				<datastoreId>datastore-998</datastoreId>
			</appliance>
		</appliances>
		<mgmtInterface>
			<connectedToId>virtualwire-1045</connectedToId>
				<addressGroups>
					<addressGroup>
						<primaryAddress>192.168.10.222</primaryAddress>
						<subnetMask>255.255.255.0</subnetMask>
					</addressGroup>
				</addressGroups>
		</mgmtInterface>
		<interfaces>
			<interface>
				<type>uplink</type>
				<mtu>1500</mtu>
				<isConnected>true</isConnected>
				<addressGroups>
					<addressGroup>
						<primaryAddress>172.16.1.2</primaryAddress>
						<subnetMask>255.255.255.0</subnetMask>
					</addressGroup>
				</addressGroups>
				<connectedToId>virtualwire-1036</connectedToId>
			</interface>
			<interface>
				<type>internal</type>
				<mtu>1500</mtu>
				<isConnected>true</isConnected>
				<addressGroups>
					<addressGroup>
						<primaryAddress>172.16.0.1</primaryAddress>
						<subnetMask>255.255.255.0</subnetMask>
					</addressGroup>
				</addressGroups>
				<connectedToId>virtualwire-1033</connectedToId>
			</interface>
			<interface>
				<type>internal</type>
				<mtu>1500</mtu>
				<isConnected>true</isConnected>
				<addressGroups>
					<addressGroup>
						<primaryAddress>172.16.20.1</primaryAddress>
						<subnetMask>255.255.255.0</subnetMask>
					</addressGroup>
				</addressGroups>
				<connectedToId>virtualwire-1035</connectedToId>
			</interface>
			<interface>
				<type>internal</type>
				<mtu>1500</mtu>
				<isConnected>true</isConnected>
				<addressGroups>
					<addressGroup>
						<primaryAddress>172.16.10.1</primaryAddress>
						<subnetMask>255.255.255.0</subnetMask>
					</addressGroup>
				</addressGroups>
				<connectedToId>virtualwire-1034</connectedToId>
			</interface>
		</interfaces>
</edge>

As you can see it’s got a lot of information.  This provides the basic build for a distributed logical router.  Let’s assume that I want to get all the ip addresses in use on this DLR.   First I need to convert this return from the RESTAPI into a XML object.  (It’s already in XML format but we need it as an object so we can interact with XML) Let’s assume all the content above is in the variable called mydata.

//Convert into XML object
var myXML = new XML(mydata);

 

Reading Data

Now that it’s an XML object we can interact with the specific nodes with ease.   If I wanted to return the management interface primary address I could use the following code:

System.log(myXML.mgmtInterface);

 

It’s a common mistake to include the edge on the node list which would fail to return results.   Lets do something more complex like return the first interface ip address:

System.log(myXML.interfaces.interface[0].addressGroups.addressGroup[0].primaryAddress);

 

As you can see I know that both interface and addressGroup might have multiple entries so I using the 0 to designate the first entry.  In reality it would be better to use a loop so we can get all interface IP addresses like this:

for each (a in myXML.interfaces.interface)
{
     for each (b in a.addressGroups.addressGroup)
     {
        System.log(b.primaryAddress);
     }

}

As you can see this will iterate through all interface entries (a) and then though all addressGroup entries(b) on a then print out the primaryAddress.

 

Deleting Data

Removing nodes from XML is really easy for example if I wanted to remove the first interface I would do:

delete myXML.interfaces.interface[0];

I hope this helps you a little on your journey.

vRealize Orchestrator scaling with 4K displays

I ran into this issue this week.   vRealize Orchestrator with Windows 10 on 4K displays makes the UI so small not even my seven year old could read it.   For those lucky enough to have 4K displays it’s a real challenge.  It’s a problem with java and dpi scaling not Orchestrator but it’s a magical challenge.   As much as I want to return to the day of using magnify glasses to read computer screens… here is a simple fix.

 

Download the client.jnlp and run it from an administrative command line with the following command:

 

javaws -J -Dsun.java2d.dpiaware=false client.jnlp

 

This should fix your vision issues and it’s cheaper that a new pair of glasses.

vRO Action to return virtual machines with a specific tag

I am a huge fan of tags in vSphere.   Meta data is the king for modular control and policy based administration.   I wrote a action for a lab I presented at VMUG sessions.   It takes the name of a tag as a string and returns the names of all virtual machines as an array of strings.  It does require a VAPI endpoint setup as explained here: (http://www.thevirtualist.org/vsphere-6-automation-vro-7-tags-vapi-part-i/) Here it is:

 

Return Type: Array/String (Could be Array VC:VirtualMachine)

Parameter: tagNameToMatch string

Code: return_vm_with_tag

 // array to hold the vm names
 var vmsWithSpecificTag = new Array();
 // VAPI connection
 var endpoints = VAPIManager.getAllEndpoints();
 //Use the first returned endpoint to gather information
 var client = endpoints[0].client();
 //var client = end.client(); 
 //Get associations
 var tagging = new com_vmware_cis_tagging_tag__association(client);
 //Get tags
 var tagMgr = new com_vmware_cis_tagging_tag(client);
 //Create object to hold VM
 var objId = new com_vmware_vapi_std_dynamic__ID() ;

//Get all virtual machines
 vms = System.getModule("com.vmware.library.vc.vm").getAllVMs();
 //loop though virtual machines
 for each (vm in vms)
 {
 // assign VM data to object
 objId.id = vm.id;
 // assign VM data to object
 objId.type = vm.vimType;
 //Get tags assigned to VM
 var tagList = tagging.list_attached_tags(objId);
 //Loop through VM assigned tags
 for each (var tagId in tagList) {
 //get object on tag
 var theTag = tagMgr.get(tagId);
 //assign name to compare
 var tagName=theTag.name;
 //compare to our requested tag
 if (tagName == tagNameToMatch) {
 System.log("VM : " + vm.name + " has the tag : " + tagName );
 // add to array
 vmsWithSpecificTag.push(vm.name);
 }
 
 }
 }


return vmsWithSpecificTag;

Learning vRealize Orchestrator

Recently I provided a lab to learn vRealize Orchestrator to the Austin VMUG.   It’s been too long since I attended a VMUG meeting due to moving to Dallas.   It was great to meet new peers in the Austin area.    The purpose of the lab was to provide people hands on experience using Orchestrator with some real world helpful examples.   I was present to answer questions and help the learning process.

I am working to bring the same lab to Dallas and Houston in the next few months but wanted to share the labs here.  It’s mostly possible to do the labs in the hands on lab environment of hol-1821-05-CMP partially made by my friend Ed Bontempo.  You will have to type a lot of code examples since HOL does not support cut and paste.   You can do it all in your home lab.    Contact me if you want to know about the next session we are presenting to a live VMUG if you want some instructor help.

Code: code_text

Lab Manual: VMUG_VRO_LAB_Manual

Enjoy!

Video’s on how to use vRealize Orchestrator

A few weeks ago I presented on Automation at the Louisville VMUG.   During the session I mentioned that using vRealize Orchestrator is really a good skill to learn.  It allows you to become the orchestrator of external services.   It’s a critical skill going forward.  I didn’t want to bore the group by watching how to video’s but promised to post them.   Here they are:

Part 1

Part 2

Enjoy