Recently, 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:
- Ensuring networking connectivity between the vCOPs server and the new vCenters (firewall rules, mainly)
- Creating an admin account on each customer vCenter for vCOPs
- 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:
- Import a list of vCenters
- Tested connectivity to each one
- 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.