Skip to content
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

Add snapshots filter to azure.disk #9414

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

dmytro-afanasiev
Copy link
Collaborator

Example:

policies:
  - name: disk-without-snapshots-within-14days
    resource: azure.disk
    filters:
      - type: snapshots
        attrs:
          - type: value
            key: properties.timeCreated
            value_type: age
            value: 14
            op: le
        count: 0

@dmytro-afanasiev
Copy link
Collaborator Author

@kapilt, hello, could you please tell whether the policy in example would work as the name suggests? Because i'm not sure whether the count is applied after performing all filtering by attrs

def process(self, resources, event=None):
self._snapshots = tuple(
item.serialize(True)
for item in self.manager.get_client().snapshots.list()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels like it should use the resource manager for snapshots to take advantage of the catch. alternatively if the cardinality on resources is small, it might be something to fetch per volume. additionally rather than iterating over the snapshot list for each volume (n*m) using a map that keys off the uniqueId would greatly reduce iterations

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for feedback!

  • Not sure what use the resource manager for snapshots to take advantage of the catch means. Does it mean i should create a separate resource type called smt like azure.snapshot and somehow utilize it for this filter? Or should i keep the result of client.snapshots.list() in a class attribute in order not to make this request each time process() is called?

  • as far as i investigated we cannot fetch snapshots for a specific volume. We can only retrieve all snapshots within a subscription/resource-group and then filter out those that belong to a specific disk (https://learn.microsoft.com/en-us/python/api/azure-mgmt-compute/azure.mgmt.compute.v2020_12_01.operations.snapshotsoperations?view=azure-python)

  • using map - ok, i'll do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants