Wednesday Tidbit: registering multiple vCenters with vCOPs

20150703 - VMwareRecently, the company I work for has done really well in bringing onboard new customers – nearly all of which we have provided with a private cloud solution running on the VMware platform.

As part of the process of transitioning from the build stage to production, the customer’s vCenter system is registered with our in-house vCenter Operations Manager platform, enabling us to constantly monitor the health of their virtual estate.

The process of registering a new vCenter is a trivial one using the vCOPs admin page.  However with twenty or so systems to add, a member of the Operations team asked for my help in automating the process.  This consisted of:

  1. Ensuring networking connectivity between the vCOPs server and the new vCenters (firewall rules, mainly)
  2. Creating an admin account on each customer vCenter for vCOPs
  3. Registering the vCenter servers

It is the last step that required a bit of work.

Familiar with Bash scripting, I decided to create a script which would run on the vCOPs server and do the following:

  1. Import a list of vCenters
  2. Tested connectivity to each one
  3. If successful, register the vCenter (if not, produce an error).

My preferred tool for testing connectivity through firewalls is the excellent netcat utility, but unfortunately this isn’t available the vCOPs SLES 11 box.  Neither is /dev/tcp.

However, cURL is. Therefore I decided to create the following script:

#!/bin/bash

# Variables

INPUT=vcenters.csv
OLDIFS=$IFS
IFS=,

# Read CSV file
while read vcname vcip vcuser vcpass
do

	# Test connectivity to the vCenter IP address
	curl -s -k --connect-timeout 5 https://$vcip >/dev/null 2>&1
	
	if [ $? -eq 0 ]   
	then   
		# Register the vCenter with vCOPs
		vcops-admin register --vc-name $vcname --vc-server https://$vcip/sdk --user $vcuser --password $vcpass --force
	else
		# Write error message
		echo "No connectivity to vCenter" $vcname" at" $vcip". Please check firewall rules"
	fi
		
# Close CSV file
done < $INPUT

# Reset IFS
IFS=$OLDIFS

This uses a CSV file such as:

vcenter1,10.11.12.1,CUSTOMER1\sa_vmw_vcops,mysecretpassword1
vcenter2,10.11.12.2,CUSTOMER2\sa_vmw_vcops,mysecretpassword2
vcenter3,10.11.12.3,CUSTOMER3\sa_vmw_vcops,mysecretpassword3

Once the firewall rules were all put in place, the script ran successfully. Within a few minutes twenty vCenters were registered with vCOPs.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.