-
Notifications
You must be signed in to change notification settings - Fork 9
Adding vm_snapshot examples to collection #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3a25ed9
Adding vm_snapshot examples to collection:
domendobnikar db3abdb
Update vm_snapshot_removal_based_on_timestamp.yml
domendobnikar 9449b62
Update vm_snapshot_special_cleanup.yml
domendobnikar a1e3219
Merge branch 'main' of https://github.com/ScaleComputing/HyperCoreAns…
domendobnikar 04a1e75
CR fixes
domendobnikar 3fb77c9
Removing env
domendobnikar d0bb96b
sanity fix
domendobnikar 8830c52
sanity fixes
domendobnikar 9d24194
sanity fix
domendobnikar aa4d748
sanity fix
domendobnikar 7132576
Extending integration tests for vm_snapshot
domendobnikar b234172
extending integration tests
domendobnikar e30bb4a
Update 02_2_vm_snapshot_uuid.yml
domendobnikar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| --- | ||
| - name: Example - delete all snapshots that are older than X days. | ||
| hosts: localhost | ||
| connection: local | ||
| gather_facts: false | ||
| vars: | ||
| # Format: 'YYYY-MM-DD hh:mm:ss' | ||
| # All snapshots older than this date will be deleted. | ||
| # use_date timezone should match the Scale cluster timezone | ||
| use_date: '1999-05-03 12:52:00' | ||
|
|
||
| tasks: | ||
| # ------------------------------------------------------ | ||
| - name: List all snapshots | ||
| scale_computing.hypercore.vm_snapshot_info: | ||
| register: snapshot_results | ||
|
|
||
| - name: Convert date to unix timestamp 'epoch' | ||
| ansible.builtin.set_fact: | ||
| epoch_timestamp: "{{ (use_date | to_datetime).strftime('%s') }}" | ||
|
|
||
| - name: Show epoch_timestamp | ||
| ansible.builtin.debug: | ||
| var: epoch_timestamp | ||
|
|
||
| - name: Create filtered_snapshots list | ||
| ansible.builtin.set_fact: | ||
| filtered_snapshots: [] | ||
|
|
||
| - name: Loop through snapshots and add snapshots that are older than 'use_date' | ||
| ansible.builtin.set_fact: | ||
| filtered_snapshots: "{{ filtered_snapshots + [item] }}" | ||
| when: item.timestamp < epoch_timestamp | int | ||
| loop: "{{ snapshot_results.records }}" | ||
| no_log: true | ||
|
|
||
| - name: Show only snapshots that are older than 'use_date' | ||
| ansible.builtin.debug: | ||
| var: filtered_snapshots | ||
|
|
||
| # We could reuse "filtered_snapshots" here instead of "snapshot_results" and avoid the "when" statement. | ||
| # But leaving it as is for example purposes. | ||
| # Since this is the only mandatory task of the playbook, can be copy-pasted and reused as standalone task. | ||
| - name: Loop through list of snapshots and delete all older than the 'use_date' | ||
| scale_computing.hypercore.vm_snapshot: | ||
| vm_name: "{{ item.vm.name }}" | ||
| uuid: "{{ item.snapshot_uuid }}" | ||
| state: absent | ||
| when: item.timestamp < epoch_timestamp | int | ||
| loop: "{{ snapshot_results.records }}" | ||
|
|
||
| - name: Create filtered_snapshots list - second time | ||
| ansible.builtin.set_fact: | ||
| filtered_snapshots: [] | ||
|
|
||
| - name: Loop through snapshots and add snapshots that are older than 'use_date' - second time | ||
| ansible.builtin.set_fact: | ||
| filtered_snapshots: "{{ filtered_snapshots + [item] }}" | ||
| when: item.timestamp < epoch_timestamp | int | ||
| loop: "{{ snapshot_results.records }}" | ||
| no_log: true | ||
|
|
||
| - name: Show only snapshots that are older than 'use_date' - second time | ||
| ansible.builtin.debug: | ||
| var: filtered_snapshots |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| --- | ||
| - name: Example - delete all snapshots with label "TEST" and type "USER". | ||
| hosts: localhost | ||
| connection: local | ||
| gather_facts: false | ||
| vars: | ||
| # This variable is used to filter and delete snapshots. | ||
| # All snapshots with 'use_label' will be DELETED. | ||
| use_label: 'TEST' | ||
|
|
||
| tasks: | ||
| # ------------------------------------------------------ | ||
| - name: List all snapshots | ||
| scale_computing.hypercore.vm_snapshot_info: | ||
| register: snapshot_results | ||
|
|
||
| - name: Create filtered_snapshots list | ||
| ansible.builtin.set_fact: | ||
| filtered_snapshots: [] | ||
|
|
||
| - name: Loop through snapshots and add snapshots with use_label and type 'USER' to filtered_snapshots | ||
| ansible.builtin.set_fact: | ||
| filtered_snapshots: "{{ filtered_snapshots + [item] }}" | ||
| when: item.label == use_label and item.type == 'USER' | ||
| loop: "{{ snapshot_results.records }}" | ||
| no_log: true | ||
|
|
||
| - name: Show only snapshots with use_label and type "USER" | ||
| ansible.builtin.debug: | ||
| var: filtered_snapshots | ||
|
|
||
| # We could reuse "filtered_snapshots" here instead of "snapshot_results" and avoid the "when" statement. | ||
| # But leaving it as is for example purposes. | ||
| # Since this is the only mandatory task of the playbook, can be copy-pasted and reused as standalone task. | ||
| - name: Loop through list of snapshots delete if label is use_label and type is 'USER' | ||
| scale_computing.hypercore.vm_snapshot: | ||
| vm_name: "{{ item.vm.name }}" | ||
| uuid: "{{ item.snapshot_uuid }}" | ||
| state: absent | ||
| when: item.label == use_label and item.type == 'USER' | ||
| loop: "{{ snapshot_results.records }}" | ||
|
|
||
| - name: List all snapshots - second time | ||
| scale_computing.hypercore.vm_snapshot_info: | ||
| register: snapshot_results | ||
|
|
||
| - name: Create filtered_snapshots list - second time | ||
| ansible.builtin.set_fact: | ||
| filtered_snapshots: [] | ||
|
|
||
| - name: Loop through snapshots and add snapshots with use_label and type 'USER' to filtered_snapshots - second time | ||
| ansible.builtin.set_fact: | ||
| filtered_snapshots: "{{ filtered_snapshots + [item] }}" | ||
| when: item.label == use_label and item.type == 'USER' | ||
| loop: "{{ snapshot_results.records }}" | ||
| no_log: true | ||
|
|
||
| - name: Show only snapshots with use_label and type 'USER' - second time | ||
| ansible.builtin.debug: | ||
| var: filtered_snapshots |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance to get a snapshot with correct label, but from a different VM?
It seems to me: filter to
domainUUID=vm_object.uuidpart is lost. And integration tests should be extended too.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We pass
VMobjectas one of the parameters in this function.It is then used with label for snapshot query if
snapshot_uuidisn't passed as parameter to playbook.The only added part was the
if module.params["uuid"]:, everything else is the same. (code was taken fromensure_presentfunction)UUID is unique throughout the platform and use a different endpoint, it does not require any additional filtering by VM or label.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will extend integration tests to include the filtering by uuid part.
Good point 👍