dustymabe commented on the pull-request: `Fix the clean ami script to remove the amis based on date` that you are following: `` Here are some slight modifications that would make this more useful I think:
```patch diff --git a/scripts/clean-amis.py b/scripts/clean-amis.py index 31d069c..b518089 100755 --- a/scripts/clean-amis.py +++ b/scripts/clean-amis.py @@ -265,8 +265,16 @@ if __name__ == '__main__': help="Delete the AMIs whose launch permissions have been removed", action="store_true", default=False) argument_parser.add_argument( - "--days", - help="Specify the number of days to run the operation", + "--howfarback", + help="How far back should we search for AMIs that need to be deleted", + type=int) + argument_parser.add_argument( + "--deletewaitperiod", + help="How long to wait after launch perms were removed before deleting", + type=int) + argument_parser.add_argument( + "--permswaitperiod", + help="Specify the number of days to wait before removing permissions", type=int) argument_parser.add_argument( "--change-perms", @@ -284,9 +292,22 @@ if __name__ == '__main__': if args.delete and args.change_perms: print('Both the argument delete and change permission is not allowed')
- days = 10 - if args.days: - days = args.days + # Default to waiting 10 days after launch permissions have been + # removed before deleting + deletewaitperiod = 10 + if args.deletewaitperiod: + deletewaitperiod + + permswaitperiod = 10 + if args.permswaitperiod: + permswaitperiod = args.permswaitperiod + + # Ideally we could search through all the AMIs that ever were + # created but this would create quite the load on datagrepper. + # default to 4 weeks + howfarback = 28 # 4 weeks + if args.howfarback: + howfarback = args.howfarback
# The AMIs deleted are the nightly AMIs that are uploaded via fedimg everyday. # The clean up of the AMIs happens through a cron job. @@ -296,12 +317,20 @@ if __name__ == '__main__': # - If no issues are reported in 10 days, the AMIs are deleted permanently.
if args.change_perms: - end = (datetime.now() - timedelta(days=5)).strftime('%s') - amis = _get_nightly_amis_nd(delta=86400 * days, end=int(end)) + if howfarback < permswaitperiod: + raise Exception # shouldn't happen + end = (datetime.now() - timedelta(days=permswaitperiod)).strftime('%s') + amis = _get_nightly_amis_nd(delta=86400 * howfarback, end=int(end)) change_amis_permission_nd(amis, dry_run=args.dry_run)
if args.delete: - end = (datetime.now() - timedelta(days=15)).strftime('%s') - amis = _get_nightly_amis_nd(delta=86400 * days, end=int(end)) + if howfarback < deletewaitperiod: + raise Exception # shouldn't happen + end = (datetime.now() - timedelta(days=deletewaitperiod)).strftime('%s') + amis = _get_nightly_amis_nd(delta=86400 * howfarback, end=int(end)) + # Here we need to see how long it's been since we removed the + # permissions. If it has been deletewaitperiod days then we can + # delete. If there is no way to tell this organically then we + # could add a tag to the AMI with a timestamp at the same time + # we remove the permissions. delete_amis_nd(amis, dry_run=args.dry_run) - ```
note the comment about possibly using tags set on the AMIs to determine when the launch permissions were removed. ``
To reply, visit the link below or just reply to this email https://pagure.io/releng/pull-request/8146