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

All Modules under Prism namespace #571

Open
wants to merge 28 commits into
base: release/2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
867b387
Added Modules for Prism namespace
abhinavbansal29 Jan 7, 2025
0394d81
Adding check mode tests
george-ghawali Jan 8, 2025
0387f28
plugins/modules/ntnx_pc_backup_target_v2.py
abhinavbansal29 Jan 12, 2025
d6ffd3d
Minor changes
abhinavbansal29 Jan 12, 2025
b0acff4
Minor Fix
abhinavbansal29 Jan 12, 2025
2bc15e5
Minor fix
abhinavbansal29 Jan 12, 2025
d81d61d
Minor fix in path of basemodule
abhinavbansal29 Jan 12, 2025
073389f
Fixed required fields and all for backup target and restore source
abhinavbansal29 Jan 12, 2025
5c3fae8
Minor Fix
abhinavbansal29 Jan 12, 2025
d169bd8
Adding tests for
george-ghawali Jan 12, 2025
74224a9
Adding prism examples file
george-ghawali Jan 13, 2025
38cb689
remove extra debug statement
george-ghawali Jan 15, 2025
1f4a5d9
Added info code for restorable_domain_managers restore_points
abhinavbansal29 Jan 15, 2025
eecdd5b
Adding restore PC test
george-ghawali Jan 16, 2025
fa2d2f2
Adding Create/Delete backup target and restore source object store
george-ghawali Jan 19, 2025
eee301d
Delete all backup targets if exists
george-ghawali Jan 19, 2025
c25cac3
Adding separate file for object store operations
george-ghawali Jan 20, 2025
ef8ed01
Adding update backup target tests
george-ghawali Jan 21, 2025
b4167ed
Initializing variables
george-ghawali Jan 21, 2025
ecebbd0
minor fixes in test
george-ghawali Jan 21, 2025
f8dcb99
remove listing backup targets with filter or limit as it is not appli…
george-ghawali Jan 21, 2025
66e72f4
Fixed restore PC, added Deploy PC tests
abhinavbansal29 Jan 23, 2025
a7729c3
Adding wait time until restore point is created after creating backup…
george-ghawali Jan 23, 2025
1a4ee11
Merge branch 'feat/prism-v4' of https://github.com/nutanix/nutanix.an…
george-ghawali Jan 23, 2025
9bc05fc
Reset prism central password after restoring
george-ghawali Jan 26, 2025
116f271
Adding fixes in cluster_location and cluster_object_store tests
george-ghawali Jan 26, 2025
0a85b45
minor fix in tests
george-ghawali Jan 26, 2025
250ed2a
Adding check mode tests for restoring PC
george-ghawali Jan 26, 2025
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
138 changes: 138 additions & 0 deletions examples/prism_v2/prism.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
---
- name: Prism playbook
hosts: localhost
gather_facts: false
module_defaults:
group/nutanix.ncp.ntnx:
nutanix_host: <pc_ip>
nutanix_username: <user>
nutanix_password: <pass>
validate_certs: false
tasks:
- name: Setting Variables
ansible.builtin.set_fact:
cluster:
uuid: "00095bb3-1234-1122-5312-ac1f6b6f97e2"
ip_pe: "10.0.0.1"

- name: List all clusters to get prism central external ID
nutanix.ncp.ntnx_clusters_info_v2:
filter: "config/clusterFunction/any(t:t eq Clustermgmt.Config.ClusterFunctionRef'PRISM_CENTRAL')"
register: result
ignore_errors: true

- name: Get prism central external ID
ansible.builtin.set_fact:
domain_manager_ext_id: "{{ result.response[0].ext_id }}"

- name: Create backup target cluster
nutanix.ncp.ntnx_pc_backup_target_v2:
domain_manager_ext_id: "{{ domain_manager_ext_id }}"
location:
cluster_location:
config:
ext_id: "{{ cluster.uuid }}"
register: result
ignore_errors: true

- name: List all backup targets and set backup target external ID
nutanix.ncp.ntnx_pc_backup_target_info_v2:
domain_manager_ext_id: "{{ domain_manager_ext_id }}"
register: result
ignore_errors: true

- name: Set backup target cluster external ID
ansible.builtin.set_fact:
backup_target_ext_id: "{{ result.response[0].ext_id }}"

- name: Create restore source cluster
nutanix.ncp.ntnx_pc_restore_source_v2:
nutanix_host: "{{ ip_pe }}"
location:
cluster_location:
config:
ext_id: "{{ cluster.uuid }}"
register: result
ignore_errors: true

