Some vRO IP address actions

I just wanted to take this opportunity to share a few vRO actions from my library that I've recently tidied up. Some started life as scriptable tasks in other workflows but it made sense to strip those bits out and put them in to discreet actions to enable better re-use.

Background

Several of these functions came from a single project. The IPAM system in use only returned an IP address for the vRA provisioned VM being worked on and a subnet mask. The gateway address had to be calculated. In another project, similar constraints existed but with the added complication of some networks having the gateway as the first address in the subnet and some having it as the last!

A couple of these functions also came in handy for some NSX automation, making sure that a new IP address was added to the correct interface of an NSX Edge Services Gateway (ESG) device.

The Actions

There are 7 actions in total. I added a couple to complete some extra functionality that was missing from the original use case requirements.

  1. areIPsInSameSubnet – Takes two IP addresses and one subnet mask as inputs and returns “true” if they're in the same subnet or “false” if not.
  2. areIPsInSameSubnetUsingCIDR – Takes two IP addresses and one subnet CIDR value as inputs and returns “true” if they're in the same subnet or “false” if not.
  3. convertCIDRToIPMask – Converts a subnet CIDR value (e.g. 24) to a subnet mask (e.g. 255.255.255.0).
  4. convertIPMaskToCIDR – Converts a subnet mask (e.g. 255.255.254.0) to a subnet CIDR value (e.g. 23).
  5. getIPBroadcastAddress – Takes an IP address and a subnet mask as inputs and returns the network broadcast address (e.g. 10.10.36.12 & 255.255.255.0 returns 10.10.36.255).
  6. getIPHostAddress – Takes a network / subnet address, a subnet mask and an address index as inputs and returns the specified IP address. The address index can either be a string or a number. If it's a number, the corresponding address in the subnet is returned (e.g. 10.10.36.0 & 255.255.255.0 & 8 returns the address 10.10.36.8). If the address index is a string, it can be one the values “first”, “last”, “broadcast”. The correct address from the range is then returned (e.g. 10.10.36.0 & 255.255.255.0 & “last” returns the address 10.10.36.254).
  7. getIPNetworkAddress – Takes an IP address and a subnet mask as inputs and returns the network / subnet address (e.g. 10.10.36.12 & 255.255.255.0 returns 10.10.36.0).

Download

I've put all 7 actions individually in a GitHub repository along with a package that contains them all. (Note: some of the actions have dependencies on the others.) They're free to use, so help yourself.

mpoore/o11n-utils-network-ipv4