This is the mail archive of the cluster-cvs@sourceware.org mailing list for the cluster.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

fence-agents: master - fence_vmware: Improve speed for statusoperation => whole fencing


Gitweb:        http://git.fedorahosted.org/git/fence-agents.git?p=fence-agents.git;a=commitdiff;h=1ab3e3473e5538d6c410332b62b796c7544f1e03
Commit:        1ab3e3473e5538d6c410332b62b796c7544f1e03
Parent:        181b7acbd71a11c15598af653365cc54988290e4
Author:        Jan Friesse <jfriesse@redhat.com>
AuthorDate:    Thu Jan 15 15:38:37 2009 +0100
Committer:     Jan Friesse <jfriesse@redhat.com>
CommitterDate: Thu Jan 15 15:38:37 2009 +0100

fence_vmware: Improve speed for status operation => whole fencing

Before this patch, agent used for implementation of get status
list operation. This is nice in code, but because list operation
on ESX with many (200+) registered VMs takes very long (21+ sec),
whole fencing (3x21+off/on) can take even longer.

Some minor remove of residuum from old vmware_vi, in helper is
removed too.
---
 fence/agents/vmware/fence_vmware.py        |   74 +++++++++++++++++-----------
 fence/agents/vmware/fence_vmware_helper.pl |   33 ++++++++-----
 2 files changed, 65 insertions(+), 42 deletions(-)

