Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2013-01-16 Thread Nhan Ngo Dinh

  
  
Hi Phuc,

Are you using the latest vcenter script?

Download it from
http://hg.linux-ha.org/glue/archive/glue-1.0.9.tar.bz2

And get the vcenter plugin in lib/plugins/stonith/external

Nhan

On 01/13/2013 05:35 PM, Phuc Hoang Ngo
  wrote:


  
  
  
  
Dear Nhan NGO,

Thanks to your guideline at http://lists.community.tummy.com/pipermail/linux-ha-dev/2011-April/018404.html,
  I could do some tests with the STONITH plugin on a VMware
  ESX/ESXi that is hosting 2 nodes. But I had to modify some
  following environment variables to make it runs:

export PERL_LWP_SSL_VERIFY_HOSTNAME=0
export
  PERL_NET_HTTPS_SSL_SOCKET_CLASS="Net::SSL"
unset https_proxy

However, the vcenter command always asks me
  to input username and password although I think that the
  credentials should be stored and reused from the file
  vicredentials.xml when I finished the steps (2) and (3) in the
  guideline without exceptions.

Moreover, I also cannot test with the
  stonith command (stonith -t external/vcenter . -iS) because
  it is hang too long and when I pressed the Ctrl-C, I saw the
  error message said the username or password is not valid.

Could you please tell me that it is still
  OK if I configure the CRM as like as the step (6) in your
  guideline?

PS: Ive just tested on the VMware cluster
  inside our intranet network, using IPs with cluster nodes.
Best
  regards,
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  PHUC NGO
  ICT/BA#1
Department
Global CyberSoft (Vietnam) JSC
  Helios
Building, Quang Trung Software City
Tan Chanh Hiep, District 12th, HCMC, Vietnam
Phone: +84-8-5437-1199 (ext 315)
Email: 
  phu...@gcs-vn.com
  Website:

  https://www.globalcybersoft.com
  
  _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

  


-- 
Nhan
  

___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2013-01-16 Thread Phuc Hoang Ngo
Hi Nhan,

Sorry that I didn't mention it in my last mail. I already used this version in 
my testing last time.
I used the following commands and configurations when I installed glue-1.0.9,

wget http://hg.linux-ha.org/glue/archive/glue-1.0.9.tar.bz2
tar -xvjf glue-1.0.9.tar.bz2
cd glue-1.0.9
./autogen.sh
./configure  --localstatedir=/var
make  make install

And I also got the stonith runs with the command: stonith -t external/vcenter -n
Could you please help me to find out the missing?

Best regards,
Phuc Ngo

From: Nhan Ngo Dinh [mailto:nngod...@tiscali.it]
Sent: Monday, January 14, 2013 3:22 PM
To: Phuc Hoang Ngo
Cc: linux-ha-dev@lists.linux-ha.org
Subject: Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

Hi Phuc,

Are you using the latest vcenter script?

Download it from
http://hg.linux-ha.org/glue/archive/glue-1.0.9.tar.bz2

And get the vcenter plugin in lib/plugins/stonith/external

Nhan
On 01/13/2013 05:35 PM, Phuc Hoang Ngo wrote:
Dear Nhan NGO,

Thanks to your guideline at 
http://lists.community.tummy.com/pipermail/linux-ha-dev/2011-April/018404.html, 
I could do some tests with the STONITH plugin on a VMware ESX/ESXi that is 
hosting 2 nodes. But I had to modify some following environment variables to 
make it runs:

export PERL_LWP_SSL_VERIFY_HOSTNAME=0
export PERL_NET_HTTPS_SSL_SOCKET_CLASS=Net::SSLNet::SSL
unset https_proxy

However, the vcenter command always asks me to input username and password 
although I think that the credentials should be stored and reused from the file 
vicredentials.xml when I finished the steps (2) and (3) in the guideline 
without exceptions.

Moreover, I also cannot test with the stonith command (stonith -t 
external/vcenter  -iS) because it is hang too long and when I pressed the 
Ctrl-C, I saw the error message said the username or password is not valid.

Could you please tell me that it is still OK if I configure the CRM as like as 
the step (6) in your guideline?

PS: I've just tested on the VMware cluster inside our intranet network, using 
IPs with cluster nodes.
Best regards,
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
PHUC NGO
ICT/BA#1 Department
Global CyberSoft (Vietnam) JSC
Helios Building, Quang Trung Software City
Tan Chanh Hiep, District 12th, HCMC, Vietnam
Phone: +84-8-5437-1199 (ext 315)
Email: phu...@gcs-vn.commailto:phu...@cybersoft-vn.com
Website: https://www.globalcybersoft.comhttps://www.cybersoft-vn.com/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/




--

Nhan
___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2013-01-16 Thread Nhan Ngo Dinh

  
  
There is something that is not working properly. Here is the output
from my reference configuration:

stonith -t external/vcenter VI_SERVER=10.1.1.1
VI_CREDSTORE="/etc/vicredentials.xml" HOSTLIST="hostname1;hostname2"
RESETPOWERON="0" -S
** INFO: Cannot get parameter VI_PORTNUMBER from StonithNVpair
** INFO: Cannot get parameter VI_PROTOCOL from StonithNVpair
** INFO: Cannot get parameter VI_SERVICEPATH from StonithNVpair
stonith: external/vcenter device OK.

And there is no password prompt: everything is taken from
vicredentials.xml.
Did you try to use vicredentials.xml with VMware tools to see if
authentication is working properly?

Nhan

On 01/14/2013 09:40 AM, Phuc Hoang Ngo
  wrote:


  
  
  
  
Hi Nhan,

Sorry that I
didnt mention it in my last mail. I already used this
version in my testing last time.
I used the
following commands and configurations when I installed
glue-1.0.9,


wget
http://hg.linux-ha.org/glue/archive/glue-1.0.9.tar.bz2
tar -xvjf
glue-1.0.9.tar.bz2
cd glue-1.0.9
./autogen.sh
./configure
--localstatedir=/var
make 
make install

And I also got
the stonith runs with the command: stonith -t
external/vcenter -n
Could you
please help me to find out the missing?


  Best regards,
  Phuc Ngo



  
From:
Nhan Ngo Dinh [mailto:nngod...@tiscali.it]

Sent: Monday, January 14, 2013 3:22 PM
To: Phuc Hoang Ngo
Cc: linux-ha-dev@lists.linux-ha.org
            Subject: Re: [Linux-ha-dev] STONITH plugin for
VMware vCenter
  


Hi Phuc,
  
  Are you using the latest vcenter script?
  
  Download it from
  http://hg.linux-ha.org/glue/archive/glue-1.0.9.tar.bz2
  
  And get the vcenter plugin in lib/plugins/stonith/external
  
  Nhan

  On 01/13/2013 05:35 PM, Phuc Hoang Ngo
wrote:


  Dear Nhan NGO,
  
  Thanks to your guideline at http://lists.community.tummy.com/pipermail/linux-ha-dev/2011-April/018404.html,
I could do some tests with the STONITH plugin on a VMware
ESX/ESXi that is hosting 2 nodes. But I had to modify some
following environment variables to make it runs:
  
  export PERL_LWP_SSL_VERIFY_HOSTNAME=0
  export PERL_NET_HTTPS_SSL_SOCKET_CLASS="Net::SSL"
  unset https_proxy
  
  However, the vcenter command always asks
me to input username and password although I think that the
credentials should be stored and reused from the file
vicredentials.xml when I finished the steps (2) and (3) in
the guideline without exceptions.
  
  Moreover, I also cannot test with the
stonith command (stonith -t external/vcenter . -iS) because
it is hang too long and when I pressed the Ctrl-C, I saw the
error message said the username or password is not valid.
  
  Could you please tell me that it is still
OK if I configure the CRM as like as the step (6) in your
guideline?
  
  PS: Ive just tested on the VMware
cluster inside our intranet network, using IPs with cluster
nodes.
  Best
regards,
  _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
PHUC NGO
ICT/BA#1
  Department
  Global CyberSoft (Vietnam) JSC
Helios
  Building, Quang Trung Software City
  Tan Chanh Hiep, District 12th, HCMC, Vietnam
  Phone: +84-8-5437-1199 (ext 315)
  Email: 
phu...@gcs-vn.com
  Website: 
https://www.globalcybersoft.com

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  




-- 
Nhan
  


-- 
Nhan
  

___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2013-01-16 Thread Phuc Hoang Ngo
Hi Nhan,

Thank you very much for your create support.
I successfully executed the stonith command without reentering password anymore.
I followed some instructions from internet to upgrade the libwww-perl to 
version 5.837 and unset the https_proxy. Then everything works fine as your 
instructions.

Best regards,
Phuc Ngo

From: Nhan Ngo Dinh [mailto:nngod...@tiscali.it]
Sent: Tuesday, January 15, 2013 3:21 PM
To: Phuc Hoang Ngo
Cc: linux-ha-dev@lists.linux-ha.org
Subject: Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

There is something that is not working properly. Here is the output from my 
reference configuration:

stonith -t external/vcenter VI_SERVER=10.1.1.1 
VI_CREDSTORE=/etc/vicredentials.xml HOSTLIST=hostname1;hostname2 
RESETPOWERON=0 -S
** INFO: Cannot get parameter VI_PORTNUMBER from StonithNVpair
** INFO: Cannot get parameter VI_PROTOCOL from StonithNVpair
** INFO: Cannot get parameter VI_SERVICEPATH from StonithNVpair
stonith: external/vcenter device OK.

And there is no password prompt: everything is taken from vicredentials.xml.
Did you try to use vicredentials.xml with VMware tools to see if authentication 
is working properly?

Nhan
On 01/14/2013 09:40 AM, Phuc Hoang Ngo wrote:
Hi Nhan,

Sorry that I didn't mention it in my last mail. I already used this version in 
my testing last time.
I used the following commands and configurations when I installed glue-1.0.9,

wget http://hg.linux-ha.org/glue/archive/glue-1.0.9.tar.bz2
tar -xvjf glue-1.0.9.tar.bz2
cd glue-1.0.9
./autogen.sh
./configure  --localstatedir=/var
make  make install

And I also got the stonith runs with the command: stonith -t external/vcenter -n
Could you please help me to find out the missing?

Best regards,
Phuc Ngo

From: Nhan Ngo Dinh [mailto:nngod...@tiscali.it]
Sent: Monday, January 14, 2013 3:22 PM
To: Phuc Hoang Ngo
Cc: linux-ha-dev@lists.linux-ha.orgmailto:linux-ha-dev@lists.linux-ha.org
Subject: Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

Hi Phuc,

Are you using the latest vcenter script?

Download it from
http://hg.linux-ha.org/glue/archive/glue-1.0.9.tar.bz2

And get the vcenter plugin in lib/plugins/stonith/external

Nhan
On 01/13/2013 05:35 PM, Phuc Hoang Ngo wrote:
Dear Nhan NGO,

Thanks to your guideline at 
http://lists.community.tummy.com/pipermail/linux-ha-dev/2011-April/018404.html, 
I could do some tests with the STONITH plugin on a VMware ESX/ESXi that is 
hosting 2 nodes. But I had to modify some following environment variables to 
make it runs:

export PERL_LWP_SSL_VERIFY_HOSTNAME=0
export PERL_NET_HTTPS_SSL_SOCKET_CLASS=Net::SSLNet::SSL
unset https_proxy

However, the vcenter command always asks me to input username and password 
although I think that the credentials should be stored and reused from the file 
vicredentials.xml when I finished the steps (2) and (3) in the guideline 
without exceptions.

Moreover, I also cannot test with the stonith command (stonith -t 
external/vcenter  -iS) because it is hang too long and when I pressed the 
Ctrl-C, I saw the error message said the username or password is not valid.

Could you please tell me that it is still OK if I configure the CRM as like as 
the step (6) in your guideline?

PS: I've just tested on the VMware cluster inside our intranet network, using 
IPs with cluster nodes.
Best regards,
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
PHUC NGO
ICT/BA#1 Department
Global CyberSoft (Vietnam) JSC
Helios Building, Quang Trung Software City
Tan Chanh Hiep, District 12th, HCMC, Vietnam
Phone: +84-8-5437-1199 (ext 315)
Email: phu...@gcs-vn.commailto:phu...@cybersoft-vn.com
Website: https://www.globalcybersoft.comhttps://www.cybersoft-vn.com/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/





--

Nhan



--

Nhan
___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2011-04-27 Thread Nhan Ngo Dinh
Hi,

I just moved the use function  in the network commands block.
Best regards,
Nhan

On Tue, 2011-04-26 at 18:22 +0200, Dejan Muhamedagic wrote: 
 Hi,
 
 On Thu, Apr 21, 2011 at 11:08:08AM +0200, Nhan Ngo Dinh wrote:
  Hi,
  
  On Tue, 2011-04-19 at 14:21 +0200, Dejan Muhamedagic wrote:
longdesc lang=en
The VMware vCenter address (default: localhost)
   
   The defaults should go into the content element (see other
   stonith plugins, e.g. external/ipmi).
  
  These defaults come from the vSphere Perl SDK, they are not handled
  inside this code. Does it make any difference? Anyway I've changed as
  you said.
  
