Blame SOURCES/bz1827652-fence_vmware_rest-1-add-filter-parameter.patch

bf99d3
From ab193580dcdd810b7bef69cc04cebef315f4781d Mon Sep 17 00:00:00 2001
bf99d3
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
bf99d3
Date: Thu, 23 Apr 2020 15:55:11 +0200
bf99d3
Subject: [PATCH] fence_vmware_rest: add filter parameter
bf99d3
bf99d3
---
bf99d3
 agents/vmware_rest/fence_vmware_rest.py   | 24 ++++++++++++++++++++---
bf99d3
 tests/data/metadata/fence_vmware_rest.xml |  9 ++++++++-
bf99d3
 2 files changed, 29 insertions(+), 4 deletions(-)
bf99d3
bf99d3
diff --git a/agents/vmware_rest/fence_vmware_rest.py b/agents/vmware_rest/fence_vmware_rest.py
bf99d3
index 1505ffe6..6daff121 100644
bf99d3
--- a/agents/vmware_rest/fence_vmware_rest.py
bf99d3
+++ b/agents/vmware_rest/fence_vmware_rest.py
bf99d3
@@ -42,7 +42,10 @@ def get_list(conn, options):
bf99d3
 	outlets = {}
bf99d3
 
bf99d3
 	try:
bf99d3
-		res = send_command(conn, "vcenter/vm")
bf99d3
+		command = "vcenter/vm"
bf99d3
+		if "--filter" in options:
bf99d3
+			command = command + "?" + options["--filter"]
bf99d3
+		res = send_command(conn, command)
bf99d3
 	except:
bf99d3
 		logging.debug("Failed: {}".format(e))
bf99d3
 		fail(EC_STATUS)
bf99d3
@@ -157,6 +160,16 @@ def define_new_opts():
bf99d3
 		"required" : "0",
bf99d3
 		"shortdesc" : "The path part of the API URL",
bf99d3
 		"order" : 2}
bf99d3
+	all_opt["filter"] = {
bf99d3
+		"getopt" : ":",
bf99d3
+		"longopt" : "filter",
bf99d3
+		"help" : "--filter=[filter]              Filter to only return relevant VMs"
bf99d3
+			 " (e.g. \"filter.names=node1&filter.names=node2\").",
bf99d3
+		"default" : "",
bf99d3
+		"required" : "0",
bf99d3
+		"shortdesc" : "Filter to only return relevant VMs. It can be used to avoid "
bf99d3
+			      "the agent failing when more than 1000 VMs should be returned.",
bf99d3
+		"order" : 2}
bf99d3
 
bf99d3
 
bf99d3
 def main():
bf99d3
@@ -169,6 +182,7 @@ def main():
bf99d3
 		"notls",
bf99d3
 		"web",
bf99d3
 		"port",
bf99d3
+		"filter",
bf99d3
 	]
bf99d3
 
bf99d3
 	atexit.register(atexit_handler)
bf99d3
@@ -181,8 +195,12 @@ def main():
bf99d3
 
bf99d3
 	docs = {}
bf99d3
 	docs["shortdesc"] = "Fence agent for VMware REST API"
bf99d3
-	docs["longdesc"] = "fence_vmware_rest is an I/O Fencing agent which can be \
bf99d3
-used with VMware API to fence virtual machines."
bf99d3
+	docs["longdesc"] = """fence_vmware_rest is an I/O Fencing agent which can be \
bf99d3
+used with VMware API to fence virtual machines.
bf99d3
+
bf99d3
+NOTE: If there's more than 1000 VMs there is a filter parameter to work around \
bf99d3
+the API limit. See https://code.vmware.com/apis/62/vcenter-management#/VM%20/get_vcenter_vm \
bf99d3
+for full list of filters."""
bf99d3
 	docs["vendorurl"] = "https://www.vmware.com"
bf99d3
 	show_docs(options, docs)
bf99d3
 
bf99d3
diff --git a/tests/data/metadata/fence_vmware_rest.xml b/tests/data/metadata/fence_vmware_rest.xml
bf99d3
index 5b497a6a..d60c8775 100644
bf99d3
--- a/tests/data/metadata/fence_vmware_rest.xml
bf99d3
+++ b/tests/data/metadata/fence_vmware_rest.xml
bf99d3
@@ -1,6 +1,8 @@
bf99d3
 
bf99d3
 <resource-agent name="fence_vmware_rest" shortdesc="Fence agent for VMware REST API" >
bf99d3
-<longdesc>fence_vmware_rest is an I/O Fencing agent which can be used with VMware API to fence virtual machines.</longdesc>
bf99d3
+<longdesc>fence_vmware_rest is an I/O Fencing agent which can be used with VMware API to fence virtual machines.
bf99d3
+
bf99d3
+NOTE: If there's more than 1000 VMs there is a filter parameter to work around the API limit. See https://code.vmware.com/apis/62/vcenter-management#/VM%20/get_vcenter_vm for full list of filters.</longdesc>
bf99d3
 <vendor-url>https://www.vmware.com</vendor-url>
bf99d3
 <parameters>
bf99d3
 	<parameter name="action" unique="0" required="1">
bf99d3
@@ -87,6 +89,11 @@
bf99d3
 		<getopt mixed="--api-path=[path]" />
bf99d3
 		<shortdesc lang="en">The path part of the API URL</shortdesc>
bf99d3
 	</parameter>
bf99d3
+	<parameter name="filter" unique="0" required="0">
bf99d3
+		<getopt mixed="--filter=[filter]" />
bf99d3
+		<content type="string" default=""  />
bf99d3
+		<shortdesc lang="en">Filter to only return relevant VMs. It can be used to avoid the agent failing when more than 1000 VMs should be returned.</shortdesc>
bf99d3
+	</parameter>
bf99d3
 	<parameter name="quiet" unique="0" required="0">
bf99d3
 		<getopt mixed="-q, --quiet" />
bf99d3
 		<content type="boolean"  />