-
Notifications
You must be signed in to change notification settings - Fork 42
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
base: release/2.0
Are you sure you want to change the base?
Changes from all commits
867b387
0394d81
0387f28
d6ffd3d
b0acff4
2bc15e5
d81d61d
073389f
5c3fae8
d169bd8
74224a9
38cb689
1f4a5d9
eecdd5b
fa2d2f2
eee301d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
""" | ||||||
|
||||||
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) |
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"]) |
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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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", | ||||||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this file