|
46 | 46 | elements: str
|
47 | 47 | choices: [ "images", "rootdir", "vztmpl", "backup", "iso", "snippets" ]
|
48 | 48 | description:
|
49 |
| - - Contents supported by the storage, not all storage |
50 |
| - types support all content types. |
| 49 | + - Contents supported by the storage, not all storage types support all content types. |
51 | 50 | nodes:
|
52 | 51 | required: false
|
53 | 52 | type: list
|
|
114 | 113 | - keep-yearly
|
115 | 114 | description:
|
116 | 115 | - The retention option to use.
|
117 |
| - - C(keep-all): Keep all backups. This option is mutually exclusive with the other options. |
118 |
| - - C(keep-last): Keep the last n backups. |
119 |
| - - C(keep-hourly): Keep backups for the last n hours. If there is more than one backup for a single hour, only the latest is kept. |
120 |
| - - C(keep-daily): Keep backups for the last n days. If there is more than one backup for a single day, only the latest is kept. |
121 |
| - - C(keep-weekly): Keep backups for the last n weeks. If there is more than one backup for a single week, only the latest is kept. Weeks start on Monday and end on Sunday. The software uses the ISO week date-system and handles weeks at the end of the year correctly. |
122 |
| - - C(keep-monthly): Keep backups for the last n months. If there is more than one backup for a single month, only the latest is kept. |
123 |
| - - C(keep-yearly): Keep backups for the last n years. If there is more than one backup for a single year, only the latest is kept. |
| 116 | + - "C(keep-all): Keep all backups. This option is mutually exclusive with the other options." |
| 117 | + - "C(keep-last): Keep the last n backups." |
| 118 | + - "C(keep-hourly): Keep backups for the last n hours. If there is more than one backup for a single hour, only the latest is kept." |
| 119 | + - "C(keep-daily): Keep backups for the last n days. If there is more than one backup for a single day, only the latest is kept." |
| 120 | + - "C(keep-weekly): Keep backups for the last n weeks. If there is more than one backup for a single week, only the latest is kept. Weeks start on Monday and end on Sunday. The software uses the ISO week date-system and handles weeks at the end of the year correctly." |
| 121 | + - "C(keep-monthly): Keep backups for the last n months. If there is more than one backup for a single month, only the latest is kept." |
| 122 | + - "C(keep-yearly): Keep backups for the last n years. If there is more than one backup for a single year, only the latest is kept." |
124 | 123 | value:
|
125 | 124 | required: true
|
126 | 125 | description:
|
@@ -426,47 +425,57 @@ def prepare_storage_args(self):
|
426 | 425 | # end cifs
|
427 | 426 | if self.maxfiles is not None:
|
428 | 427 | self.module.warn("'maxfiles' parameter is deprecated, use 'prune_backups' parameter instead")
|
429 |
| - if "backup" not in self.content: |
| 428 | + if 'backup' not in self.content: |
430 | 429 | self.module.fail_json(
|
431 | 430 | msg="'maxfiles' parameter is not allowed when there is no 'backup' in 'content' parameter"
|
432 | 431 | )
|
433 | 432 | if self.prune_backups is not None:
|
434 |
| - if "backup" not in self.content: |
435 |
| - self.module.fail_json( |
436 |
| - msg="'prune_backups' parameter is not allowed when there is no 'backup' in 'content' parameter" |
437 |
| - ) |
438 |
| - |
439 |
| - if len(self.prune_backups) != len(set(cfg["option"] for cfg in self.prune_backups)): |
440 |
| - self.module.fail_json(msg="'prune_backups' parameter has duplicate entries") |
441 |
| - |
442 |
| - keep_all_entries = [cfg for cfg in self.prune_backups if cfg["option"] == "keep-all"] |
443 |
| - keep_all_entry = keep_all_entries[0] if len(keep_all_entries) > 0 else None |
444 |
| - other_entries = [cfg for cfg in self.prune_backups if cfg["option"] != "keep-all"] |
445 |
| - if keep_all_entry and len(other_entries) > 0: |
446 |
| - self.module.fail_json( |
447 |
| - msg="'keep-all' is mutually exclusive with other options in 'prune_backups' parameter" |
448 |
| - ) |
449 |
| - |
450 |
| - if keep_all_entry and type(keep_all_entry["value"]) is not bool: |
451 |
| - self.module.fail_json(msg="value of 'keep-all' option must be a boolean in 'prune_backups' parameter") |
452 |
| - if any(type(cfg["value"]) is not int for cfg in other_entries): |
453 |
| - self.module.fail_json( |
454 |
| - msg="all values except for the 'keep-all' option must be integers in 'prune_backups' parameter" |
455 |
| - ) |
456 |
| - |
457 |
| - args["prune-backups"] = ( |
458 |
| - "keep-all={value}".format(value=(1 if keep_all_entry["value"] else 0)) |
| 433 | + # order is important for prune_backups, hence we accept a list of options instead of a dict |
| 434 | + keep_all_entry, other_entries = self.validate_storage_prune_backups_option() |
| 435 | + |
| 436 | + # the format for the prune-backups argument is (see https://pve.proxmox.com/pve-docs/api-viewer/index.html#/storage/{storage}): |
| 437 | + # [keep-all=<1|0>][,keep-daily=<N>][,keep-hourly=<N>][,keep-last=<N>][,keep-monthly=<N>][,keep-weekly=<N>][,keep-yearly=<N>] |
| 438 | + args['prune-backups'] = ( |
| 439 | + # keep-all is mutually exclusive with the other options, we checked that earlier |
| 440 | + # example: "keep-all=1" |
| 441 | + 'keep-all={}'.format(1 if keep_all_entry['value'] else 0) |
459 | 442 | if keep_all_entry
|
| 443 | + # example: "keep-last=3,keep-hourly=6" |
460 | 444 | else ",".join(
|
461 |
| - map(lambda cfg: "{}={}".format(cfg["option"], cfg["value"]), other_entries) |
| 445 | + map(lambda cfg: '{}={}'.format(cfg['option'], cfg['value']), other_entries) |
462 | 446 | )
|
463 | 447 | )
|
464 |
| - |
465 | 448 | if self.krbd is not None and self.type != 'rbd':
|
466 | 449 | self.module.fail_json(msg="krbd is only allowed with 'rbd' storage type")
|
467 | 450 |
|
468 | 451 | return args
|
469 | 452 |
|
| 453 | + def validate_storage_prune_backups_option(self): |
| 454 | + if 'backup' not in self.content: |
| 455 | + self.module.fail_json( |
| 456 | + msg="'prune_backups' parameter is not allowed when there is no 'backup' in 'content' parameter" |
| 457 | + ) |
| 458 | + |
| 459 | + if len(self.prune_backups) != len(set(cfg['option'] for cfg in self.prune_backups)): |
| 460 | + self.module.fail_json(msg="'prune_backups' parameter has duplicate entries") |
| 461 | + |
| 462 | + keep_all_entries = [cfg for cfg in self.prune_backups if cfg['option'] == 'keep-all'] |
| 463 | + keep_all_entry = keep_all_entries[0] if len(keep_all_entries) > 0 else None |
| 464 | + other_entries = [cfg for cfg in self.prune_backups if cfg['option'] != 'keep-all'] |
| 465 | + if keep_all_entry and len(other_entries) > 0: |
| 466 | + self.module.fail_json( |
| 467 | + msg="'keep-all' is mutually exclusive with other options in 'prune_backups' parameter" |
| 468 | + ) |
| 469 | + |
| 470 | + if keep_all_entry and type(keep_all_entry['value']) is not bool: |
| 471 | + self.module.fail_json(msg="value of 'keep-all' option must be a boolean in 'prune_backups' parameter") |
| 472 | + if any(type(cfg['value']) is not int for cfg in other_entries): |
| 473 | + self.module.fail_json( |
| 474 | + msg="all values except for the 'keep-all' option must be integers in 'prune_backups' parameter" |
| 475 | + ) |
| 476 | + |
| 477 | + return keep_all_entry, other_entries |
| 478 | + |
470 | 479 | def create_storage(self):
|
471 | 480 | new_storage = self.prepare_storage_args()
|
472 | 481 | try:
|
|
0 commit comments