diff --git a/fence/agents/vmware/fence_vmware.py b/fence/agents/vmware/fence_vmware.py
index 1d98317..f30cbfe 100644
--- a/fence/agents/vmware/fence_vmware.py
+++ b/fence/agents/vmware/fence_vmware.py
@@ -136,53 +136,69 @@ def vmware_run_command(options,add_login_params,additional_params,additional_tim
 
 	return res_output
 
-def get_outlets_status(conn, options):
+# Get outlet list with status as hash table. If you will use add_vm_name, only VM with vmname is
+# returned. This is used in get_status function
+def vmware_get_outlets_vi(conn, options, add_vm_name):
 	outlets={}
 
-	if (vmware_internal_type==VMWARE_TYPE_ESX):
-		all_machines=vmware_run_command(options,True,"--operation list",0)
+	if (add_vm_name):
+		all_machines=vmware_run_command(options,True,("--operation status --vmname '%s'"%(options["-n"])),0)
+	else:
+		all_machines=vmware_run_command(options,True,"--operation list",POWER_TIMEOUT)
 
-		all_machines_array=all_machines.splitlines()
+	all_machines_array=all_machines.splitlines()
 
-		for machine in all_machines_array:
-			machine_array=dsv_split(machine)
-			if (len(machine_array)==4):
-				if (machine_array[0] in outlets):
-					fail_usage("Failed. More machines with same name %s found!"%(machine_array[0]))
+	for machine in all_machines_array:
+		machine_array=dsv_split(machine)
+		if (len(machine_array)==4):
+			if (machine_array[0] in outlets):
+				fail_usage("Failed. More machines with same name %s found!"%(machine_array[0]))
 
-				if (vmware_disconnected_hack):
-					outlets[machine_array[0]]=("",(
-							((machine_array[2].lower() in ["poweredon"]) and
-							 (machine_array[3].lower()=="connected"))
-							and "on" or "off"))
-				else:
-					outlets[machine_array[0]]=("",((machine_array[2].lower() in ["poweredon"]) and "on" or "off"))
+			if (vmware_disconnected_hack):
+				outlets[machine_array[0]]=("",(
+						((machine_array[2].lower() in ["poweredon"]) and
+						 (machine_array[3].lower()=="connected"))
+						and "on" or "off"))
+			else:
+				outlets[machine_array[0]]=("",((machine_array[2].lower() in ["poweredon"]) and "on" or "off"))
+	return outlets
 
-	if ((vmware_internal_type==VMWARE_TYPE_SERVER1) or (vmware_internal_type==VMWARE_TYPE_SERVER2)):
-		running_machines=vmware_run_command(options,True,"list",0)
-		running_machines_array=running_machines.splitlines()[1:]
+# Get outlet list with status as hash table.
+def vmware_get_outlets_vix(conn,options):
+	outlets={}
 
-		if (vmware_internal_type==VMWARE_TYPE_SERVER2):
-			all_machines=vmware_run_command(options,True,"listRegisteredVM",0)
-			all_machines_array=all_machines.splitlines()[1:]
-		elif (vmware_internal_type==VMWARE_TYPE_SERVER1):
-			all_machines_array=running_machines_array
+	running_machines=vmware_run_command(options,True,"list",0)
+	running_machines_array=running_machines.splitlines()[1:]
 
-		for machine in all_machines_array:
-			if (machine!=""):
-				outlets[machine]=("",((machine in running_machines_array) and "on" or "off"))
+	if (vmware_internal_type==VMWARE_TYPE_SERVER2):
+		all_machines=vmware_run_command(options,True,"listRegisteredVM",0)
+		all_machines_array=all_machines.splitlines()[1:]
+	elif (vmware_internal_type==VMWARE_TYPE_SERVER1):
+		all_machines_array=running_machines_array
+
+	for machine in all_machines_array:
+		if (machine!=""):
+			outlets[machine]=("",((machine in running_machines_array) and "on" or "off"))
 
 	return outlets
 
+def get_outlets_status(conn, options):
+	if (vmware_internal_type==VMWARE_TYPE_ESX):
+		return vmware_get_outlets_vi(conn,options,False)
+	if ((vmware_internal_type==VMWARE_TYPE_SERVER1) or (vmware_internal_type==VMWARE_TYPE_SERVER2)):
+		return vmware_get_outlets_vix(conn,options)
+
 def get_power_status(conn,options):
-	outlets=get_outlets_status(conn,options)
+	if (vmware_internal_type==VMWARE_TYPE_ESX):
+		outlets=vmware_get_outlets_vi(conn,options,True)
+	else:
+		outlets=get_outlets_status(conn,options,False)
 
 	if ((vmware_internal_type==VMWARE_TYPE_SERVER2) or (vmware_internal_type==VMWARE_TYPE_ESX)):
 		if (not (options["-n"] in outlets)):
 			fail_usage("Failed: You have to enter existing name of virtual machine!")
 		else:
 			return outlets[options["-n"]][1]
-
 	elif (vmware_internal_type==VMWARE_TYPE_SERVER1):
 		return ((options["-n"] in outlets) and "on" or "off")
 
diff --git a/fence/agents/vmware/fence_vmware_helper.pl b/fence/agents/vmware/fence_vmware_helper.pl
index eb18630..e60805e 100644
--- a/fence/agents/vmware/fence_vmware_helper.pl
+++ b/fence/agents/vmware/fence_vmware_helper.pl
@@ -40,7 +40,8 @@ sub convert_field_to_dsv {
 my %opts = (
    'operation' => {
       type => "=s",
-      help => "The operation to perform (on,off,list). Operations on/off require name of the virtual machine",
+      help => "The operation to perform (on,off,list,status). "
+             . "Operations on/off/status require name of the virtual machine",
       default => "list",
       required => 0,
    },
@@ -73,15 +74,15 @@ Opts::add_options(%opts);
 Opts::parse();
 Opts::validate();
 
-if (!(Opts::get_option('operation')=~/^(on|off|list)$/i)) {
-  show_error "Operation should be on, off or list!\n";
+if (!(Opts::get_option('operation')=~/^(on|off|list|status)$/i)) {
+  show_error "Operation should be on, off, list or status!\n";
   exit 2;
 }
 
 my $operation=lc(Opts::get_option('operation'));
 
 if (($operation ne 'list') && (!defined Opts::get_option('vmname'))) {
-  show_error "Operation on, off require vmname parameter!\n";
+  show_error "Operation on, off, status require vmname parameter!\n";
   exit 2;
 }
 
@@ -125,7 +126,7 @@ my $found=0;
 
 # Traverse all found vm
 foreach $vm(@$vm_views) {
-  if ($operation eq 'list') {
+  if (($operation eq 'list') or ($operation eq 'status')) {
     if (!$vm->summary->config->template) {
       print convert_field_to_dsv($vm->name).":".
             convert_field_to_dsv($vm->summary->config->vmPathName).":".
@@ -169,12 +170,12 @@ __END__
 
 =head1 NAME
 
-fence_vmware_vi_helper - Perform list of virtual machines and
+fence_vmware_helper - Perform list of virtual machines and
                poweron, poweroff  of operations on virtual machines.
 
 =head1 SYNOPSIS
 
- fence_vmware_vi_helper --operation <on|off|list> [options]
+ fence_vmware_helper --operation <on|off|list|status> [options]
 
 =head1 DESCRIPTION
 
@@ -195,6 +196,7 @@ Operation to be performed.  One of the following:
   <on> (power on one or more virtual machines),
   <off> (power off one  or more virtual machines),
   <list> (list virtual machines and their status)
+  <status> (same as list, but show only machines with vmname)
 
 =item B<vmname>
 
@@ -212,27 +214,32 @@ Operations will be performed on all the virtual machines under the given datacen
 
 Power on a virtual machine
 
-   fence_vmware_vi_helper --username administrator --password administrator --operation on
+   fence_vmware_helper --username administrator --password administrator --operation on
                 --vmname rhel --server win1
 
-   fence_vmware_vi_helper --username administrator --password administrator --operation on
+   fence_vmware_helper --username administrator --password administrator --operation on
                 --vmname rhel --server win1 --datacenter Datacenter
 
 Power off a virtual machine
 
-   fence_vmware_vi_helper --username administrator --password administrator --operation off
+   fence_vmware_helper --username administrator --password administrator --operation off
                 --vmname rhel --server win1
 
-   perl fence_vmware_vi_helper --username administrator --password administrator --operation off
+   perl fence_vmware_helper --username administrator --password administrator --operation off
                 --vmname rhel --server win1 --datacenter Datacenter
 
 List of virtual machines
 
-   fence_vmware_vi_helper --username administrator --password administrator --server win1
+   fence_vmware_helper --username administrator --password administrator --server win1
 
-   fence_vmware_vi_helper --username administrator --password administrator --server win1
+   fence_vmware_helper --username administrator --password administrator --server win1
                 --operation list
 
+Get status of virtual machine
+
+   fence_vmware_helper --username administrator --password administrator --server win1
+	    --vmname rhel --operation status
+
 =head1 SUPPORTED PLATFORMS
 
 All operations supported on ESX 3.0.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]