Wednesday, November 5, 2008

VMware RCLI Creating a session file for ESXi

The RCLI utility comes with the ability to create a session file for your host so that you do not need to repeat the user ID and password to a host when passing multiple perl script commands.

The session file that is created will have the host name and ID and password saved in it. This allows you to call/use this file when executing .pl scripts against the host, thus saving you the time of entering your ID and password every time.

Creating the session file:

In the following location of the RCLI install (assuming default path) you will find a save_session.pl, you will use this script to create your sesssion file.

C:\Program Files\VMware\VMware VI Remote CLI\Perl\apps\session>save_session.pl

The command looks like this:
>save_session.pl --savesessionfile c:\users\robert\ESX1host --server 10.10.1.105 --username root --password pass

This will create a file in c:\users\robert called ESX1host. The file is a session files that contains the informaiton for the host (10.10.1.105) wiht the ID or root and using a password of pass.

NOTE for Vista users - by default you do not have the ability to create files in the default installation folder of the RCLI application. Instead of using c:\users\robert you could have just as easly only put the file name. The perl scritp will then create the files in the same directory as the save_session.pl file. The scrit will not error out! But it will also NOT create the file (even when is says is did). So please use a path to a directory that you have the ability to write.

Now that you have a sessoin file for your host you can used it as follows:

Command without using the session file...
>vicfg-ntp.pl --server 10.10.1.105 --list
Enter username: root
Enter password:
No NTP servers configured.

Command using the session file...
>vicfg-ntp.pl --sessionfile c:\users\robert\ESX1host --list
No NTP servers configured.

At first it looks like more effort to create the file than to just enter the server name, user ID and password everytime. And it is if you only running a single command, but if you are going to run multiple commands againts a server all you have to do now is keep calling the same session file with a new script

>vicfg-vswitch.pl --sessionfile c:\users\robert\ESX1host --list
Switch Name Num Ports Used Ports MTU UplinksvSwitch0 64 4 1500 vmnic0
PortGroup Name VLAN ID Used Ports Uplinks VM Network 0 0 vmnic0 Management Network 0 1 vmnic0

or

>vicfg-vmknic.pl --sessionfile c:\users\robert\ESX1host --list
Interface Port Group IP Address Netmask MAC Addressvmk0 Management Network 10.10.1.105 255.255.255.0 00:0c:29:0e:8e:e2

Its worth the effort to create if you run more then one command... Espically since the file, once created can be used over and over again (assuming the password to the host has not changed).

No comments: