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

New Modules for NDB features for 1.8.0-beta.1 release #292

Merged
merged 33 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
32cc98f
era basic spec design
bhati-pradeep Oct 6, 2022
80310bf
database CRUD code
bhati-pradeep Oct 10, 2022
a6cbc39
Handling new fields for era connection and fixing crud flows
bhati-pradeep Oct 13, 2022
a95c69b
Test automation for database instance crud
bhati-pradeep Oct 14, 2022
939d7f1
Minor fix
bhati-pradeep Oct 14, 2022
be43701
Feat/era info (#290)
Gevorg-Khachatryan-97 Oct 18, 2022
6e02c02
Add option for version ID in software profile
bhati-pradeep Oct 18, 2022
38755f2
Merge branch 'feat/era-postgress-beta' of github.com:nutanix/nutanix.…
bhati-pradeep Oct 18, 2022
f25db06
Add info tests for database in crud tests
bhati-pradeep Oct 18, 2022
15cd08e
Minro update
bhati-pradeep Oct 18, 2022
06efa52
Handling error cases
bhati-pradeep Oct 18, 2022
dc566fa
1. Doc fixes. 2. Let entity class handle failed api errors then clien…
bhati-pradeep Oct 19, 2022
b40cd15
Add example in docs
bhati-pradeep Oct 19, 2022
ee9da4e
Doc fixes
bhati-pradeep Oct 19, 2022
588298e
Add examples
alaa-bish Oct 19, 2022
ccb605d
supress output for ndb tests
bhati-pradeep Oct 19, 2022
f4ea401
Merge branch 'feat/era-postgress-beta' of github.com:nutanix/nutanix.…
bhati-pradeep Oct 19, 2022
41091cb
Minor doc update
bhati-pradeep Oct 19, 2022
a7834f9
fixing tests
bhati-pradeep Oct 19, 2022
14e4dde
Minor test fix
bhati-pradeep Oct 19, 2022
de55b12
use nutanix_* based creds terms for ndb as well
bhati-pradeep Oct 19, 2022
2f35779
Minor doc fix
bhati-pradeep Oct 19, 2022
b6e7612
formatting
bhati-pradeep Oct 19, 2022
f32ace6
Minor fix
bhati-pradeep Oct 19, 2022
51c1513
ADD return
alaa-bish Oct 19, 2022
380cc62
Doc updates
bhati-pradeep Oct 19, 2022
1a8673a
Example for postgress database creation
bhati-pradeep Oct 19, 2022
dd16980
read me changes
bhati-pradeep Oct 19, 2022
11bdfbc
Docs and examples
bhati-pradeep Oct 19, 2022
6beec0b
minor fixes
bhati-pradeep Oct 19, 2022
faca3db
Add soft delete example
bhati-pradeep Oct 20, 2022
fbcdcb1
Release docs update
bhati-pradeep Oct 20, 2022
61d979c
Minor change log update
bhati-pradeep Oct 20, 2022
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
8 changes: 8 additions & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@ action_groups:
- ntnx_karbon_clusters_info
- ntnx_karbon_registries
- ntnx_karbon_registries_info
- ntnx_ndb_databases_info
- ntnx_ndb_clones_info
- ntnx_ndb_time_machines_info
- ntnx_ndb_profiles_info
- ntnx_ndb_db_servers_info
- ntnx_ndb_slas_info
- ntnx_ndb_databases
- ntnx_ndb_clusters_info
41 changes: 41 additions & 0 deletions plugins/doc_fragments/ntnx_ndb_base_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-

# Copyright: (c) 2017, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function

__metaclass__ = type


class ModuleDocFragment(object):

# Plugin options for ntnx ndb
DOCUMENTATION = r"""
options:
nutanix_host:
description:
- ndb era server IP address
- C(nutanix_host). If not set then the value of the C(NUTANIX_HOST), environment variable is used.
type: str
required: true
nutanix_password:
description:
- ndb era server password
- C(nutanix_password). If not set then the value of the C(NUTANIX_PASSWORD), environment variable is used.
type: str
required: true
nutanix_username:
description:
- ndb era server username
- C(nutanix_username). If not set then the value of the C(NUTANIX_USERNAME), environment variable is used.
type: str
required: true
validate_certs:
description:
- Set value to C(False) to skip validation for self signed certificates
- This is not recommended for production setup
- C(validate_certs). If not set then the value of the C(VALIDATE_CERTS), environment variable is used.
type: bool
default: true
"""
12 changes: 12 additions & 0 deletions plugins/module_utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,15 @@ class EntityFilterExpressionList:
"right_hand_side": {"collection": "SELF_OWNED"},
},
}


class NDB:

OPERATIONS_POLLING_DELAY = 30

class DatabaseTypes:
POSTGRES = "postgres_database"

