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