Blame SOURCES/bz1287059-2-fence_rhevm-add-filter-header.patch

e4ffb1
From 786f5e1d5af984a958dc5502a8d065a24cb66970 Mon Sep 17 00:00:00 2001
e4ffb1
From: Juan Hernandez <juan.hernandez@redhat.com>
e4ffb1
Date: Thu, 5 May 2016 11:50:03 +0200
e4ffb1
Subject: [PATCH] Explicitly use version 3 of the oVirt API
e4ffb1
e4ffb1
Version on 4 of the oVirt engine will support two versions of the API:
e4ffb1
version 3, which will be backwards compatible with older versions of the
e4ffb1
engine, and version 4, which won't be compatible. The default used by
e4ffb1
the server will be version 4, but clients can explicitly request a
e4ffb1
version of the API using the "Version" header or the "/v3" URL prefix.
e4ffb1
The header is the preferred mechanism because it is just ignored by
e4ffb1
older versions of the server. This patch modifies the oVirt fence agent
e4ffb1
so that the it will always send the "Version: 3" header, in order to
e4ffb1
work correctly with version 3 compatibility mode of the API.
e4ffb1
e4ffb1
Signed-off-by: Juan Hernandez <juan.hernandez@redhat.com>
e4ffb1
---
e4ffb1
 fence/agents/rhevm/fence_rhevm.py   | 34 +++++++++++++++++++++++++++++++---
e4ffb1
 tests/data/metadata/fence_rhevm.xml |  5 +++++
e4ffb1
 2 files changed, 36 insertions(+), 3 deletions(-)
e4ffb1
e4ffb1
diff --git a/fence/agents/rhevm/fence_rhevm.py b/fence/agents/rhevm/fence_rhevm.py
e4ffb1
index 3926f3b..46453c9 100644
e4ffb1
--- a/fence/agents/rhevm/fence_rhevm.py
e4ffb1
+++ b/fence/agents/rhevm/fence_rhevm.py
e4ffb1
@@ -81,14 +81,24 @@ def send_command(opt, command, method="GET"):
e4ffb1
 		url = "https:"
e4ffb1
 	else:
e4ffb1
 		url = "http:"
e4ffb1
+	if opt.has_key("--api-path"):
e4ffb1
+		api_path = opt["--api-path"]
e4ffb1
+	else:
e4ffb1
+		api_path = "/ovirt-engine/api"
e4ffb1
 
e4ffb1
-	url += "//" + opt["--ip"] + ":" + str(opt["--ipport"]) + "/api/" + command
e4ffb1
+	url += "//" + opt["--ip"] + ":" + str(opt["--ipport"]) + api_path + "/" + command
e4ffb1
 
e4ffb1
 	## send command through pycurl
e4ffb1
 	conn = pycurl.Curl()
e4ffb1
 	web_buffer = StringIO.StringIO()
e4ffb1
 	conn.setopt(pycurl.URL, url)
e4ffb1
-	conn.setopt(pycurl.HTTPHEADER, ["Content-type: application/xml", "Accept: application/xml", "Prefer: persistent-auth", "Filter: true"])
e4ffb1
+	conn.setopt(pycurl.HTTPHEADER, [
e4ffb1
+		"Version: 3",
e4ffb1
+		"Content-type: application/xml",
e4ffb1
+		"Accept: application/xml",
e4ffb1
+		"Prefer: persistent-auth",
e4ffb1
+		"Filter: true",
e4ffb1
+	])
e4ffb1
 
e4ffb1
 	if opt.has_key("cookie"):
e4ffb1
 		conn.setopt(pycurl.COOKIE, opt["cookie"])
e4ffb1
@@ -136,9 +146,27 @@ def define_new_opts():
e4ffb1
 		"required" : "0",
e4ffb1
 		"shortdesc" : "Reuse cookies for authentication",
e4ffb1
 		"order" : 1}
e4ffb1
+	all_opt["api_path"] = {
e4ffb1
+		"getopt" : ":",
e4ffb1
+		"longopt" : "api-path",
e4ffb1
+		"help" : "--api-path=[path]              The path of the API URL",
e4ffb1
+		"default" : "/ovirt-engine/api",
e4ffb1
+		"required" : "0",
e4ffb1
+		"shortdesc" : "The path of the API URL",
e4ffb1
+		"order" : 2}
e4ffb1
 
e4ffb1
 def main():
e4ffb1
-	device_opt = ["ipaddr", "login", "passwd", "ssl", "notls", "web", "port", "use_cookies" ]
e4ffb1
+	device_opt = [
e4ffb1
+		"ipaddr",
e4ffb1
+		"api_path",
e4ffb1
+		"login",
e4ffb1
+		"passwd",
e4ffb1
+		"ssl",
e4ffb1
+		"notls",
e4ffb1
+		"web",
e4ffb1
+		"port",
e4ffb1
+		"use_cookies",
e4ffb1
+	]
e4ffb1
 
e4ffb1
 	atexit.register(atexit_handler)
e4ffb1
 	define_new_opts()
e4ffb1
diff --git a/tests/data/metadata/fence_rhevm.xml b/tests/data/metadata/fence_rhevm.xml
e4ffb1
index 893a3c5..5fa2e21 100644
e4ffb1
--- a/tests/data/metadata/fence_rhevm.xml
e4ffb1
+++ b/tests/data/metadata/fence_rhevm.xml
e4ffb1
@@ -73,6 +73,11 @@
e4ffb1
 		<content type="boolean"  />
e4ffb1
 		<shortdesc lang="en">Reuse cookies for authentication</shortdesc>
e4ffb1
 	</parameter>
e4ffb1
+	<parameter name="api_path" unique="0" required="0">
e4ffb1
+		<getopt mixed="--api-path=[path]" />
e4ffb1
+		<content type="string" default="/ovirt-engine/api"  />
e4ffb1
+		<shortdesc lang="en">The path of the API URL</shortdesc>
e4ffb1
+	</parameter>
e4ffb1
 	<parameter name="verbose" unique="0" required="0">
e4ffb1
 		<getopt mixed="-v, --verbose" />
e4ffb1
 		<content type="boolean"  />