class StatusCodes:
SUCCESS = "5"
FAILURE = "4"
14 changes: 11 additions & 3 deletions plugins/module_utils/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def update(
raise_error=True,
no_response=False,
timeout=30,
method="PUT",
):
url = self.base_url + "/{0}".format(uuid) if uuid else self.base_url
if endpoint:
Expand All @@ -98,7 +99,7 @@ def update(
url = self._build_url_with_query(url, query)
return self._fetch_url(
url,
method="PUT",
method=method,
data=data,
raise_error=raise_error,
no_response=no_response,
Expand Down Expand Up @@ -136,6 +137,7 @@ def delete(
raise_error=True,
no_response=False,
timeout=30,
data=None,
):
url = self.base_url + "/{0}".format(uuid) if uuid else self.base_url
if endpoint:
Expand All @@ -145,6 +147,7 @@ def delete(
return self._fetch_url(
url,
method="DELETE",
data=data,
raise_error=raise_error,
no_response=no_response,
timeout=timeout,
Expand Down Expand Up @@ -373,7 +376,12 @@ def _fetch_url(
return resp_json

if status_code >= 300:
err = info.get("msg", "Status code != 2xx")
if resp_json and resp_json.get("message"): # for ndb apis
err = resp_json["message"]
elif info.get("msg"):
err = info["msg"]
else:
err = "Status code != 2xx"
self.module.fail_json(
msg="Failed fetching URL: {0}".format(url),
status_code=status_code,
Expand All @@ -384,7 +392,7 @@ def _fetch_url(
if no_response:
return {"status_code": status_code}

if not resp_json:
if resp_json is None:
self.module.fail_json(
msg="Failed to convert API response to json",
status_code=status_code,
Expand Down
Empty file.
18 changes: 18 additions & 0 deletions plugins/module_utils/ndb/base_info_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright: 2021, Ansible Project
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause )
from __future__ import absolute_import, division, print_function

from copy import deepcopy

from .base_module import NdbBaseModule

__metaclass__ = type


class NdbBaseInfoModule(NdbBaseModule):
def __init__(self, **kwargs):
self.argument_spec = deepcopy(NdbBaseModule.argument_spec)
self.argument_spec.pop("state")
self.argument_spec.pop("wait")
self.argument_spec.pop("timeout")
super(NdbBaseInfoModule, self).__init__(**kwargs)
41 changes: 41 additions & 0 deletions plugins/module_utils/ndb/base_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright: 2021, Ansible Project
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause )
from __future__ import absolute_import, division, print_function

from ansible.module_utils.basic import AnsibleModule, env_fallback

__metaclass__ = type


class NdbBaseModule(AnsibleModule):
argument_spec = dict(
nutanix_host=dict(
type="str", required=True, fallback=(env_fallback, ["NUTANIX_HOST"])
),
nutanix_username=dict(
type="str", fallback=(env_fallback, ["NUTANIX_USERNAME"]), required=True
),
nutanix_password=dict(
type="str",
no_log=True,
fallback=(env_fallback, ["NUTANIX_PASSWORD"]),
required=True,
),
validate_certs=dict(
type="bool", default=True, fallback=(env_fallback, ["VALIDATE_CERTS"])
),
state=dict(type="str", choices=["present", "absent"], default="present"),
timeout=dict(type="int", required=False, default=35 * 60),
wait=dict(type="bool", default=True),
)

def __init__(self, **kwargs):
if kwargs.get("argument_spec"):
kwargs["argument_spec"].update(self.argument_spec)
else:
kwargs["argument_spec"] = self.argument_spec

if not kwargs.get("supports_check_mode"):
kwargs["supports_check_mode"] = True

super(NdbBaseModule, self).__init__(**kwargs)
28 changes: 28 additions & 0 deletions plugins/module_utils/ndb/clones.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file is part of Ansible
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function

__metaclass__ = type


from .nutanix_database import NutanixDatabase


class Clone(NutanixDatabase):
def __init__(self, module):
resource_type = "/clones"
super(Clone, self).__init__(module, resource_type=resource_type)

def get_clone(self, uuid=None, name=None):
if uuid:
resp = self.read(uuid=uuid)
elif name:
query = {"value-type": "name", "value": name}
resp = self.read(query=query)
if not resp:
return None, "Clone with name {0} not found".format(name)
resp = resp[0]
else:
return None, "Please provide either uuid or name for fetching clone details"

return resp, None
62 changes: 62 additions & 0 deletions plugins/module_utils/ndb/clusters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This file is part of Ansible
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function

__metaclass__ = type


from .nutanix_database import NutanixDatabase


class Cluster(NutanixDatabase):
def __init__(self, module):
resource_type = "/clusters"
super(Cluster, self).__init__(module, resource_type=resource_type)

def get_uuid(
self,
value,
key="name",
data=None,
entity_type=None,
raise_error=True,
no_response=False,
):
endpoint = "{0}/{1}".format(key, value)
resp = self.read(uuid=None, endpoint=endpoint)
return resp.get("id")

def get_cluster(self, uuid=None, name=None):
if uuid:
resp = self.read(uuid=uuid)
elif name:
endpoint = "{0}/{1}".format("name", name)
resp = self.read(endpoint=endpoint)

# we fetch cluster using ID again to get complete info.
if resp and resp.get("id"):
resp = self.read(uuid=resp["id"])

else:
return (
None,
"Please provide either uuid or name for fetching cluster details",
)

return resp, None


# helper functions


def get_cluster_uuid(module, config):
uuid = ""
if config.get("name"):
clusters = Cluster(module)
uuid = clusters.get_uuid(config["name"])
elif config.get("uuid"):
uuid = config["uuid"]
else:
error = "cluster config {0} doesn't have name or uuid key".format(config)
return error, None
return uuid, None
Loading