| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from __future__ import absolute_import, division, print_function |
| 6 |
|
| 7 |
__metaclass__ = type |
| 8 |
|
| 9 |
DOCUMENTATION = """ |
| 10 |
module: na_santricity_snapshot |
| 11 |
short_description: NetApp E-Series storage system's snapshots. |
| 12 |
description: Manage NetApp E-Series manage the storage system's snapshots. |
| 13 |
author: |
| 14 |
- Nathan Swartz (@swartzn) |
| 15 |
- Vu Tran (@VuTran007) |
| 16 |
extends_documentation_fragment: |
| 17 |
- netapp_eseries.santricity.santricity.santricity_doc |
| 18 |
options: |
| 19 |
state: |
| 20 |
description: |
| 21 |
- When I(state==absent) ensures the I(type) has been removed. |
| 22 |
- When I(state==present) ensures the I(type) is available. |
| 23 |
- When I(state==rollback) the consistency group will be rolled back to the point-in-time snapshot images selected by I(pit_name or pit_timestamp). |
| 24 |
- I(state==rollback) will always return changed since it is not possible to evaluate the current state of the base volume in relation to a snapshot image. |
| 25 |
type: str |
| 26 |
choices: |
| 27 |
- absent |
| 28 |
- present |
| 29 |
- rollback |
| 30 |
default: present |
| 31 |
required: false |
| 32 |
type: |
| 33 |
description: |
| 34 |
- Type of snapshot object to effect. |
| 35 |
- Group indicates a snapshot consistency group; consistency groups may have one or more base volume members which are defined in I(volumes). |
| 36 |
- Pit indicates a snapshot consistency group point-in-time image(s); a snapshot image will be taken of each base volume when I(state==present). |
| 37 |
- Warning! When I(state==absent and type==pit), I(pit_name) or I(pit_timestamp) must be defined and all point-in-time images created prior to the |
| 38 |
selection will also be deleted. |
| 39 |
- View indicates a consistency group snapshot volume of particular point-in-time image(s); snapshot volumes will be created for each base volume member. |
| 40 |
- Views are created from images from a single point-in-time so once created they cannot be modified. |
| 41 |
type: str |
| 42 |
default: group |
| 43 |
choices: |
| 44 |
- group |
| 45 |
- pit |
| 46 |
- view |
| 47 |
required: false |
| 48 |
group_name: |
| 49 |
description: |
| 50 |
- Name of the snapshot consistency group or snapshot volume. |
| 51 |
- Be sure to use different names for snapshot consistency groups and snapshot volumes to avoid name conflicts. |
| 52 |
type: str |
| 53 |
required: true |
| 54 |
volumes: |
| 55 |
description: |
| 56 |
- Details for each consistency group base volume for defining reserve capacity, preferred reserve capacity storage pool, and snapshot volume options. |
| 57 |
- When I(state==present and type==group) the volume entries will be used to add or remove base volume from a snapshot consistency group. |
| 58 |
- When I(state==present and type==view) the volume entries will be used to select images from a point-in-time for their respective snapshot volumes. |
| 59 |
- If I(state==present and type==view) and I(volume) is not specified then all volumes will be selected with the defaults. |
| 60 |
- Views are created from images from a single point-in-time so once created they cannot be modified. |
| 61 |
- When I(state==rollback) then I(volumes) can be used to specify which base volumes to rollback; otherwise all consistency group volumes will rollback. |
| 62 |
type: list |
| 63 |
elements: dict |
| 64 |
required: false |
| 65 |
suboptions: |
| 66 |
volume: |
| 67 |
description: |
| 68 |
- Base volume for consistency group. |
| 69 |
type: str |
| 70 |
required: true |
| 71 |
reserve_capacity_pct: |
| 72 |
description: |
| 73 |
- Percentage of base volume capacity to reserve for snapshot copy-on-writes (COW). |
| 74 |
- Used to define reserve capacity for both snapshot consistency group volume members and snapshot volumes. |
| 75 |
type: int |
| 76 |
default: 40 |
| 77 |
required: false |
| 78 |
preferred_reserve_storage_pool: |
| 79 |
description: |
| 80 |
- Preferred storage pool or volume group for the reserve capacity volume. |
| 81 |
- The base volume's storage pool or volume group will be selected by default if not defined. |
| 82 |
- Used to specify storage pool or volume group for both snapshot consistency group volume members and snapshot volumes |
| 83 |
type: str |
| 84 |
required: false |
| 85 |
snapshot_volume_writable: |
| 86 |
description: |
| 87 |
- Whether snapshot volume of base volume images should be writable. |
| 88 |
type: bool |
| 89 |
default: true |
| 90 |
required: false |
| 91 |
snapshot_volume_validate: |
| 92 |
description: |
| 93 |
- Whether snapshot volume should be validated which includes both a media scan and parity validation. |
| 94 |
type: bool |
| 95 |
default: false |
| 96 |
required: false |
| 97 |
snapshot_volume_host: |
| 98 |
description: |
| 99 |
- Host or host group to map snapshot volume. |
| 100 |
type: str |
| 101 |
required: false |
| 102 |
snapshot_volume_lun: |
| 103 |
description: |
| 104 |
- LUN ID for snapshot volume. |
| 105 |
type: int |
| 106 |
required: false |
| 107 |
maximum_snapshots: |
| 108 |
description: |
| 109 |
- Total number of snapshot images to maintain. |
| 110 |
type: int |
| 111 |
default: 32 |
| 112 |
required: false |
| 113 |
reserve_capacity_pct: |
| 114 |
description: |
| 115 |
- Default percentage of base volume capacity to reserve for snapshot copy-on-writes (COW). |
| 116 |
- Used to define reserve capacity for both snapshot consistency group volume members and snapshot volumes. |
| 117 |
type: int |
| 118 |
default: 40 |
| 119 |
required: false |
| 120 |
preferred_reserve_storage_pool: |
| 121 |
description: |
| 122 |
- Default preferred storage pool or volume group for the reserve capacity volume. |
| 123 |
- The base volume's storage pool or volume group will be selected by default if not defined. |
| 124 |
- Used to specify storage pool or volume group for both snapshot consistency group volume members and snapshot volumes |
| 125 |
type: str |
| 126 |
required: false |
| 127 |
alert_threshold_pct: |
| 128 |
description: |
| 129 |
- Percent of filled reserve capacity to issue alert. |
| 130 |
type: int |
| 131 |
default: 75 |
| 132 |
required: false |
| 133 |
reserve_capacity_full_policy: |
| 134 |
description: |
| 135 |
- Policy for full reserve capacity. |
| 136 |
- Purge deletes the oldest snapshot image for the base volume in the consistency group. |
| 137 |
- Reject writes to base volume (keep snapshot images valid). |
| 138 |
choices: |
| 139 |
- purge |
| 140 |
- reject |
| 141 |
type: str |
| 142 |
default: purge |
| 143 |
required: false |
| 144 |
rollback_priority: |
| 145 |
description: |
| 146 |
- Storage system priority given to restoring snapshot point in time. |
| 147 |
type: str |
| 148 |
choices: |
| 149 |
- highest |
| 150 |
- high |
| 151 |
- medium |
| 152 |
- low |
| 153 |
- lowest |
| 154 |
default: medium |
| 155 |
required: false |
| 156 |
rollback_backup: |
| 157 |
description: |
| 158 |
- Whether a point-in-time snapshot should be taken prior to performing a rollback. |
| 159 |
type: bool |
| 160 |
default: true |
| 161 |
required: false |
| 162 |
pit_name: |
| 163 |
description: |
| 164 |
- Name of a consistency group's snapshot images. |
| 165 |
type: str |
| 166 |
required: false |
| 167 |
pit_description: |
| 168 |
description: |
| 169 |
- Arbitrary description for a consistency group's snapshot images |
| 170 |
type: str |
| 171 |
required: false |
| 172 |
pit_timestamp: |
| 173 |
description: |
| 174 |
- Snapshot image timestamp in the YYYY-MM-DD HH:MM:SS (AM|PM) (hours, minutes, seconds, and day-period are optional) |
| 175 |
- Define only as much time as necessary to distinguish the desired snapshot image from the others. |
| 176 |
- 24 hour time will be assumed if day-period indicator (AM, PM) is not specified. |
| 177 |
- The terms latest and oldest may be used to select newest and oldest consistency group images. |
| 178 |
- Mutually exclusive with I(pit_name or pit_description) |
| 179 |
type: str |
| 180 |
required: false |
| 181 |
view_name: |
| 182 |
description: |
| 183 |
- Consistency group snapshot volume group. |
| 184 |
- Required when I(state==volume) or when ensuring the views absence when I(state==absent). |
| 185 |
type: str |
| 186 |
required: false |
| 187 |
view_host: |
| 188 |
description: |
| 189 |
- Default host or host group to map snapshot volumes. |
| 190 |
type: str |
| 191 |
required: false |
| 192 |
view_writable: |
| 193 |
description: |
| 194 |
- Default whether snapshot volumes should be writable. |
| 195 |
type: bool |
| 196 |
default: true |
| 197 |
required: false |
| 198 |
view_validate: |
| 199 |
description: |
| 200 |
- Default whether snapshop volumes should be validated. |
| 201 |
type: bool |
| 202 |
default: false |
| 203 |
required: false |
| 204 |
notes: |
| 205 |
- Key-value pairs are used to keep track of snapshot names and descriptions since the snapshot point-in-time images do have metadata associated with their |
| 206 |
data structures; therefore, it is necessary to clean out old keys that are no longer associated with an actual image. This cleaning action is performed each |
| 207 |
time this module is executed. |
| 208 |
""" |
| 209 |
EXAMPLES = """ |
| 210 |
- name: Ensure snapshot consistency group exists. |
| 211 |
na_santricity_snapshot: |
| 212 |
ssid: "1" |
| 213 |
api_url: https://192.168.1.100:8443/devmgr/v2 |
| 214 |
api_username: admin |
| 215 |
api_password: adminpass |
| 216 |
state: present |
| 217 |
type: group |
| 218 |
group_name: snapshot_group1 |
| 219 |
volumes: |
| 220 |
- volume: vol1 |
| 221 |
reserve_capacity_pct: 20 |
| 222 |
preferred_reserve_storage_pool: vg1 |
| 223 |
- volume: vol2 |
| 224 |
reserve_capacity_pct: 30 |
| 225 |
- volume: vol3 |
| 226 |
alert_threshold_pct: 80 |
| 227 |
maximum_snapshots: 30 |
| 228 |
- name: Take the current consistency group's base volumes point-in-time snapshot images. |
| 229 |
na_santricity_snapshot: |
| 230 |
ssid: "1" |
| 231 |
api_url: https://192.168.1.100:8443/devmgr/v2 |
| 232 |
api_username: admin |
| 233 |
api_password: adminpass |
| 234 |
state: present |
| 235 |
type: pit |
| 236 |
group_name: snapshot_group1 |
| 237 |
pit_name: pit1 |
| 238 |
pit_description: Initial consistency group's point-in-time snapshot images. |
| 239 |
- name: Ensure snapshot consistency group view exists and is mapped to host group. |
| 240 |
na_santricity_snapshot: |
| 241 |
ssid: "1" |
| 242 |
api_url: https://192.168.1.100:8443/devmgr/v2 |
| 243 |
api_username: admin |
| 244 |
api_password: adminpass |
| 245 |
state: present |
| 246 |
type: view |
| 247 |
group_name: snapshot_group1 |
| 248 |
pit_name: pit1 |
| 249 |
view_name: view1 |
| 250 |
view_host: view1_hosts_group |
| 251 |
volumes: |
| 252 |
- volume: vol1 |
| 253 |
reserve_capacity_pct: 20 |
| 254 |
preferred_reserve_storage_pool: vg4 |
| 255 |
snapshot_volume_writable: false |
| 256 |
snapshot_volume_validate: true |
| 257 |
- volume: vol2 |
| 258 |
reserve_capacity_pct: 20 |
| 259 |
preferred_reserve_storage_pool: vg4 |
| 260 |
snapshot_volume_writable: true |
| 261 |
snapshot_volume_validate: true |
| 262 |
- volume: vol3 |
| 263 |
reserve_capacity_pct: 20 |
| 264 |
preferred_reserve_storage_pool: vg4 |
| 265 |
snapshot_volume_writable: false |
| 266 |
snapshot_volume_validate: true |
| 267 |
alert_threshold_pct: 80 |
| 268 |
maximum_snapshots: 30 |
| 269 |
- name: Rollback base volumes to consistency group's point-in-time pit1. |
| 270 |
na_santricity_snapshot: |
| 271 |
ssid: "1" |
| 272 |
api_url: https://192.168.1.100:8443/devmgr/v2 |
| 273 |
api_username: admin |
| 274 |
api_password: adminpass |
| 275 |
state: present |
| 276 |
type: group |
| 277 |
group_name: snapshot_group1 |
| 278 |
pit_name: pit1 |
| 279 |
rollback: true |
| 280 |
rollback_priority: high |
| 281 |
- name: Ensure snapshot consistency group view no longer exists. |
| 282 |
na_santricity_snapshot: |
| 283 |
ssid: "1" |
| 284 |
api_url: https://192.168.1.100:8443/devmgr/v2 |
| 285 |
api_username: admin |
| 286 |
api_password: adminpass |
| 287 |
state: absent |
| 288 |
type: view |
| 289 |
group_name: snapshot_group1 |
| 290 |
view_name: view1 |
| 291 |
- name: Ensure that the consistency group's base volumes point-in-time snapshot images pit1 no longer exists. |
| 292 |
na_santricity_snapshot: |
| 293 |
ssid: "1" |
| 294 |
api_url: https://192.168.1.100:8443/devmgr/v2 |
| 295 |
api_username: admin |
| 296 |
api_password: adminpass |
| 297 |
state: absent |
| 298 |
type: image |
| 299 |
group_name: snapshot_group1 |
| 300 |
pit_name: pit1 |
| 301 |
- name: Ensure snapshot consistency group no longer exists. |
| 302 |
na_santricity_snapshot: |
| 303 |
ssid: "1" |
| 304 |
api_url: https://192.168.1.100:8443/devmgr/v2 |
| 305 |
api_username: admin |
| 306 |
api_password: adminpass |
| 307 |
state: absent |
| 308 |
type: group |
| 309 |
group_name: snapshot_group1 |
| 310 |
""" |
| 311 |
RETURN = """ |
| 312 |
changed: |
| 313 |
description: Whether changes have been made. |
| 314 |
type: bool |
| 315 |
returned: always |
| 316 |
group_changes: |
| 317 |
description: All changes performed to the consistency group. |
| 318 |
type: dict |
| 319 |
returned: always |
| 320 |
deleted_metadata_keys: |
| 321 |
description: Keys that were purged from the key-value datastore. |
| 322 |
type: list |
| 323 |
returned: always |
| 324 |
""" |
| 325 |
from datetime import datetime |
| 326 |
import re |
| 327 |
from time import sleep |
| 328 |
|
| 329 |
from ansible_collections.netapp_eseries.santricity.plugins.module_utils.santricity import NetAppESeriesModule |
| 330 |
|
| 331 |
|
| 332 |
class NetAppESeriesSnapshot(NetAppESeriesModule): |
| 333 |
def __init__(self): |
| 334 |
ansible_options = dict(state=dict(type="str", default="present", choices=["absent", "present", "rollback"], required=False), |
| 335 |
type=dict(type="str", default="group", choices=["group", "pit", "view"], required=False), |
| 336 |
group_name=dict(type="str", required=True), |
| 337 |
volumes=dict(type="list", elements="dict", required=False, |
| 338 |
options=dict(volume=dict(type="str", required=True), |
| 339 |
reserve_capacity_pct=dict(type="int", default=40, required=False), |
| 340 |
preferred_reserve_storage_pool=dict(type="str", required=False), |
| 341 |
snapshot_volume_writable=dict(type="bool", default=True, required=False), |
| 342 |
snapshot_volume_validate=dict(type="bool", default=False, required=False), |
| 343 |
snapshot_volume_host=dict(type="str", default=None, required=False), |
| 344 |
snapshot_volume_lun=dict(type="int", default=None, required=False))), |
| 345 |
maximum_snapshots=dict(type="int", default=32, required=False), |
| 346 |
reserve_capacity_pct=dict(type="int", default=40, required=False), |
| 347 |
preferred_reserve_storage_pool=dict(type="str", required=False), |
| 348 |
alert_threshold_pct=dict(type="int", default=75, required=False), |
| 349 |
reserve_capacity_full_policy=dict(type="str", default="purge", choices=["purge", "reject"], required=False), |
| 350 |
rollback_priority=dict(type="str", default="medium", choices=["highest", "high", "medium", "low", "lowest"], required=False), |
| 351 |
rollback_backup=dict(type="bool", default=True, required=False), |
| 352 |
pit_name=dict(type="str", required=False), |
| 353 |
pit_description=dict(type="str", required=False), |
| 354 |
pit_timestamp=dict(type="str", required=False), |
| 355 |
view_name=dict(type="str", required=False), |
| 356 |
view_host=dict(type="str", default=None, required=False), |
| 357 |
view_writable=dict(type="bool", default=True, required=False), |
| 358 |
view_validate=dict(type="bool", default=False, required=False)) |
| 359 |
|
| 360 |
super(NetAppESeriesSnapshot, self).__init__(ansible_options=ansible_options, |
| 361 |
web_services_version="05.00.0000.0000", |
| 362 |
supports_check_mode=True) |
| 363 |
args = self.module.params |
| 364 |
self.state = args["state"] |
| 365 |
self.type = args["type"] |
| 366 |
self.group_name = args["group_name"] |
| 367 |
self.maximum_snapshots = args["maximum_snapshots"] |
| 368 |
self.reserve_capacity_pct = args["reserve_capacity_pct"] |
| 369 |
self.preferred_reserve_storage_pool = args["preferred_reserve_storage_pool"] |
| 370 |
self.alert_threshold_pct = args["alert_threshold_pct"] |
| 371 |
self.reserve_capacity_full_policy = "purgepit" if args["reserve_capacity_full_policy"] == "purge" else "failbasewrites" |
| 372 |
self.rollback_priority = args["rollback_priority"] |
| 373 |
self.rollback_backup = args["rollback_backup"] |
| 374 |
self.rollback_priority = args["rollback_priority"] |
| 375 |
self.pit_name = args["pit_name"] |
| 376 |
self.pit_description = args["pit_description"] |
| 377 |
self.view_name = args["view_name"] |
| 378 |
self.view_host = args["view_host"] |
| 379 |
self.view_writable = args["view_writable"] |
| 380 |
self.view_validate = args["view_validate"] |
| 381 |
|
| 382 |
|
| 383 |
self.volumes = {} |
| 384 |
if args["volumes"]: |
| 385 |
for volume_info in args["volumes"]: |
| 386 |
reserve_capacity_pct = volume_info["reserve_capacity_pct"] if "reserve_capacity_pct" in volume_info else self.reserve_capacity_pct |
| 387 |
snapshot_volume_writable = volume_info["snapshot_volume_writable"] if "snapshot_volume_writable" in volume_info else self.view_writable |
| 388 |
snapshot_volume_validate = volume_info["snapshot_volume_validate"] if "snapshot_volume_validate" in volume_info else self.view_validate |
| 389 |
snapshot_volume_host = volume_info["snapshot_volume_host"] if "snapshot_volume_host" in volume_info else self.view_host |
| 390 |
snapshot_volume_lun = volume_info["snapshot_volume_lun"] if "snapshot_volume_lun" in volume_info else None |
| 391 |
if "preferred_reserve_storage_pool" in volume_info and volume_info["preferred_reserve_storage_pool"]: |
| 392 |
preferred_reserve_storage_pool = volume_info["preferred_reserve_storage_pool"] |
| 393 |
else: |
| 394 |
preferred_reserve_storage_pool = self.preferred_reserve_storage_pool |
| 395 |
|
| 396 |
self.volumes.update({volume_info["volume"]: {"reserve_capacity_pct": reserve_capacity_pct, |
| 397 |
"preferred_reserve_storage_pool": preferred_reserve_storage_pool, |
| 398 |
"snapshot_volume_writable": snapshot_volume_writable, |
| 399 |
"snapshot_volume_validate": snapshot_volume_validate, |
| 400 |
"snapshot_volume_host": snapshot_volume_host, |
| 401 |
"snapshot_volume_lun": snapshot_volume_lun}}) |
| 402 |
|
| 403 |
|
| 404 |
self.pit_timestamp = None |
| 405 |
self.pit_timestamp_tokens = 0 |
| 406 |
if args["pit_timestamp"]: |
| 407 |
if args["pit_timestamp"] in ["newest", "oldest"]: |
| 408 |
self.pit_timestamp = args["pit_timestamp"] |
| 409 |
elif re.match("[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} (AM|PM|am|pm)", args["pit_timestamp"]): |
| 410 |
self.pit_timestamp = datetime.strptime(args["pit_timestamp"], "%Y-%m-%d %I:%M:%S %p") |
| 411 |
self.pit_timestamp_tokens = 6 |
| 412 |
elif re.match("[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2} (AM|PM|am|pm)", args["pit_timestamp"]): |
| 413 |
self.pit_timestamp = datetime.strptime(args["pit_timestamp"], "%Y-%m-%d %I:%M %p") |
| 414 |
self.pit_timestamp_tokens = 5 |
| 415 |
elif re.match("[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2} (AM|PM|am|pm)", args["pit_timestamp"]): |
| 416 |
self.pit_timestamp = datetime.strptime(args["pit_timestamp"], "%Y-%m-%d %I %p") |
| 417 |
self.pit_timestamp_tokens = 4 |
| 418 |
elif re.match("[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}", args["pit_timestamp"]): |
| 419 |
self.pit_timestamp = datetime.strptime(args["pit_timestamp"], "%Y-%m-%d %H:%M:%S") |
| 420 |
self.pit_timestamp_tokens = 6 |
| 421 |
elif re.match("[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}", args["pit_timestamp"]): |
| 422 |
self.pit_timestamp = datetime.strptime(args["pit_timestamp"], "%Y-%m-%d %H:%M") |
| 423 |
self.pit_timestamp_tokens = 5 |
| 424 |
elif re.match("[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}", args["pit_timestamp"]): |
| 425 |
self.pit_timestamp = datetime.strptime(args["pit_timestamp"], "%Y-%m-%d %H") |
| 426 |
self.pit_timestamp_tokens = 4 |
| 427 |
elif re.match("[0-9]{4}-[0-9]{2}-[0-9]{2}", args["pit_timestamp"]): |
| 428 |
self.pit_timestamp = datetime.strptime(args["pit_timestamp"], "%Y-%m-%d") |
| 429 |
self.pit_timestamp_tokens = 3 |
| 430 |
else: |
| 431 |
self.module.fail_json(msg="Invalid argument! pit_timestamp must be in the form YYYY-MM-DD HH:MM:SS (AM|PM) (time portion is optional)." |
| 432 |
" Array [%s]." % self.ssid) |
| 433 |
|
| 434 |
|
| 435 |
if self.state == "present": |
| 436 |
if self.type == "group": |
| 437 |
if not self.volumes: |
| 438 |
self.module.fail_json(msg="Missing argument! Volumes must be defined to create a snapshot consistency group." |
| 439 |
" Group [%s]. Array [%s]" % (self.group_name, self.ssid)) |
| 440 |
elif self.type == "pit": |
| 441 |
if self.pit_timestamp and self.pit_name: |
| 442 |
self.module.fail_json(msg="Invalid arguments! Either define pit_name with or without pit_description or pit_timestamp." |
| 443 |
" Group [%s]. Array [%s]" % (self.group_name, self.ssid)) |
| 444 |
|
| 445 |
elif self.type == "view": |
| 446 |
if not self.view_name: |
| 447 |
self.module.fail_json(msg="Missing argument! view_name must be defined to create a snapshot consistency group view." |
| 448 |
" Group [%s]. Array [%s]" % (self.group_name, self.ssid)) |
| 449 |
if not (self.pit_name or self.pit_timestamp): |
| 450 |
self.module.fail_json(msg="Missing argument! Either pit_name or pit_timestamp must be defined to create a consistency group point-in-time" |
| 451 |
" snapshot. Group [%s]. Array [%s]" % (self.group_name, self.ssid)) |
| 452 |
elif self.state == "rollback": |
| 453 |
if not (self.pit_name or self.pit_timestamp): |
| 454 |
self.module.fail_json(msg="Missing argument! Either pit_name or pit_timestamp must be defined to create a consistency group point-in-time" |
| 455 |
" snapshot. Group [%s]. Array [%s]" % (self.group_name, self.ssid)) |
| 456 |
else: |
| 457 |
if self.type == "pit": |
| 458 |
if self.pit_name and self.pit_timestamp: |
| 459 |
self.module.fail_json(msg="Invalid arguments! Either define pit_name or pit_timestamp." |
| 460 |
" Group [%s]. Array [%s]" % (self.group_name, self.ssid)) |
| 461 |
if not (self.pit_name or self.pit_timestamp): |
| 462 |
self.module.fail_json(msg="Missing argument! Either pit_name or pit_timestamp must be defined to create a consistency group point-in-time" |
| 463 |
" snapshot. Group [%s]. Array [%s]" % (self.group_name, self.ssid)) |
| 464 |
elif self.type == "view": |
| 465 |
if not self.view_name: |
| 466 |
self.module.fail_json(msg="Missing argument! view_name must be defined to create a snapshot consistency group view." |
| 467 |
" Group [%s]. Array [%s]" % (self.group_name, self.ssid)) |
| 468 |
|
| 469 |
|
| 470 |
self.url_path_prefix = "" |
| 471 |
if not self.is_embedded(): |
| 472 |
if self.ssid == "0" or self.ssid.lower() == "proxy": |
| 473 |
self.module.fail_json(msg="Snapshot is not a valid operation for SANtricity Web Services Proxy! ssid cannot be '0' or 'proxy'." |
| 474 |
" Array [%s]" % self.ssid) |
| 475 |
self.url_path_prefix = "storage-systems/%s/forward/devmgr/v2/" % self.ssid |
| 476 |
|
| 477 |
self.cache = {"get_consistency_group": {}, |
| 478 |
"get_all_storage_pools_by_id": {}, |
| 479 |
"get_all_storage_pools_by_name": {}, |
| 480 |
"get_all_volumes_by_id": {}, |
| 481 |
"get_all_volumes_by_name": {}, |
| 482 |
"get_all_hosts_and_hostgroups_by_name": {}, |
| 483 |
"get_all_hosts_and_hostgroups_by_id": {}, |
| 484 |
"get_mapping_by_id": {}, |
| 485 |
"get_mapping_by_name": {}, |
| 486 |
"get_all_concat_volumes_by_id": {}, |
| 487 |
"get_pit_images_by_timestamp": {}, |
| 488 |
"get_pit_images_by_name": {}, |
| 489 |
"get_pit_images_metadata": {}, |
| 490 |
"get_unused_pit_key_values": [], |
| 491 |
"get_pit_info": None, |
| 492 |
"get_consistency_group_view": {}, |
| 493 |
"view_changes_required": []} |
| 494 |
|
| 495 |
def get_all_storage_pools_by_id(self): |
| 496 |
"""Retrieve and return all storage pools/volume groups.""" |
| 497 |
if not self.cache["get_all_storage_pools_by_id"]: |
| 498 |
try: |
| 499 |
rc, storage_pools = self.request("storage-systems/%s/storage-pools" % self.ssid) |
| 500 |
|
| 501 |
for storage_pool in storage_pools: |
| 502 |
self.cache["get_all_storage_pools_by_id"].update({storage_pool["id"]: storage_pool}) |
| 503 |
self.cache["get_all_storage_pools_by_name"].update({storage_pool["name"]: storage_pool}) |
| 504 |
except Exception as error: |
| 505 |
self.module.fail_json(msg="Failed to retrieve volumes! Error [%s]. Array [%s]." % (error, self.ssid)) |
| 506 |
|
| 507 |
return self.cache["get_all_storage_pools_by_id"] |
| 508 |
|
| 509 |
def get_all_storage_pools_by_name(self): |
| 510 |
"""Retrieve and return all storage pools/volume groups.""" |
| 511 |
if not self.cache["get_all_storage_pools_by_name"]: |
| 512 |
self.get_all_storage_pools_by_id() |
| 513 |
|
| 514 |
return self.cache["get_all_storage_pools_by_name"] |
| 515 |
|
| 516 |
def get_all_volumes_by_id(self): |
| 517 |
"""Retrieve and return a dictionary of all thick and thin volumes keyed by id.""" |
| 518 |
if not self.cache["get_all_volumes_by_id"]: |
| 519 |
try: |
| 520 |
rc, thick_volumes = self.request("storage-systems/%s/volumes" % self.ssid) |
| 521 |
rc, thin_volumes = self.request("storage-systems/%s/thin-volumes" % self.ssid) |
| 522 |
|
| 523 |
for volume in thick_volumes + thin_volumes: |
| 524 |
self.cache["get_all_volumes_by_id"].update({volume["id"]: volume}) |
| 525 |
self.cache["get_all_volumes_by_name"].update({volume["name"]: volume}) |
| 526 |
except Exception as error: |
| 527 |
self.module.fail_json(msg="Failed to retrieve volumes! Error [%s]. Array [%s]." % (error, self.ssid)) |
| 528 |
|
| 529 |
return self.cache["get_all_volumes_by_id"] |
| 530 |
|
| 531 |
def get_all_volumes_by_name(self): |
| 532 |
"""Retrieve and return a dictionary of all thick and thin volumes keyed by name.""" |
| 533 |
if not self.cache["get_all_volumes_by_name"]: |
| 534 |
self.get_all_volumes_by_id() |
| 535 |
|
| 536 |
return self.cache["get_all_volumes_by_name"] |
| 537 |
|
| 538 |
def get_all_hosts_and_hostgroups_by_id(self): |
| 539 |
"""Retrieve and return a dictionary of all host and host groups keyed by name.""" |
| 540 |
if not self.cache["get_all_hosts_and_hostgroups_by_id"]: |
| 541 |
try: |
| 542 |
rc, hostgroups = self.request("storage-systems/%s/host-groups" % self.ssid) |
| 543 |
|
| 544 |
hostgroup_by_id = dict((hostgroup["id"], hostgroup) for hostgroup in hostgroups) |
| 545 |
|
| 546 |
rc, hosts = self.request("storage-systems/%s/hosts" % self.ssid) |
| 547 |
for host in hosts: |
| 548 |
if host["clusterRef"] != "0000000000000000000000000000000000000000": |
| 549 |
hostgroup_name = hostgroup_by_id[host["clusterRef"]]["name"] |
| 550 |
|
| 551 |
if host["clusterRef"] not in self.cache["get_all_hosts_and_hostgroups_by_id"].keys(): |
| 552 |
hostgroup_by_id[host["clusterRef"]].update({"hostgroup": True, "host_ids": [host["id"]]}) |
| 553 |
self.cache["get_all_hosts_and_hostgroups_by_id"].update({host["clusterRef"]: hostgroup_by_id[host["clusterRef"]]}) |
| 554 |
self.cache["get_all_hosts_and_hostgroups_by_name"].update({hostgroup_name: hostgroup_by_id[host["clusterRef"]]}) |
| 555 |
else: |
| 556 |
self.cache["get_all_hosts_and_hostgroups_by_id"][host["clusterRef"]]["host_ids"].append(host["id"]) |
| 557 |
self.cache["get_all_hosts_and_hostgroups_by_name"][hostgroup_name]["host_ids"].append(host["id"]) |
| 558 |
|
| 559 |
self.cache["get_all_hosts_and_hostgroups_by_id"].update({host["id"]: host, "hostgroup": False}) |
| 560 |
self.cache["get_all_hosts_and_hostgroups_by_name"].update({host["name"]: host, "hostgroup": False}) |
| 561 |
except Exception as error: |
| 562 |
self.module.fail_json(msg="Failed to retrieve all host and host group objects! Error [%s]. Array [%s]." % (error, self.ssid)) |
| 563 |
|
| 564 |
return self.cache["get_all_hosts_and_hostgroups_by_id"] |
| 565 |
|
| 566 |
def get_all_hosts_and_hostgroups_by_name(self): |
| 567 |
"""Retrieve and return a dictionary of all thick and thin volumes keyed by name.""" |
| 568 |
if not self.cache["get_all_hosts_and_hostgroups_by_name"]: |
| 569 |
self.get_all_hosts_and_hostgroups_by_id() |
| 570 |
|
| 571 |
return self.cache["get_all_hosts_and_hostgroups_by_name"] |
| 572 |
|
| 573 |
def get_mapping_by_id(self): |
| 574 |
"""Retrieve and return a dictionary of """ |
| 575 |
if not self.cache["get_mapping_by_id"]: |
| 576 |
existing_hosts_and_hostgroups_by_id = self.get_all_hosts_and_hostgroups_by_id() |
| 577 |
existing_hosts_and_hostgroups_by_name = self.get_all_hosts_and_hostgroups_by_name() |
| 578 |
try: |
| 579 |
rc, mappings = self.request("storage-systems/%s/volume-mappings" % self.ssid) |
| 580 |
|
| 581 |
for mapping in mappings: |
| 582 |
host_ids = [mapping["mapRef"]] |
| 583 |
map_entry = {mapping["lun"]: mapping["volumeRef"]} |
| 584 |
|
| 585 |
if mapping["type"] == "cluster": |
| 586 |
host_ids = existing_hosts_and_hostgroups_by_id[mapping["mapRef"]]["host_ids"] |
| 587 |
if mapping["mapRef"] in self.cache["get_mapping_by_id"].keys(): |
| 588 |
self.cache["get_mapping_by_id"][mapping["mapRef"]].update(map_entry) |
| 589 |
self.cache["get_mapping_by_name"][mapping["mapRef"]].update(map_entry) |
| 590 |
else: |
| 591 |
self.cache["get_mapping_by_id"].update({mapping["mapRef"]: map_entry}) |
| 592 |
self.cache["get_mapping_by_name"].update({mapping["mapRef"]: map_entry}) |
| 593 |
|
| 594 |
for host_id in host_ids: |
| 595 |
if host_id in self.cache["get_mapping_by_id"].keys(): |
| 596 |
self.cache["get_mapping_by_id"][mapping["mapRef"]].update(map_entry) |
| 597 |
self.cache["get_mapping_by_name"][mapping["mapRef"]].update(map_entry) |
| 598 |
else: |
| 599 |
self.cache["get_mapping_by_id"].update({host_id: map_entry}) |
| 600 |
self.cache["get_mapping_by_name"].update({host_id: map_entry}) |
| 601 |
except Exception as error: |
| 602 |
self.module.fail_json(msg="Failed to retrieve all volume map definitions! Error [%s]. Array [%s]." % (error, self.ssid)) |
| 603 |
|
| 604 |
return self.cache["get_mapping_by_id"] |
| 605 |
|
| 606 |
def get_mapping_by_name(self): |
| 607 |
"""Retrieve and return a dictionary of """ |
| 608 |
if not self.cache["get_mapping_by_name"]: |
| 609 |
self.get_mapping_by_id() |
| 610 |
|
| 611 |
return self.cache["get_mapping_by_name"] |
| 612 |
|
| 613 |
def get_all_concat_volumes_by_id(self): |
| 614 |
"""Retrieve and return a dictionary of all thick and thin volumes keyed by id.""" |
| 615 |
if not self.cache["get_all_concat_volumes_by_id"]: |
| 616 |
try: |
| 617 |
rc, concat_volumes = self.request("storage-systems/%s/repositories/concat" % self.ssid) |
| 618 |
|
| 619 |
for volume in concat_volumes: |
| 620 |
self.cache["get_all_concat_volumes_by_id"].update({volume["id"]: volume}) |
| 621 |
except Exception as error: |
| 622 |
self.module.fail_json(msg="Failed to retrieve reserve capacity volumes! Error [%s]. Array [%s]." % (error, self.ssid)) |
| 623 |
|
| 624 |
return self.cache["get_all_concat_volumes_by_id"] |
| 625 |
|
| 626 |
def get_consistency_group(self): |
| 627 |
"""Retrieve consistency groups and return information on the expected group.""" |
| 628 |
existing_volumes = self.get_all_volumes_by_id() |
| 629 |
|
| 630 |
if not self.cache["get_consistency_group"]: |
| 631 |
try: |
| 632 |
rc, consistency_groups = self.request("storage-systems/%s/consistency-groups" % self.ssid) |
| 633 |
|
| 634 |
for consistency_group in consistency_groups: |
| 635 |
if consistency_group["label"] == self.group_name: |
| 636 |
rc, member_volumes = self.request("storage-systems/%s/consistency-groups/%s/member-volumes" % (self.ssid, consistency_group["id"])) |
| 637 |
|
| 638 |
self.cache["get_consistency_group"].update({"consistency_group_id": consistency_group["cgRef"], |
| 639 |
"alert_threshold_pct": consistency_group["fullWarnThreshold"], |
| 640 |
"maximum_snapshots": consistency_group["autoDeleteLimit"], |
| 641 |
"rollback_priority": consistency_group["rollbackPriority"], |
| 642 |
"reserve_capacity_full_policy": consistency_group["repFullPolicy"], |
| 643 |
"sequence_numbers": consistency_group["uniqueSequenceNumber"], |
| 644 |
"base_volumes": []}) |
| 645 |
|
| 646 |
for member_volume in member_volumes: |
| 647 |
base_volume = existing_volumes[member_volume["volumeId"]] |
| 648 |
base_volume_size_b = int(base_volume["totalSizeInBytes"]) |
| 649 |
total_reserve_capacity_b = int(member_volume["totalRepositoryCapacity"]) |
| 650 |
reserve_capacity_pct = int(round(float(total_reserve_capacity_b) / float(base_volume_size_b) * 100)) |
| 651 |
|
| 652 |
rc, concat = self.request("storage-systems/%s/repositories/concat/%s" % (self.ssid, member_volume["repositoryVolume"])) |
| 653 |
|
| 654 |
self.cache["get_consistency_group"]["base_volumes"].append({"name": base_volume["name"], |
| 655 |
"id": base_volume["id"], |
| 656 |
"base_volume_size_b": base_volume_size_b, |
| 657 |
"total_reserve_capacity_b": total_reserve_capacity_b, |
| 658 |
"reserve_capacity_pct": reserve_capacity_pct, |
| 659 |
"repository_volume_info": concat}) |
| 660 |
break |
| 661 |
|
| 662 |
except Exception as error: |
| 663 |
self.module.fail_json(msg="Failed to retrieve snapshot consistency groups! Error [%s]. Array [%s]." % (error, self.ssid)) |
| 664 |
|
| 665 |
return self.cache["get_consistency_group"] |
| 666 |
|
| 667 |
def get_candidate(self, volume_name, volume_info): |
| 668 |
"""Return candidate for volume.""" |
| 669 |
existing_storage_pools_by_id = self.get_all_storage_pools_by_id() |
| 670 |
existing_storage_pools_by_name = self.get_all_storage_pools_by_name() |
| 671 |
existing_volumes_by_name = self.get_all_volumes_by_name() |
| 672 |
|
| 673 |
if volume_name in existing_volumes_by_name: |
| 674 |
base_volume_storage_pool_id = existing_volumes_by_name[volume_name]["volumeGroupRef"] |
| 675 |
base_volume_storage_pool_name = existing_storage_pools_by_id[base_volume_storage_pool_id]["name"] |
| 676 |
|
| 677 |
preferred_reserve_storage_pool = base_volume_storage_pool_id |
| 678 |
if volume_info["preferred_reserve_storage_pool"]: |
| 679 |
if volume_info["preferred_reserve_storage_pool"] in existing_storage_pools_by_name: |
| 680 |
preferred_reserve_storage_pool = existing_storage_pools_by_name[volume_info["preferred_reserve_storage_pool"]]["id"] |
| 681 |
else: |
| 682 |
self.module.fail_json(msg="Preferred storage pool or volume group does not exist! Storage pool [%s]. Group [%s]." |
| 683 |
" Array [%s]." % (volume_info["preferred_reserve_storage_pool"], self.group_name, self.ssid)) |
| 684 |
|
| 685 |
volume_info.update({"name": volume_name, |
| 686 |
"id": existing_volumes_by_name[volume_name]["id"], |
| 687 |
"storage_pool_name": base_volume_storage_pool_name, |
| 688 |
"storage_pool_id": base_volume_storage_pool_id, |
| 689 |
"preferred_reserve_storage_pool": preferred_reserve_storage_pool, |
| 690 |
"candidate": None}) |
| 691 |
|
| 692 |
else: |
| 693 |
self.module.fail_json(msg="Volume does not exist! Volume [%s]. Group [%s]. Array [%s]." % (volume_name, self.group_name, self.ssid)) |
| 694 |
|
| 695 |
candidate_request = {"candidateRequest": {"baseVolumeRef": volume_info["id"], |
| 696 |
"percentCapacity": volume_info["reserve_capacity_pct"], |
| 697 |
"concatVolumeType": "snapshot"}} |
| 698 |
try: |
| 699 |
rc, candidates = self.request("storage-systems/%s/repositories/concat/single" % self.ssid, method="POST", data=candidate_request) |
| 700 |
for candidate in candidates: |
| 701 |
if candidate["volumeGroupId"] == volume_info["preferred_reserve_storage_pool"]: |
| 702 |
volume_info["candidate"] = candidate |
| 703 |
break |
| 704 |
else: |
| 705 |
self.module.fail_json(msg="Failed to retrieve capacity volume candidate in preferred storage pool or volume group!" |
| 706 |
" Volume [%s]. Group [%s]. Array [%s]." % (volume_info["name"], self.group_name, self.ssid)) |
| 707 |
except Exception as error: |
| 708 |
self.module.fail_json(msg="Failed to get reserve capacity candidates!" |
| 709 |
" Volumes %s. Group [%s]. Array [%s]. Error [%s]" % (volume_info["name"], self.group_name, self.ssid, error)) |
| 710 |
|
| 711 |
return volume_info |
| 712 |
|
| 713 |
def get_pit_images_metadata(self): |
| 714 |
"""Retrieve and return consistency group snapshot images' metadata keyed on timestamps.""" |
| 715 |
if not self.cache["get_pit_images_metadata"]: |
| 716 |
try: |
| 717 |
rc, key_values = self.request(self.url_path_prefix + "key-values") |
| 718 |
|
| 719 |
for entry in key_values: |
| 720 |
if re.search("ansible\\|%s\\|" % self.group_name, entry["key"]): |
| 721 |
name = entry["key"].replace("ansible|%s|" % self.group_name, "") |
| 722 |
values = entry["value"].split("|") |
| 723 |
if len(values) == 3: |
| 724 |
timestamp, image_id, description = values |
| 725 |
self.cache["get_pit_images_metadata"].update({timestamp: {"name": name, "description": description}}) |
| 726 |
|
| 727 |
except Exception as error: |
| 728 |
self.module.fail_json(msg="Failed to retrieve consistency group snapshot images metadata! Array [%s]. Error [%s]." % (self.ssid, error)) |
| 729 |
|
| 730 |
return self.cache["get_pit_images_metadata"] |
| 731 |
|
| 732 |
def get_pit_images_by_timestamp(self): |
| 733 |
"""Retrieve and return snapshot images.""" |
| 734 |
if not self.cache["get_pit_images_by_timestamp"]: |
| 735 |
group_id = self.get_consistency_group()["consistency_group_id"] |
| 736 |
images_metadata = self.get_pit_images_metadata() |
| 737 |
existing_volumes_by_id = self.get_all_volumes_by_id() |
| 738 |
|
| 739 |
try: |
| 740 |
rc, images = self.request("storage-systems/%s/consistency-groups/%s/snapshots" % (self.ssid, group_id)) |
| 741 |
for image_info in images: |
| 742 |
|
| 743 |
metadata = {"id": "", "name": "", "description": ""} |
| 744 |
if image_info["pitTimestamp"] in images_metadata.keys(): |
| 745 |
metadata = images_metadata[image_info["pitTimestamp"]] |
| 746 |
|
| 747 |
timestamp = datetime.fromtimestamp(int(image_info["pitTimestamp"])) |
| 748 |
info = {"id": image_info["id"], |
| 749 |
"name": metadata["name"], |
| 750 |
"timestamp": timestamp, |
| 751 |
"description": metadata["description"], |
| 752 |
"sequence_number": image_info["pitSequenceNumber"], |
| 753 |
"base_volume_id": image_info["baseVol"], |
| 754 |
"base_volume_name": existing_volumes_by_id[image_info["baseVol"]]["name"], |
| 755 |
"image_info": image_info} |
| 756 |
|
| 757 |
if timestamp not in self.cache["get_pit_images_by_timestamp"].keys(): |
| 758 |
self.cache["get_pit_images_by_timestamp"].update({timestamp: {"sequence_number": image_info["pitSequenceNumber"], "images": [info]}}) |
| 759 |
if metadata["name"]: |
| 760 |
self.cache["get_pit_images_by_name"].update({metadata["name"]: {"sequence_number": image_info["pitSequenceNumber"], |
| 761 |
"images": [info]}}) |
| 762 |
else: |
| 763 |
self.cache["get_pit_images_by_timestamp"][timestamp]["images"].append(info) |
| 764 |
if metadata["name"]: |
| 765 |
self.cache["get_pit_images_by_name"][metadata["name"]]["images"].append(info) |
| 766 |
|
| 767 |
except Exception as error: |
| 768 |
self.module.fail_json(msg="Failed to retrieve consistency group snapshot images!" |
| 769 |
" Group [%s]. Array [%s]. Error [%s]." % (self.group_name, self.ssid, error)) |
| 770 |
|
| 771 |
return self.cache["get_pit_images_by_timestamp"] |
| 772 |
|
| 773 |
def get_pit_images_by_name(self): |
| 774 |
"""Retrieve and return snapshot images.""" |
| 775 |
if not self.cache["get_pit_images_by_name"]: |
| 776 |
self.get_pit_images_by_timestamp() |
| 777 |
|
| 778 |
return self.cache["get_pit_images_by_name"] |
| 779 |
|
| 780 |
def get_unused_pit_key(self): |
| 781 |
"""Determine all embedded pit key-values that do not match existing snapshot images.""" |
| 782 |
if not self.cache["get_unused_pit_key_values"]: |
| 783 |
try: |
| 784 |
rc, images = self.request("storage-systems/%s/snapshot-images" % self.ssid) |
| 785 |
rc, key_values = self.request("key-values") |
| 786 |
|
| 787 |
for key_value in key_values: |
| 788 |
key = key_value["key"] |
| 789 |
value = key_value["value"] |
| 790 |
if re.match("ansible\\|.*\\|.*", value): |
| 791 |
for image in images: |
| 792 |
if str(image["pitTimestamp"]) == value.split("|")[0]: |
| 793 |
break |
| 794 |
else: |
| 795 |
self.cache["get_unused_pit_key_values"].append(key) |
| 796 |
except Exception as error: |
| 797 |
self.module.warn("Failed to retrieve all snapshots to determine all key-value pairs that do no match a point-in-time snapshot images!" |
| 798 |
" Array [%s]. Error [%s]." % (self.ssid, error)) |
| 799 |
|
| 800 |
return self.cache["get_unused_pit_key_values"] |
| 801 |
|
| 802 |
def get_pit_info(self): |
| 803 |
"""Determine consistency group's snapshot images base on provided arguments (pit_name or timestamp).""" |
| 804 |
|
| 805 |
def _check_timestamp(timestamp): |
| 806 |
"""Check whether timestamp matches I(pit_timestamp)""" |
| 807 |
return (self.pit_timestamp.year == timestamp.year and |
| 808 |
self.pit_timestamp.month == timestamp.month and |
| 809 |
self.pit_timestamp.day == timestamp.day and |
| 810 |
(self.pit_timestamp_tokens < 4 or self.pit_timestamp.hour == timestamp.hour) and |
| 811 |
(self.pit_timestamp_tokens < 5 or self.pit_timestamp.minute == timestamp.minute) and |
| 812 |
(self.pit_timestamp_tokens < 6 or self.pit_timestamp.second == timestamp.second)) |
| 813 |
|
| 814 |
if self.cache["get_pit_info"] is None: |
| 815 |
group = self.get_consistency_group() |
| 816 |
pit_images_by_timestamp = self.get_pit_images_by_timestamp() |
| 817 |
pit_images_by_name = self.get_pit_images_by_name() |
| 818 |
|
| 819 |
if self.pit_name: |
| 820 |
if self.pit_name in pit_images_by_name.keys(): |
| 821 |
self.cache["get_pit_info"] = pit_images_by_name[self.pit_name] |
| 822 |
|
| 823 |
if self.pit_timestamp: |
| 824 |
for image in self.cache["get_pit_info"]["images"]: |
| 825 |
if not _check_timestamp(image["timestamp"]): |
| 826 |
self.module.fail_json(msg="Snapshot image does not exist that matches both name and supplied timestamp!" |
| 827 |
" Group [%s]. Image [%s]. Array [%s]." % (self.group_name, image, self.ssid)) |
| 828 |
elif self.pit_timestamp and pit_images_by_timestamp: |
| 829 |
sequence_number = None |
| 830 |
if self.pit_timestamp == "newest": |
| 831 |
sequence_number = group["sequence_numbers"][-1] |
| 832 |
|
| 833 |
for image_timestamp in pit_images_by_timestamp.keys(): |
| 834 |
if int(pit_images_by_timestamp[image_timestamp]["sequence_number"]) == int(sequence_number): |
| 835 |
self.cache["get_pit_info"] = pit_images_by_timestamp[image_timestamp] |
| 836 |
break |
| 837 |
elif self.pit_timestamp == "oldest": |
| 838 |
sequence_number = group["sequence_numbers"][0] |
| 839 |
for image_timestamp in pit_images_by_timestamp.keys(): |
| 840 |
if int(pit_images_by_timestamp[image_timestamp]["sequence_number"]) == int(sequence_number): |
| 841 |
self.cache["get_pit_info"] = pit_images_by_timestamp[image_timestamp] |
| 842 |
break |
| 843 |
else: |
| 844 |
for image_timestamp in pit_images_by_timestamp.keys(): |
| 845 |
if _check_timestamp(image_timestamp): |
| 846 |
if sequence_number and sequence_number != pit_images_by_timestamp[image_timestamp]["sequence_number"]: |
| 847 |
self.module.fail_json(msg="Multiple snapshot images match the provided timestamp and do not have the same sequence number!" |
| 848 |
" Group [%s]. Array [%s]." % (self.group_name, self.ssid)) |
| 849 |
|
| 850 |
sequence_number = pit_images_by_timestamp[image_timestamp]["sequence_number"] |
| 851 |
self.cache["get_pit_info"] = pit_images_by_timestamp[image_timestamp] |
| 852 |
|
| 853 |
if self.state != "absent" and self.type != "pit" and self.cache["get_pit_info"] is None: |
| 854 |
self.module.fail_json(msg="Snapshot consistency group point-in-time image does not exist! Name [%s]. Timestamp [%s]. Group [%s]." |
| 855 |
" Array [%s]." % (self.pit_name, self.pit_timestamp, self.group_name, self.ssid)) |
| 856 |
|
| 857 |
return self.cache["get_pit_info"] |
| 858 |
|
| 859 |
def create_changes_required(self): |
| 860 |
"""Determine the required state changes for creating a new consistency group.""" |
| 861 |
changes = {"create_group": {"name": self.group_name, |
| 862 |
"alert_threshold_pct": self.alert_threshold_pct, |
| 863 |
"maximum_snapshots": self.maximum_snapshots, |
| 864 |
"reserve_capacity_full_policy": self.reserve_capacity_full_policy, |
| 865 |
"rollback_priority": self.rollback_priority}, |
| 866 |
"add_volumes": self.volumes} |
| 867 |
|
| 868 |
return changes |
| 869 |
|
| 870 |
def update_changes_required(self): |
| 871 |
"""Determine the required state changes for updating an existing consistency group.""" |
| 872 |
group = self.get_consistency_group() |
| 873 |
changes = {"update_group": {}, |
| 874 |
"add_volumes": [], |
| 875 |
"remove_volumes": [], |
| 876 |
"expand_reserve_capacity": [], |
| 877 |
"trim_reserve_capacity": []} |
| 878 |
|
| 879 |
|
| 880 |
if group["alert_threshold_pct"] != self.alert_threshold_pct: |
| 881 |
changes["update_group"].update({"alert_threshold_pct": self.alert_threshold_pct}) |
| 882 |
if group["maximum_snapshots"] != self.maximum_snapshots: |
| 883 |
changes["update_group"].update({"maximum_snapshots": self.maximum_snapshots}) |
| 884 |
if group["rollback_priority"] != self.rollback_priority: |
| 885 |
changes["update_group"].update({"rollback_priority": self.rollback_priority}) |
| 886 |
if group["reserve_capacity_full_policy"] != self.reserve_capacity_full_policy: |
| 887 |
changes["update_group"].update({"reserve_capacity_full_policy": self.reserve_capacity_full_policy}) |
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
remaining_base_volumes = dict((base_volumes["name"], base_volumes) for base_volumes in group["base_volumes"]) |
| 892 |
add_volumes = {} |
| 893 |
expand_volumes = {} |
| 894 |
|
| 895 |
for volume_name, volume_info in self.volumes.items(): |
| 896 |
reserve_capacity_pct = volume_info["reserve_capacity_pct"] |
| 897 |
if volume_name in remaining_base_volumes: |
| 898 |
|
| 899 |
|
| 900 |
base_volume_reserve_capacity_pct = remaining_base_volumes[volume_name]["reserve_capacity_pct"] |
| 901 |
if reserve_capacity_pct > base_volume_reserve_capacity_pct: |
| 902 |
expand_reserve_capacity_pct = reserve_capacity_pct - base_volume_reserve_capacity_pct |
| 903 |
expand_volumes.update({volume_name: {"reserve_capacity_pct": expand_reserve_capacity_pct, |
| 904 |
"preferred_reserve_storage_pool": volume_info["preferred_reserve_storage_pool"], |
| 905 |
"reserve_volume_id": remaining_base_volumes[volume_name]["repository_volume_info"]["id"]}}) |
| 906 |
|
| 907 |
elif reserve_capacity_pct < base_volume_reserve_capacity_pct: |
| 908 |
existing_volumes_by_id = self.get_all_volumes_by_id() |
| 909 |
existing_volumes_by_name = self.get_all_volumes_by_name() |
| 910 |
existing_concat_volumes_by_id = self.get_all_concat_volumes_by_id() |
| 911 |
trim_pct = base_volume_reserve_capacity_pct - reserve_capacity_pct |
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
for timestamp, image in self.get_pit_images_by_timestamp(): |
| 916 |
if existing_volumes_by_id(image["base_volume_id"])["name"] == volume_name: |
| 917 |
self.module.fail_json(msg="Reserve capacity cannot be trimmed when snapshot images exist for base volume!" |
| 918 |
" Base volume [%s]. Group [%s]. Array [%s]." % (volume_name, self.group_name, self.ssid)) |
| 919 |
|
| 920 |
|
| 921 |
concat_volume_id = remaining_base_volumes[volume_name]["repository_volume_info"]["id"] |
| 922 |
concat_volume_info = existing_concat_volumes_by_id[concat_volume_id] |
| 923 |
base_volume_info = existing_volumes_by_name[volume_name] |
| 924 |
base_volume_size_bytes = int(base_volume_info["totalSizeInBytes"]) |
| 925 |
|
| 926 |
total_member_volume_size_bytes = 0 |
| 927 |
member_volumes_to_trim = [] |
| 928 |
for trim_count, member_volume_id in enumerate(reversed(concat_volume_info["memberRefs"][1:])): |
| 929 |
member_volume_info = existing_volumes_by_id[member_volume_id] |
| 930 |
member_volumes_to_trim.append(member_volume_info) |
| 931 |
|
| 932 |
total_member_volume_size_bytes += int(member_volume_info["totalSizeInBytes"]) |
| 933 |
total_trimmed_size_pct = round(total_member_volume_size_bytes / base_volume_size_bytes * 100) |
| 934 |
|
| 935 |
if total_trimmed_size_pct >= trim_pct: |
| 936 |
changes["trim_reserve_capacity"].append({"concat_volume_id": concat_volume_id, "trim_count": trim_count + 1}) |
| 937 |
|
| 938 |
|
| 939 |
if total_trimmed_size_pct > trim_pct: |
| 940 |
expand_reserve_capacity_pct = total_trimmed_size_pct - trim_pct |
| 941 |
expand_volumes.update({volume_name: {"reserve_capacity_pct": expand_reserve_capacity_pct, |
| 942 |
"preferred_reserve_storage_pool": volume_info["preferred_reserve_storage_pool"], |
| 943 |
"reserve_volume_id": remaining_base_volumes[volume_name]["repository_volume_info"]["id"]}}) |
| 944 |
break |
| 945 |
else: |
| 946 |
initial_reserve_volume_info = existing_volumes_by_id[concat_volume_info["memberRefs"][0]] |
| 947 |
minimum_capacity_pct = round(int(initial_reserve_volume_info["totalSizeInBytes"]) / base_volume_size_bytes * 100) |
| 948 |
self.module.fail_json(msg="Cannot delete initial reserve capacity volume! Minimum reserve capacity percent [%s]. Base volume [%s]. " |
| 949 |
"Group [%s]. Array [%s]." % (minimum_capacity_pct, volume_name, self.group_name, self.ssid)) |
| 950 |
|
| 951 |
remaining_base_volumes.pop(volume_name) |
| 952 |
else: |
| 953 |
add_volumes.update({volume_name: {"reserve_capacity_pct": reserve_capacity_pct, |
| 954 |
"preferred_reserve_storage_pool": volume_info["preferred_reserve_storage_pool"]}}) |
| 955 |
|
| 956 |
changes["add_volumes"] = add_volumes |
| 957 |
changes["expand_reserve_capacity"] = expand_volumes |
| 958 |
changes["remove_volumes"] = remaining_base_volumes |
| 959 |
return changes |
| 960 |
|
| 961 |
def get_consistency_group_view(self): |
| 962 |
"""Determine and return consistency group view.""" |
| 963 |
group_id = self.get_consistency_group()["consistency_group_id"] |
| 964 |
|
| 965 |
if not self.cache["get_consistency_group_view"]: |
| 966 |
try: |
| 967 |
rc, views = self.request("storage-systems/%s/consistency-groups/%s/views" % (self.ssid, group_id)) |
| 968 |
|
| 969 |
|
| 970 |
for view in views: |
| 971 |
if view["name"] == self.view_name: |
| 972 |
self.cache["get_consistency_group_view"] = view |
| 973 |
self.cache["get_consistency_group_view"].update({"snapshot_volumes": []}) |
| 974 |
|
| 975 |
|
| 976 |
try: |
| 977 |
rc, snapshot_volumes = self.request("storage-systems/%s/snapshot-volumes" % self.ssid) |
| 978 |
|
| 979 |
for snapshot_volume in snapshot_volumes: |
| 980 |
if (snapshot_volume["membership"] and |
| 981 |
snapshot_volume["membership"]["viewType"] == "member" and |
| 982 |
snapshot_volume["membership"]["cgViewRef"] == view["cgViewRef"]): |
| 983 |
self.cache["get_consistency_group_view"]["snapshot_volumes"].append(snapshot_volume) |
| 984 |
except Exception as error: |
| 985 |
self.module.fail_json(msg="Failed to retrieve host mapping information!." |
| 986 |
" Group [%s]. Array [%s]. Error [%s]." % (self.group_name, self.ssid, error)) |
| 987 |
except Exception as error: |
| 988 |
self.module.fail_json(msg="Failed to retrieve consistency group's views!" |
| 989 |
" Group [%s]. Array [%s]. Error [%s]." % (self.group_name, self.ssid, error)) |
| 990 |
|
| 991 |
return self.cache["get_consistency_group_view"] |
| 992 |
|
| 993 |
def create_view_changes_required(self): |
| 994 |
"""Determine whether snapshot consistency group point-in-time view needs to be created.""" |
| 995 |
changes = {} |
| 996 |
snapshot_images_info = self.get_pit_info() |
| 997 |
changes.update({"name": self.view_name, |
| 998 |
"sequence_number": snapshot_images_info["sequence_number"], |
| 999 |
"images": snapshot_images_info["images"], |
| 1000 |
"volumes": self.volumes}) |
| 1001 |
|
| 1002 |
return changes |
| 1003 |
|
| 1004 |
def update_view_changes_required(self): |
| 1005 |
"""Determine the changes required for snapshot consistency group point-in-time view.""" |
| 1006 |
changes = {"expand_reserve_capacity": [], |
| 1007 |
"trim_reserve_capacity": [], |
| 1008 |
"map_snapshot_volumes_mapping": [], |
| 1009 |
"unmap_snapshot_volumes_mapping": [], |
| 1010 |
"move_snapshot_volumes_mapping": [], |
| 1011 |
"update_snapshot_volumes_writable": []} |
| 1012 |
view = self.get_consistency_group_view() |
| 1013 |
host_objects_by_name = self.get_all_hosts_and_hostgroups_by_name() |
| 1014 |
host_objects_by_id = self.get_all_hosts_and_hostgroups_by_id() |
| 1015 |
existing_volumes_by_id = self.get_all_volumes_by_id() |
| 1016 |
if view: |
| 1017 |
if len(view["snapshot_volumes"]) != len(self.volumes): |
| 1018 |
self.module.fail_json(msg="Cannot add or remove snapshot volumes once view is created! Group [%s]. Array [%s]." % (self.group_name, self.ssid)) |
| 1019 |
|
| 1020 |
expand_volumes = {} |
| 1021 |
writable_volumes = {} |
| 1022 |
for snapshot_volume in view["snapshot_volumes"]: |
| 1023 |
for volume_name, volume_info in self.volumes.items(): |
| 1024 |
if existing_volumes_by_id[snapshot_volume["baseVol"]]["name"] == volume_name: |
| 1025 |
|
| 1026 |
|
| 1027 |
if volume_info["snapshot_volume_host"] and not snapshot_volume["listOfMappings"]: |
| 1028 |
changes["map_snapshot_volumes_mapping"].append({"mappableObjectId": snapshot_volume["id"], |
| 1029 |
"lun": volume_info["snapshot_volume_lun"], |
| 1030 |
"targetId": host_objects_by_name[volume_info["snapshot_volume_host"]]["id"]}) |
| 1031 |
|
| 1032 |
|
| 1033 |
elif not volume_info["snapshot_volume_host"] and snapshot_volume["listOfMappings"]: |
| 1034 |
changes["unmap_snapshot_volumes_mapping"].append({"snapshot_volume_name": snapshot_volume["name"], |
| 1035 |
"lun_mapping_reference": snapshot_volume["listOfMappings"][0]["lunMappingRef"]}) |
| 1036 |
|
| 1037 |
|
| 1038 |
elif (snapshot_volume["listOfMappings"] and |
| 1039 |
((volume_info["snapshot_volume_host"] != host_objects_by_id[snapshot_volume["listOfMappings"][0]["mapRef"]]["name"]) or |
| 1040 |
(volume_info["snapshot_volume_lun"] != snapshot_volume["listOfMappings"][0]["lun"]))): |
| 1041 |
changes["move_snapshot_volumes_mapping"].append({"lunMappingRef": snapshot_volume["listOfMappings"][0]["lunMappingRef"], |
| 1042 |
"lun": volume_info["snapshot_volume_lun"], |
| 1043 |
"mapRef": host_objects_by_name[volume_info["snapshot_volume_host"]]["id"]}) |
| 1044 |
|
| 1045 |
if volume_info["snapshot_volume_writable"] != (snapshot_volume["accessMode"] == "readWrite"): |
| 1046 |
volume_info.update({"snapshot_volume_id": snapshot_volume["id"]}) |
| 1047 |
writable_volumes.update({volume_name: volume_info}) |
| 1048 |
|
| 1049 |
|
| 1050 |
if volume_info["snapshot_volume_writable"] and snapshot_volume["accessMode"] == "readWrite": |
| 1051 |
current_reserve_capacity_pct = int(round(float(snapshot_volume["repositoryCapacity"]) / |
| 1052 |
float(snapshot_volume["baseVolumeCapacity"]) * 100)) |
| 1053 |
if volume_info["reserve_capacity_pct"] > current_reserve_capacity_pct: |
| 1054 |
expand_reserve_capacity_pct = volume_info["reserve_capacity_pct"] - current_reserve_capacity_pct |
| 1055 |
expand_volumes.update({volume_name: {"reserve_capacity_pct": expand_reserve_capacity_pct, |
| 1056 |
"preferred_reserve_storage_pool": volume_info["preferred_reserve_storage_pool"], |
| 1057 |
"reserve_volume_id": snapshot_volume["repositoryVolume"]}}) |
| 1058 |
|
| 1059 |
elif volume_info["reserve_capacity_pct"] < current_reserve_capacity_pct: |
| 1060 |
existing_volumes_by_id = self.get_all_volumes_by_id() |
| 1061 |
existing_volumes_by_name = self.get_all_volumes_by_name() |
| 1062 |
existing_concat_volumes_by_id = self.get_all_concat_volumes_by_id() |
| 1063 |
trim_pct = current_reserve_capacity_pct - volume_info["reserve_capacity_pct"] |
| 1064 |
|
| 1065 |
|
| 1066 |
concat_volume_id = snapshot_volume["repositoryVolume"] |
| 1067 |
concat_volume_info = existing_concat_volumes_by_id[concat_volume_id] |
| 1068 |
base_volume_info = existing_volumes_by_name[volume_name] |
| 1069 |
base_volume_size_bytes = int(base_volume_info["totalSizeInBytes"]) |
| 1070 |
|
| 1071 |
total_member_volume_size_bytes = 0 |
| 1072 |
member_volumes_to_trim = [] |
| 1073 |
for trim_count, member_volume_id in enumerate(reversed(concat_volume_info["memberRefs"][1:])): |
| 1074 |
member_volume_info = existing_volumes_by_id[member_volume_id] |
| 1075 |
member_volumes_to_trim.append(member_volume_info) |
| 1076 |
|
| 1077 |
total_member_volume_size_bytes += int(member_volume_info["totalSizeInBytes"]) |
| 1078 |
total_trimmed_size_pct = round(total_member_volume_size_bytes / base_volume_size_bytes * 100) |
| 1079 |
|
| 1080 |
if total_trimmed_size_pct >= trim_pct: |
| 1081 |
changes["trim_reserve_capacity"].append({"concat_volume_id": concat_volume_id, "trim_count": trim_count + 1}) |
| 1082 |
|
| 1083 |
|
| 1084 |
if total_trimmed_size_pct > trim_pct: |
| 1085 |
expand_reserve_capacity_pct = total_trimmed_size_pct - trim_pct |
| 1086 |
expand_volumes.update({ |
| 1087 |
volume_name: {"reserve_capacity_pct": expand_reserve_capacity_pct, |
| 1088 |
"preferred_reserve_storage_pool": volume_info["preferred_reserve_storage_pool"], |
| 1089 |
"reserve_volume_id": snapshot_volume["repositoryVolume"]}}) |
| 1090 |
break |
| 1091 |
else: |
| 1092 |
initial_reserve_volume_info = existing_volumes_by_id[concat_volume_info["memberRefs"][0]] |
| 1093 |
minimum_capacity_pct = round(int(initial_reserve_volume_info["totalSizeInBytes"]) / base_volume_size_bytes * 100) |
| 1094 |
self.module.fail_json(msg="Cannot delete initial reserve capacity volume! Minimum reserve capacity percent [%s]. " |
| 1095 |
"Base volume [%s]. Group [%s]. Array [%s]." % (minimum_capacity_pct, volume_name, |
| 1096 |
self.group_name, self.ssid)) |
| 1097 |
changes.update({"expand_reserve_capacity": expand_volumes, |
| 1098 |
"update_snapshot_volumes_writable": writable_volumes}) |
| 1099 |
return changes |
| 1100 |
|
| 1101 |
def rollback_changes_required(self): |
| 1102 |
"""Determine the changes required for snapshot consistency group point-in-time rollback.""" |
| 1103 |
return self.get_pit_info() |
| 1104 |
|
| 1105 |
def remove_snapshot_consistency_group(self, info): |
| 1106 |
"""remove a new snapshot consistency group.""" |
| 1107 |
try: |
| 1108 |
rc, resp = self.request("storage-systems/%s/consistency-groups/%s" % (self.ssid, info["consistency_group_id"]), method="DELETE") |
| 1109 |
except Exception as error: |
| 1110 |
self.module.fail_json(msg="Failed to remove snapshot consistency group! Group [%s]. Array [%s]." % (self.group_name, self.ssid)) |
| 1111 |
|
| 1112 |
def create_snapshot_consistency_group(self, group_info): |
| 1113 |
"""Create a new snapshot consistency group.""" |
| 1114 |
consistency_group_request = {"name": self.group_name, |
| 1115 |
"fullWarnThresholdPercent": group_info["alert_threshold_pct"], |
| 1116 |
"autoDeleteThreshold": group_info["maximum_snapshots"], |
| 1117 |
"repositoryFullPolicy": group_info["reserve_capacity_full_policy"], |
| 1118 |
"rollbackPriority": group_info["rollback_priority"]} |
| 1119 |
|
| 1120 |
try: |
| 1121 |
rc, group = self.request("storage-systems/%s/consistency-groups" % self.ssid, method="POST", data=consistency_group_request) |
| 1122 |
self.cache["get_consistency_group"].update({"consistency_group_id": group["cgRef"]}) |
| 1123 |
except Exception as error: |
| 1124 |
self.module.fail_json(msg="Failed to remove snapshot consistency group! Group [%s]. Array [%s]." % (self.group_name, self.ssid)) |
| 1125 |
|
| 1126 |
def update_snapshot_consistency_group(self, group_info): |
| 1127 |
"""Create a new snapshot consistency group.""" |
| 1128 |
group_id = self.get_consistency_group()["consistency_group_id"] |
| 1129 |
consistency_group_request = {"name": self.group_name} |
| 1130 |
if "alert_threshold_pct" in group_info.keys(): |
| 1131 |
consistency_group_request.update({"fullWarnThresholdPercent": group_info["alert_threshold_pct"]}) |
| 1132 |
if "maximum_snapshots" in group_info.keys(): |
| 1133 |
consistency_group_request.update({"autoDeleteThreshold": group_info["maximum_snapshots"]}) |
| 1134 |
if "reserve_capacity_full_policy" in group_info.keys(): |
| 1135 |
consistency_group_request.update({"repositoryFullPolicy": group_info["reserve_capacity_full_policy"]}) |
| 1136 |
if "rollback_priority" in group_info.keys(): |
| 1137 |
consistency_group_request.update({"rollbackPriority": group_info["rollback_priority"]}) |
| 1138 |
|
| 1139 |
try: |
| 1140 |
rc, group = self.request("storage-systems/%s/consistency-groups/%s" % (self.ssid, group_id), method="POST", data=consistency_group_request) |
| 1141 |
return group["cgRef"] |
| 1142 |
except Exception as error: |
| 1143 |
self.module.fail_json(msg="Failed to remove snapshot consistency group! Group [%s]. Array [%s]." % (self.group_name, self.ssid)) |
| 1144 |
|
| 1145 |
def add_base_volumes(self, volumes): |
| 1146 |
"""Add base volume(s) to the consistency group.""" |
| 1147 |
group_id = self.get_consistency_group()["consistency_group_id"] |
| 1148 |
member_volume_request = {"volumeToCandidates": {}} |
| 1149 |
|
| 1150 |
for volume_name, volume_info in volumes.items(): |
| 1151 |
candidate = self.get_candidate(volume_name, volume_info) |
| 1152 |
member_volume_request["volumeToCandidates"].update({volume_info["id"]: candidate["candidate"]["candidate"]}) |
| 1153 |
|
| 1154 |
try: |
| 1155 |
rc, resp = self.request("storage-systems/%s/consistency-groups/%s/member-volumes/batch" % (self.ssid, group_id), |
| 1156 |
method="POST", data=member_volume_request) |
| 1157 |
except Exception as error: |
| 1158 |
self.module.fail_json(msg="Failed to add reserve capacity volume! Base volumes %s. Group [%s]. Error [%s]." |
| 1159 |
" Array [%s]." % (", ".join(volume for volume in member_volume_request.keys()), self.group_name, error, self.ssid)) |
| 1160 |
|
| 1161 |
def remove_base_volumes(self, volume_info_list): |
| 1162 |
"""Add base volume(s) to the consistency group.""" |
| 1163 |
group_id = self.get_consistency_group()["consistency_group_id"] |
| 1164 |
|
| 1165 |
for name, info in volume_info_list.items(): |
| 1166 |
try: |
| 1167 |
rc, resp = self.request("storage-systems/%s/consistency-groups/%s/member-volumes/%s" % (self.ssid, group_id, info["id"]), method="DELETE") |
| 1168 |
except Exception as error: |
| 1169 |
self.module.fail_json(msg="Failed to remove reserve capacity volume! Base volume [%s]. Group [%s]. Error [%s]. " |
| 1170 |
"Array [%s]." % (name, self.group_name, error, self.ssid)) |
| 1171 |
|
| 1172 |
def expand_reserve_capacities(self, reserve_volumes): |
| 1173 |
"""Expand base volume(s) reserve capacity.""" |
| 1174 |
for volume_name, volume_info in reserve_volumes.items(): |
| 1175 |
candidate = self.get_candidate(volume_name, volume_info) |
| 1176 |
expand_request = {"repositoryRef": volume_info["reserve_volume_id"], |
| 1177 |
"expansionCandidate": candidate["candidate"]["candidate"]} |
| 1178 |
try: |
| 1179 |
rc, resp = self.request("/storage-systems/%s/repositories/concat/%s/expand" % (self.ssid, volume_info["reserve_volume_id"]), |
| 1180 |
method="POST", data=expand_request) |
| 1181 |
except Exception as error: |
| 1182 |
self.module.fail_json(msg="Failed to expand reserve capacity volume! Group [%s]. Error [%s]. Array [%s]." % (self.group_name, error, self.ssid)) |
| 1183 |
|
| 1184 |
def trim_reserve_capacities(self, trim_reserve_volume_info_list): |
| 1185 |
"""trim base volume(s) reserve capacity.""" |
| 1186 |
for info in trim_reserve_volume_info_list: |
| 1187 |
trim_request = {"concatVol": info["concat_volume_id"], |
| 1188 |
"trimCount": info["trim_count"], |
| 1189 |
"retainRepositoryMembers": False} |
| 1190 |
try: |
| 1191 |
rc, trim = self.request("storage-systems/%s/symbol/trimConcatVolume?verboseErrorResponse=true" % self.ssid, method="POST", data=trim_request) |
| 1192 |
except Exception as error: |
| 1193 |
self.module.fail_json(msg="Failed to trim reserve capacity. Group [%s]. Array [%s]. Error [%s]." % (self.group_name, self.ssid, error)) |
| 1194 |
|
| 1195 |
def create_pit_images(self): |
| 1196 |
"""Generate snapshot image(s) for the base volumes in the consistency group.""" |
| 1197 |
group_id = self.get_consistency_group()["consistency_group_id"] |
| 1198 |
|
| 1199 |
try: |
| 1200 |
rc, images = self.request("storage-systems/%s/consistency-groups/%s/snapshots" % (self.ssid, group_id), method="POST") |
| 1201 |
|
| 1202 |
|
| 1203 |
if self.pit_name: |
| 1204 |
try: |
| 1205 |
rc, key_values = self.request(self.url_path_prefix + "key-values/ansible|%s|%s" % (self.group_name, self.pit_name), method="POST", |
| 1206 |
data="%s|%s|%s" % (images[0]["pitTimestamp"], self.pit_name, self.pit_description)) |
| 1207 |
except Exception as error: |
| 1208 |
self.module.fail_json(msg="Failed to create metadata for snapshot images!" |
| 1209 |
" Group [%s]. Array [%s]. Error [%s]." % (self.group_name, self.ssid, error)) |
| 1210 |
except Exception as error: |
| 1211 |
self.module.fail_json(msg="Failed to create consistency group snapshot images!" |
| 1212 |
" Group [%s]. Array [%s]. Error [%s]." % (self.group_name, self.ssid, error)) |
| 1213 |
|
| 1214 |
def remove_pit_images(self, pit_info): |
| 1215 |
"""Remove selected snapshot point-in-time images.""" |
| 1216 |
group_id = self.get_consistency_group()["consistency_group_id"] |
| 1217 |
|
| 1218 |
pit_sequence_number = int(pit_info["sequence_number"]) |
| 1219 |
sequence_numbers = set(int(pit_image["sequence_number"]) for timestamp, pit_image in self.get_pit_images_by_timestamp().items() |
| 1220 |
if int(pit_image["sequence_number"]) < pit_sequence_number) |
| 1221 |
sequence_numbers.add(pit_sequence_number) |
| 1222 |
|
| 1223 |
for sequence_number in sorted(sequence_numbers): |
| 1224 |
|
| 1225 |
try: |
| 1226 |
rc, images = self.request("storage-systems/%s/consistency-groups/%s/snapshots/%s" % (self.ssid, group_id, sequence_number), method="DELETE") |
| 1227 |
except Exception as error: |
| 1228 |
self.module.fail_json(msg="Failed to create consistency group snapshot images!" |
| 1229 |
" Group [%s]. Array [%s]. Error [%s]." % (self.group_name, self.ssid, error)) |
| 1230 |
|
| 1231 |
|
| 1232 |
if self.pit_name: |
| 1233 |
try: |
| 1234 |
rc, key_values = self.request(self.url_path_prefix + "key-values/ansible|%s|%s" % (self.group_name, self.pit_name), method="DELETE") |
| 1235 |
except Exception as error: |
| 1236 |
self.module.fail_json(msg="Failed to delete metadata for snapshot images!" |
| 1237 |
" Group [%s]. Array [%s]. Error [%s]." % (self.group_name, self.ssid, error)) |
| 1238 |
|
| 1239 |
def cleanup_old_pit_metadata(self, keys): |
| 1240 |
"""Delete unused point-in-time image metadata.""" |
| 1241 |
for key in keys: |
| 1242 |
try: |
| 1243 |
rc, images = self.request("key-values/%s" % key, method="DELETE") |
| 1244 |
except Exception as error: |
| 1245 |
self.module.fail_json(msg="Failed to purge unused point-in-time image metadata! Key [%s]. Array [%s]." |
| 1246 |
" Error [%s]." % (key, self.ssid, error)) |
| 1247 |
|
| 1248 |
def create_view(self, view_info): |
| 1249 |
"""Generate consistency group view.""" |
| 1250 |
group_id = self.get_consistency_group()["consistency_group_id"] |
| 1251 |
view_request = {"name": view_info["name"], |
| 1252 |
"pitSequenceNumber": view_info["sequence_number"], |
| 1253 |
"requests": []} |
| 1254 |
|
| 1255 |
for volume_name, volume_info in view_info["volumes"].items(): |
| 1256 |
candidate = None |
| 1257 |
if volume_info["snapshot_volume_writable"]: |
| 1258 |
candidate = self.get_candidate(volume_name, volume_info) |
| 1259 |
|
| 1260 |
for image in view_info["images"]: |
| 1261 |
if volume_name == image["base_volume_name"]: |
| 1262 |
view_request["requests"].append({"pitId": image["id"], |
| 1263 |
"candidate": candidate["candidate"]["candidate"] if candidate else None, |
| 1264 |
"accessMode": "readWrite" if volume_info["snapshot_volume_writable"] else "readOnly", |
| 1265 |
"scanMedia": volume_info["snapshot_volume_validate"], |
| 1266 |
"validateParity": volume_info["snapshot_volume_validate"]}) |
| 1267 |
break |
| 1268 |
else: |
| 1269 |
self.module.fail_json(msg="Base volume does not exist! Volume [%s]. Group [%s]. Array [%s]." % (volume_name, self.group_name, self.ssid)) |
| 1270 |
try: |
| 1271 |
rc, images = self.request("storage-systems/%s/consistency-groups/%s/views/batch" % (self.ssid, group_id), method="POST", data=view_request) |
| 1272 |
|
| 1273 |
|
| 1274 |
view = self.get_consistency_group_view() |
| 1275 |
existing_volumes_by_id = self.get_all_volumes_by_id() |
| 1276 |
existing_hosts_by_name = self.get_all_hosts_and_hostgroups_by_name() |
| 1277 |
for volume_name, volume_info in self.volumes.items(): |
| 1278 |
if volume_info["snapshot_volume_host"]: |
| 1279 |
for snapshot_volume in view["snapshot_volumes"]: |
| 1280 |
if volume_name == existing_volumes_by_id[snapshot_volume["baseVol"]]["name"]: |
| 1281 |
snapshot_volume_map_request = {"mappableObjectId": snapshot_volume["id"], |
| 1282 |
"lun": volume_info["snapshot_volume_lun"], |
| 1283 |
"targetId": existing_hosts_by_name[volume_info["snapshot_volume_host"]]["id"]} |
| 1284 |
try: |
| 1285 |
rc, mapping = self.request("storage-systems/%s/volume-mappings" % self.ssid, method="POST", data=snapshot_volume_map_request) |
| 1286 |
except Exception as error: |
| 1287 |
self.module.fail_json(msg="Failed to map snapshot volume! Snapshot volume [%s]. View [%s]. Group [%s]. Array [%s]." |
| 1288 |
" Error [%s]" % (snapshot_volume["name"], self.view_name, self.group_name, self.ssid, error)) |
| 1289 |
break |
| 1290 |
except Exception as error: |
| 1291 |
self.module.fail_json(msg="Failed to create consistency group snapshot volumes!" |
| 1292 |
" Group [%s]. Array [%s]. Error [%s]." % (self.group_name, self.ssid, error)) |
| 1293 |
|
| 1294 |
def map_view(self, map_information_list): |
| 1295 |
"""Map consistency group point-in-time snapshot volumes to host or host group.""" |
| 1296 |
existing_volumes = self.get_all_volumes_by_id() |
| 1297 |
existing_host_or_hostgroups = self.get_all_hosts_and_hostgroups_by_id() |
| 1298 |
for map_request in map_information_list: |
| 1299 |
try: |
| 1300 |
rc, mapping = self.request("storage-systems/%s/volume-mappings" % self.ssid, method="POST", data=map_request) |
| 1301 |
except Exception as error: |
| 1302 |
self.module.fail_json(msg="Failed to map snapshot volume! Snapshot volume [%s]. Target [%s]. Lun [%s]. Group [%s]. Array [%s]." |
| 1303 |
" Error [%s]." % (existing_volumes[map_request["mappableObjectId"]], |
| 1304 |
existing_host_or_hostgroups[map_request["targetId"]], |
| 1305 |
map_request["lun"], self.group_name, self.ssid, error)) |
| 1306 |
|
| 1307 |
def unmap_view(self, unmap_info_list): |
| 1308 |
"""Unmap consistency group point-in-time snapshot volumes from host or host group.""" |
| 1309 |
for unmap_info in unmap_info_list: |
| 1310 |
try: |
| 1311 |
rc, unmap = self.request("storage-systems/%s/volume-mappings/%s" % (self.ssid, unmap_info["lun_mapping_reference"]), method="DELETE") |
| 1312 |
except Exception as error: |
| 1313 |
self.module.fail_json(msg="Failed to unmap snapshot volume! Snapshot volume [%s]. View [%s]. Group [%s]. Array [%s]." |
| 1314 |
" Error [%s]." % (unmap_info["snapshot_volume_name"], self.view_name, self.group_name, self.ssid, error)) |
| 1315 |
|
| 1316 |
def move_view_mapping(self, map_information_list): |
| 1317 |
"""Move consistency group point-in-time snapshot volumes to a different host or host group.""" |
| 1318 |
existing_volumes = self.get_all_volumes_by_id() |
| 1319 |
existing_host_or_hostgroups = self.get_all_hosts_and_hostgroups_by_id() |
| 1320 |
for map_request in map_information_list: |
| 1321 |
try: |
| 1322 |
rc, mapping = self.request("storage-systems/%s/symbol/moveLUNMapping?verboseErrorResponse=true" % self.ssid, method="POST", data=map_request) |
| 1323 |
except Exception as error: |
| 1324 |
self.module.fail_json(msg="Failed to move snapshot volume mapping! Snapshot volume [%s]. Target [%s]. Lun [%s]. Group [%s]. Array [%s]." |
| 1325 |
" Error [%s]." % (existing_volumes[map_request["mappableObjectId"]], |
| 1326 |
existing_host_or_hostgroups[map_request["targetId"]], |
| 1327 |
map_request["lun"], self.group_name, self.ssid, error)) |
| 1328 |
|
| 1329 |
def convert_view_to_writable(self, convert_view_information_list): |
| 1330 |
"""Make consistency group point-in-time snapshot volumes writable.""" |
| 1331 |
for volume_name, volume_info in convert_view_information_list.items(): |
| 1332 |
candidate = self.get_candidate(volume_name, volume_info) |
| 1333 |
convert_request = {"fullThreshold": self.alert_threshold_pct, |
| 1334 |
"repositoryCandidate": candidate["candidate"]["candidate"]} |
| 1335 |
try: |
| 1336 |
rc, convert = self.request("/storage-systems/%s/snapshot-volumes/%s/convertReadOnly" % (self.ssid, volume_info["snapshot_volume_id"]), |
| 1337 |
method="POST", data=convert_request) |
| 1338 |
except Exception as error: |
| 1339 |
self.module.fail_json(msg="Failed to convert snapshot volume to read/write! Snapshot volume [%s]. View [%s] Group [%s]. Array [%s]." |
| 1340 |
" Error [%s]." % (volume_info["snapshot_volume_id"], self.view_name, self.group_name, self.ssid, error)) |
| 1341 |
|
| 1342 |
def remove_view(self, view_id): |
| 1343 |
"""Remove a consistency group view.""" |
| 1344 |
group_id = self.get_consistency_group()["consistency_group_id"] |
| 1345 |
|
| 1346 |
try: |
| 1347 |
rc, images = self.request("storage-systems/%s/consistency-groups/%s/views/%s" % (self.ssid, group_id, view_id), method="DELETE") |
| 1348 |
except Exception as error: |
| 1349 |
self.module.fail_json(msg="Failed to create consistency group snapshot volumes!" |
| 1350 |
" Group [%s]. Array [%s]. Error [%s]." % (self.group_name, self.ssid, error)) |
| 1351 |
|
| 1352 |
def rollback(self, rollback_info): |
| 1353 |
"""Rollback consistency group base volumes to point-in-time snapshot images.""" |
| 1354 |
group_info = self.get_consistency_group() |
| 1355 |
group_id = group_info["consistency_group_id"] |
| 1356 |
|
| 1357 |
if self.rollback_backup: |
| 1358 |
self.create_pit_images() |
| 1359 |
|
| 1360 |
|
| 1361 |
if self.rollback_priority: |
| 1362 |
try: |
| 1363 |
rc, resp = self.request("storage-systems/%s/consistency-groups/%s" % (self.ssid, group_id), method="POST", |
| 1364 |
data={"rollbackPriority": self.rollback_priority}) |
| 1365 |
except Exception as error: |
| 1366 |
self.module.fail_json(msg="Failed to updated consistency group rollback priority!" |
| 1367 |
" Group [%s]. Array [%s]. Error [%s]." % (self.group_name, self.ssid, error)) |
| 1368 |
|
| 1369 |
try: |
| 1370 |
rc, resp = self.request("storage-systems/%s/symbol/startPITRollback" % self.ssid, method="POST", |
| 1371 |
data={"pitRef": [image["id"] for image in rollback_info["images"]]}) |
| 1372 |
except Exception as error: |
| 1373 |
self.module.fail_json(msg="Failed to initiate rollback operations!" " Group [%s]. Array [%s]. Error [%s]." % (self.group_name, self.ssid, error)) |
| 1374 |
|
| 1375 |
def complete_volume_definitions(self): |
| 1376 |
"""Determine the complete self.volumes structure.""" |
| 1377 |
group = self.get_consistency_group() |
| 1378 |
|
| 1379 |
if not self.volumes: |
| 1380 |
for volume in group["base_volumes"]: |
| 1381 |
self.volumes.update({volume["name"]: {"reserve_capacity_pct": self.reserve_capacity_pct, |
| 1382 |
"preferred_reserve_storage_pool": self.preferred_reserve_storage_pool, |
| 1383 |
"snapshot_volume_writable": self.view_writable, |
| 1384 |
"snapshot_volume_validate": self.view_validate, |
| 1385 |
"snapshot_volume_host": self.view_host, |
| 1386 |
"snapshot_volume_lun": None}}) |
| 1387 |
|
| 1388 |
|
| 1389 |
existing_storage_pools_by_id = self.get_all_storage_pools_by_id() |
| 1390 |
existing_storage_pools_by_name = self.get_all_storage_pools_by_name() |
| 1391 |
existing_volumes_by_name = self.get_all_volumes_by_name() |
| 1392 |
existing_volumes_by_id = self.get_all_volumes_by_id() |
| 1393 |
existing_mappings = self.get_mapping_by_id() |
| 1394 |
existing_host_and_hostgroup_by_id = self.get_all_hosts_and_hostgroups_by_id() |
| 1395 |
existing_host_and_hostgroup_by_name = self.get_all_hosts_and_hostgroups_by_name() |
| 1396 |
for volume_name, volume_info in self.volumes.items(): |
| 1397 |
base_volume_storage_pool_id = existing_volumes_by_name[volume_name]["volumeGroupRef"] |
| 1398 |
base_volume_storage_pool_name = existing_storage_pools_by_id[base_volume_storage_pool_id]["name"] |
| 1399 |
|
| 1400 |
|
| 1401 |
if not volume_info["preferred_reserve_storage_pool"]: |
| 1402 |
volume_info["preferred_reserve_storage_pool"] = base_volume_storage_pool_name |
| 1403 |
elif volume_info["preferred_reserve_storage_pool"] not in existing_storage_pools_by_name.keys(): |
| 1404 |
self.module.fail_json(msg="Preferred storage pool or volume group does not exist! Storage pool [%s]. Group [%s]." |
| 1405 |
" Array [%s]." % (volume_info["preferred_reserve_storage_pool"], self.group_name, self.ssid)) |
| 1406 |
|
| 1407 |
|
| 1408 |
if self.state == "present" and self.type == "view": |
| 1409 |
view_info = self.get_consistency_group_view() |
| 1410 |
|
| 1411 |
if volume_info["snapshot_volume_host"]: |
| 1412 |
if volume_info["snapshot_volume_host"] not in existing_host_and_hostgroup_by_name: |
| 1413 |
self.module.fail_json(msg="Specified host or host group does not exist! Host [%s]. Group [%s]." |
| 1414 |
" Array [%s]." % (volume_info["snapshot_volume_host"], self.group_name, self.ssid)) |
| 1415 |
|
| 1416 |
if not volume_info["snapshot_volume_lun"]: |
| 1417 |
if view_info: |
| 1418 |
for snapshot_volume in view_info["snapshot_volumes"]: |
| 1419 |
if snapshot_volume["listOfMappings"]: |
| 1420 |
mapping = snapshot_volume["listOfMappings"][0] |
| 1421 |
if (volume_name == existing_volumes_by_id[snapshot_volume["baseVol"]]["name"] and |
| 1422 |
volume_info["snapshot_volume_host"] == existing_host_and_hostgroup_by_id[mapping["mapRef"]]["name"]): |
| 1423 |
volume_info["snapshot_volume_lun"] = mapping["lun"] |
| 1424 |
break |
| 1425 |
else: |
| 1426 |
host_id = existing_host_and_hostgroup_by_name[volume_info["snapshot_volume_host"]]["id"] |
| 1427 |
for next_lun in range(1, 100): |
| 1428 |
|
| 1429 |
if host_id not in existing_mappings.keys(): |
| 1430 |
existing_mappings.update({host_id: {}}) |
| 1431 |
|
| 1432 |
if next_lun not in existing_mappings[host_id].keys(): |
| 1433 |
volume_info["snapshot_volume_lun"] = next_lun |
| 1434 |
existing_mappings[host_id].update({next_lun: None}) |
| 1435 |
break |
| 1436 |
|
| 1437 |
def apply(self): |
| 1438 |
"""Apply any required snapshot state changes.""" |
| 1439 |
changes_required = False |
| 1440 |
group = self.get_consistency_group() |
| 1441 |
group_changes = {} |
| 1442 |
|
| 1443 |
|
| 1444 |
if group: |
| 1445 |
|
| 1446 |
|
| 1447 |
if self.state == "absent": |
| 1448 |
if self.type == "group": |
| 1449 |
if self.group_name: |
| 1450 |
changes_required = True |
| 1451 |
elif self.type == "pit": |
| 1452 |
group_changes = self.get_pit_info() |
| 1453 |
if group_changes: |
| 1454 |
changes_required = True |
| 1455 |
elif self.type == "view": |
| 1456 |
group_changes = self.get_consistency_group_view() |
| 1457 |
if group_changes: |
| 1458 |
changes_required = True |
| 1459 |
|
| 1460 |
elif self.state == "present": |
| 1461 |
self.complete_volume_definitions() |
| 1462 |
|
| 1463 |
if self.type == "group": |
| 1464 |
group_changes = self.update_changes_required() |
| 1465 |
if (group_changes["update_group"] or |
| 1466 |
group_changes["add_volumes"] or |
| 1467 |
group_changes["remove_volumes"] or |
| 1468 |
group_changes["expand_reserve_capacity"] or |
| 1469 |
group_changes["trim_reserve_capacity"]): |
| 1470 |
changes_required = True |
| 1471 |
|
| 1472 |
elif self.type == "pit": |
| 1473 |
changes_required = True |
| 1474 |
|
| 1475 |
elif self.type == "view": |
| 1476 |
if self.get_consistency_group_view(): |
| 1477 |
group_changes = self.update_view_changes_required() |
| 1478 |
if (group_changes["expand_reserve_capacity"] or |
| 1479 |
group_changes["trim_reserve_capacity"] or |
| 1480 |
group_changes["map_snapshot_volumes_mapping"] or |
| 1481 |
group_changes["unmap_snapshot_volumes_mapping"] or |
| 1482 |
group_changes["move_snapshot_volumes_mapping"] or |
| 1483 |
group_changes["update_snapshot_volumes_writable"]): |
| 1484 |
changes_required = True |
| 1485 |
else: |
| 1486 |
group_changes = self.create_view_changes_required() |
| 1487 |
changes_required = True |
| 1488 |
|
| 1489 |
elif self.state == "rollback": |
| 1490 |
self.complete_volume_definitions() |
| 1491 |
if not self.volumes: |
| 1492 |
for volume in group["base_volumes"]: |
| 1493 |
self.volumes.update({volume["name"]: None}) |
| 1494 |
group_changes = self.rollback_changes_required() |
| 1495 |
if group_changes: |
| 1496 |
changes_required = True |
| 1497 |
|
| 1498 |
else: |
| 1499 |
if self.state == "present": |
| 1500 |
if self.type == "group": |
| 1501 |
self.complete_volume_definitions() |
| 1502 |
group_changes = self.create_changes_required() |
| 1503 |
changes_required = True |
| 1504 |
elif self.type == "pit": |
| 1505 |
self.module.fail_json(msg="Snapshot point-in-time images cannot be taken when the snapshot consistency group does not exist!" |
| 1506 |
" Group [%s]. Array [%s]." % (self.group_name, self.ssid)) |
| 1507 |
elif self.type == "view": |
| 1508 |
self.module.fail_json(msg="Snapshot view cannot be created when the snapshot consistency group does not exist!" |
| 1509 |
" Group [%s]. Array [%s]." % (self.group_name, self.ssid)) |
| 1510 |
elif self.state == "rollback": |
| 1511 |
self.module.fail_json(msg="Rollback operation is not available when the snapshot consistency group does not exist!" |
| 1512 |
" Group [%s]. Array [%s]." % (self.group_name, self.ssid)) |
| 1513 |
|
| 1514 |
|
| 1515 |
unused_pit_keys = self.get_unused_pit_key() |
| 1516 |
|
| 1517 |
|
| 1518 |
if (changes_required or unused_pit_keys) and not self.module.check_mode: |
| 1519 |
if group: |
| 1520 |
if self.state == "absent": |
| 1521 |
if self.type == "group": |
| 1522 |
self.remove_snapshot_consistency_group(group) |
| 1523 |
elif self.type == "pit": |
| 1524 |
self.remove_pit_images(group_changes) |
| 1525 |
elif self.type == "view": |
| 1526 |
self.remove_view(group_changes["id"]) |
| 1527 |
|
| 1528 |
elif self.state == "present": |
| 1529 |
|
| 1530 |
if self.type == "group": |
| 1531 |
if group_changes["update_group"]: |
| 1532 |
self.update_snapshot_consistency_group(group_changes["update_group"]) |
| 1533 |
if group_changes["add_volumes"]: |
| 1534 |
self.add_base_volumes(group_changes["add_volumes"]) |
| 1535 |
if group_changes["remove_volumes"]: |
| 1536 |
self.remove_base_volumes(group_changes["remove_volumes"]) |
| 1537 |
if group_changes["trim_reserve_capacity"]: |
| 1538 |
self.trim_reserve_capacities(group_changes["trim_reserve_capacity"]) |
| 1539 |
if group_changes["expand_reserve_capacity"]: |
| 1540 |
sleep(15) |
| 1541 |
if group_changes["expand_reserve_capacity"]: |
| 1542 |
self.expand_reserve_capacities(group_changes["expand_reserve_capacity"]) |
| 1543 |
|
| 1544 |
elif self.type == "pit": |
| 1545 |
self.create_pit_images() |
| 1546 |
|
| 1547 |
elif self.type == "view": |
| 1548 |
view = self.get_consistency_group_view() |
| 1549 |
if view: |
| 1550 |
if group_changes["trim_reserve_capacity"]: |
| 1551 |
self.trim_reserve_capacities(group_changes["trim_reserve_capacity"]) |
| 1552 |
if group_changes["expand_reserve_capacity"]: |
| 1553 |
sleep(15) |
| 1554 |
if group_changes["expand_reserve_capacity"]: |
| 1555 |
self.expand_reserve_capacities(group_changes["expand_reserve_capacity"]) |
| 1556 |
if group_changes["map_snapshot_volumes_mapping"]: |
| 1557 |
self.map_view(group_changes["map_snapshot_volumes_mapping"]) |
| 1558 |
if group_changes["unmap_snapshot_volumes_mapping"]: |
| 1559 |
self.unmap_view(group_changes["unmap_snapshot_volumes_mapping"]) |
| 1560 |
if group_changes["move_snapshot_volumes_mapping"]: |
| 1561 |
self.move_view_mapping(group_changes["move_snapshot_volumes_mapping"]) |
| 1562 |
if group_changes["update_snapshot_volumes_writable"]: |
| 1563 |
self.convert_view_to_writable(group_changes["update_snapshot_volumes_writable"]) |
| 1564 |
else: |
| 1565 |
self.create_view(group_changes) |
| 1566 |
|
| 1567 |
elif self.state == "rollback": |
| 1568 |
self.rollback(group_changes) |
| 1569 |
|
| 1570 |
elif self.type == "group": |
| 1571 |
self.create_snapshot_consistency_group(group_changes["create_group"]) |
| 1572 |
self.add_base_volumes(group_changes["add_volumes"]) |
| 1573 |
|
| 1574 |
if unused_pit_keys: |
| 1575 |
self.cleanup_old_pit_metadata() |
| 1576 |
|
| 1577 |
self.module.exit_json(changed=changes_required, group_changes=group_changes, deleted_metadata_keys=unused_pit_keys) |
| 1578 |
|
| 1579 |
|
| 1580 |
def main(): |
| 1581 |
snapshot = NetAppESeriesSnapshot() |
| 1582 |
snapshot.apply() |
| 1583 |
|
| 1584 |
|
| 1585 |
if __name__ == "__main__": |
| 1586 |
main() |