Cloud-custodian: actions: mark-for-op, hours as well as days

Created on 8 Feb 2018  路  3Comments  路  Source: cloud-custodian/cloud-custodian

When creating a mark-for-op action inside a cloud custodian policy you can define the number of days until the operation is carried out.

How hard would it be to add an optional hours parameter, so that operations could be executed hours after the policy was executed, rather than days? It might also be useful to have a minutes option.

eg.

actions:
  - type: mark-for-op
    op: stop
    hours: 4
areactions kinenhancement

All 3 comments

sounds good

Thanks you for doing the work to add Hours for mark-for-op. I wanted to ask about a design decision that caught me a bit by surprise and understand the reasoning behind it.

The use case we are looking to support it to give users ~1 hour to tag their resources within our Sandbox account before those resource were removed.

When generating the current datetime you round down the minutes to "0".

n = datetime.now(tz=self.tz).replace(minute=0)

What this means is that if I set the policy action to something like:

    actions:
      - type: mark-for-op
        op: terminate
        hours: 1

Then the user only has up to the start of the next hour before their instance is eligible for termination. For example, if a user creates an instance at 00:59 UTC, then the instance becomes eligible for termination in 1 minute (i.e. 01:00 UTC).

I wanted to understand why the time is rounded down to the hour. I guess I expected that if I say 4 hours it's not 3 - 4 hours. But maybe there is something I am missing.

I'm happy to submit a PR to change not round down, if that make sense. I've made the change in my own branch already and it seems to work fine, by changing the line to:

n = datetime.now(tz=self.tz)

Thanks again!

OK, I see that when filtering for marked-for-op it only looks like it works if the datetime is rounded to the hour. Still seems to me it would be ideal to have better fidelity now that hours are supported.

Haven't tracked down the code quite yet for this, but happy to make this work with better fidelity assuming it make sense.

Was this page helpful?
0 / 5 - 0 ratings