Too tired to type environment variables everytime I need to start a session, too often I forgot to login before firing up some commands, too paranoid to store my secret inside clear text file, I wrote this small abusive script to help me with govc.
Now whenever I call it unauthenticated, a humble interactive prompt will greet me to enter my credentials, with invisible password typing, before evaluating my command inside a new shell.
Just exit from the shell, and all those credentials in my environment are gone.
This is tricky.
A fake govc
executable and a bashrc
snippet are the playmakers.
Before logged-in,
they will masquerade the real govc
from the path,
and supply the fake one.
And after logged-in,
they hide the fake one,
and will reveal the real govc
to the path.
This masquerading and revealing mechanism is abusing shell executable path priority.
But I desperately need shell completion,
even before logged-in.
And this is the trickiest part.
So I shamelessly modified the govc_bash_completion
from vmware/govmomi.
-
The fake
govc
needs the real one: govc. -
For the
govc-vmid
andgovc-vmrc
: jq. -
For the
govc-vmrc
tool: vmrc.
The real govc
does not need to be accessible from the path.
But both jq
and vmrc
should be.
-
Fill in the
govc-autologin.conf
with your default govc environment.The real
govc
does not need to be accessible from the path beforehand. But then you must supply the realgovc
full path, and cannot simply useGOVC_REAL_BIN="$(which govc)"
. -
Source the
govc-autologin.bash
from yourbashrc
, e.g.. ${HOME}/bin/govc-autologin/govc-autologin.bash
-
Open a new shell, and all is set.
Run
govc ls /
to test.
-
Run
which govc
and note the result. -
Fire up
exit
, and runwhich govc
again.Note the difference with previous result.
Assuming each VM has a unique name accross vSphere datacenters, you can get any VM ID or open its console only by its name.
For example:
-
govc-vmid salt
to get the ID of salt VM. -
govc-vmrc ns1
to open ns1 VM console.Or better, simply call
vmrc ns1
. Since the realvmrc
is overridden bygovc-vmrc
using alias,
While this script and tools still work as expected,
sometimes I get both govc-autologin
and govc-autologin/tools
paths added twice.
Not sure for now, but I guess it's Konsole and yakuake messing up my environment variables.