Using iTerm2 with Cisco VIRL

I love using VIRL to do quick self-check of a config, personal education, and learning the behavior of particular features. I also love using the iTerm2 Terminal Emulator on the Mac. Unfortunately, it isn’t obvious how to make the two play well together. I have had to re-educate myself on this over and over again as I get new computers, mess up my settings and do certain upgrades. I’m pretty sure I copied some of this configuration and the script that I will share from somewhere. So if this looks familiar, reach out to me and I will link back to the source.

This post meant to both share the config and caveats with others as well as to document the nuances for my future reference. In short, there is a standard configuration and a custom configuration for the terminal settings in VIRL’s VMMaestro. These are found in “VMMaestro -> Preferences.”

VMMaestroTerm2

These settings control whether the built-in (VMMaestro’s client) is used or an external terminal client should be used. I much prefer an external client and iTerm2 is my current client of choice. To eliminate the need of manually launching and connecting, I have customized the Applescript code found below. This can be duplicated by opening the Applescript editor, copying the text and saving as virlterm.scpt.

virlterm.scpt

on run argv
	-- last argument should be the window title
	set windowtitle to item (the count of argv) of argv as text
	
	-- all but last argument go into CLI parameters
	set cliargs to ""
	repeat with arg in items 1 thru -2 of argv
		set cliargs to cliargs & " " & arg as text
	end repeat
	tell application "iTerm"
		activate
		tell current window
			set newTab to (create tab with default profile)
			tell the current session of newTab
				set name to windowtitle
				write text cliargs
			end tell
		end tell
	end tell
end run

The function of this script is to read in the command line arguments, launch iTerm2 with a Tab Name derived from the last parameter, and pass the reminding arguments as an initial command to the OSX shell. These can be leveraged by passing derived variables from VMMaestro.

VMMaestro uses the following placeholders to pass as command line arguements.

%h = Host (i.e. the IP address)
%p = TCP Port
%t = Title
%r = Redirect command for ssh

To launch an Applescript, we need to call it from osascript and my virlterm.scpt file is in Documents. Therefore, my current settings are as follows:

Telnet Command:
/usr/bin/osascript
Telnet arguments:
/Users//Documents/virlterm.scpt telnet %h %p ‘%t’

SSH Command:
/usr/bin/osascript
SSH arguments:
/Users//Documents/virlterm.scpt ssh guest@%h -p %p ‘%r’ ‘%t’

TerminalSettings

This seems to work well most of the time. Basically for telnet, it launches iTerm2 and connects to %h on port %p. The tab name will be %t. For ssh, it will connect to guest@%h on port %p. Again, the title is derived from %t.

I said this works well most of the time. Here are a few of the caveats that could potentially be eliminated with more a elaborate script, configuration or code fixes.

  • iTerm2 seems to have an issue if the application is open without any windows and I try to create a new tab from Applescript. In this case, it crashes. Fortunately, retrying resolves the issue because it works fine with application launch or an existing window. I believe this is an iTerm2 issue that could be resolved with a bugfix. I’m testing with 3.1Beta5 (and have duplicated the behavior with Beta4).
  • SSH in VIRL is mainly to connect through an LXC redirect. The script, combined with the above configuration, properly passes through the default username of ‘guest’. Once connected, the user will also need to pass the correct password for the ssh session (the LXC instance uses ‘guest’ by default). Subsequently, the %r is the command that is executed and includes the proper telnet connection through to the destination
  • Connecting to the Management IP (third option in the telnet submenu when you right-click), you will need connectivity to the appropriate management network. This configuration is the same as what I used in this article.

Conclusion

VIRL and iTerm2 make a great combination but can take a bit of time to understand the interaction. This article should help streamline that process. If you have further streamlined this process or have something similar to share, please provide feedback by commenting below.

Disclaimer: This article includes the independent thoughts, opinions, commentary or technical detail of Paul Stewart. This may or may does not reflect the position of past, present or future employers.

No related content found.

About Paul Stewart, CCIE 26009 (Security)

Paul is a Network and Security Engineer, Trainer and Blogger who enjoys understanding how things really work. With over 15 years of experience in the technology industry, Paul has helped many organizations build, maintain and secure their networks and systems.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply