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

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