Hi,
On Thu, Aug 20, 2009 at 11:07:15AM +0200, Thomas Glanzmann wrote:
> Hello,
> find attached, a vsphere (works with esx-server 3/4 virual center 2.X
> and 4) stonith plugin, a squid3 resource agent for debian lenny and a
> example configuration.
Many thanks, I'll take a look at the contributions. BTW, was
there anything wrong with the Squid OCF RA or you just didn't see
it? The vsphere stonith agent contains no license.
Thanks,
Dejan
>
> Thomas
> use_logd yes
> bcast eth0
> node ha-01 ha-02
> watchdog /dev/watchdog
> crm on
> #!/bin/sh
>
> if [ -z "${OCF_ROOT}" ]; then
> export OCF_ROOT=/usr/lib/ocf/
> fi
>
> . ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
>
> SQUID_PORT=3128
> INIT_SCRIPT=/etc/init.d/squid3
> PID=/var/run/squid3.pid
> CHECK_URLS="http://www.google.de/ http://www.glanzmann.de/
> http://www.uni-erlangen.de"
>
> case "$1" in
> start)
> if [ -f "${PID}" ]; then
> kill -0 `cat ${PID}` &> /dev/null && exit 0;
>
> else
> rm -f "${PID}"
> fi
>
> ${INIT_SCRIPT} start > /dev/null 2>&1 && exit || exit 1
> ;;
>
> stop)
> if [ -f "${PID}" ]; then
> ${INIT_SCRIPT} stop > /dev/null 2>&1 && exit || exit 1
> fi
>
> exit 0;
> ;;
>
> status)
> if [ -f "${PID}" ]; then
> kill -0 `cat ${PID}` && exit;
> fi
>
> exit 1;
> ;;
>
> monitor)
> if [ -f "${PID}" ]; then
> kill -0 `cat ${PID}` || exit 7
> else
> exit 7;
> fi
>
> for URL in ${CHECK_URLS}; do
> http_proxy=http://localhost:${SQUID_PORT}/ wget -o
> /dev/null -O /dev/null -T 1 -t 1 ${URL} && exit
> done
>
> exit 1;
> ;;
>
> meta-data)
> cat <<END
> <?xml version="1.0"?>
> <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
> <resource-agent name="squid">
> <version>1.0</version>
>
> <longdesc lang="en">
> OCF Ressource Agent on top of squid init script shipped with debian.
> </longdesc>
>
> <shortdesc lang="en">OCF Ressource Agent on top of squid init script
> shipped with debian.</shortdesc>
>
> <actions>
> <action name="start" timeout="90" />
> <action name="stop" timeout="100" />
> <action name="status" timeout="60" />
> <action name="monitor" depth="0" timeout="30s" interval="10s"
> start-delay="10s" />
> <action name="meta-data" timeout="5s" />
> <action name="validate-all" timeout="20s" />
> </actions>
> </resource-agent>
> END
> ;;
> esac
> #!/usr/bin/perl
>
> use strict;
> use warnings FATAL => 'all';
>
> # Thomas Glanzmann 10:28 09-08-19
> # apt-get install libarchive-zip-perl libclass-methodmaker-perl
> libcompress-raw-zlib-perl libcompress-zlib-perl libcompress-zlib-perl
> libdata-dump-perl libio-compress-base-perl libio-compress-zlib-perl
> libsoap-lite-perl liburi-perl libuuid-perl libxml-libxml-perl
> libxml-libxml-common-perl libxml-namespacesupport-perl libwww-perl
> # tar xfz ~/VMware-vSphere-SDK-for-Perl-4.0.0-161974.i386.tar.gz
> # answer all questins with no
>
> use lib '/usr/lib/vmware-vcli/apps/';
> use VMware::VIRuntime;
> use AppUtil::VMUtil;
>
> sub
> connect
> {
> Opts::parse();
> Opts::validate();
> Util::connect();
> }
>
> my $vm_views = undef;
>
> sub poweron_vm {
> foreach (@$vm_views) {
> my $mor_host = $_->runtime->host;
> my $hostname = Vim::get_view(mo_ref => $mor_host)->name;
> eval {
> $_->PowerOnVM();
> Util::trace(0, "\nvirtual machine '" . $_->name .
> "' under host $hostname powered on
> \n");
> };
> if ($@) {
> if (ref($@) eq 'SoapFault') {
> Util::trace (0, "\nError in '" . $_->name .
> "' under host $hostname: ");
> if (ref($...@->detail) eq 'NotSupported') {
> Util::trace(0,"Virtual machine is
> marked as a template ");
>
> } elsif (ref($...@->detail) eq
> 'InvalidPowerState') {
> Util::trace(0, "The attempted
> operation".
> " cannot be performed
> in the current state" );
>
> } elsif (ref($...@->detail) eq
> 'InvalidState') {
> Util::trace(0,"Current State of the "
> ." virtual machine is
> not supported for this operation");
>
> } else {
> Util::trace(0, "VM '" .$_->name.
> "' can't be powered
> on \n" . $@ . "" );
> }
>
> } else {
> Util::trace(0, "VM '" .$_->name.
> "' can't be powered on \n" .
> $@ . "" );
> }
> Util::disconnect();
> exit 1;
> }
> }
> }
>
> sub poweroff_vm {
> foreach (@$vm_views) {
> my $mor_host = $_->runtime->host;
> my $hostname = Vim::get_view(mo_ref => $mor_host)->name;
> eval {
> $_->PowerOffVM();
> Util::trace (0, "\nvirtual machine '" . $_->name .
> "' under host $hostname powered off
> ");
> };
>
> if ($@) {
> if (ref($@) eq 'SoapFault') {
> Util::trace (0, "\nError in '" . $_->name .
> "' under host $hostname: ");
> if (ref($...@->detail) eq
> 'InvalidPowerState') {
> Util::trace(0, "The attempted
> operation".
> " cannot be performed
> in the current state" );
>
> } elsif (ref($...@->detail) eq
> 'InvalidState') {
> Util::trace(0,"Current State of the".
> " virtual machine is
> not supported for this operation");
>
> } elsif(ref($...@->detail) eq 'NotSupported')
> {
> Util::trace(0,"Virtual machine is
> marked as template");
>
> } else {
> Util::trace(0, "VM '" .$_->name. "'
> can't be powered off \n"
> . $@ . "" );
> }
>
> } else {
> Util::trace(0, "VM '" .$_->name. "' can't be
> powered off \n" . $@ . "" );
> }
> Util::disconnect();
> exit 1;
> }
> }
> }
>
> sub reset_vm {
> foreach (@$vm_views) {
> my $mor_host = $_->runtime->host;
> my $hostname = Vim::get_view(mo_ref => $mor_host)->name;
> eval {
> $_->ResetVM();
> Util::trace(0, "\nvirtual machine '" . $_->name . "'
> under host".
> " $hostname reset successfully ");
> };
> if ($@) {
> if (ref($@) eq 'SoapFault') {
> Util::trace (0, "\nError in '" . $_->name .
> "' under host $hostname: ");
> if (ref($...@->detail) eq 'InvalidState') {
> Util::trace(0,"Host is in maintenance
> mode");
>
> } elsif (ref($...@->detail) eq
> 'InvalidPowerState') {
> Util::trace(0, "The attempted
> operation".
> " cannot be performed
> in the current state" );
>
> } elsif (ref($...@->detail) eq
> 'NotSupported') {
> Util::trace(0,"Virtual machine is
> marked as a template ");
>
> } else {
> Util::trace(0, "VM '" .$_->name. "'
> can't be reset \n" . $@ . "");
> }
>
> } else {
> Util::trace(0, "VM '" .$_->name. "' can't be
> reset \n" . $@ . "");
> }
> Util::disconnect();
> exit 1;
> }
> }
> }
>
> if ($ARGV[0] eq 'gethosts') {
> &connect;
> $vm_views = VMUtils::get_vms ('VirtualMachine', $ENV{'vm'});
> foreach (@$vm_views) {
> print $_->{name} . "\n";
> }
> Util::disconnect();
>
> } elsif ($ARGV[0] eq 'on') {
> &connect;
> $vm_views = VMUtils::get_vms ('VirtualMachine', $ENV{'vm'});
> poweron_vm;
> Util::disconnect();
>
> } elsif ($ARGV[0] eq 'off') {
> &connect;
> $vm_views = VMUtils::get_vms ('VirtualMachine', $ENV{'vm'});
> poweroff_vm;
> Util::disconnect();
>
> } elsif ($ARGV[0] eq 'reset') {
> &connect;
> $vm_views = VMUtils::get_vms ('VirtualMachine', $ENV{'vm'});
> reset_vm;
> Util::disconnect();
>
> } elsif ($ARGV[0] eq 'status') {
> &connect;
> Util::disconnect();
>
> } elsif ($ARGV[0] eq 'getconfignames') {
> print <<EOF;
> vm
> VI_SERVER
> VI_USERNAME
> VI_PASSWORD
> EOF
>
> } elsif ($ARGV[0] eq 'getinfo-devid') {
> print "vSphere STONITH device\n";
>
> } elsif ($ARGV[0] eq 'getinfo-devname') {
> print "vSphere STONITH external device\n";
>
> } elsif ($ARGV[0] eq 'getinfo-devdescr') {
> print "vSphere-based host reset\n";
>
> } elsif ($ARGV[0] eq 'getinfo-devurl') {
> print "http://www.vmware.com/support/developer/viperltoolkit/\n"
>
> } elsif ($ARGV[0] eq 'getinfo-xml') {
> print <<IPMIXML
> <parameters>
> <parameter name="vm" unique="1">
> <content type="string" />
> <shortdesc lang="en">
> vm to reset
> </shortdesc>
> <longdesc lang="en">
> The name of the host to be managed by this STONITH device
> </longdesc>
> </parameter>
>
> <parameter name="VI_SERVER" unique="1">
> <content type="string" />
> <shortdesc lang="en">
> IP Address
> </shortdesc>
> <longdesc lang="en">
> The IP address of the ESX server or vSphere Center
> </longdesc>
> </parameter>
>
> <parameter name="VI_USERNAME" unique="1">
> <content type="string" />
> <shortdesc lang="en">
> Login
> </shortdesc>
> <longdesc lang="en">
> The username used for logging in to the ESX server or vSphere Center
> </longdesc>
> </parameter>
>
> <parameter name="VI_PASSWORD" unique="1">
> <content type="string" />
> <shortdesc lang="en">
> Password
> </shortdesc>
> <longdesc lang="en">
> The password used for logging in to the ESX server or vSphere Center
> </longdesc>
> </parameter>
> </parameters>
> IPMIXML
>
> } else {
> exit 1
> }
> _______________________________________________
> Linux-HA mailing list
> [email protected]
> http://lists.linux-ha.org/mailman/listinfo/linux-ha
> See also: http://linux-ha.org/ReportingProblems
_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems