Prototype Fencing Agent for Raritan eRIC G4

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As the subject line says. The agent is attached.
As all currently included fencing agents, this one is also written in Perl, and has the same requirements and dependencies as the DRAC fencing agent (Net::Telnet, Getopt::Std).

What does it take to get it included in the distro? ;)

Many thanks.

Gordan
#!/usr/bin/perl
###############################################################################
# Fencing agent for Raritan eRIC G4
###############################################################################

###############################################################################
# Pragmas
###############################################################################
use strict;
use warnings;

###############################################################################
# Dependencies
###############################################################################
use Getopt::Std;
use Net::Telnet;
use Switch;

###############################################################################
# Global Variables
###############################################################################

###############################################################################
# Function Prototypes
###############################################################################
sub Main();
sub PowerOn($);
sub PowerOff($);
sub Usage();

Main();

###############################################################################
# Main ()
###############################################################################
sub Main()
{
	#######################################################################
	# Parameters:
	#
	# In:	None
	# Out:	None
	#######################################################################

	#######################################################################
	# Local Variables
	#######################################################################
	my $Telnet;
	my %Opts;

	#######################################################################
	# Body
	#######################################################################

	getopts('ha:l:o:p:', \%Opts);

	if (	defined($Opts{h}) or
		not
		(
			defined ($Opts{a}) and
			defined ($Opts{l}) and
			defined ($Opts{p})
		)
	)
	{
		Usage();
		exit 0;
	}

	$Telnet = new Net::Telnet (Timeout => 20, Prompt => '/eSH\> /');
	eval
	{
		$Telnet -> open ($Opts{a});
	};

	if ($@)
	{
		print "FAILED: $@\n" if ($ENV{DEBUG});
		exit 1;
	}

	$Telnet -> login ($Opts{l}, $Opts{p});

	unless ($Opts{o})
	{
		$Opts{o} = 'reboot';
	}

	switch ($Opts{o})
	{
		case 'on'
		{
			PowerOn($Telnet);
		}

		case 'off'
		{
			PowerOff($Telnet);
		}

		case 'reboot'
		{
			PowerOff($Telnet);
			sleep 5;
			PowerOn($Telnet);
		}
	}

	exit(0);
}

###############################################################################
# Usage ()
###############################################################################
sub Usage()
{
	#######################################################################
	# Parameters:
	#
	# In:	None
	# Out:	None
	#######################################################################

	#######################################################################
	# Local Variables
	#######################################################################

	#######################################################################
	# Body
	#######################################################################

	print '
Usage:

fence_eric [options]

Options:
  -a <ip>          IP address or hostname of eRIC
  -h               usage
  -l <name>        Login name
  -o <string>      Action: reboot (default), off or on
  -p <string>      Login password

CCS Options:
  action = "string"      Action: reboot (default), off or on
  ipaddr = "ip"          IP address or hostname of eRIC
  login  = "name"        Login name
  passwd = "string"      Login password

';

}

###############################################################################
# PowerOff ($Telnet)
###############################################################################
sub PowerOff($)
{
	#######################################################################
	# Parameters:
	#
	# In:	$Telnet
	# Out:	$Success
	#######################################################################
	my $Telnet = $_[0];

	#######################################################################
	# Local Variables
	#######################################################################
	my @Lines = undef;
	my $Line;

	#######################################################################
	# Body
	#######################################################################

	@Lines = $Telnet -> cmd ('power info');
	if ($Lines[0] eq "The server is powered off.\n")
	{
		print "SUCCESS: OFF\n" if ($ENV{DEBUG});
		return;
	}
	else
	{
		$Telnet -> put ("power off\n");
		$Telnet -> getline();
		$Line = $Telnet -> getline();

		if ($Line eq "Warning: This may result in data loss on the server!\n")
		{
			$Telnet -> put ("y\n");
		}
		else
		{
			chomp($Line);
			print "FAILED: Expected 'Warning: This may result in data loss on the server!' but got '$Line'!\n" if ($ENV{DEBUG});
			exit 1;
		}		
	}

	$Telnet -> getline();
	$Telnet -> getline();
	$Telnet -> getline();

	$Telnet -> cmd ("power info");
	$Telnet -> getline();
	$Line = $Telnet -> getline();

	if ($Line eq "The server is powered off.\n")
	{
		print "SUCCESS: OFF\n" if ($ENV{DEBUG});
		return;
	}
	else
	{
		print "FAILED: Status reads: $Line" if ($ENV{DEBUG});
		exit 1;
	}

}

###############################################################################
# PowerOn ($Telnet)
###############################################################################
sub PowerOn($)
{
	#######################################################################
	# Parameters:
	#
	# In:	$Telnet
	# Out:	None
	#######################################################################
	my $Telnet = $_[0];

	#######################################################################
	# Local Variables
	#######################################################################
	my @Lines = undef;
	my $Line;

	#######################################################################
	# Body
	#######################################################################

	$Telnet -> cmd ('');
	@Lines = $Telnet -> cmd ('power info');
	@Lines = $Telnet -> cmd ('power info');

	if ($Lines[0] eq "The server is powered on.\n")
	{
		print "SUCCESS: ON\n" if ($ENV{DEBUG});
		return;
	}
	else
	{
		@Lines = $Telnet -> cmd ('power on');
	}

	$Telnet -> cmd ('');
	@Lines = $Telnet -> cmd ('power info');
	@Lines = $Telnet -> cmd ('power info');

	if ($Lines[0] eq "The server is powered on.\n")
	{
		print "SUCCESS: ON\n" if ($ENV{DEBUG});
		return;
	}
	else
	{
		print "FAIL: Status reads: '$Lines[0]'\n" if ($ENV{DEBUG});
		exit 1;
	}
}
--
Linux-cluster mailing list
Linux-cluster@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/linux-cluster

[Index of Archives]     [Corosync Cluster Engine]     [GFS]     [Linux Virtualization]     [Centos Virtualization]     [Centos]     [Linux RAID]     [Fedora Users]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite Camping]

  Powered by Linux