Skip to contentSkip to conversation

some fence_virsh, fene_apc patches for RHEL6 backports

Cluster-devel Bogdan Dobrelya 2 participants 9 messages Dec 11, 2013 – Jan 6, 2014 2 messages not in the archive

lore
Share & tools
lore
#2 lore raw
In reply to a message not in the archive

Hello.
Description for suggested patches:

fence_virsh: I believe the uuid support is a good idea, cuz every spawned VM would have an UUID in its dmidecode, equal to its virsh domuuid. Thus, to fence it, we should not either know the domain name, nor query libvirt to find it out.

fence_apc: As I can see from my research activities, fence_apc is quite a vendor specific agent, thus it would require custom options for command-prompt as well as ssh-options.

Signature · 24 lines
Best regards,
Bogdan Dobrelya,
Researcher TechLead, Mirantis, Inc.
+38 (066) 051 07 53
Skype bogdando_at_yahoo.com
38, Lenina ave.
Kharkov, Ukraine
www.mirantis.com
www.mirantis.ru
bdobrelia at mirantis.com




-------------- next part --------------
From d95896825c89085b7d516547406454b7b21ffc17 Mon Sep 17 00:00:00 2001
From: Bogdan Dobrelya <[email protected]>
Date: Tue, 10 Dec 2013 14:32:26 +0200
Subject: [PATCH 1/2] Add uuid support for fence_virsh

Signed-off-by: Bogdan Dobrelya <[email protected]>
---
 fence/agents/virsh/fence_virsh.py |   89 +++++++++++++++++++++++++++++++++----
 1 file changed, 80 insertions(+), 9 deletions(-)
fence/agents/virsh/fence_virsh.py +80 -9
index 13099da..80242ab 100644
@@ -3,6 +3,7 @@
 # The Following Agent Has Been Tested On:
 #
 # Virsh 0.3.3 on RHEL 5.2 with xen-3.0.3-51
+# Virsh 0.9.13,0.10.2 on Ubuntu 12.10 with qemu-kvm-1.2.0
 #
 
 import sys, re, pexpect, exceptions
@@ -13,11 +14,15 @@ from fencing import *
 RELEASE_VERSION="Virsh fence agent"
 REDHAT_COPYRIGHT=""
 BUILD_DATE=""
+UUID_PATTERN=r"^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$"
+STATE_PATTERN=r"^(\b\w+)\s?(\b\w+)?$"
 #END_VERSION_GENERATION
 
 def get_outlets_status(conn, options):
-	try:
-		conn.sendline("virsh list --all")
+    if options.has_key("-n"):
+        try:
+                #Restrict virsh list by header and by matched domain name only (if any), assumes it would be unique
+		conn.sendline("virsh list --all|awk '/Name|%s/'"%(options["-n"]))
 		conn.log_expect(options, options["-c"], int(options["-Y"]))
 	except pexpect.EOF:
 		fail(EC_CONNECTION_LOST)
@@ -38,32 +43,98 @@ def get_outlets_status(conn, options):
 			elif (fa_status==1):
 				result[domain.group(2)]=("",(domain.group(3).lower() in ["running","blocked","idle","no state","paused"] and "on" or "off"))
 	return result