- name: Get restore source cluster
nutanix.ncp.ntnx_pc_restore_source_info_v2:
nutanix_host: "{{ ip_pe }}"
ext_id: "{{ result.response.ext_id }}"
register: result
ignore_errors: true

- name: Set restore source cluster external ID
ansible.builtin.set_fact:
restore_source_ext_id: "{{ result.response.ext_id }}"

- name: List all backup targets
nutanix.ncp.ntnx_pc_backup_target_info_v2:
domain_manager_ext_id: "{{ domain_manager_ext_id }}"
register: result
ignore_errors: true

- name: List all backup targets with filter
nutanix.ncp.ntnx_pc_backup_target_info_v2:
domain_manager_ext_id: "{{ domain_manager_ext_id }}"
filter: location/clusterLocation/config/ext_id eq '{{ cluster.uuid }}'
register: result
ignore_errors: true

- name: List all backup targets with limit
nutanix.ncp.ntnx_pc_backup_target_info_v2:
domain_manager_ext_id: "{{ domain_manager_ext_id }}"
limit: 1
register: result
ignore_errors: true

- name: Fetch backup target details using external ID
nutanix.ncp.ntnx_pc_backup_target_info_v2:
domain_manager_ext_id: "{{ domain_manager_ext_id }}"
ext_id: "{{ backup_target_ext_id }}"
register: result
ignore_errors: true

- name: Delete restore source cluster
nutanix.ncp.ntnx_pc_restore_source_v2:
nutanix_host: "{{ ip_pe }}"
ext_id: "{{ restore_source_ext_id }}"
state: absent
register: result
ignore_errors: true

- name: Delete backup target cluster
nutanix.ncp.ntnx_pc_backup_target_v2:
ext_id: "{{ backup_target_ext_id }}"
domain_manager_ext_id: "{{ domain_manager_ext_id }}"
state: absent
register: result
ignore_errors: true

- name: List all PCs
nutanix.ncp.ntnx_pc_config_info_v2:
register: result
ignore_errors: true

- name: Set PC external ID and name
ansible.builtin.set_fact:
pc_external_id: "{{ result.response[0].ext_id }}"
pc_name: "{{ result.response[0].config.name }}"

- name: List all PCs with filter
nutanix.ncp.ntnx_pc_config_info_v2:
filter: name eq '{{ pc_name }}'
register: result
ignore_errors: true

- name: List all PCs with limit
nutanix.ncp.ntnx_pc_config_info_v2:
limit: 1
register: result
ignore_errors: true

- name: Fetch PC details using external ID
nutanix.ncp.ntnx_pc_config_info_v2:
ext_id: "{{ pc_external_id }}"
register: result
ignore_errors: true
10 changes: 10 additions & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,13 @@ action_groups:
- ntnx_storage_containers_stats_v2
- ntnx_storage_containers_info_v2
- ntnx_storage_containers_v2
- ntnx_pc_unregistration_v2
- ntnx_pc_backup_target_info_v2
- ntnx_pc_backup_target_v2
- ntnx_pc_config_info_v2
- ntnx_pc_deploy_v2
- ntnx_pc_restore_v2
- ntnx_pc_restore_source_info_v2
- ntnx_pc_restore_source_v2
- ntnx_pc_restorable_domain_managers_info_v2
- ntnx_pc_restore_points_info_v2
31 changes: 31 additions & 0 deletions plugins/module_utils/v4/pe/base_info_module.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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 BasePEModule

__metaclass__ = type


class BaseInfoModule(BasePEModule):
"""
Base Info module class for Nutanix PC v4 list APIs based modules
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Base Info module class for Nutanix PC v4 list APIs based modules
Base Info module class for Nutanix PE v4 list APIs based modules

"""

info_argument_spec = dict(
filter=dict(type="str"),
page=dict(type="int"),
limit=dict(type="int"),
orderby=dict(type="str"),
select=dict(type="str"),
)

def __init__(self, skip_info_args=False, **kwargs):
self.argument_spec = deepcopy(BasePEModule.argument_spec)
self.argument_spec.pop("state")
self.argument_spec.pop("wait")
if not skip_info_args:
self.argument_spec.update(self.info_argument_spec)
super(BaseInfoModule, self).__init__(**kwargs)
60 changes: 60 additions & 0 deletions plugins/module_utils/v4/pe/base_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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 ansible.module_utils.basic import AnsibleModule, env_fallback

__metaclass__ = type


class BasePEModule(AnsibleModule):
"""Basic module with common arguments for PE"""

