Skip to content

Commit b6958ac

Browse files
Module for Storage domain and Policy update
1 parent fa8f0fd commit b6958ac

File tree

5 files changed

+488
-89
lines changed

5 files changed

+488
-89
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
.. _cohesity_storage_domain_module:
2+
3+
4+
cohesity_storage_domain -- Management of Cohesity Storage Domains.
5+
==================================================================
6+
7+
.. contents::
8+
:local:
9+
:depth: 1
10+
11+
12+
Synopsis
13+
--------
14+
15+
Ansible Module used to create or remove a storage domain from a Cohesity Cluster.
16+
17+
When executed in a playbook the appropriate state action will be applied.
18+
19+
20+
21+
22+
23+
24+
Parameters
25+
----------
26+
27+
cluster (optional, str, None)
28+
IP or FQDN for the Cohesity Cluster
29+
30+
31+
cohesity_admin (optional, str, None)
32+
Username with which Ansible will connect to the Cohesity Cluster. Domain Specific credentails can be configured in following formats
33+
34+
AD.domain.com/username
35+
36+
AD.domain.com/username@tenant
37+
38+
LOCAL/username@tenant
39+
40+
41+
cohesity_password (optional, str, None)
42+
Password belonging to the selected Username. This parameter will not be logged.
43+
44+
45+
ad_domain_name (False, str, None)
46+
Specifies the active directory name that the view box is mapped to.
47+
48+
49+
cluster_partition_id (optional, int, 3)
50+
The Cluster Partition id where the Storage Domain (View Box) will be created.
51+
52+
53+
state (optional, str, present)
54+
Determines the state of the storage domain.
55+
56+
57+
cluster_partition_name (optional, str, DefaultPartition)
58+
Name of the cluster partition where the Storage Domain (View Box) will be created.
59+
60+
61+
default_view_quota (optional, str, False)
62+
Specifies an optional default logical quota limit (in bytes) for the Views in this Storage Domain (View Box).
63+
64+
65+
kms_Server_id (optional, str, None)
66+
Specifies the associated KMS Server ID.
67+
68+
69+
validate_certs (optional, bool, True)
70+
Switch determines if SSL Validation should be enabled.
71+
72+
73+
ldap_provider_id (optional, str, None)
74+
When set, the following provides the LDAP provider the view box is mapped to.
75+
76+
77+
storage_policy (optional, dict, None)
78+
Specifies the storage options applied to the Storage Domain (View Box).
79+
80+
Supports keys duplicate and compression\_policy.
81+
82+
83+
erasure_coding_params (optional, dict, None)
84+
Specifies information for erasure coding.
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
Examples
95+
--------
96+
97+
.. code-block:: yaml+jinja
98+
99+
100+
# Create a view box in the cohesity cluster.
101+
- cohesity_storage_domain:
102+
server: cohesity.lab
103+
username: admin
104+
password: password
105+
name: Custom
106+
partition_name: DefaultPartition
107+
state: present
108+
109+
# Remove a viewbox from the cohesity cluster.
110+
- cohesity_storage_domain:
111+
server: cohesity.lab
112+
username: admin
113+
password: password
114+
name: Custom
115+
state: absent
116+
117+
118+
119+
120+
121+
Status
122+
------
123+
124+
125+
126+
127+
128+
Authors
129+
~~~~~~~
130+
131+
- Naveena (@naveena-maplelabs)
132+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Playbook to create storage domain (view-box).
2+
---
3+
- hosts: localhost
4+
become: false
5+
collections:
6+
- cohesity.dataprotect
7+
tasks:
8+
- name: Create view box in the cohesity server.
9+
cohesity_storage_domain:
10+
cluster: "{{ cohesity_server }}"
11+
username: "{{ cohesity_username }}"
12+
password: "{{ cohesity_password }}"
13+
validate_certs: "{{ cohesity_validate_certs }}"
14+
name: 'Ansible'
15+
state: 'present'
16+
cluster_partition_id: 3
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Playbook to delete a storage domain (view-box).
2+
---
3+
- hosts: localhost
4+
become: false
5+
collections:
6+
- cohesity.dataprotect
7+
tasks:
8+
- name: Create view box in the cohesity server.
9+
cohesity_storage_domain:
10+
cluster: "{{ cohesity_server }}"
11+
username: "{{ cohesity_username }}"
12+
password: "{{ cohesity_password }}"
13+
validate_certs: "{{ cohesity_validate_certs }}"
14+
name: 'Ansible'
15+
state: 'absent'
16+