Enable/disable a PowerOnVM on reset when the target virtual machine is 
off
Allowed values: 0, 1
   
   This should default to 1. For better or worse, that's what
   stonith prescribes and other plugins adhere to.
  
  Ok. I've also added an error if RESETPOWERON is set and machine is
  powered off.
 
 OK.
 
   Is this the only error which can happen? If not, then no error
   will be logged in that case. Ditto for another occurence below.
  
  This is what happens according to SDK, however I've added also a generic
  error handling procedure to die() if anything other fails.
 
 Good. One (probably) never knows future.
 
 I'll push the plugin now to the public repository.
 
 We just need one more thing to fix. The info commands such as
 getinfo-xml have to work without software which would otherwise
 be required for the plugin's operation, in this case it's the
 VMware::VIRuntime module. I guess that you need to use the eval
 command.
 
 Many thanks for the contribution. Not least for the
 documentation!
 
 Cheers,
 
 Dejan
 
  Best regards,
  Nhan
  
  
 
 
  ___
  Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
  http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
  Home Page: http://linux-ha.org/
 
 ___
 Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
 http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
 Home Page: http://linux-ha.org/
 



vcenter
Description: Perl program
___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2011-04-27 Thread Dejan Muhamedagic
Hi,

On Wed, Apr 27, 2011 at 09:01:24AM +0200, Nhan Ngo Dinh wrote:
 Hi,
 
 I just moved the use function  in the network commands block.

Thanks. Please update from the repository in future and provide
patches instead.

Cheers,

Dejan

 Best regards,
 Nhan
 
 On Tue, 2011-04-26 at 18:22 +0200, Dejan Muhamedagic wrote: 
  Hi,
  
  On Thu, Apr 21, 2011 at 11:08:08AM +0200, Nhan Ngo Dinh wrote:
   Hi,
   
   On Tue, 2011-04-19 at 14:21 +0200, Dejan Muhamedagic wrote:
 longdesc lang=en
 The VMware vCenter address (default: localhost)

The defaults should go into the content element (see other
stonith plugins, e.g. external/ipmi).
   
   These defaults come from the vSphere Perl SDK, they are not handled
   inside this code. Does it make any difference? Anyway I've changed as
   you said.
   
 Enable/disable a PowerOnVM on reset when the target virtual machine 
 is off
 Allowed values: 0, 1

This should default to 1. For better or worse, that's what
stonith prescribes and other plugins adhere to.
   
   Ok. I've also added an error if RESETPOWERON is set and machine is
   powered off.
  
  OK.
  
Is this the only error which can happen? If not, then no error
will be logged in that case. Ditto for another occurence below.
   
   This is what happens according to SDK, however I've added also a generic
   error handling procedure to die() if anything other fails.
  
  Good. One (probably) never knows future.
  
  I'll push the plugin now to the public repository.
  
  We just need one more thing to fix. The info commands such as
  getinfo-xml have to work without software which would otherwise
  be required for the plugin's operation, in this case it's the
  VMware::VIRuntime module. I guess that you need to use the eval
  command.
  
  Many thanks for the contribution. Not least for the
  documentation!
  
  Cheers,
  
  Dejan
  
   Best regards,
   Nhan
   
   
  
  
   ___
   Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
   http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
   Home Page: http://linux-ha.org/
  
  ___
  Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
  http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
  Home Page: http://linux-ha.org/
  
 


 ___
 Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
 http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
 Home Page: http://linux-ha.org/

___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2011-04-26 Thread Dejan Muhamedagic
Hi,

On Thu, Apr 21, 2011 at 11:08:08AM +0200, Nhan Ngo Dinh wrote:
 Hi,
 
 On Tue, 2011-04-19 at 14:21 +0200, Dejan Muhamedagic wrote:
   longdesc lang=en
   The VMware vCenter address (default: localhost)
  
  The defaults should go into the content element (see other
  stonith plugins, e.g. external/ipmi).
 
 These defaults come from the vSphere Perl SDK, they are not handled
 inside this code. Does it make any difference? Anyway I've changed as
 you said.
 
   Enable/disable a PowerOnVM on reset when the target virtual machine is off
   Allowed values: 0, 1
  
  This should default to 1. For better or worse, that's what
  stonith prescribes and other plugins adhere to.
 
 Ok. I've also added an error if RESETPOWERON is set and machine is
 powered off.

OK.

  Is this the only error which can happen? If not, then no error
  will be logged in that case. Ditto for another occurence below.
 
 This is what happens according to SDK, however I've added also a generic
 error handling procedure to die() if anything other fails.

Good. One (probably) never knows future.

I'll push the plugin now to the public repository.

We just need one more thing to fix. The info commands such as
getinfo-xml have to work without software which would otherwise
be required for the plugin's operation, in this case it's the
VMware::VIRuntime module. I guess that you need to use the eval
command.

Many thanks for the contribution. Not least for the
documentation!

Cheers,

Dejan

 Best regards,
 Nhan
 
 


 ___
 Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
 http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
 Home Page: http://linux-ha.org/

___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2011-04-21 Thread Nhan Ngo Dinh
Hi,

On Tue, 2011-04-19 at 14:21 +0200, Dejan Muhamedagic wrote:
  longdesc lang=en
  The VMware vCenter address (default: localhost)
 
 The defaults should go into the content element (see other
 stonith plugins, e.g. external/ipmi).

These defaults come from the vSphere Perl SDK, they are not handled
inside this code. Does it make any difference? Anyway I've changed as
you said.

  Enable/disable a PowerOnVM on reset when the target virtual machine is off
  Allowed values: 0, 1
 
 This should default to 1. For better or worse, that's what
 stonith prescribes and other plugins adhere to.

Ok. I've also added an error if RESETPOWERON is set and machine is
powered off.

 Is this the only error which can happen? If not, then no error
 will be logged in that case. Ditto for another occurence below.

This is what happens according to SDK, however I've added also a generic
error handling procedure to die() if anything other fails.

Best regards,
Nhan




vcenter
Description: Perl program
___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2011-04-20 Thread Lars Ellenberg
On Tue, Apr 19, 2011 at 02:21:38PM +0200, Dejan Muhamedagic wrote:
 Hi,
 
 On Fri, Apr 08, 2011 at 11:38:23AM +0200, Nhan Ngo Dinh wrote:
  Logging added
 
 Many thanks. Please see below for a few more comments, mainly
 about the meta-data.
 
 Lars, any more comments on from you?

No time right now.

I'd say take it and let users complain about whatever they find.

Lars
___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2011-04-19 Thread Dejan Muhamedagic
Hi,

On Fri, Apr 08, 2011 at 11:38:23AM +0200, Nhan Ngo Dinh wrote:
 Logging added

Many thanks. Please see below for a few more comments, mainly
about the meta-data.

Lars, any more comments on from you?

Cheers,

