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