+    elif options.has_key("-U"):
+        return get_outlets_status_by_uuid(conn, options)
+    else: # other cases , f.e. action list
+        try:
+                conn.sendline("virsh list --all")
+                conn.log_expect(options, options["-c"], int(options["-Y"]))
+        except pexpect.EOF:
+                fail(EC_CONNECTION_LOST)
+        except pexpect.TIMEOUT:
+                fail(EC_TIMED_OUT)
+
+        result={}
+
+        #This is status of mini finite automata. 0 = we didn't found Id and Name, 1 = we did
+        fa_status=0
+
+        for line in conn.before.splitlines():
+                domain=re.search("^\s*(\S+)\s+(\S+)\s+(\S+).*$",line)
+                if (domain!=None):   
+                        if ((fa_status==0) and (domain.group(1).lower()=="id") and (domain.group(2).lower()=="name")):
+                                fa_status=1
+                        elif (fa_status==1):
+                                result[domain.group(2)]=("",(domain.group(3).lower() in ["running","blocked","idle","no state","paused"] and "on" or "off"))
+        return result
+
+#Do the same as get_outlets_status, but using -U <uuid> option
+def get_outlets_status_by_uuid(conn, options):
+        try:
+                #Restrict virsh list by matched domain uuid only (if any), assumes it would be unique
+                conn.sendline("virsh list --all --uuid|awk '/%s/'"%(options["-U"].lower()))
+                conn.log_expect(options, options["-c"], int(options["-Y"]))
+        except pexpect.EOF:
+                fail(EC_CONNECTION_LOST)
+        except pexpect.TIMEOUT:
+                fail(EC_TIMED_OUT)
+
+        result={}
+
+        for line in conn.before.splitlines():
+                uuid=re.search(UUID_PATTERN,line)
+                if (uuid!=None):
+                        result[uuid.group().lower()]=("",get_domstate(conn,options,uuid.group().lower()).lower() in ["running","blocked","idle","no state","paused"] and "on" or "off")
+        return result
+
+#Get virsh domstate by uuid
+def get_domstate(conn, options, uuid):
+        try:
+                conn.sendline("virsh domstate %s"%(uuid))
+                conn.log_expect(options, options["-c"], int(options["-Y"]))
+        except pexpect.EOF:
+                fail(EC_CONNECTION_LOST)
+        except pexpect.TIMEOUT:
+                fail(EC_TIMED_OUT)
+        
+        for line in conn.before.splitlines():
+                #Search for domain state
+                state=re.search(STATE_PATTERN,line)
+                if (state!=None):
+                            return state.group()
+
+#Return domain name/port, if -n was specified, otherwise assume -U was used instead and return domain uuid.
+def get_name_or_uuid(options):
+        if options.has_key("-n"):
+            return options["-n"]
+        else:
+            return options["-U"].lower()
 
 def get_power_status(conn, options):
 	outlets=get_outlets_status(conn,options)
-
-        if (not (options["-n"] in outlets)):
-                fail_usage("Failed: You have to enter existing name of virtual machine!")
+        if (not (get_name_or_uuid(options) in outlets)):
+                fail_usage("Failed: You have to enter existing name/uuid of virtual machine!")
         else:
-                return outlets[options["-n"]][1]
+                return outlets[get_name_or_uuid(options)][1]
 
 def set_power_status(conn, options):
 	try:
-		conn.sendline("virsh %s "%(options["-o"] == "on" and "start" or "destroy")+options["-n"])
+		conn.sendline("virsh %s "%(options["-o"] == "on" and "start" or "destroy")+get_name_or_uuid(options))
 
 		conn.log_expect(options, options["-c"], int(options["-g"]))
-                time.sleep(1)
+                time.sleep(int(options["-G"]))
 
 	except pexpect.EOF:
 		fail(EC_CONNECTION_LOST)
 	except pexpect.TIMEOUT:
 		fail(EC_TIMED_OUT)
 
+# Add uuid support
 def main():
 	device_opt = [  "help", "version", "agent", "quiet", "verbose", "debug",
 			"action", "ipaddr", "login", "passwd", "passwd_script",
 			"secure", "identity_file", "test", "port", "separator",
-			"inet4_only", "inet6_only", "ipport",
+			"inet4_only", "inet6_only", "ipport", "uuid",
 			"power_timeout", "shell_timeout", "login_timeout", "power_wait" ]
 
 	atexit.register(atexit_handler)
Signature · 25 lines
1.7.10.4



