From 6941ce678d8b13dd70760b465f3054ab95269621 Mon Sep 17 00:00:00 2001 From: ss-px Date: Thu, 12 Dec 2024 12:25:40 +0530 Subject: [PATCH] PB-8755: Add labels for backup schedule request --- ansible-collection/examples/backup/create.yaml | 1 + ansible-collection/examples/backup_schedule/create.yaml | 3 ++- ansible-collection/examples/backup_schedule/update.yaml | 7 ++++++- .../group_vars/backup_schedule/inspect_vars.yaml | 8 ++++++++ .../backup_schedule/{update.yaml => update_vars.yaml} | 3 ++- .../plugins/modules/px_backup/backup_schedule.py | 3 +++ 6 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 ansible-collection/inventory/group_vars/backup_schedule/inspect_vars.yaml rename ansible-collection/inventory/group_vars/backup_schedule/{update.yaml => update_vars.yaml} (94%) diff --git a/ansible-collection/examples/backup/create.yaml b/ansible-collection/examples/backup/create.yaml index 495eb5a..d620ff2 100644 --- a/ansible-collection/examples/backup/create.yaml +++ b/ansible-collection/examples/backup/create.yaml @@ -45,6 +45,7 @@ volume_snapshot_class_mapping: "{{ item.volume_snapshot_class_mapping | default(omit) }}" direct_kdmp: "{{ item.direct_kdmp | default(omit) }}" validate_certs: "{{ item.validate_certs | default(true) }}" + labels: "{{ item.labels | default(omit) }}" loop: "{{ backups }}" register: backup_result loop_control: diff --git a/ansible-collection/examples/backup_schedule/create.yaml b/ansible-collection/examples/backup_schedule/create.yaml index 4c14d59..da0ec9d 100644 --- a/ansible-collection/examples/backup_schedule/create.yaml +++ b/ansible-collection/examples/backup_schedule/create.yaml @@ -36,10 +36,11 @@ cluster_ref: "{{ item.cluster_ref }}" backup_object_type: "{{ item.backup_object_type }}" skip_vm_auto_exec_rules: "{{ item.skip_vm_auto_exec_rules | default(omit) }}" - volume_snapshot_class_mapping: "{{ item.volume_snapshot_class_mapping }}" + volume_snapshot_class_mapping: "{{ item.volume_snapshot_class_mapping | default(omit) }}" direct_kdmp: "{{ item.direct_kdmp }}" owner: "admin" exclude_resource_types: "{{ item.exclude_resource_types | default(omit) }}" + labels: "{{ item.labels | default(omit) }}" loop: "{{ backup_schedules }}" register: backup_result loop_control: diff --git a/ansible-collection/examples/backup_schedule/update.yaml b/ansible-collection/examples/backup_schedule/update.yaml index 1717077..0fc6b35 100644 --- a/ansible-collection/examples/backup_schedule/update.yaml +++ b/ansible-collection/examples/backup_schedule/update.yaml @@ -5,7 +5,7 @@ vars_files: - "{{ inventory_dir }}/group_vars/common/all.yaml" - - "{{ inventory_dir }}/group_vars/backup_schedule/update.yaml" + - "{{ inventory_dir }}/group_vars/backup_schedule/update_vars.yaml" pre_tasks: - name: Validate required variables @@ -20,6 +20,8 @@ current_timestamp: "{{ lookup('pipe', 'date +%Y-%m-%d-%H-%M-%S') }}" tasks: + - name: Login and fetch Px-Backup token + include_tasks: "{{ playbook_dir | dirname }}/auth/auth.yaml" - name: Backup and update schedules block: - name: Get current configurations @@ -36,6 +38,7 @@ backup_location_ref: "{{ item.backup_location_ref }}" pre_exec_rule_ref: "{{ item.pre_exec_rule_ref | default(omit) }}" post_exec_rule_ref: "{{ item.post_exec_rule_ref | default(omit) }}" + labels: "{{ item.labels | default(omit) }}" register: current_configs loop: "{{ backup_schedules_update }}" loop_control: @@ -64,6 +67,7 @@ backup_location_ref: "{{ item.backup_location_ref }}" pre_exec_rule_ref: "{{ item.pre_exec_rule_ref | default(omit) }}" post_exec_rule_ref: "{{ item.post_exec_rule_ref | default(omit) }}" + labels: "{{ item.labels | default(omit) }}" register: update_result loop: "{{ backup_schedules_update }}" loop_control: @@ -92,6 +96,7 @@ backup_location_ref: "{{ item.backup_location_ref }}" pre_exec_rule_ref: "{{ item.pre_exec_rule_ref | default(omit) }}" post_exec_rule_ref: "{{ item.post_exec_rule_ref | default(omit) }}" + labels: "{{ item.labels | default(omit) }}" register: final_validation loop: "{{ backup_schedules_update }}" loop_control: diff --git a/ansible-collection/inventory/group_vars/backup_schedule/inspect_vars.yaml b/ansible-collection/inventory/group_vars/backup_schedule/inspect_vars.yaml new file mode 100644 index 0000000..5ef4093 --- /dev/null +++ b/ansible-collection/inventory/group_vars/backup_schedule/inspect_vars.yaml @@ -0,0 +1,8 @@ +--- +# Backup schedules to inspect +backup_schedules_inspect: + - name: "bs-1" + uid: "uid-1" + + - name: "bl-2" + uid: "uid-1" diff --git a/ansible-collection/inventory/group_vars/backup_schedule/update.yaml b/ansible-collection/inventory/group_vars/backup_schedule/update_vars.yaml similarity index 94% rename from ansible-collection/inventory/group_vars/backup_schedule/update.yaml rename to ansible-collection/inventory/group_vars/backup_schedule/update_vars.yaml index 8f18d8e..a243724 100644 --- a/ansible-collection/inventory/group_vars/backup_schedule/update.yaml +++ b/ansible-collection/inventory/group_vars/backup_schedule/update_vars.yaml @@ -20,7 +20,8 @@ backup_schedules_update: backup_location_ref: name: "s3-backup-loc" uid: "backup-loc-uid" - + labels: + key: value # Global update configuration backup_configs: true \ No newline at end of file diff --git a/ansible-collection/plugins/modules/px_backup/backup_schedule.py b/ansible-collection/plugins/modules/px_backup/backup_schedule.py index a4692d4..35c6997 100644 --- a/ansible-collection/plugins/modules/px_backup/backup_schedule.py +++ b/ansible-collection/plugins/modules/px_backup/backup_schedule.py @@ -367,6 +367,9 @@ def backup_schedule_request_body(module): if module.params.get('volume_snapshot_class_mapping'): backup_schedule_request['volume_snapshot_class_mapping'] = module.params['volume_snapshot_class_mapping'] + if module.params.get('labels'): + backup_schedule_request['metadata']['labels'] = module.params['labels'] + return backup_schedule_request def run_module():