Dejan

 Regards,
 Nhan

 #!/usr/bin/perl
 #
 # External STONITH module for VMWare vCenter/ESX
 #
 # Author:  Nhan Ngo Dinh
 # License: GNU General Public License (GPL)
 #
 
 require 5.010;
 
 use strict;
 use warnings;
 use VMware::VIRuntime;
 
 sub dielog {
   my $msg = [;
   $msg .= $ARGV[0] if defined($ARGV[0]);
   $msg .=  $ARGV[1] if defined($ARGV[1]);
   $msg .= ];
   ( $_ ) = @_;
   $msg .=  $_;
   system(ha_log.sh, err, $msg);
   die();
 }
 
 # Define command groups
 my @configCommands = qw{getconfignames getinfo-devid getinfo-devname 
 getinfo-devdescr getinfo-devurl getinfo-xml};
 my @actionCommands = qw{reset on off};
 my @netCommands = (@actionCommands, qw{status gethosts});
 
 # Process command line arguments
 my $command = $ARGV[0] || dielog(No command specified\n);
 
 # Command belongs to the group of commands that do not require any connection 
 to VMware vCenter
 if ($command ~~ @configCommands) {
   if ($command eq getconfignames) {
   print 
 VI_SERVER\nVI_PORTNUMBER\nVI_PROTOCOL\nVI_SERVICEPATH\nVI_CREDSTORE\nHOSTLIST\nRESETPOWERON\n;
   }
   elsif ($command eq getinfo-devid) {
   print VMware vCenter STONITH device\n;
   }
   elsif ($command eq getinfo-devname) {
   print VMware vCenter STONITH device\n;
   }
   elsif ($command eq getinfo-devdescr) {
   print VMWare vCenter STONITH device\n;
   }
   elsif ($command eq getinfo-devurl) {
   print http://www.vmware.com/\n;;
   }
   elsif ($command eq getinfo-xml) {
   print q{parameters
 parameter name=HOSTLIST required=1
 content type=string/
 shortdesc lang=enList of hosts and virtual machines (required)/shortdesc
 longdesc lang=en
 The list of hosts that the VMware vCenter STONITH device controls.
 Syntax is:
   hostname1[=VirtualMachineName1];hostname2[=VirtualMachineName2]
 
 NOTE: omit =VirtualMachineName if hostname and virtual machine names are 
 identical
 
 Example:
   cluster1=VMCL1;cluster2=VMCL2
 /longdesc
 /parameter
 parameter name=VI_SERVER
 content type=string/
 shortdesc lang=enVMware vCenter address/shortdesc
 longdesc lang=en
 The VMware vCenter address (default: localhost)

The defaults should go into the content element (see other
stonith plugins, e.g. external/ipmi).

 /longdesc
 /parameter
 parameter name=VI_PROTOCOL
 content type=string/
 shortdesc lang=enVMware vCenter protocol/shortdesc
 longdesc lang=en
 The VMware vCenter protocol (default: https)
 /longdesc
 /parameter
 parameter name=VI_PORTNUMBER
 content type=string/
 shortdesc lang=enVMware vCenter port number/shortdesc
 longdesc lang=en
 The VMware vCenter port number (default: 443)
 /longdesc
 /parameter
 parameter name=VI_SERVICEPATH
 content type=string/
 shortdesc lang=enVMware vCenter service path/shortdesc
 longdesc lang=en
 The VMware vCenter services path (default: /sdk)
 /longdesc
 /parameter
 parameter name=VI_CREDSTORE required=1
 content type=string/
 shortdesc lang=enVMware vCenter credentials store file/shortdesc
 longdesc lang=en
 VMware vCenter credentials store file
 /longdesc
 /parameter
 parameter name=RESETPOWERON
 content type=string/
 shortdesc lang=enPowerOnVM on reset/shortdesc
 longdesc lang=en
 Enable/disable a PowerOnVM on reset when the target virtual machine is off
 Allowed values: 0, 1

This should default to 1. For better or worse, that's what
stonith prescribes and other plugins adhere to.

 /longdesc
 /parameter
 /parameters} . \n;
   }
   else { dielog(Invalid command specified: $command\n); }
 }
 
 # Command belongs to the group of commands that require connecting to VMware 
 vCenter
 elsif ($command ~~ @netCommands) {
 
   # A valid VI_CREDSTORE is required to avoid interactive prompt
   ( exists $ENV{'VI_CREDSTORE'} ) || dielog(VI_CREDSTORE not 
 specified\n);
 
   # HOSTLIST is mandatory
   exists $ENV{'HOSTLIST'} || dielog(HOSTLIST not specified\n);
 
   # Parse HOSTLIST to %host_to_vm and %vm_to_host
   my @hostlist = split(';', $ENV{'HOSTLIST'});
   my %host_to_vm = ();
   my %vm_to_host = ();
   foreach my $host (@hostlist) {
   my @config = split(/=/, $host);
   my $key = $config[0]; my $value = $config[1];
   if (!defined($value)) { $value = $config[0]; }
   $host_to_vm{$key} = $value;
   $vm_to_host{(lc $value)} = $key;
   }
 
   eval {
   # VI API: reads options from the environment variables into 
 appropriate data structures for validation.
   Opts::parse();
   # VI API: ensures that input values from environment variable 
 are complete, consistent and valid.
   Opts::validate();
  

Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2011-04-08 Thread Nhan Ngo Dinh
Logging added
Regards,
Nhan



vcenter
Description: Perl program
___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2011-04-07 Thread Nhan Ngo Dinh
To help people testing it, here is what to do in each cluster node.
You can test it with ESX/ESXi or vCenter: it should work in both cases.

1) install VMware vSphere CLI, which includes Perl SDK and
administrative tools for generating the credentials XML file:
http://www.vmware.com/download/download.do?downloadGroup=VCLI41 ,

2) put vcenter script attached previously
in /usr/lib/stonith/plugins/external/ or wherever the external stonith
plugins are.

3) create the credentials file with credstore_admin.pl:

/usr/lib/vmware-vcli/apps/general/credstore_admin.pl -s 10.1.1.1 -u
myuser -p mypass

This should create $HOME/.vmware/credstore/vicredentials.xml . I suggest
to copy it at least to /etc

cp -p $HOME/.vmware/credstore/vicredentials.xml /etc

4) do the very first testing:

VI_SERVER=10.1.1.1 VI_CREDSTORE=/etc/vicredentials.xml
HOSTLIST=hostname1=vmname1;hostname2=vmname2
RESETPOWERON=0 /usr/lib/stonith/plugins/external/vcenter gethosts

If everything works correctly you should get:

hostname1
hostname2

You can even test reset, off and on commands, to test (carefully!)
the full chain. E.g.

VI_SERVER=10.1.1.1 VI_CREDSTORE=/etc/vicredentials.xml
HOSTLIST=hostname1=vmname1;hostname2=vmname2
RESETPOWERON=0 /usr/lib/stonith/plugins/external/vcenter reset hostname2

5) test if stonith can see the script:

stonith -t external/vcenter -n

