|
|
44709c |
commit 1dc12749623e3e3a06c3265260f5f049cdf6632b
|
|
|
44709c |
Author: Marek 'marx' Grac <mgrac@redhat.com>
|
|
|
44709c |
Date: Wed Jun 17 19:42:32 2015 +0200
|
|
|
44709c |
|
|
|
44709c |
fence_rhevm: Add support for cookies based authentication
|
|
|
44709c |
|
|
|
44709c |
The first command is authenticated as usually but rest can be used without additional authentication.
|
|
|
44709c |
This is useful only for reboot or obtaining status of several nodes at once.
|
|
|
44709c |
|
|
|
44709c |
Resolves: rhbz#1145769
|
|
|
44709c |
|
|
|
44709c |
diff --git a/fence/agents/rhevm/fence_rhevm.py b/fence/agents/rhevm/fence_rhevm.py
|
|
|
44709c |
index 444fb56..bb34054 100644
|
|
|
44709c |
--- a/fence/agents/rhevm/fence_rhevm.py
|
|
|
44709c |
+++ b/fence/agents/rhevm/fence_rhevm.py
|
|
|
44709c |
@@ -87,9 +87,16 @@ def send_command(opt, command, method="GET"):
|
|
|
44709c |
conn = pycurl.Curl()
|
|
|
44709c |
web_buffer = StringIO.StringIO()
|
|
|
44709c |
conn.setopt(pycurl.URL, url)
|
|
|
44709c |
- conn.setopt(pycurl.HTTPHEADER, ["Content-type: application/xml", "Accept: application/xml"])
|
|
|
44709c |
- conn.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_BASIC)
|
|
|
44709c |
- conn.setopt(pycurl.USERPWD, opt["--username"] + ":" + opt["--password"])
|
|
|
44709c |
+ conn.setopt(pycurl.HTTPHEADER, ["Content-type: application/xml", "Accept: application/xml", "Prefer: persistent-auth"])
|
|
|
44709c |
+
|
|
|
44709c |
+ if opt.has_key("cookie"):
|
|
|
44709c |
+ conn.setopt(pycurl.COOKIE, opt["cookie"])
|
|
|
44709c |
+ else:
|
|
|
44709c |
+ conn.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_BASIC)
|
|
|
44709c |
+ conn.setopt(pycurl.USERPWD, opt["--username"] + ":" + opt["--password"])
|
|
|
44709c |
+ if opt.has_key("--use-cookies"):
|
|
|
44709c |
+ conn.setopt(pycurl.COOKIEFILE, "")
|
|
|
44709c |
+
|
|
|
44709c |
conn.setopt(pycurl.TIMEOUT, int(opt["--shell-timeout"]))
|
|
|
44709c |
if opt.has_key("--ssl") or opt.has_key("--ssl-secure"):
|
|
|
44709c |
conn.setopt(pycurl.SSL_VERIFYPEER, 1)
|
|
|
44709c |
@@ -104,6 +111,15 @@ def send_command(opt, command, method="GET"):
|
|
|
44709c |
|
|
|
44709c |
conn.setopt(pycurl.WRITEFUNCTION, web_buffer.write)
|
|
|
44709c |
conn.perform()
|
|
|
44709c |
+
|
|
|
44709c |
+ if not opt.has_key("cookie") and opt.has_key("--use-cookies"):
|
|
|
44709c |
+ cookie = ""
|
|
|
44709c |
+ for c in conn.getinfo(pycurl.INFO_COOKIELIST):
|
|
|
44709c |
+ tokens = c.split("\t",7)
|
|
|
44709c |
+ cookie = cookie + tokens[5] + "=" + tokens[6] + ";"
|
|
|
44709c |
+
|
|
|
44709c |
+ opt["cookie"] = cookie
|
|
|
44709c |
+
|
|
|
44709c |
result = web_buffer.getvalue()
|
|
|
44709c |
|
|
|
44709c |
logging.debug("%s\n", command)
|
|
|
44709c |
@@ -111,10 +127,20 @@ def send_command(opt, command, method="GET"):
|
|
|
44709c |
|
|
|
44709c |
return result
|
|
|
44709c |
|
|
|
44709c |
+def define_new_opts():
|
|
|
44709c |
+ all_opt["use_cookies"] = {
|
|
|
44709c |
+ "getopt" : "s",
|
|
|
44709c |
+ "longopt" : "use-cookies",
|
|
|
44709c |
+ "help" : "--use-cookies Reuse cookies for authentication",
|
|
|
44709c |
+ "required" : "0",
|
|
|
44709c |
+ "shortdesc" : "Reuse cookies for authentication",
|
|
|
44709c |
+ "order" : 1}
|
|
|
44709c |
+
|
|
|
44709c |
def main():
|
|
|
44709c |
- device_opt = ["ipaddr", "login", "passwd", "ssl", "notls", "web", "port"]
|
|
|
44709c |
+ device_opt = ["ipaddr", "login", "passwd", "ssl", "notls", "web", "port", "use_cookies" ]
|
|
|
44709c |
|
|
|
44709c |
atexit.register(atexit_handler)
|
|
|
44709c |
+ define_new_opts()
|
|
|
44709c |
|
|
|
44709c |
all_opt["power_wait"]["default"] = "1"
|
|
|
44709c |
|
|
|
44709c |
diff --git a/tests/data/metadata/fence_rhevm.xml b/tests/data/metadata/fence_rhevm.xml
|
|
|
44709c |
index 1eccd26..e0c9516 100644
|
|
|
44709c |
--- a/tests/data/metadata/fence_rhevm.xml
|
|
|
44709c |
+++ b/tests/data/metadata/fence_rhevm.xml
|
|
|
44709c |
@@ -53,6 +53,11 @@
|
|
|
44709c |
<content type="boolean" />
|
|
|
44709c |
<shortdesc lang="en">SSL connection</shortdesc>
|
|
|
44709c |
</parameter>
|
|
|
44709c |
+ <parameter name="use_cookies" unique="0" required="0">
|
|
|
44709c |
+ <getopt mixed="--use-cookies" />
|
|
|
44709c |
+ <content type="boolean" />
|
|
|
44709c |
+ <shortdesc lang="en">Reuse cookies for authentication</shortdesc>
|
|
|
44709c |
+ </parameter>
|
|
|
44709c |
<parameter name="ssl_insecure" unique="0" required="0">
|
|
|
44709c |
<getopt mixed="--ssl-insecure" />
|
|
|
44709c |
<content type="boolean" />
|