#!/usr/bin/env perl

##
## $Id: CreateSnapshot.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 $retval = 0;
my $remote;

my $volName = undef;
my $snapName = undef;

print "usage: $0 volume_name volume_size\n" and exit 1 if ($#ARGV != 0);
$volName = $ARGV[0];

#
# 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 extract the output
#

@result = $remote->cmd("vol sel $volName snapshot create-now") or print "Failed to create snapshot for volume $volName\n", $remote->errmsg and exit 1;

#
# On success, extract the iSCSI target name from the output
#

my $result = join("", @result);
$result =~ /snapshot name is\s+(.*)$/;
$snapName = $1;

printf("volume '%s', snapshot name '%s' created successfully\n", $volName, $snapName);

#
# Dump information about the volume snapshots
#

@result = $remote->cmd("vol sel $volName snapshot select $snapName show") or print "Failed to show information about volume snapshot $volName:\n", $remote->errmsg and exit 1;

printf("volume snapshot $snapName:\n");
print @result;

exit 0;