6) configure crm. In a 2-node configuration, with no previous stonith
entry and with stonith-enabled set to false:

crm configure primitive vfencing stonith::external/vcenter params
VI_SERVER=10.1.1.1 VI_CREDSTORE=/etc/vicredentials.xml
HOSTLIST=hostname1=vmname1;hostname2=vmname2 RESETPOWERON=0 op
monitor interval=60s

crm configure clone Fencing vfencing

crm configure property stonith-enabled=true

===
I've tested it with VMware vCenter 4.1, the cluster is a 2-node cluster
based on Debian 6.0 Squeeze with distribution clustering stack:
CoroSync 1.2.1 / Pacemaker 1.0.9.1 . Cluster nodes are on different ESXi
4.1 servers.

Nhan


___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2011-04-07 Thread Dejan Muhamedagic
Hi,

On Thu, Apr 07, 2011 at 10:36:11AM +0200, Nhan Ngo Dinh wrote:
 To help people testing it, here is what to do in each cluster node.
 You can test it with ESX/ESXi or vCenter: it should work in both cases.
 
 1) install VMware vSphere CLI, which includes Perl SDK and
 administrative tools for generating the credentials XML file:
 http://www.vmware.com/download/download.do?downloadGroup=VCLI41 ,
 
 2) put vcenter script attached previously
 in /usr/lib/stonith/plugins/external/ or wherever the external stonith
 plugins are.
 
 3) create the credentials file with credstore_admin.pl:
 
 /usr/lib/vmware-vcli/apps/general/credstore_admin.pl -s 10.1.1.1 -u
 myuser -p mypass
 
 This should create $HOME/.vmware/credstore/vicredentials.xml . I suggest
 to copy it at least to /etc
 
 cp -p $HOME/.vmware/credstore/vicredentials.xml /etc
 
 4) do the very first testing:
 
 VI_SERVER=10.1.1.1 VI_CREDSTORE=/etc/vicredentials.xml
 HOSTLIST=hostname1=vmname1;hostname2=vmname2
 RESETPOWERON=0 /usr/lib/stonith/plugins/external/vcenter gethosts
 
 If everything works correctly you should get:
 
 hostname1
 hostname2
 
 You can even test reset, off and on commands, to test (carefully!)
 the full chain. E.g.
 
 VI_SERVER=10.1.1.1 VI_CREDSTORE=/etc/vicredentials.xml
 HOSTLIST=hostname1=vmname1;hostname2=vmname2
 RESETPOWERON=0 /usr/lib/stonith/plugins/external/vcenter reset hostname2
 
 5) test if stonith can see the script:
 
 stonith -t external/vcenter -n
 
 6) configure crm. In a 2-node configuration, with no previous stonith
 entry and with stonith-enabled set to false:
 
 crm configure primitive vfencing stonith::external/vcenter params
 VI_SERVER=10.1.1.1 VI_CREDSTORE=/etc/vicredentials.xml
 HOSTLIST=hostname1=vmname1;hostname2=vmname2 RESETPOWERON=0 op
 monitor interval=60s
 
 crm configure clone Fencing vfencing
 
 crm configure property stonith-enabled=true
 
 ===
 I've tested it with VMware vCenter 4.1, the cluster is a 2-node cluster
 based on Debian 6.0 Squeeze with distribution clustering stack:
 CoroSync 1.2.1 / Pacemaker 1.0.9.1 . Cluster nodes are on different ESXi
 4.1 servers.

You could actually reformat this slightly and we add that as
README.vcenter to the repository.

Cheers,

Dejan

 Nhan
 
 

 ___
 Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
 http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
 Home Page: http://linux-ha.org/

___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2011-04-07 Thread Dejan Muhamedagic
Hi,

On Thu, Apr 07, 2011 at 01:54:59PM +0200, Nhan Ngo Dinh wrote:
 Hi,
 
 please find it attached.

Great!

A few notes below.

 Best regards,
 Nhan
 
 VMware vCenter/ESX STONITH Module
 =
 
 1. Intro
 
 
 VMware vCenter/ESX STONITH Module is intended to provide STONITH support to
 clusters in VMware Virtual Infrastructures. It is able to deal with virtual
 machines running on physically different HostSystems (e.g. ESX/ESXi) by using
 VMware vSphere Web Services SDK 
 http://www.vmware.com/support/developer/vc-sdk/
 and connecting directly on each HostSystem or through a VMware vCenter: in 
 this
 last case the module locates the specified virtual machine in the Virtual
 Infrastructure and performs actions required by cluster policies.
 
 2. Software requirements
 
 
 VMware vSphere CLI, which includes both CLI tools and Perl SDK
 http://www.vmware.com/support/developer/vcli/ . The plugin has been tested 
 with
 version 4.1  http://www.vmware.com/download/download.do?downloadGroup=VCLI41
 
 
 3. vCenter/ESX authentication settings
 --
 
 Create the credentials file with credstore_admin.pl:
 
 /usr/lib/vmware-vcli/apps/general/credstore_admin.pl \
   -s 10.1.1.1 -u myuser -p mypass
 
 This should create $HOME/.vmware/credstore/vicredentials.xml
 Copy it to a system folder, e.g. /etc
 
 cp -p $HOME/.vmware/credstore/vicredentials.xml /etc
 
 
 4. Testing
 --
 
 The plugin can be invoked directly to perform a very first connection test
 (replace all the provided sample values):
 
 VI_SERVER=10.1.1.1 \
   VI_CREDSTORE=/etc/vicredentials.xml \
   HOSTLIST=hostname1=vmname1;hostname2=vmname2 \
   RESETPOWERON=0 \
   /usr/lib/stonith/plugins/external/vcenter gethosts

This is not the right way to test manually. Best to use
stonith(8):

stonith -t external/vcenter VI_SERVER=10.1.1.1 \
   VI_CREDSTORE=/etc/vicredentials.xml \
   HOSTLIST=hostname1=vmname1;hostname2=vmname2 \
   RESETPOWERON=0 -lS

or

# export VI_SERVER=10.1.1.1 \
   VI_CREDSTORE=/etc/vicredentials.xml \
   HOSTLIST=hostname1=vmname1;hostname2=vmname2 \
   RESETPOWERON=0
# stonith -t external/vcenter -E -lS

