only slightly related ... as i do a lot of openbsd testing, i make frequent use 
of multiple kvm instances. i've scripted my vnc connections to those, using 
aliases, with this somewhat ugly bash script; it runs on a client machine (such 
as my macbook or linux laptop): 

#!/usr/bin/env bash 

vncviewer=`which vncviewer` 

test "${1}" = "debug" && { DEBUG=true ; shift ; } 
HOST=${1} 
ALIAS=${2} 
START=${3} 
test "${4}" = "net" && OPTS='order=n' 
USER=root 
SSH="ssh ${USER}@${HOST}" 

function usage { echo usage: ${0} '[debug] host [vm] [start|start net]' ; } 
function available { echo available KVM VMs: ; ${SSH} vmadm list | egrep -e 
UUID -e KVM ; } 

test -n "${HOST}" || { usage ; exit 0 ; } 
test -n "${ALIAS}" || { available ; exit 0 ; } 

VMID=`${SSH} vmadm lookup alias="${ALIAS}"` 
test -n "${VMID}" || { echo ERROR: unknown VM "${ALIAS}" ... ; available ; exit 
0 ; } 

test "x${START}" = "xstop" && { ${SSH} vmadm stop ${VMID} ; exit 0 ; } 
test "x${START}" = "xstophard" && { ${SSH} vmadm stop ${VMID} -F ; exit 0 ; } 

test "x${START}" = "xstart" && ${SSH} vmadm start ${VMID} ${OPTS} && sleep 3 
VNCPORT=`${SSH} "vmadm info ${VMID} vnc | json vnc.port"` 

test -z "${DEBUG}" || { 
echo 
echo "DEBUG: ALIAS = ${ALIAS}" 
echo "DEBUG: VMID = ${VMID}" 
echo "DEBUG: VNCPORT = ${VNCPORT}" 
echo 
} 

test -z "${VNCPORT}" || ${vncviewer} ${HOST}:${VNCPORT} 

----- Original Message -----

> From: "Steven McDowall via smartos-discuss"
> <[email protected]>
> To: [email protected], "Neal Lauver"
> <[email protected]>
> Sent: Thursday, May 22, 2014 3:55:10 AM
> Subject: Re: [smartos-discuss] Anyone else dynamically creating
> environment variables for their zone aliases?

> Why not just put that logic in a nice bash function -- and then call
> the function in your bashrc type file, but then at the command line
> you could do something like:

> $ zonealias

> Assuming you put that logic in

> function zonealias() {
> blah blah blah
> }

> Useful idea!

> /Steve

> On May 22, 2014, at 1:50 AM, Neal Lauver via smartos-discuss <
> [email protected] > wrote:

> > Hello all,
> 

> > This is potentially only of interest to folks running their own
> > smartos physical hosts instead of those running Joyent-hosted
> > systems. I completely understand that cloud providers can't trust
> > that customer-specified zone aliases are unique on their systems.
> > However, those of us running our own smartos physical hosts have
> > the
> > luxury of being certain that we have chosen unique aliases. I
> > suspect most of us find it more convenient to use aliases for our
> > zones instead of UUIDs. I thought I'd share what I'm doing and see
> > whether anyone else is doing something better that I might use.
> 

> > I find it most convenient to have environment variables like this
> > available to me at the bash prompt:
> 

> > app1=3d0b54a4-e16b-11e3-99a7-e7babf74a922
> 
> > app2=3d0c2226-e16b-11e3-82ca-4b426c2af9d0
> 
> > buildzone=3d0c8630-e16b-11e3-9a3c-ab1be656b213
> 
> > firewall=3d0bb7fa-e16b-11e3-95c7-fb732fb88e96
> 
> > webserver1=3d0a8d4e-e16b-11e3-9e9c-cb3596cd1c02
> 

> > webserver2=3d0af04a-e16b-11e3-8237-171c0fded46a
> 
> > To make this happen automatically, I use the following code in my
> > .bashrc:
> 
> > VMLIST=~/.vmadm-list.$$
> 
> > NICKNAMES=~/.bash-vmadm-nicknames.$$
> 
> > #First we create a list of the zones using vmadm and save it to a
> > file we can parse
> 
> > vmadm list > ${VMLIST}
> 
> > #Now we iterate over that list creating variable assignments of the
> > form NICKNAME=UUID and save it to a file we can source
> 
> > egrep -v '^UUID.*ALIAS$' ${VMLIST} | awk '{print $NF" "$1}' | while
> > read nickname uuid ; do echo "export ${nickname}=${uuid}" ; done |
> > sort -u > ${NICKNAMES}
> 
> > #Source the list of variable assignments
> 
> > source ${NICKNAMES}
> 
> > #Clean up
> 

> > rm -f ${VMLIST} ${NICKNAMES}
> 

> > The reason I like doing things this way is that it makes it
> > possible
> > for me to things like:
> 
> > zfs send -R zones/${app2}@some_snapshot
> 
> > or:
> 
> > zoneadm -z $app2 halt
> 
> > The only problem I have with the above scheme is that if I create a
> > *new* zone, I need to log out of the global zone and log in again
> > (or I suppose source my .bashrc again) to pick up the new alias and
> > create the environment variable for it.
> 
> > I have seen others override commands like vmadm with a bash
> > function
> > that calls "vmadm lookup", but the reason I don't use the same is
> > that it would require that I create a bash function for each
> > command
> > I'm interested in overriding (vmadm, zoneadm, etc.) and wouldn't
> > work for things like arguments to my zfs send above.
> 

> > Just wondering if anyone else has a better method for doing this.
> 
> > Thanks,
> 
> > Neal Lauver
> 

> > smartos-discuss | Archives | Modify Your Subscription
> 
> smartos-discuss | Archives | Modify Your Subscription


-------------------------------------------
smartos-discuss
Archives: https://www.listbox.com/member/archive/184463/=now
RSS Feed: https://www.listbox.com/member/archive/rss/184463/25769125-55cfbc00
Modify Your Subscription: 
https://www.listbox.com/member/?member_id=25769125&id_secret=25769125-7688e9fb
Powered by Listbox: http://www.listbox.com

Reply via email to