Skip to content

Commit 6a71ad9

Browse files
committed
add volume snapshot policy
1 parent 3328a1f commit 6a71ad9

File tree

4 files changed

+185
-2
lines changed

4 files changed

+185
-2
lines changed

plugins/modules/volume_snapshot_policy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@
3232
- ROOT
3333
vm:
3434
description:
35-
- Name of the instance to select the volume from.
35+
- Name of the VM/instance to select the volume from.
3636
- Use I(volume_type) if VM has a DATADISK and ROOT volume.
3737
- In case of I(volume_type=DATADISK), additionally use I(device_id) if VM has more than one DATADISK volume.
3838
- Either I(volume) or I(vm) is required.
3939
type: str
40+
aliases: [ instance ]
4041
device_id:
4142
description:
4243
- ID of the device on a VM the volume is attached to.
@@ -307,7 +308,7 @@ def main():
307308
dict(
308309
volume=dict(),
309310
volume_type=dict(choices=["DATADISK", "ROOT"]),
310-
vm=dict(),
311+
vm=dict(type="str", aliases=["instance"]),
311312
device_id=dict(type="int"),
312313
vpc=dict(),
313314
interval_type=dict(default="daily", choices=["hourly", "daily", "weekly", "monthly"], aliases=["interval"]),
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cloud/cs
2+
shippable/cs/group2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
dependencies:
3+
- cs_common
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
---
2+
- name: setup instance
3+
ngine_io.cloudstack.instance:
4+
name: "{{ cs_resource_prefix }}-vm-snapshot-policy"
5+
template: "{{ cs_common_template }}"
6+
zone: "{{ cs_common_zone_adv }}"
7+
service_offering: "{{ cs_common_service_offering }}"
8+
register: instance
9+
- name: verify setup instance
10+
assert:
11+
that:
12+
- instance is successful
13+
14+
- name: setup snapshot policy absent
15+
ngine_io.cloudstack.volume_snapshot_policy:
16+
vm: "{{ cs_resource_prefix }}-vm-snapshot-policy"
17+
interval_type: hourly
18+
state: absent
19+
register: snapshot
20+
- name: verify setup snapshot policy absent
21+
assert:
22+
that:
23+
- snapshot is successful
24+
25+
- name: create snapshot policy in check mode
26+
ngine_io.cloudstack.volume_snapshot_policy:
27+
vm: "{{ cs_resource_prefix }}-vm-snapshot-policy"
28+
interval_type: hourly
29+
schedule: 5
30+
check_mode: true
31+
register: snapshot
32+
- name: verify create snapshot policy in check mode
33+
assert:
34+
that:
35+
- snapshot is changed
36+
37+
- name: create snapshot policy
38+
ngine_io.cloudstack.volume_snapshot_policy:
39+
vm: "{{ cs_resource_prefix }}-vm-snapshot-policy"
40+
interval_type: hourly
41+
schedule: 5
42+
register: snapshot
43+
- name: verify create snapshot policy
44+
assert:
45+
that:
46+
- snapshot is changed
47+
- snapshot.schedule == "5"
48+
- snapshot.interval_type == "hourly"
49+
- snapshot.volume != ""
50+
51+
- name: create snapshot policy idempotence
52+
ngine_io.cloudstack.volume_snapshot_policy:
53+
vm: "{{ cs_resource_prefix }}-vm-snapshot-policy"
54+
interval_type: hourly
55+
schedule: 5
56+
register: snapshot
57+
- name: verify create snapshot policy idempotence
58+
assert:
59+
that:
60+
- snapshot is not changed
61+
- snapshot.schedule == "5"
62+
- snapshot.interval_type == "hourly"
63+
- snapshot.volume != ""
64+
65+
- name: update snapshot policy
66+
ngine_io.cloudstack.volume_snapshot_policy:
67+
vm: "{{ cs_resource_prefix }}-vm-snapshot-policy"
68+
interval_type: hourly
69+
schedule: 6
70+
check_mode: true
71+
register: snapshot
72+
- name: verify update snapshot policy
73+
assert:
74+
that:
75+
- snapshot is changed
76+
- snapshot.schedule == "5"
77+
- snapshot.interval_type == "hourly"
78+
- snapshot.volume != ""
79+
80+
- name: update snapshot policy in check mode
81+
ngine_io.cloudstack.volume_snapshot_policy:
82+
vm: "{{ cs_resource_prefix }}-vm-snapshot-policy"
83+
interval_type: hourly
84+
schedule: 6
85+
max_snaps: 3
86+
time_zone: "Europe/Zurich"
87+
check_mode: true
88+
register: snapshot
89+
- name: verify update snapshot policy in check mode
90+
assert:
91+
that:
92+
- snapshot is changed
93+
- snapshot.schedule == "5"
94+
- snapshot.interval_type == "hourly"
95+
- snapshot.volume != ""
96+
- snapshot.max_snaps == 8
97+
- snapshot.time_zone == "UTC"
98+
99+
- name: update snapshot policy
100+
ngine_io.cloudstack.volume_snapshot_policy:
101+
vm: "{{ cs_resource_prefix }}-vm-snapshot-policy"
102+
interval_type: hourly
103+
schedule: 6
104+
max_snaps: 3
105+
time_zone: "Europe/Zurich"
106+
register: snapshot
107+
- name: verify update snapshot policy
108+
assert:
109+
that:
110+
- snapshot is changed
111+
- snapshot.schedule == "6"
112+
- snapshot.interval_type == "hourly"
113+
- snapshot.volume != ""
114+
- snapshot.max_snaps == 3
115+
- snapshot.time_zone == "Europe/Zurich"
116+
117+
- name: update snapshot policy idempotence
118+
ngine_io.cloudstack.volume_snapshot_policy:
119+
vm: "{{ cs_resource_prefix }}-vm-snapshot-policy"
120+
interval_type: hourly
121+
schedule: 6
122+
max_snaps: 3
123+
time_zone: "Europe/Zurich"
124+
register: snapshot
125+
- name: verify update snapshot policy idempotence
126+
assert:
127+
that:
128+
- snapshot is not changed
129+
- snapshot.schedule == "6"
130+
- snapshot.interval_type == "hourly"
131+
- snapshot.volume != ""
132+
- snapshot.max_snaps == 3
133+
- snapshot.time_zone == "Europe/Zurich"
134+
135+
- name: remove snapshot policy in check mode
136+
ngine_io.cloudstack.volume_snapshot_policy:
137+
vm: "{{ cs_resource_prefix }}-vm-snapshot-policy"
138+
interval_type: hourly
139+
state: absent
140+
check_mode: true
141+
register: snapshot
142+
- name: verify remove snapshot policy in check mode
143+
assert:
144+
that:
145+
- snapshot is changed
146+
- snapshot.schedule == "6"
147+
- snapshot.interval_type == "hourly"
148+
- snapshot.volume != ""
149+
- snapshot.max_snaps == 3
150+
- snapshot.time_zone == "Europe/Zurich"
151+
152+
- name: remove snapshot policy
153+
ngine_io.cloudstack.volume_snapshot_policy:
154+
vm: "{{ cs_resource_prefix }}-vm-snapshot-policy"
155+
interval_type: hourly
156+
state: absent
157+
register: snapshot
158+
- name: verify remove snapshot policy
159+
assert:
160+
that:
161+
- snapshot is changed
162+
- snapshot.schedule == "6"
163+
- snapshot.interval_type == "hourly"
164+
- snapshot.volume != ""
165+
- snapshot.max_snaps == 3
166+
- snapshot.time_zone == "Europe/Zurich"
167+
168+
- name: remove snapshot policy idempotence
169+
ngine_io.cloudstack.volume_snapshot_policy:
170+
vm: "{{ cs_resource_prefix }}-vm-snapshot-policy"
171+
interval_type: hourly
172+
state: absent
173+
register: snapshot
174+
- name: verify remove snapshot policy idempotence
175+
assert:
176+
that:
177+
- snapshot is not changed

0 commit comments

Comments
 (0)