Another thing, there's an external program ha_log.sh, guaranteed
to be in the path, which can be used for logging. Though I can't
recall seeing any logging in the plugin, perhaps you should do
some. If you use stonith(8) it will print log messages to
stdout/stderr.

 If everything works correctly you should get:
 
 hostname1
 hostname2
 
 When invoked in this way, the plugin connects to VI_SERVER, authenticates with
 credentials stored in VI_CREDSTORE and tries to retrieve the list of virtual
 machines (case insensitive) matching vmname1 and vmname2 (and any other 
 listed).
 When finished, it reports the list back by mapping virtual machine names to
 hostnames as provided in HOSTLIST. If you see the full list of hostnames as a
 result, then everything is going well. If otherwise you are having a partial 
 or
 empty list, you have to check parameters.
 
 You can even test reset, off and on commands, to test (carefully!) the
 full chain. E.g.
 
 VI_SERVER=10.1.1.1 \
   VI_CREDSTORE=/etc/vicredentials.xml \
   HOSTLIST=hostname1=vmname1;hostname2=vmname2 \
   RESETPOWERON=0 \
   /usr/lib/stonith/plugins/external/vcenter reset hostname2

Ditto, use stonith ... -T reset/on/off node

 In the above examples the referring infrastructure is a vCenter with several
 ESXi nodes. Server IP and credentials are referred to vCenter.
 
 5. CRM configuration
 
 
 The following is a sample procedure to setup STONITH for an HA 2-node cluster
 (replace all the provided sample values):
 
 crm configure primitive vfencing stonith::external/vcenter params \
   VI_SERVER=10.1.1.1 VI_CREDSTORE=/etc/vicredentials.xml \
   HOSTLIST=hostname1=vmname1;hostname2=vmname2 RESETPOWERON=0 \
   op monitor interval=60s
 
 crm configure clone Fencing vfencing
 
 crm configure property stonith-enabled=true

BTW, didn't notice this earlier, could you make parameters lower
case. All or at least most other stonith plugins use lower case
parameter names.

Cheers,

Dejan

 ___
 Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
 http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
 Home Page: http://linux-ha.org/

___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2011-04-07 Thread Nhan Ngo Dinh
Hi,

On Thu, 2011-04-07 at 15:35 +0200, Dejan Muhamedagic wrote:
  4. Testing
  --
  
  The plugin can be invoked directly to perform a very first connection test
  (replace all the provided sample values):
  
  VI_SERVER=10.1.1.1 \
VI_CREDSTORE=/etc/vicredentials.xml \
HOSTLIST=hostname1=vmname1;hostname2=vmname2 \
RESETPOWERON=0 \
/usr/lib/stonith/plugins/external/vcenter gethosts
 
 This is not the right way to test manually. Best to use
 stonith(8):
 
 stonith -t external/vcenter VI_SERVER=10.1.1.1 \
VI_CREDSTORE=/etc/vicredentials.xml \
HOSTLIST=hostname1=vmname1;hostname2=vmname2 \
RESETPOWERON=0 -lS
 
 or
 
 # export VI_SERVER=10.1.1.1 \
VI_CREDSTORE=/etc/vicredentials.xml \
HOSTLIST=hostname1=vmname1;hostname2=vmname2 \
RESETPOWERON=0
 # stonith -t external/vcenter -E -lS

This is definitely better, I'll update README (see attached).

 In external program ha_log.sh, guaranteed
 to be in the path, which can be used for logging. Though I can't
 recall seeing any logging in the plugin, perhaps you should do
 some. If you use stonith(8) it will print log messages to
 stdout/stderr.

I saw that any stonith stdout/stderr is logged as well, perhaps this is
because of my corosync settings... I'll take a look to this.

  VI_SERVER=10.1.1.1 \
VI_CREDSTORE=/etc/vicredentials.xml \
HOSTLIST=hostname1=vmname1;hostname2=vmname2 \
RESETPOWERON=0 \
/usr/lib/stonith/plugins/external/vcenter reset hostname2
 
 Ditto, use stonith ... -T reset/on/off node

Updated as well.

 BTW, didn't notice this earlier, could you make parameters lower
 case. All or at least most other stonith plugins use lower case
 parameter names.

I've used some of the vSphere Perl SDK environment variables as
pass-through (as also Lars suggested), that's the reason of using
uppercase parameter names. HOSTLIST and RESETPOWERON are uppercase too
essentially to be similar to VI_* tokens. I can put them lowercase but I
think that mixing cases can be confusing somehow. On the other hand I
can map vi_* to VI_*, but it sounds to me a little bit tricky especially
because I would like to leave the possibility to include more parameters
than the ones listed as far as they'll become available in the vSphere
Perl SDK (may be there are some others right now): I feel that a case
converter may be annoying...

Nhan

VMware vCenter/ESX STONITH Module
=

1. Intro


VMware vCenter/ESX STONITH Module is intended to provide STONITH support to
clusters in VMware Virtual Infrastructures. It is able to deal with virtual
machines running on physically different HostSystems (e.g. ESX/ESXi) by using
VMware vSphere Web Services SDK http://www.vmware.com/support/developer/vc-sdk/
and connecting directly on each HostSystem or through a VMware vCenter: in this
last case the module locates the specified virtual machine in the Virtual
Infrastructure and performs actions required by cluster policies.

2. Software requirements


VMware vSphere CLI, which includes both CLI tools and Perl SDK
http://www.vmware.com/support/developer/vcli/ . The plugin has been tested with
version 4.1  http://www.vmware.com/download/download.do?downloadGroup=VCLI41


3. vCenter/ESX authentication settings
--

Create the credentials file with credstore_admin.pl:

/usr/lib/vmware-vcli/apps/general/credstore_admin.pl \
  -s 10.1.1.1 -u myuser -p mypass

This should create $HOME/.vmware/credstore/vicredentials.xml
Copy it to a system folder, e.g. /etc

cp -p $HOME/.vmware/credstore/vicredentials.xml /etc


4. Testing
--

You can use stonith to test the plugin directly before configuring crm (replace
all the provided sample values):

stonith -t external/vcenter VI_SERVER=10.1.1.1 \
   VI_CREDSTORE=/etc/vicredentials.xml \
   HOSTLIST=hostname1=vmname1;hostname2=vmname2 \
   RESETPOWERON=0 -lS

If everything works correctly you should get:

stonith: external/vcenter device OK.
hostname1
hostname2

When invoked in this way, the plugin connects to VI_SERVER, authenticates with
credentials stored in VI_CREDSTORE and tries to retrieve the list of virtual
machines (case insensitive) matching vmname1 and vmname2 (and any other listed).
When finished, it reports the list back by mapping virtual machine names to
hostnames as provided in HOSTLIST. If you see the full list of hostnames as a
result, then everything is going well. If otherwise you are having a partial or
empty list, you have to check parameters.

You can even test reset, off and on commands, to test (carefully!) the
full chain. E.g.

stonith -t external/vcenter VI_SERVER=10.1.1.1 \
   VI_CREDSTORE=/etc/vicredentials.xml \
   HOSTLIST=hostname1=vmname1;hostname2=vmname2 \
   RESETPOWERON=0 -T reset hostname2

In the above examples the referring infrastructure is a vCenter with several
ESXi nodes. Server IP and credentials are referred to vCenter.

