Scripting storage (amber road aka fishworks)

Most people have taken the next two weeks off; I've decided to get a few things done that I don't get a chance to do... Like working with new hardware, trying out some software development, etc.

I recently got several Amber Road (fishworks) boxes, and I've developed a couple of rather simplistic (crude) scripts just to understand the capabilities of the boxes.

It's pretty amazing; with very little documentation, I hacked out a couple of rather useful scripts. One creates a new project, one creates a LUN in a given project and hands back the IQN (iSCSI Qualified Name). I was working on another to clone a LUN and drop it in another project.

Why you ask? Well, we're beginning to shift to using xVM for some of our hosting projects. xVM gives us the ability to dynamically move between front ends, expand the footprint for a particular app, etc. And running all this off iscsi based on ZFS really makes sense. We can install once, make a "gold master" and then just clone that as many times as we want. Really fast, really easy and efficient use of disk.

So, for your edification, two simple scripts for amber road. Use them at your own risk; I don't guarantee that they work on anything other than my own personal machine.

create-project.ksh
#!/usr/bin/ksh
#
# Create a project named $1
#
SERVER="root@amberroad.yourdomain.com"

if [ x"$1" = x ]; then
	echo "ERROR: You must specify a project name"
	exit 1
fi

#
# create the project with the defaults
# 	set shareiscsi=on
#	set sharenfs=off
#

ssh -T $SERVER <<EOF
script
	try {
		run('shares project $1');
	} catch (err) {
		if (err.code == EAKSH_NAS_BADPROJECTNAME) {
			printf('Error! "$1" is an invalid project name!\\n');
			exit(1);
		}
		if (err.code == EAKSH_ENTITY_EXISTS) {
			printf('Error! "$1" already exists!\\n');
			exit(1);
		}
		throw(err);
	}
	run('set shareiscsi=on');
	run('set sharenfs=off');
	run('commit');
EOF


ssh -T $SERVER <<EOF
script
	run('shares');
	projects = list();
	printf("Projects:\\n");
	for (i=0; i<projects.length; i++) {
		printf("\\t%s\\n", projects[i]);
	}
EOF

And the other script - create a LUN in a project for use as iscsi target

create-lun.ksh
#!/usr/bin/ksh
#
# Create a LUN in a given PROJECT
# USAGE: create-lun.ksh   []
#
SERVER="root@amberroad.yourdomain.com"

if [ x"$1" = x ]; then
	echo "Invalid argument!"
	echo "usage: $0   []"
	exit 1
fi
if [ x"$2" = x ]; then
	echo "Invalid argument!"
	echo "usage: $0   []"
	exit 1
fi
if [ x"$3" = x ]; then
	SIZE="1G"
else
	SIZE="$3G"
fi
echo "Creating LUN $2 in PROJECT $1 of size $SIZE"

ssh -T $SERVER <<EOF
script
	run('shares select $1');
	try {
		run('lun $2');
	} catch (err) {
		if (err.code == EAKSH_NAS_BADLUNNAME) {
			printf("%s: bad LUN name\\n", $2);
			exit(1);
		} 
		if (err.code == EAKSH_NAS_LUNEXISTS) {
			printf('Error! "$2" already exists!\\n');
			exit(1);
		}
		if (err.code == EAKSH_ENTITY_BADSELECT) {
			printf('Error! "PROJECT $1 is invalid!\\n');
			exit(1);
		}
		throw(err);
	}
	run('set volsize=$SIZE');
	run('set sparse=true');
	run('commit');
EOF

echo "Created $2 ($SIZE) in $1"
# don't know why it takes a while to assign an IQN, but if you don't wait you get an error!
echo "Waiting for IQN to be assigned..."
sleep 10
ssh -T $SERVER <<EOF
script
	run('shares select $1');
	run('select $2');
	printf("IQN: %s\\n", get('iqn'));
	run ('cd ../../..');
EOF

        
    
Comments:

dude your tab indents are crazy-too-big! :)

Posted by rama roberts on December 23, 2008 at 02:07 PM PST #

Post a Comment:
Comments are closed for this entry.
About

I run the engineering group responsible for Sun.com and the high volume websites at Sun.

Will Snow
Sr. Engineering Director

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today