-------------- next part --------------
From 199b1374e0d6fcd70e0275ad6ecd0af2271293b3 Mon Sep 17 00:00:00 2001
From: Bogdan Dobrelya <[email protected]>
Date: Mon, 9 Dec 2013 19:16:56 +0200
Subject: [PATCH 2/2] Add command_prompt, ssh-options to fence_apc

Signed-off-by: Bogdan Dobrelya <[email protected]>

Conflicts:
	usr/sbin/fence_apc

Signed-off-by: Bogdan Dobrelya <[email protected]>

Conflicts:
	README.md

Signed-off-by: Bogdan Dobrelya <[email protected]>
---
 fence/agents/apc/fence_apc.py  |    7 ++++---
 fence/agents/lib/fencing.py.py |    7 +++++++
 2 files changed, 11 insertions(+), 3 deletions(-)
fence/agents/apc/fence_apc.py +4 -3
index 78e709f..cf56a65 100644
@@ -218,18 +218,19 @@ def main():
 	device_opt = [  "help", "version", "agent", "quiet", "verbose", "debug",
 			"action", "ipaddr", "login", "passwd", "passwd_script",
 			"secure", "port", "identity_file", "switch", "test", "separator",
-			"inet4_only", "inet6_only", "ipport", "cmd_prompt",
+			"inet4_only", "inet6_only", "ipport", "cmd_prompt", "ssh_options",
 			"power_timeout", "shell_timeout", "login_timeout", "power_wait" ]
 
 	atexit.register(atexit_handler)
 
-	all_opt["cmd_prompt"]["default"] = [ "\n>", "\napc>" ]
+        all_opt["cmd_prompt"]["default"] = [ "\n>", "\napc>" ]
+        all_opt["ssh_options"]["default"] = "-1 -c blowfish"
+
 	options = check_input(device_opt, process_input(device_opt))
 
 	## 
 	## Fence agent specific defaults
 	#####
-	options["ssh_options"] = "-1 -c blowfish"
 
 	docs = { }
 	docs["shortdesc"] = "Fence agent for APC over telnet/ssh"
fence/agents/lib/fencing.py.py +7 -0
index 1de9a15..a7f1548 100644
@@ -189,6 +189,13 @@ all_opt = {
 		"shortdesc" : "SSH connection",
 		"required" : "0",
 		"order" : 1 },
