- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My login script: create a "stateful" vCLI experience.
One of the things everyone seems to struggle with when using vCLI is just logging in. I had the same struggles so I decided to write a script to help out. The two problems I try to solve are:
1) I don't ever remember my server IP addresses.
2) I don't want to type my password every time.
Before you begin using this script you have to define a VI_SESSIONFILE environment variable, which defines where your session will get saved.
Also, you should note that this script takes advantage of the so-called "credential cache". Full disclosure: this cache is not cryptographically secure, similar to the observations made in this blog. The cache is protected by filesystem security, so you probably shouldn't use this script on a disk that you can't physically secure.
With all that out of the way, here's a sample of this script in action.
vmware@ubuntu:~$ vcli-login Select the host you want to access or enter its Name/IP: 10.21.4.62 Using host 10.21.4.62 Enter your username: Administrator Enter password: Session information saved. Login succeeded. Caching credential.
Since I just logged in to a vCenter server, whenever I want to run a command I have to use -h. Here I list the NICs on one of my hosts.
vmware@ubuntu:~$ vicfg-nics -l -h 192.168.1.11 Name PCI Driver Link Speed Duplex MAC Address MTU Description vmnic0 02:00.0 e1000 Up 1000Mbps Full 00:0c:29:ef:17:fb Intel Corporation Abstract PRO/1000 MT Single Port Adapter vmnic1 02:03.0 e1000 Up 1000Mbps Full 00:0c:29:ef:17:05 1500 Intel Corporation Abstract PRO/1000 MT Single Port Adapter vmnic2 02:04.0 e1000 Up 1000Mbps Full 00:0c:29:ef:17:0f Intel Corporation Abstract PRO/1000 MT Single Port Adapter vmnic3 02:05.0 e1000 Up 1000Mbps Full 00:0c:29:ef:17:19 Intel Corporation Abstract PRO/1000 MT Single Port Adapter
Now let me switch to a different server, this time an ESX server.
vmware@ubuntu:~$ vcli-login Available hosts: [1] 10.21.4.62 Select the host you want to access or enter its Name/IP: 10.21.1.83 Using host 10.21.1.83 Enter your username: root Enter password: Session information saved. Login succeeded. Caching credential.
Here I don't need -h.
vmware@ubuntu:~$ vicfg-nics -l Name PCI Driver Link Speed Duplex MAC Address MTU Description vmnic0 03:00.0 bnx2 Up 1000Mbps Full 00:1e:4f:3f:04:e4 1500 Broadcom Corporation Broadcom NetXtreme II BCM5708 1000Base-T vmnic1 07:00.0 bnx2 Up 1000Mbps Full 00:1e:4f:3f:04:e6 1500 Broadcom Corporation Broadcom NetXtreme II BCM5708 1000Base-T vmnic2 0a:00.0 e1000e Down 0Mbps Half 00:15:17:74:4a:fe 1500 Intel Corporation 82571EB Gigabit Ethernet Controller vmnic3 0a:00.1 e1000e Down 0Mbps Half 00:15:17:74:4a:ff 1500 Intel Corporation 82571EB Gigabit Ethernet Controller
Now I switch back to my vCenter, taking advantage of the fact that my credentials are cached. Note that I don't enter a password.
vmware@ubuntu:~$ vcli-login 10.21.4.62 Using host 10.21.4.62 Using user Administrator. You can override this by re-running the command with a user specified. Session information saved. vmware@ubuntu:~$ vicfg-nics -l -h 192.168.1.11 Name PCI Driver Link Speed Duplex MAC Address MTU Description vmnic0 02:00.0 e1000 Up 1000Mbps Full 00:0c:29:ef:17:fb Intel Corporation Abstract PRO/1000 MT Single Port Adapter vmnic1 02:03.0 e1000 Up 1000Mbps Full 00:0c:29:ef:17:05 1500 Intel Corporation Abstract PRO/1000 MT Single Port Adapter vmnic2 02:04.0 e1000 Up 1000Mbps Full 00:0c:29:ef:17:0f Intel Corporation Abstract PRO/1000 MT Single Port Adapter vmnic3 02:05.0 e1000 Up 1000Mbps Full 00:0c:29:ef:17:19 Intel Corporation Abstract PRO/1000 MT Single Port Adapter
The script is attached, hopefully someone will find it useful. Note that script only works on Linux. If you have any improvements or suggestions let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sounds like a neat script, will have to give it a try when I get some time. It sounds like a 'ghetto' version of vi-fastpass ![]()
I noticed the code base was similar to that of credstore_admin.pl from the vSphere SDK for Perl?
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
VMware Code Central - Scripts/Sample code for Developers and Administrators
![]()
If you find this information useful, please award points for "correct" or "helpful".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It does use the same libraries as credstore_admin.
The main difference between this and fastpass is that fastpass will create accounts for you on ESX, which this doesn't do.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If anyone tried this script and found it not working, I've updated it to reflect a change that was made between vCLI RC and vCLI GA.
=====
Carter Shanklin