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: 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