|
|
83de4b |
From a4e8b77ac51a0e4a6de489823ee1be47cbc7eb18 Mon Sep 17 00:00:00 2001
|
|
|
83de4b |
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
|
|
|
83de4b |
Date: Thu, 9 May 2019 12:09:48 +0200
|
|
|
83de4b |
Subject: [PATCH] fence_rhevm: add RHEV v4 API support and auto-detection
|
|
|
83de4b |
|
|
|
83de4b |
---
|
|
|
83de4b |
agents/rhevm/fence_rhevm.py | 44 +++++++++++++++++++++++------
|
|
|
83de4b |
tests/data/metadata/fence_rhevm.xml | 7 ++++-
|
|
|
83de4b |
2 files changed, 41 insertions(+), 10 deletions(-)
|
|
|
83de4b |
|
|
|
83de4b |
diff --git a/agents/rhevm/fence_rhevm.py b/agents/rhevm/fence_rhevm.py
|
|
|
83de4b |
index a1cdaf605..6012c4239 100644
|
|
|
83de4b |
--- a/agents/rhevm/fence_rhevm.py
|
|
|
83de4b |
+++ b/agents/rhevm/fence_rhevm.py
|
|
|
83de4b |
@@ -9,7 +9,8 @@
|
|
|
83de4b |
from fencing import fail, EC_FETCH_VM_UUID, run_delay
|
|
|
83de4b |
|
|
|
83de4b |
RE_GET_ID = re.compile("
|
|
|
83de4b |
-RE_STATUS = re.compile("<state>(.*?)</state>", re.IGNORECASE)
|
|
|
83de4b |
+RE_STATUS = re.compile("<status>(.*?)</status>", re.IGNORECASE)
|
|
|
83de4b |
+RE_STATE = re.compile("<state>(.*?)</state>", re.IGNORECASE)
|
|
|
83de4b |
RE_GET_NAME = re.compile("<name>(.*?)</name>", re.IGNORECASE)
|
|
|
83de4b |
|
|
|
83de4b |
def get_power_status(conn, options):
|
|
|
83de4b |
@@ -25,7 +26,10 @@ def get_power_status(conn, options):
|
|
|
83de4b |
|
|
|
83de4b |
options["id"] = result.group(2)
|
|
|
83de4b |
|
|
|
83de4b |
- result = RE_STATUS.search(res)
|
|
|
83de4b |
+ if tuple(map(int, options["--api-version"].split(".")))[0] > 3:
|
|
|
83de4b |
+ result = RE_STATUS.search(res)
|
|
|
83de4b |
+ else:
|
|
|
83de4b |
+ result = RE_STATE.search(res)
|
|
|
83de4b |
if result == None:
|
|
|
83de4b |
# We were able to parse ID so output is correct
|
|
|
83de4b |
# in some cases it is possible that RHEV-M output does not
|
|
|
83de4b |
@@ -59,7 +63,10 @@ def get_list(conn, options):
|
|
|
83de4b |
lines = res.split("
|
|
|
83de4b |
for i in range(1, len(lines)):
|
|
|
83de4b |
name = RE_GET_NAME.search(lines[i]).group(1)
|
|
|
83de4b |
- status = RE_STATUS.search(lines[i]).group(1)
|
|
|
83de4b |
+ if tuple(map(int, options["--api-version"].split(".")))[0] > 3:
|
|
|
83de4b |
+ status = RE_STATUS.search(lines[i]).group(1)
|
|
|
83de4b |
+ else:
|
|
|
83de4b |
+ status = RE_STATE.search(lines[i]).group(1)
|
|
|
83de4b |
outlets[name] = ("", status)
|
|
|
83de4b |
except AttributeError:
|
|
|
83de4b |
return {}
|
|
|
83de4b |
@@ -69,6 +76,13 @@ def get_list(conn, options):
|
|
|
83de4b |
return outlets
|
|
|
83de4b |
|
|
|
83de4b |
def send_command(opt, command, method="GET"):
|
|
|
83de4b |
+ if opt["--api-version"] == "auto":
|
|
|
83de4b |
+ opt["--api-version"] = "4"
|
|
|
83de4b |
+ res = send_command(opt, "")
|
|
|
83de4b |
+ if re.search("<title>Error</title>", res):
|
|
|
83de4b |
+ opt["--api-version"] = "3"
|
|
|
83de4b |
+ logging.debug("auto-detected API version: " + opt["--api-version"])
|
|
|
83de4b |
+
|
|
|
83de4b |
## setup correct URL
|
|
|
83de4b |
if "--ssl" in opt or "--ssl-secure" in opt or "--ssl-insecure" in opt:
|
|
|
83de4b |
url = "https:"
|
|
|
83de4b |
@@ -90,7 +104,7 @@ def send_command(opt, command, method="GET"):
|
|
|
83de4b |
web_buffer = io.BytesIO()
|
|
|
83de4b |
conn.setopt(pycurl.URL, url.encode("UTF-8"))
|
|
|
83de4b |
conn.setopt(pycurl.HTTPHEADER, [
|
|
|
83de4b |
- "Version: 3",
|
|
|
83de4b |
+ "Version: {}".format(opt["--api-version"]),
|
|
|
83de4b |
"Content-type: application/xml",
|
|
|
83de4b |
"Accept: application/xml",
|
|
|
83de4b |
"Prefer: persistent-auth",
|
|
|
83de4b |
@@ -130,8 +144,9 @@ def send_command(opt, command, method="GET"):
|
|
|
83de4b |
|
|
|
83de4b |
result = web_buffer.getvalue().decode("UTF-8")
|
|
|
83de4b |
|
|
|
83de4b |
- logging.debug("%s\n", command)
|
|
|
83de4b |
- logging.debug("%s\n", result)
|
|
|
83de4b |
+ logging.debug("url: %s\n", url)
|
|
|
83de4b |
+ logging.debug("command: %s\n", command)
|
|
|
83de4b |
+ logging.debug("result: %s\n", result)
|
|
|
83de4b |
|
|
|
83de4b |
return result
|
|
|
83de4b |
|
|
|
83de4b |
@@ -151,6 +166,15 @@ def define_new_opts():
|
|
|
83de4b |
"required" : "0",
|
|
|
83de4b |
"shortdesc" : "Reuse cookies for authentication",
|
|
|
83de4b |
"order" : 1}
|
|
|
83de4b |
+ all_opt["api_version"] = {
|
|
|
83de4b |
+ "getopt" : ":",
|
|
|
83de4b |
+ "longopt" : "api-version",
|
|
|
83de4b |
+ "help" : "--api-version "
|
|
|
83de4b |
+ "Version of RHEV API (default: auto)",
|
|
|
83de4b |
+ "required" : "0",
|
|
|
83de4b |
+ "order" : 2,
|
|
|
83de4b |
+ "default" : "auto",
|
|
|
83de4b |
+ }
|
|
|
83de4b |
all_opt["api_path"] = {
|
|
|
83de4b |
"getopt" : ":",
|
|
|
83de4b |
"longopt" : "api-path",
|
|
|
83de4b |
@@ -158,20 +182,19 @@ def define_new_opts():
|
|
|
83de4b |
"default" : "/ovirt-engine/api",
|
|
|
83de4b |
"required" : "0",
|
|
|
83de4b |
"shortdesc" : "The path part of the API URL",
|
|
|
83de4b |
- "order" : 2}
|
|
|
83de4b |
+ "order" : 3}
|
|
|
83de4b |
all_opt["disable_http_filter"] = {
|
|
|
83de4b |
"getopt" : "",
|
|
|
83de4b |
"longopt" : "disable-http-filter",
|
|
|
83de4b |
"help" : "--disable-http-filter Set HTTP Filter header to false",
|
|
|
83de4b |
"required" : "0",
|
|
|
83de4b |
"shortdesc" : "Set HTTP Filter header to false",
|
|
|
83de4b |
- "order" : 3}
|
|
|
83de4b |
+ "order" : 4}
|
|
|
83de4b |
|
|
|
83de4b |
|
|
|
83de4b |
def main():
|
|
|
83de4b |
device_opt = [
|
|
|
83de4b |
"ipaddr",
|
|
|
83de4b |
- "api_path",
|
|
|
83de4b |
"login",
|
|
|
83de4b |
"passwd",
|
|
|
83de4b |
"ssl",
|
|
|
83de4b |
@@ -179,6 +202,8 @@ def main():
|
|
|
83de4b |
"web",
|
|
|
83de4b |
"port",
|
|
|
83de4b |
"use_cookies",
|
|
|
83de4b |
+ "api_version",
|
|
|
83de4b |
+ "api_path",
|
|
|
83de4b |
"disable_http_filter",
|
|
|
83de4b |
]
|
|
|
83de4b |
|
|
|
83de4b |
@@ -186,6 +211,7 @@ def main():
|
|
|
83de4b |
define_new_opts()
|
|
|
83de4b |
|
|
|
83de4b |
all_opt["power_wait"]["default"] = "1"
|
|
|
83de4b |
+ all_opt["shell_timeout"]["default"] = "5"
|
|
|
83de4b |
|
|
|
83de4b |
options = check_input(device_opt, process_input(device_opt))
|
|
|
83de4b |
|
|
|
83de4b |
diff --git a/tests/data/metadata/fence_rhevm.xml b/tests/data/metadata/fence_rhevm.xml
|
|
|
83de4b |
index 6344db79f..c56cf64b6 100644
|
|
|
83de4b |
--- a/tests/data/metadata/fence_rhevm.xml
|
|
|
83de4b |
+++ b/tests/data/metadata/fence_rhevm.xml
|
|
|
83de4b |
@@ -98,6 +98,11 @@
|
|
|
83de4b |
<content type="string" />
|
|
|
83de4b |
<shortdesc lang="en">Login name</shortdesc>
|
|
|
83de4b |
</parameter>
|
|
|
83de4b |
+ <parameter name="api_version" unique="0" required="0">
|
|
|
83de4b |
+ <getopt mixed="--api-version" />
|
|
|
83de4b |
+ <content type="string" default="auto" />
|
|
|
83de4b |
+ <shortdesc lang="en">Version of RHEV API (default: auto)</shortdesc>
|
|
|
83de4b |
+ </parameter>
|
|
|
83de4b |
<parameter name="api_path" unique="0" required="0">
|
|
|
83de4b |
<getopt mixed="--api-path=[path]" />
|
|
|
83de4b |
<shortdesc lang="en">The path part of the API URL</shortdesc>
|
|
|
83de4b |
@@ -164,7 +169,7 @@
|
|
|
83de4b |
</parameter>
|
|
|
83de4b |
<parameter name="shell_timeout" unique="0" required="0">
|
|
|
83de4b |
<getopt mixed="--shell-timeout=[seconds]" />
|
|
|
83de4b |
- <content type="second" default="3" />
|
|
|
83de4b |
+ <content type="second" default="5" />
|
|
|
83de4b |
<shortdesc lang="en">Wait X seconds for cmd prompt after issuing command</shortdesc>
|
|
|
83de4b |
</parameter>
|
|
|
83de4b |
<parameter name="retry_on" unique="0" required="0">
|