5. CRM configuration

Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2011-04-06 Thread Lars Ellenberg
On Tue, Apr 05, 2011 at 06:27:19PM +0200, Nhan Ngo Dinh wrote:
 VMware perl library allows to use a .vimrc file in the user home,

Ouch.

I guess they all use emacs, then.
Or notepad ;-)

-- 
: Lars Ellenberg
: LINBIT | Your Way to High Availability
: DRBD/HA support and consulting http://www.linbit.com
___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2011-04-06 Thread Nhan Ngo Dinh
Sorry, I was confusing :)
.visdkrc

In the attached external/vcenter I've hopefully merged all the hints.
Dejan, I've also considered your notes.

Just few comments:

1) you proposed:

my $regex = join | map { qr/\Q$_\E/ } values %$hosts; 
my $vms = Vim::find_entity_views(view_type = VirtualMachine, filter
= { name = qr/^($regex)$/i });

But I didn't succeed to make it working, instead I had to replace it
with:

my $regex = join | map { qr/\Q$_\E/i } values %$hosts; 
my $vms = Vim::find_entity_views(view_type = VirtualMachine, filter
= { name = qr/^($regex)$/ });

Is it right?

2) I've performed an lc on the keys of the virtual machine hash and on
whatever needed to make it working with VMware case insensitive virtual
machine matching

3) I've used VMware credstore to allow improve security by using
VI_CREDSTORE parameter.

4) I've managed runtime.powerState to prevent from doing anything when a
cluster node is suspended

5) I've added RESETPOWERON to control whether or not sending a PowerOnVM
when the node is found off on reset. This is also needed because,
differently from what specified on the docs, ResetVM on a closed virtual
machine gives out an exception. However, may be that cluster admins
would like to have the opportunity to shut down nodes and to prevent crm
from making them on again (of course they can rename VMs, but... you
know).

6) To make everyone happier, I did not change to given/when :)

I've tested it again i a 2-node cluster, crm stonith configuration is:

===
primitive vfencing stonith:external/vcenter \
params VI_SERVER=10.1.1.1 VI_CREDSTORE=/etc/vicredentials.xml
HOSTLIST=vm1;vm2 RESETPOWERON=1 \
op monitor interval=60s
clone Fencing vfencing
===

Best regards,

On Wed, 2011-04-06 at 16:41 +0200, Lars Ellenberg wrote: 

 On Tue, Apr 05, 2011 at 06:27:19PM +0200, Nhan Ngo Dinh wrote:
  VMware perl library allows to use a .vimrc file in the user home,
 
 Ouch.
 
 I guess they all use emacs, then.
 Or notepad ;-)
 




vcenter
Description: Perl program
___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2011-04-05 Thread Dejan Muhamedagic
Hi,