unsupported_spec_keys = ["obj"]
argument_spec = dict(
nutanix_host_pe=dict(
type="str", fallback=(env_fallback, ["NUTANIX_PE_HOST"]), required=True
),
nutanix_port=dict(
default="9440", type="str", fallback=(env_fallback, ["NUTANIX_PORT"])
),
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"),
wait=dict(type="bool", default=True),
)

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

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

super(BasePEModule, self).__init__(**kwargs)

def strip_extra_attributes(self, argument_spec):
"""
This recursive method checks argument spec and remove extra spec definations which are not allowed in ansible
"""
for spec in argument_spec.values():
for k in self.unsupported_spec_keys:
spec.pop(k, None)
if spec.get("options"):
self.strip_extra_attributes(spec["options"])
98 changes: 98 additions & 0 deletions plugins/module_utils/v4/prism/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from __future__ import absolute_import, division, print_function

__metaclass__ = type

from ..utils import raise_api_exception # noqa: E402


def get_restore_source(module, api_instance, ext_id):
"""
This method will return restore source info using external ID.
Args:
module: Ansible module
api_instance: DomainManagerBackupApi instance from ntnx_prism_py_client sdk
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
api_instance: DomainManagerBackupApi instance from ntnx_prism_py_client sdk
api_instance: DomainManagerBackupsApi instance from ntnx_prism_py_client sdk

ext_id (str): restore source info external ID
return:
restore_source_info (object): restore source info
"""
try:
return api_instance.get_restore_source_by_id(extId=ext_id).data
except Exception as e:
raise_api_exception(
module=module,
exception=e,
msg="Api Exception raised while fetching restore source info using ext_id",
)


def get_backup_target(module, api_instance, ext_id):
"""
This method will return backup target info using external ID.
Args:
module: Ansible module
api_instance: DomainManagerBackupApi instance from ntnx_prism_py_client sdk
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
api_instance: DomainManagerBackupApi instance from ntnx_prism_py_client sdk
api_instance: DomainManagerBackupsApi instance from ntnx_prism_py_client sdk

ext_id (str): backup target info external ID
return:
backup_target_info (object): backup target info
"""
domain_manager_ext_id = module.params.get("domain_manager_ext_id")
try:
return api_instance.get_backup_target_by_id(
extId=ext_id, domainManagerExtId=domain_manager_ext_id
).data
except Exception as e:
raise_api_exception(
module=module,
exception=e,
msg="Api Exception raised while fetching backup target info using ext_id and domain_manager_ext_id",
)


def get_pc_config(module, api_instance, ext_id):
"""
This method will return pc config info using external ID.
Args:
module: Ansible module
api_instance: DomainManagerBackupApi instance from ntnx_prism_py_client sdk
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
api_instance: DomainManagerBackupApi instance from ntnx_prism_py_client sdk
api_instance: DomainManagerBackupsApi instance from ntnx_prism_py_client sdk

ext_id (str): pc external ID
return:
pc_config_info (object): pc config info
"""
try:
return api_instance.get_domain_manager_by_id(extId=ext_id).data
except Exception as e:
raise_api_exception(
module=module,
exception=e,
msg="Api Exception raised while fetching pc config info using ext_id",
)


def get_restore_point(
module,
api_instance,
ext_id,
restore_source_ext_id,
restorable_domain_manager_ext_id,
):
"""
This method will return restore point info using external ID.
Args:
module: Ansible module
api_instance: DomainManagerBackupApi instance from ntnx_prism_py_client sdk
ext_id (str): restore point info external ID
return:
restore_point_info (object): restore point info
"""
try:
return api_instance.get_restore_point_by_id(
restoreSourceExtId=restore_source_ext_id,
restorableDomainManagerExtId=restorable_domain_manager_ext_id,
extId=ext_id,
).data
except Exception as e:
raise_api_exception(
module=module,
exception=e,
msg="Api Exception raised while fetching restore point info using ext_id",
)
12 changes: 12 additions & 0 deletions plugins/module_utils/v4/prism/pc_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,15 @@ def get_domain_manager_api_instance(module):
"""
api_client = get_pc_api_client(module)
return ntnx_prism_py_client.DomainManagerApi(api_client=api_client)


def get_domain_manager_backup_api_instance(module):
"""
This method will return domain manager backup api instance.
Args:
module (object): Ansible module object
return:
api_instance (object): domain manager backup api instance
"""
api_client = get_pc_api_client(module)
return ntnx_prism_py_client.DomainManagerBackupsApi(api_client=api_client)
Loading
Loading