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