On Mon, Apr 04, 2011 at 09:23:17PM +0200, Lars Ellenberg wrote:
 On Sun, Apr 03, 2011 at 10:15:50AM +0200, Nhan Ngo Dinh wrote:
  Hello all,
  
  Please find the attached plugin.
  
  It requires vSphere SDK for Perl:
  http://www.vmware.com/support/developer/viperltoolkit/
  
  Parameters:
  
  hostlist (e.g. hostname1=VMNAME;hostname2=VMNAME2), ip (vCenter IP),
  username, password
  
  Tested with 4.1
 
 I don't know too much about vCenter, I'll assume that the interactions
 with it are correct, whatever that means.
 
 But I know my share of perl and pacemaker.
 So here are a few comments.
 
 
  #!/usr/bin/perl
  #
  # External STONITH module for VMWare vCenter
  #
  # Author:  Nhan Ngo Dinh
  # License:  GNU General Public License (GPL)
  #
  
  use strict;
  use warnings;
  use Switch;
 
 I don't like that Switch.pm thingy ;-)
 But never mind...
 
  use VMware::VIRuntime;
  
  my $command = $ARGV[0];
  my $targetHost;
  if ( defined $ARGV[1] ) {
  $targetHost = $ARGV[1];
  }
 
 This end result of this is still the same as just writing
   my $targetHost = $ARGV[1];
  
 
  if (defined($ENV{'ip'})) {
 
 If you mean to test for existence of hash elements, please always use
 exists. The above will create an empty but from now on exported 'ip'
 variable into to environment.
 You likely want to say
 
 if (exists $ENV{ip}) {
 
 (and yes, you can give it more line noise,
 if you feel more comfortable that way)
 
 If you actually want to say if defined,
 then you could also just do away with the if,
 and assign directly.
 
$ENV{'VI_PORTNUMBER'} = 443;
$ENV{'VI_PROTOCOL'} = https;
$ENV{'VI_SERVER'} = $ENV{'ip'};
 
 
 Why would you only override VI_PORTNUMBER and VI_PROTOCOL
 if the ip is defined?
 
 Why would you want to have your own ip environment,
 and not expose VI_SERVER directly?
 
 
  }
  
  if (defined($ENV{'username'})) {
$ENV{'VI_USERNAME'} = $ENV{'username'};
$ENV{'VI_PASSWORD'} = $ENV{'password'};
Opts::parse();
Opts::validate();
  } else {
Opts::parse();
 
 No validate here? Why not?
 
  }
 
 I suppose the Opts::validate() is supposed to throw an error (aka die()),
 if there is insufficient information to contact the management entity?
 If so, please document that.
 
 Probably you want to catch that via eval {},
 and log the error message with some context information
 about where it comes from, before propagating the error.
 
  
  my $ret = 255;
  my $hosts = {};
  my $realTarget;
  
  if ( defined $ENV{'hostlist'} ) {
  my @lines;
  my $line;
  @lines = split(/;/, $ENV{'hostlist'});
  foreach $line (@lines) {
  my @config = split(/=/, $line);
  $hosts-{$config[0]} = $config[1];
  }
  if (defined $targetHost) { $realTarget = $hosts-{$targetHost}; }
  }
 
 Please add a comment what this is supposed to do, and why.
 Not what it does, that's clear ;-)
 
 Also: clearly document that no whitespace is allowed, nowhere,
 and hostname=VMNAME; is a hard requirement, even if hostname and VMNAME
 should match.
 Or change the code to allow that special case to be written as just
 hostname; in the hostlist.
 
 Since you later do the reverse mapping in nested loops,
 how about constructing both forward and backward mapping hashes here?
 %host_to_vm = ();
 %vm_to_host = ();
 ...
 
  sub getvms {
  Util::connect();
  my $regex = ;
  for (keys %$hosts) {
  if (length($regex)  0) { $regex .= |; }
  $regex .= $hosts-{$_};
  }
  my $vms = Vim::find_entity_views(view_type = VirtualMachine, 
  filter = { 'name' = qr/^($regex)/ });
 
 I'm not sure if you really mean what you wrote there.
 
 My guess would be that you actually meant to say
 my $regex = join | map { qr/\Q$_\E/ } values %$hosts;
 my $vms = Vim::find_entity_views(view_type = VirtualMachine, filter = { 
 'name' = qr/^($regex)$/i });
 
 What's the difference?
 So it is written differently.
 So what. You can also write that as a for (keys ...) {} no problem.
 
 Then, it does a case insensitive match (I'm not sure, but I assume
 VMNAME is supposed to be matched case insensitive?)
 
 It does not omit the trailing $,
 so VMNAM would not match both VMNAM and VMNAME ;-)
 
 Most importantly, it \Q-ot-\E-s the VMNAMEs, so VM.NA.ME won't match
 VMxNAyME, but only VM.NA.ME.
 
  Util::disconnect();
  return $vms;
  }
  
  switch ($command) {
  case reset {
 
 Bah. Did I mention that I dislike switch statements in Perl?
 Ah, never you mind ;)
 
  Util::connect();
  my $vm = Vim::find_entity_view(view_type = VirtualMachine, 
  filter = { name = $realTarget });
 
 Unless this filter thing has a special mode where it internally does a
 $x eq $y for scalars and $x =~ $y for explicitly designated qr//
 Regexp objects, I'd suggest to here also do
   filter = { name = qr/^\Q$realTarget\E$/i }
 
  my $hostname = Vim::get_view(mo_ref = 
  $vm-{runtime}-{host})-name;
 
 What is the 

Re: [Linux-ha-dev] STONITH plugin for VMware vCenter

2011-04-04 Thread Lars Ellenberg
On Sun, Apr 03, 2011 at 10:15:50AM +0200, Nhan Ngo Dinh wrote:
 Hello all,
 
 Please find the attached plugin.
 
 It requires vSphere SDK for Perl:
 http://www.vmware.com/support/developer/viperltoolkit/
 
 Parameters:
 
 hostlist (e.g. hostname1=VMNAME;hostname2=VMNAME2), ip (vCenter IP),
 username, password
 
 Tested with 4.1

I don't know too much about vCenter, I'll assume that the interactions
with it are correct, whatever that means.

But I know my share of perl and pacemaker.
So here are a few comments.


 #!/usr/bin/perl
 #
 # External STONITH module for VMWare vCenter
 #
 # Author:  Nhan Ngo Dinh
 # License:  GNU General Public License (GPL)
 #
 
 use strict;
 use warnings;
 use Switch;

I don't like that Switch.pm thingy ;-)
But never mind...

 use VMware::VIRuntime;
 
 my $command = $ARGV[0];
 my $targetHost;
 if ( defined $ARGV[1] ) {
 $targetHost = $ARGV[1];
 }

This end result of this is still the same as just writing
  my $targetHost = $ARGV[1];
 

 if (defined($ENV{'ip'})) {

If you mean to test for existence of hash elements, please always use
exists. The above will create an empty but from now on exported 'ip'
variable into to environment.
You likely want to say

if (exists $ENV{ip}) {

(and yes, you can give it more line noise,
if you feel more comfortable that way)

If you actually want to say if defined,
then you could also just do away with the if,
and assign directly.

   $ENV{'VI_PORTNUMBER'} = 443;
   $ENV{'VI_PROTOCOL'} = https;
   $ENV{'VI_SERVER'} = $ENV{'ip'};


Why would you only override VI_PORTNUMBER and VI_PROTOCOL
if the ip is defined?

Why would you want to have your own ip environment,
and not expose VI_SERVER directly?


 }
 
 if (defined($ENV{'username'})) {
   $ENV{'VI_USERNAME'} = $ENV{'username'};
   $ENV{'VI_PASSWORD'} = $ENV{'password'};
   Opts::parse();
   Opts::validate();
 } else {
   Opts::parse();

No validate here? Why not?

 }

I suppose the Opts::validate() is supposed to throw an error (aka die()),
if there is insufficient information to contact the management entity?
If so, please document that.

Probably you want to catch that via eval {},
and log the error message with some context information
about where it comes from, before propagating the error.

 
 my $ret = 255;
 my $hosts = {};
 my $realTarget;
 
 if ( defined $ENV{'hostlist'} ) {
   my @lines;
   my $line;
   @lines = split(/;/, $ENV{'hostlist'});
 foreach $line (@lines) {
 my @config = split(/=/, $line);
 $hosts-{$config[0]} = $config[1];
 }
   if (defined $targetHost) { $realTarget = $hosts-{$targetHost}; }
 }

Please add a comment what this is supposed to do, and why.
Not what it does, that's clear ;-)

Also: clearly document that no whitespace is allowed, nowhere,
and hostname=VMNAME; is a hard requirement, even if hostname and VMNAME
should match.
Or change the code to allow that special case to be written as just
hostname; in the hostlist.

Since you later do the reverse mapping in nested loops,
how about constructing both forward and backward mapping hashes here?
%host_to_vm = ();
%vm_to_host = ();
...

 sub getvms {
   Util::connect();
   my $regex = ;
   for (keys %$hosts) {
   if (length($regex)  0) { $regex .= |; }
   $regex .= $hosts-{$_};
   }
 my $vms = Vim::find_entity_views(view_type = VirtualMachine, 
 filter = { 'name' = qr/^($regex)/ });

I'm not sure if you really mean what you wrote there.

My guess would be that you actually meant to say
my $regex = join | map { qr/\Q$_\E/ } values %$hosts;
my $vms = Vim::find_entity_views(view_type = VirtualMachine, filter = { 
'name' = qr/^($regex)$/i });

What's the difference?
So it is written differently.
So what. You can also write that as a for (keys ...) {} no problem.

Then, it does a case insensitive match (I'm not sure, but I assume
VMNAME is supposed to be matched case insensitive?)

It does not omit the trailing $,
so VMNAM would not match both VMNAM and VMNAME ;-)

Most importantly, it \Q-ot-\E-s the VMNAMEs, so VM.NA.ME won't match
VMxNAyME, but only VM.NA.ME.

   Util::disconnect();
   return $vms;
 }
 
 switch ($command) {
   case reset {

Bah. Did I mention that I dislike switch statements in Perl?
Ah, never you mind ;)

   Util::connect();
   my $vm = Vim::find_entity_view(view_type = VirtualMachine, 
 filter = { name = $realTarget });

Unless this filter thing has a special mode where it internally does a
$x eq $y for scalars and $x =~ $y for explicitly designated qr//
Regexp objects, I'd suggest to here also do
filter = { name = qr/^\Q$realTarget\E$/i }

   my $hostname = Vim::get_view(mo_ref = 
 $vm-{runtime}-{host})-name;

What is the hostname used for, now?

   $vm-ResetVM();

Hm. Apparently the filter thingy did something different,
the return value seems to be a reference to some manageable VM object,
previously it was supposed to be a