#!/usr/bin/env perl

##
## $Id: CreateVolume.pl,v 1.1.2.2 2003/05/23 17:59:48 seth Exp $
##

#######################################################################
## Copyright (c) 2002, 2003 by EqualLogic, Inc.
##
## All rights reserved.  This software may not be copied, disclosed,
## transferred, or used except in accordance with a license granted
## by EqualLogic, Inc.  This software embodies proprietary information
## and trade secrets of EqualLogic, Inc.
#######################################################################

use strict;

# this will store the directory containing the script into $Bin
use FindBin qw($Bin);

# this will add the directory you need to 
# @INC (list of library directories)
use lib ("${Bin}/..");

use Getopt::Std;
use EqlScript;

my $host = 'mygroup';
my $user = 'myaccount';
my $pass = 'mypass';
my @result;
my $remote;

my $volName = undef;
my $volSize = 0;

print "usage: $0 volume_name volume_size\n" and exit 1 if ($#ARGV != 1);
$volName = $ARGV[0];

$volSize = $ARGV[1];
##die "invalid volume size" unless $volSize =~ /\d+[gGmM]/;

#
# Log into the PSS
#

$remote = EqlScript->new() or print "Failed to create instance of EqlScript\n" and exit 1;
$remote->timeout(10);

$remote->open( $host ) or print "Failed to connect to $host\n" and exit 1;

$remote->login( $user, $pass ) or print "Failed to log into group\n" and exit 1;

#
# Send the volume create command and extrac the output
#

(@result) = $remote->cmd("vol create $volName $volSize unrestricted") or print "Failed to create volume $volName size $volSize:\n", $remote->errmsg and exit 1;

#
# On success, extract the iSCSI target name from the output
#

my $result = join("", @result);
$result =~ /iSCSI target name is\s+(.*)$/;


printf("volume '%s', iSCSI name '%s' created successfully\n", $volName, $1);

#
# Dump information about the volume
#

@result = $remote->cmd("vol sel $volName show") or print "Failed to show information about volume $volName: $remote->errmsg" and exit 1;

print @result;

exit 0;

