Tuesday, 27 May 2008

Using RCLI to configure multiple ESX 3.5 Servers

So I deal with a lot of customers on my travels, and most have multiple ESX servers and occasionally I receive the odd request for a change here and there. As you all know, with VI3 and the latest releases of ESX3.5/VC2.5, almost all configuration and most advanced configuration can be achieved by using the VI Client connected to VirtualCenter.

But how long would it take to add another portgroup to a vSwitch with a VLAN ID for 20 ESX servers? Quite long, if you have the time or the patience then thats fine, but I'd rather script something like that.

By using the VMware RCLI (Remote Client) you can send vicfg- (esxcfg) commands to both ESX 3.5 and ESXi hosts. Originally it was intended for use with ESXi due to it having limited service console but the functionality is also provided for ESX 3.5 hosts.

The VMware Infrastructure Remote CLI provides a command-line interface for datacenter management from a remote server. This interface is fully supported on VMware ESXi 3.5 and experimental for VMware ESX 3.5. Storage VMotion is a feature that lets you migrate a virtual machine from one datastore to another. It is used by executing the svmotion command from the Remote CLI. The svmotion command, unlike other RCLI commands, is fully supported for VMware ESX 3.5.

I use the RCLI with SSH access enabled, so now my RCLI acts as a service console proxy server. To send an esxcfg- command to an ESX 3.5 host, I would now log into the RCLI using SSH and then send the commands from the RCLI's command line, or execute a .sh script on the RCLI.

So let's use our example above.... to add another portgroup to vSwitch1, with a VLAN ID of 123 onto 20 ESX 3.5 hosts.

  1. Log into the RCLI using SSH
  2. the command line command is very similar to esxcfg- but we use vicfg- instead
  3. vicfg-vswitch --add-pg=VLAN123 vSwitch1 --server= --username=root --password=
  4. Now you can either repeat the above for all 20 servers or script it into a shell script..
  5. Create a new script on the RCLI called addportgroup.sh
#Script to add portgroup with vlad id of 123 to vSwitch1 onto all ESX 3.5 hosts

# Assign port groups to vSwitch1
vicfg-vswitch --add-pg=VLAN123 vSwitch1 --server= --username=root --password=

vicfg-vswitch --add-pg=VLAN123 vSwitch1 --server= --username=root --password=

vicfg-vswitch --add-pg=VLAN123 vSwitch1 --server= --username=root --password=

#Assign vlan ids to port groups
vicfg-vswitch -v 123 -p VLAN123 vSwitch1 --server= --username=root --password=

vicfg-vswitch -v 123 -p VLAN123 vSwitch1 --server= --username=root --password=

vicfg-vswitch -v 123 -p VLAN123 vSwitch1 --server= --username=root --password=

Now save, make the script executable and then launch it, and the script will create the new portgroups on all the servers in a couple of seconds.


dam said...

I dont see a v* command to shut down an (or many :) ESXi host(s), in case of power outage ?

Hugo said...

No there isn't one. vicfg- commands are for configuring ESX hosts, but if you have SSH open then you could write a script that shuts down all hosts in the script? A bit dangerous though.

Anonymous said...

A very useful little script, thanks a lot.