plugins/modules/cohesity_policy.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,81 @@ def create_policy(module):
457457
raise__cohesity_exception__handler(error, module)
458458

459459

460+
461+
def update_policy(module, policy):
462+
"""
463+
Function to update a protection policy.
464+
:param module: object that holds parameters passed to the module
465+
:param policy: existing policy object.
466+
:return:
467+
"""
468+
try:
469+
policy = ProtectionPolicyRequest()
470+
policy.name = module.params.get("name")
471+
policy.description = module.params.get("description")
472+
policy.days_to_keep = module.params.get("days_to_retain")
473+
policy.retries = module.params.get("retries")
474+
policy.retry_interval_mins = module.params.get("retry_interval")
475+
if module.params.get("blackout_window"):
476+
policy.blackout_periods = blackout_window(module)
477+
478+
if module.params.get("incremental_backup_schedule"):
479+
policy.incremental_scheduling_policy = policy_schedule(
480+
module, module.params.get("incremental_backup_schedule")
481+
)
482+
483+
if module.params.get("full_backup_schedule"):
484+
policy.full_scheduling_policy = policy_schedule(
485+
module, module.params.get("full_backup_schedule")
486+
)
487+
488+
if module.params.get("log_backup_schedule"):
489+
policy.log_scheduling_policy = policy_schedule(
490+
module, module.params.get("log_backup_schedule")
491+
)
492+
policy.days_to_keep_log = module.params.get(
493+
"log_backup_schedule"
494+
).get("days_to_retain", module.params.get("days_to_retain"))
495+
496+
if module.params.get("bmr_backup_schedule"):
497+
policy.system_scheduling_policy = policy_schedule(
498+
module, module.params.get("bmr_backup_schedule")
499+
)
500+
policy.days_to_keep_system = module.params.get(
501+
"bmr_backup_schedule"
502+
).get("days_to_retain", module.params.get("days_to_retain"))
503+
504+
if module.params.get("extended_retention"):
505+
policy.extended_retention_policies = extended_retention(module)
506+
507+
if module.params.get("replication_copy"):
508+
policy.snapshot_replication_copy_policies = (
509+
replication_copy_policies(module)
510+
)
511+
if module.params.get("archival_copy"):
512+
policy.snapshot_archival_copy_policies = archival_copy_policies(
513+
module
514+
)
515+
516+
policy_response = cohesity_client.protection_policies.update_protection_policy(
517+
policy, policy.id
518+
)
519+
520+
result = dict(
521+
changed=True,
522+
msg="Cohesity protection policy is updated successfully",
523+
id=policy_response.id,
524+
task_name=module.params.get("name"),
525+
)
526+
module.exit_json(**result)
527+
except APIException as ex:
528+
raise__cohesity_exception__handler(
529+
str(json.loads(ex.context.response.raw_body)), module
530+
)
531+
except Exception as error:
532+
raise__cohesity_exception__handler(error, module)
533+
534+
460535
def delete_policy(module, policy_id):
461536
"""
462537
function to delete the protection policy
@@ -569,6 +644,7 @@ def main():
569644
module.exit_json(**check_mode_results)
570645

571646
elif module.params.get("state") == "present":
647+
update_policy = update_policy(module, policy_details)
572648
if policy_exists:
573649
results = dict(
574650
changed=False,

0 commit comments

Comments
 (0)