Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imprv/issue#409 #436

Open
wants to merge 2 commits into
base: release/1.9.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions plugins/inventory/ntnx_prism_vm_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
- Default length(number of records to retrieve) has been set to 500
default: {"offset": 0, "length": 500}
type: dict
timeout:
description:
- timeout for polling of operation, after which module will error out
type: int
required: false
default: 60
validate_certs:
description:
- Set value to C(False) to skip validation for self signed certificates
Expand All @@ -76,14 +82,15 @@


class Mock_Module:
def __init__(self, host, port, username, password, validate_certs=False):
def __init__(self, host, port, username, password, validate_certs=False, timeout=30):
self.tmpdir = tempfile.gettempdir()
self.params = {
"nutanix_host": host,
"nutanix_port": port,
"nutanix_username": username,
"nutanix_password": password,
"validate_certs": validate_certs,
"timeout": timeout,
"load_params_without_defaults": False,
}

Expand All @@ -92,7 +99,7 @@ def jsonify(self, data):


class InventoryModule(BaseInventoryPlugin, Constructable):
"""Nutanix VM dynamic invetory module for ansible"""
"""Nutanix VM dynamic inventory module for ansible"""

NAME = "nutanix.ncp.ntnx_prism_vm_inventory"

Expand All @@ -119,6 +126,7 @@ def parse(self, inventory, loader, path, cache=True):
self.nutanix_port = self.get_option("nutanix_port")
self.data = self.get_option("data")
self.validate_certs = self.get_option("validate_certs")
self.timeout = self.get_option("timeout")
# Determines if composed variables or groups using nonexistent variables is an error
strict = self.get_option("strict")

Expand All @@ -128,6 +136,7 @@ def parse(self, inventory, loader, path, cache=True):
self.nutanix_username,
self.nutanix_password,
self.validate_certs,
self.timeout
)
vm = vms.VM(module)
self.data["offset"] = self.data.get("offset", 0)
Expand Down
1 change: 1 addition & 0 deletions plugins/module_utils/base_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class BaseModule(AnsibleModule):
),
state=dict(type="str", choices=["present", "absent"], default="present"),
wait=dict(type="bool", default=True),
timeout=dict(type="int", required=False),
)

def __init__(self, **kwargs):
Expand Down
14 changes: 14 additions & 0 deletions plugins/module_utils/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def create(
url = self.base_url + "/{0}".format(endpoint) if endpoint else self.base_url
if query:
url = self._build_url_with_query(url, query)

timeout = self.module.params.get("timeout", timeout)

return self._fetch_url(
url,
method=method,
Expand All @@ -73,6 +76,9 @@ def read(
url = url + "/{0}".format(endpoint)
if query:
url = self._build_url_with_query(url, query)

timeout = self.module.params.get("timeout", timeout)

return self._fetch_url(
url,
method="GET",
Expand All @@ -97,6 +103,9 @@ def update(
url = url + "/{0}".format(endpoint)
if query:
url = self._build_url_with_query(url, query)

timeout = self.module.params.get("timeout", timeout)

return self._fetch_url(
url,
method=method,
Expand Down Expand Up @@ -144,6 +153,9 @@ def delete(
url = url + "/{0}".format(endpoint)
if query:
url = self._build_url_with_query(url, query)

timeout = self.module.params.get("timeout", timeout)

return self._fetch_url(
url,
method="DELETE",
Expand All @@ -166,6 +178,8 @@ def list(
if endpoint:
url = url + "/{0}".format(endpoint)

timeout = self.module.params.get("timeout", timeout)

resp = self._fetch_url(
url,
method="POST",
Expand Down
Loading