+        "ssh_options" : {
+                "getopt" : "X:",
+                "longopt" : "ssh-options",
+                "help" : "--ssh-options=[options]         SSH options to use",
+                "shortdesc" : "SSH options to use",
+                "required" : "0",
+                "order" : 1 },
 	"ssl" : {
 		"getopt" : "z",
 		"longopt" : "ssl",
Signature · 1 line
1.7.10.4
#3 lore raw
In reply to a message not in the archive

Hi,

Thanks for a patches,

Quoted 8 lines · Bogdan Dobrelya

Hello.
Description for suggested patches:

Quoted 5 lines

fence_virsh: I believe the uuid support is a good idea, cuz every spawned VM would have an UUID in its dmidecode, equal to its virsh domuuid. Thus, to fence it, we should not either know the domain name, nor query libvirt to find it out.

Based on your patch, I have sent a new patch to cluster-devel@ ; the main difference is that patch is based on current version (as there were several changes vs RHEL6). The other difference is that I have removed obtaining status of plug from list function because it can not work easily with UUID. Instead we call directly 'virsh domstate' ; on older systems there can be a problem with 'virsh --uuid --all' because '--uuid' is relatively new (yes, supported in RHEL6+) so I did not use this feature.

Quoted 3 lines
Quoted 3 lines

fence_apc: As I can see from my research activities, fence_apc is quite a vendor specific agent, thus it would require custom options for command-prompt as well as ssh-options.

--ssh-options are already available in upstream

m,

#4 lore raw
Quoted 22 lines · Marek Grac

Hi,

Thanks for a patches,

Quoted 8 lines · Bogdan Dobrelya

Hello.
Description for suggested patches:

Quoted 5 lines

fence_virsh: I believe the uuid support is a good idea, cuz every spawned VM would have an UUID in its dmidecode, equal to its virsh domuuid. Thus, to fence it, we should not either know the domain name, nor query libvirt to find it out.

Based on your patch, I have sent a new patch to cluster-devel@ ; the main difference is that patch is based on current version (as there were several changes vs RHEL6). The other difference is that I have removed obtaining status of plug from list function because it can not work easily with UUID. Instead we call directly 'virsh domstate' ; on older systems there can be a problem with 'virsh --uuid --all' because '--uuid' is relatively new (yes, supported in RHEL6+) so I did not use this feature.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

fence_apc: As I can see from my research activities, fence_apc is quite a vendor specific agent, thus it would require custom options for command-prompt as well as ssh-options.

--ssh-options are already available in upstream

m,

Hello.
Thank you for your support. I'd be glad to see it implemented in upstream. One more thing.

As far as I was testing my Tripplite PDU device with standard fence agents, I've tried to find any suitable agent for it (fence_apc, fence_apc_snmp) but didn't succeed. That's why I've played with cmd-prompt and ssh-options of fence_apc agent mentioned above.

But I've managed to succeed with customized fence_pdu_snmp (not with fence_pdu tho) agent I created from fence_apc_snmp with minimal changes (fixed OIDs and that is almost all).
I'd like to propose this fence_pdu_snmp agent as well (tested with PDUMH20HVNET 12.04.0055 (snmp v1,v2c,v3) device). See a patch in attachement, targeted for RHEL6 branch. I believe, it might be compatible with any switched PDU devices, if slightly modified.

Signature · 19 lines
Best regards,
Bogdan Dobrelya,
Researcher TechLead, Mirantis, Inc.
+38 (066) 051 07 53
Skype bogdando_at_yahoo.com
Irc #bogdando
38, Lenina ave.
Kharkov, Ukraine
www.mirantis.com
www.mirantis.ru
bdobrelia at mirantis.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-fence_pdu_snmp-agent-for-Tripplite-switched-PDUs.patch
Type: text/x-patch
Size: 7284 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/cluster-devel/attachments/20131216/594cc0b2/attachment.bin>
#8 lore raw
In reply to Marek Grac
Quoted 13 lines · Marek Grac

Hi,

Thanks for a patches,

Quoted 8 lines · Bogdan Dobrelya

Hello.
Description for suggested patches:

Quoted 5 lines

fence_virsh: I believe the uuid support is a good idea, cuz every spawned VM would have an UUID in its dmidecode, equal to its virsh domuuid. Thus, to fence it, we should not either know the domain name, nor query libvirt to find it out.

Quoted 8 lines

Based on your patch, I have sent a new patch to cluster-devel@ ; the main difference is that patch is based on current version (as there were several changes vs RHEL6). The other difference is that I have removed obtaining status of plug from list function because it can not work easily with UUID. Instead we call directly 'virsh domstate' ; on older systems there can be a problem with 'virsh --uuid --all' because '--uuid' is relatively new (yes, supported in RHEL6+) so I did not use this feature.

Hello. I believe, the device opt for "uuid" should be added as well (see patch in attachment). Correct me, If I'm wrong...

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

fence_apc: As I can see from my research activities, fence_apc is quite a vendor specific agent, thus it would require custom options for command-prompt as well as ssh-options.

--ssh-options are already available in upstream

m,

Signature · 19 lines
Best regards,
Bogdan Dobrelya,
Researcher TechLead, Mirantis, Inc.
+38 (066) 051 07 53
Skype bogdando_at_yahoo.com
Irc #bogdando
38, Lenina ave.
Kharkov, Ukraine
www.mirantis.com
www.mirantis.ru
bdobrelia at mirantis.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-missed-uuid-device-opt.patch
Type: text/x-patch
Size: 883 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/cluster-devel/attachments/20131218/3b56bb3f/attachment.bin>
#9 lore raw
Quoted 10 lines · Bogdan Dobrelya
Quoted 8 lines

Based on your patch, I have sent a new patch to cluster-devel@ ; the main difference is that patch is based on current version (as there were several changes vs RHEL6). The other difference is that I have removed obtaining status of plug from list function because it can not work easily with UUID. Instead we call directly 'virsh domstate' ; on older systems there can be a problem with 'virsh --uuid --all' because '--uuid' is relatively new (yes, supported in RHEL6+) so I did not use this feature.

Hello. I believe, the device opt for "uuid" should be added as well (see patch in attachment). Correct me, If I'm wrong...

Hi,

The 'uuid' is detected automatically (via standard python uuid library) so for user it enough to just enter it as --plug/-n. The options["--uuid"] is filled automatically in fencing library if uuid is detected. The same approach is used also in fence_vmware_soap.

I know that documentation is the weak point and if everything will go as planned, I should spend most of the January by writing first drafts.

m,

#5 lore raw

[Cluster-devel] Fence agent for Tripplite PDU

In reply to Bogdan Dobrelya
Quoted 6 lines · Bogdan Dobrelya

As far as I was testing my Tripplite PDU device with standard fence agents, I've tried to find any suitable agent for it (fence_apc, fence_apc_snmp) but didn't succeed. That's why I've played with cmd-prompt and ssh-options of fence_apc agent mentioned above.

Quoted 8 lines

But I've managed to succeed with customized fence_pdu_snmp (not with fence_pdu tho) agent I created from fence_apc_snmp with minimal changes (fixed OIDs and that is almost all).
I'd like to propose this fence_pdu_snmp agent as well (tested with PDUMH20HVNET 12.04.0055 (snmp v1,v2c,v3) device). See a patch in attachement, targeted for RHEL6 branch. I believe, it might be compatible with any switched PDU devices, if slightly modified.

If the only modification was done in OIDs, I will prefer to include it into fence_apc_snmp. We have already used a symlinks to run fence agents with different default options and I believe we can use same approach there as well (e.g. fence_ilo3 / fence_ipmilan). Can you take a look at current upstream version and test it there? Ideally check if it will work without additional switches or we should implement there a variable which will be set only for tripplite and not for apc.

m,

#10 lore raw
In reply to Marek Grac
Quoted 20 lines · Marek Grac
Quoted 10 lines · Bogdan Dobrelya
Quoted 8 lines

Based on your patch, I have sent a new patch to cluster-devel@ ; the main difference is that patch is based on current version (as there were several changes vs RHEL6). The other difference is that I have removed obtaining status of plug from list function because it can not work easily with UUID. Instead we call directly 'virsh domstate' ; on older systems there can be a problem with 'virsh --uuid --all' because '--uuid' is relatively new (yes, supported in RHEL6+) so I did not use this feature.

Hello. I believe, the device opt for "uuid" should be added as well (see patch in attachment). Correct me, If I'm wrong...

Hi,

The 'uuid' is detected automatically (via standard python uuid library) so for user it enough to just enter it as --plug/-n. The options["--uuid"] is filled automatically in fencing library if uuid is detected. The same approach is used also in fence_vmware_soap.

Quoted 4 lines

I know that documentation is the weak point and if everything will go as planned, I should spend most of the January by writing first drafts.

m,

Hello. I've attached your uuid patch from master, backported to RHEL6 branch as well. I've tested it manually, by connecting to my libvirt host using -U <uuid>, -n <name>, -o list options.
I hope we will see it for RHEL6 soon, uuid support is usefull feature.

Signature · 18 lines
Best regards,
Bogdan Dobrelya,
Researcher TechLead, Mirantis, Inc.
+38 (066) 051 07 53
Skype bogdando_at_yahoo.com
Irc #bogdando
38, Lenina ave.
Kharkov, Ukraine
www.mirantis.com
www.mirantis.ru
bdobrelia at mirantis.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-RHEL6-fence_virsh-Add-UUID-support-for-fence_virsh.patch
Type: text/x-patch
Size: 2708 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/cluster-devel/attachments/20131224/0f537e16/attachment.bin>
#6 lore raw

[Cluster-devel] Fence agent for Tripplite PDU

In reply to Marek Grac
Quoted 15 lines · Marek Grac
Quoted 6 lines · Bogdan Dobrelya

As far as I was testing my Tripplite PDU device with standard fence agents, I've tried to find any suitable agent for it (fence_apc, fence_apc_snmp) but didn't succeed. That's why I've played with cmd-prompt and ssh-options of fence_apc agent mentioned above.

Quoted 8 lines

But I've managed to succeed with customized fence_pdu_snmp (not with fence_pdu tho) agent I created from fence_apc_snmp with minimal changes (fixed OIDs and that is almost all).
I'd like to propose this fence_pdu_snmp agent as well (tested with PDUMH20HVNET 12.04.0055 (snmp v1,v2c,v3) device). See a patch in attachement, targeted for RHEL6 branch. I believe, it might be compatible with any switched PDU devices, if slightly modified.

Quoted 2 lines

If the only modification was done in OIDs, I will prefer to include it into fence_apc_snmp. We have already used a symlinks to run fence agents

Done. Here are 2 patches for master and RHEL6 branches for fence_apc_snmp agent, with added Tripplite PDU support.

Quoted 3 lines

with different default options and I believe we can use same approach there as well (e.g. fence_ilo3 / fence_ipmilan). Can you take a look at current upstream version and test it there? Ideally check if it will

I've tested the patch for RHEL6 branch with my Tripplite PDU. And as you could have noticed, there is no difference between the patch for RHEL6 and one for master branch, thus, you can assume tests is OK for master as well...

Quoted 4 lines

work without additional switches or we should implement there a variable which will be set only for tripplite and not for apc.

m,

As you can see from fence_apc_snmp's original README, it doesn't support ganged or 'daisy-chained' switches yet, thus nothing was changed here.

Signature · 25 lines
Best regards,
Bogdan Dobrelya,
Researcher TechLead, Mirantis, Inc.
+38 (066) 051 07 53
Skype bogdando_at_yahoo.com
Irc #bogdando
38, Lenina ave.
Kharkov, Ukraine
www.mirantis.com
www.mirantis.ru
bdobrelia at mirantis.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-MASTER-Add-Tripplite-PDU-support-to-fence_apc_snmp.patch
Type: text/x-patch
Size: 3044 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/cluster-devel/attachments/20131224/8f82e8e5/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-RHEL6-Add-Tripplite-PDU-support-to-fence_apc_snmp.patch
Type: text/x-patch
Size: 2807 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/cluster-devel/attachments/20131224/8f82e8e5/attachment-0001.bin>
#7 lore raw

[Cluster-devel] Fence agent for Tripplite PDU

Hi,

Quoted 5 lines · Bogdan Dobrelya
Quoted 2 lines

If the only modification was done in OIDs, I will prefer to include it into fence_apc_snmp. We have already used a symlinks to run fence agents

Done. Here are 2 patches for master and RHEL6 branches for fence_apc_snmp agent, with added Tripplite PDU support.

Quoted 8 lines
Quoted 3 lines

with different default options and I believe we can use same approach there as well (e.g. fence_ilo3 / fence_ipmilan). Can you take a look at current upstream version and test it there? Ideally check if it will

I've tested the patch for RHEL6 branch with my Tripplite PDU. And as you could have noticed, there is no difference between the patch for RHEL6 and one for master branch, thus, you can assume tests is OK for master as well...

Thanks for patch, I have no objection and patch is now included in the upstream.

m,